Passing Data between Scripts and Virtual Users
In Eggplant Performance tests, you often need to pass data from one script in a workflow to another.
Let us assume we have the following workflow running against a call center banking application:
When the CreateCustomer script creates a new customer in the database, the application returns a CustomerId that uniquely identifies that customer in the application. Both the CreateSavingsAccount and EditCustomer scripts require a CustomerId against which they can associate a savings account and make edits to a customer's personal details. So the challenge is to pass the CustomerId from CreateCustomer to scripts later in the workflow.
Passing data between scripts within the same workflow is achieved by utilizing the Virtual User Data Dictionary. The Virtual User (VU) data dictionary is typically populated from data sources assigned either at the test level or VU Group Level. To read data from the VU data dictionary, you use get methods such as getString and getInt. However, you can add data to the VU data dictionary from script code by using data dictionary set methods such as setString and setInt.
For the above example workflow, your scripts might include the following code:
Code for CreateCustomer
// set the value of CustomerId in the VU data dictionary
setString("CustomerId", newCustomerId);
Code for CreateSavingsAccount
// retrieve the value of CustomerId set by CreateCustomer
string customerId = getString("CustomerId");
Code for EditCustomer
// retrieve the value of CustomerId set by CreateCustomer
string customerId = getString("CustomerId");
Passing Data between Virtual Users
Passing data between VUs is a little more complicated than passing data between scripts. VUs have their own separate data dictionaries; there is no shared data dictionary. Further, VUs can be running on separate injectors so that data has to be passed between physical machines.
To pass data between VUs, you must utilize the Shared Data Server. The shared data server listens for requests from VUs to add, read, or remove data. VUs from any injector can access it because it runs on a Windows machine (often the controller). VUs connect to it via its IP address and port. See Shared Data Server for more information.