Skip to main content

Named Data Tables in Eggplant Performance

Anonymous Data Tables

A common scenario is for a data binding to assign rows from a data table to virtual users (VUs) within a group, and then for each VU to access a different row of data on each iteration. For example, a VU might search for a different search term in each iteration of the workflow it is executing, and a data table with many rows can be used to provide the VU with a variety of search terms. The Row advancement option set to Automatically advance to the next row at the end of each iteration on the Advanced data binding options dialog will achieve this.

Data is retrieved using the various get methods, e.g.:

string surname = getString("custSurname");

Because the data tables are controlled by the VU, the script code can just look for a column named "searchTerm", and the data may come from any (anonymous) data source assigned using a data binding. The VU automatically retrieves the next row allocated to it from the data table at the end of the iteration, so on the next iteration getString("searchTerm") will return something different.

Named Data Tables

If the Row advancement option is instead set to Advance to the next row only when requested to by a script, then the script can have more control over how the data is retrieved. The data table source should be assigned to the VU group using a data binding in the same way as before, but this time the code for retrieving the data is different. The data table is first accessed by name (the name of the data table, not the data binding), and a reference to it is stored in a variable. Then, methods are called on the data table to retrieve the data and move through the available rows.

DataTable table = getDataTable("searchKeywords"); // The name is as it appears in the Data Sources folder within Studio

int count = 0;
int maxRows = 5;
List<String> searchTerms = new ArrayList<String>();

while (table.hasNext() && count < maxRows) // grab up to the max # of rows
{
table.next(); // Move to the next row
String searchTerm = table.getString("searchTerm");
writeMessage("searchTerm: " + searchTerm);

searchTerms.add(searchTerm);

count++;
}

writeMessage(String.format("Collected %d searchTerms.", searchTerms.size()));

Instead of using the generic getString() method, the data is accessed using the getString() method on the named data table.

Data Table API

The methods available for working with named data tables can be found in the Data Table APIs.