21 Using the Shared Data Module

This chapter provides instructions on using the OpenScript Shared Data Module, which allows data to be passed between scripts using a shared data queue.

21.1 About the Shared Data Module

The Shared Data Module is an extension module to the OpenScript Basic Module that extends the other testing modules with message queue and hash map capabilities.

Shared Data is typically used to pass data between load testing scripts running as Virtual Users in Oracle Load Testing. The Shared Data can also be used to pass data between functional testing scripts running from the command line.

Virtual users can put a message object in a queue, and take a message object from the same queue. Virtual users can also create a hash map or get an existing map and put key-values into the hash map. The virtual users can put or get message objects to the same queue or hash map in different agents/machines.

21.1.1 Key Features of the Shared Data Module

The Shared Data module provides the following features:

  • Preferences - shared data connection preferences can be set under the OpenScript Playback preferences.

  • Message Queue Manipulation - create, peek, and poll message queues.

  • Hash Map Manipulation - create, put, and get key-value data in hash maps.

  • Shared Data Module API - The Shared Data Module API includes a "sharedData" class that provides additional programming functionality.

21.2 Setting Shared Data Preferences

To set Shared Data preferences:

  1. Start OpenScript.

  2. Select OpenScript Preferences from the View menu.

  3. Expand the OpenScript node and the Playback category.

  4. Select Shared Data.

  5. Set the Shared Data Preferences as follows:

    OATS Credentials: Specifies the authentication credentials to use to establish the communication between the shared queue and the Virtual User.

    • Enable global shared data access credentials: When selected, when selected, the shard data access credentials are enabled. Specify the Address, User Name, and Password.

    • Address: Specifies the address of the Oracle Load Testing for Web Application server to use for the shared data service.

    • User name: Specifies the user name to use for authentication. The default name is oats unless changed in the Oracle Application Testing Suite configuration.

    • Password: Specifies the password to use for authentication. This should be the same password specified in the Encryption setting of the General preferences if the Encrypt script data setting is selected.

    Actions on Shared Data: Specifies actions on shared data.

    • Timeout: Specifies the maximum number of seconds to wait for actions on shared data to occur before timing out.

  6. Click OK.

21.3 Using the Shared Data Service

This section describes how to enable and use the Shared Data Service.

21.3.1 Basic Scenarios

The following are the basic scenarios for using the Shared Data Service:

  • Queue Mode: Items are stored sequentially in queues. Scripts can get the first or last data item in the queue. Other items cannot be accessed randomly.

    Script A is run by 100 Virtual Users, which act as message producers putting message objects to the shared data queues.

    Script B is run by another 100 Virtual Users, which act as consumers getting message objects from the shared data queues.

    Consumer Virtual Users can get an object from the beginning or end and the information from a queue. If the queue is empty, the consumer Virtual User is blocked until the timeout is reached. Once the object can be retrieved, the consumer Virtual User is resumed.

  • Hash Map mode: Any item can be accessed using a key. The hash map may already contain a mapping for a key. The hash map needs to be checked before a new item is put into a hash map.

    Script A is run by 100 Virtual Users, which put key-value objects to a shared data hash map.

    Script B is run by another 100 Virtual Users, which get values with keys from the shared data hash map.

    If a Virtual User cannot get the value to which the specified key is mapped, it will be blocked until the timeout is reached or the key-value is added to the map.

21.3.2 Enabling the Shared Data Service

To enable the Shared Data Service:

  1. Start OpenScript.

  2. Open an existing script or create and record a new script.

  3. Select Script Properties from the Script menu.

  4. Select the Modules category.

  5. Select the Shared Data module.

  6. Click OK. The Shared Data Service will be added to the script class in the Java Code as follows.

    @ScriptService oracle.oats.scripting.modules.sharedData.api.SharedDataService sharedData;
    

    Once you have enabled the Shared Data service, you can set the password encryption and the connection parameters and then use the Shared Data API to manipulate message queues or hash maps. You use the sharedData class in the Java code view to create manipulate message queues and hash maps.

21.3.3 Setting the Password Encryption

The Password encryption is set in the General Preferences. To set the password encryption:

  1. Select OpenScript Preferences from the View menu.

  2. Expand the OpenScript node and the General category.

  3. Select Encryption.

  4. Select Obfuscate script data or Encrypt script data to make sure the connection to the Shared Data Service uses an obfuscated or encrypted password.

  5. If you select Encrypt script data, you will be asked to specify a password for the script if you create new scripts containing sensitive data or when opening encrypted scripts for playback.

  6. Click OK.

Specific script encryption passwords can also be set using the Script Encryption options on the Tools menu. To set script encryption passwords:

  1. Select Script Encryption options from the Tools menu.

  2. Select script Encryption type from the sub menu.

  3. If necessary for the encryption type, enter the encryption password to use for the script. This password will be required to play back the script in Oracle OpenScript, Oracle Test Manager, and Oracle Load Testing.

21.3.4 Setting the Connection Parameters

The connection parameters specify the Oracle Load Testing server to use for the Shared Data Service and the authentication settings. During a load test, the Shared Data Service is limited to running only on the Oracle Load Testing controller running the test. To set the connection parameters:

  1. Make sure the Shared Data Service is enabled and the password encryption is specified as previously described.

  2. Select the script node where you want to set the connection parameters.

  3. Select Add from the Script menu and then select Other.

  4. Expand the Shared Data folder.

  5. Select Set Connection Parameters and click OK.

  6. Set the connection parameters as follows:

    Address: Specify the address of the machine to use for the Shared Data Service. For example: t3://localhost:8088 or t3://machinename.com:8088.

    User Name: Specify the user name to use for authentication. The default name is oats unless changed in the Oracle Application Testing Suite configuration.

    Password: Specify the password to use for authentication.

  7. Click OK. A Connection Parameters node will be added to the script tree.

  8. In the Java Code view, the Connection Parameters consist of the code executed in the sharedData.setConnectionParameters procedure:

    sharedData.setConnectionParameters("t3://localhost:8088", "oats",
      decrypt("L4I57b+KpnI2BQSRKPG88w=="));
    

After setting the connection parameters, you can user the Shared Data API in the Java Code view to manipulate data in message queues and hash maps.

21.3.5 Creating a Shared Data Queue

To create a shared data queue:

  1. Create an script project.

  2. Make sure the Shared Data Service is enabled, the password encryption, and connection parameters are specified as previously described.

  3. Open the Java Code view and insert the sharedData.createQueue code with a life time value into the script where you want to create the queue, as follows:

    info("Create queueA with life time of 10 minutes");
    sharedData.createQueue("queueA", 10);
    

    The maximum number of queues is 1000. The maximum capacity of a queue is 65535. If the maximum is exceeded, an exception occurs. Once the life time expires, the queue is destroyed.

21.3.6 Inserting Data into a Shared Data Queue

The types of the "values" that can be put into a queue are as follows:

  • String

  • boolean

  • integer

  • long

  • double

  • float

  • a List of any of the above data types

  • User-defined serializable java objects.

To insert data into an existing queue:

  1. Set up the shared data service and create a queue as previously described.

  2. Open the Java Code view and insert the sharedData.offerFirst or sharedData.offerLast code with a value into the script where you want to insert data into the queue, as follows:

    int iterationNum = getIteration().getTotalIterationsCompleted() + 1;
    info("Insert data at the front of an existing queueA");
    sharedData.offerFirst("queueA", "first" + iterationNum);
    

    or

    int iterationNum = getIteration().getTotalIterationsCompleted() + 1;
    info("Insert data at the end of an existing queueA");
    sharedData.offerLast("queueA", "last" + iterationNum);
    
    info("parameter type - String");
    sharedData.offerFirst("queueA", "value");
    
    info("parameter type - list of Strings");
    ArrayList<String> listOfStr = new ArrayList<String>();
    listOfStr.add(0, "val1");
    listOfStr.add(1, "val2");
    sharedData.offerFirst("queueA", listOfStr);
    ArrayList<String> queueValue = (ArrayList<String>) 
       sharedData.pollFirst("queueA");
    
    info("parameter type - boolean");
    sharedData.offerFirst("queueA", true);
    
    info("parameter type - int");
    sharedData.offerFirst("queueA", 10);
    
    info("parameter type - double");
    sharedData.offerFirst("queueA", 10.5);
    
    info("parameter type - long");
    sharedData.offerFirst("queueA", 100);
    

21.3.7 Getting Data from a Shared Data Queue

To get data from a queue:

  1. Set up the shared data service, create a queue, and insert data to the queue as previously described.

  2. Open the Java Code view and insert the Shared Data method(s) to use to get data into the script where you want to get data from the queue. The Shared Data Service includes methods for getting the length and peeking (gets the data) and polling (gets and removes the data) data, as follows:

    info("Get the length of queueA");
    int actualLength = sharedData.getLengthOfQueue("queueA");
    
    info("Get the most current item of queueA");
    String queueValue1 = (String) sharedData.peekFirst("queueA");
    
    info("Get the most current item of queueA - timeout after 5 seconds");
    String queueValue2 = (String) sharedData.peekFirst("queueA", 5000);
    
    info("Get the oldest item of queueA");
    String queueValue1 = (String) sharedData.peekLast("queueA");
    
    info("Get the oldest item of queueA - timeout after 5 seconds");
    String queueValue2 = (String) sharedData.peekLast("queueA", 5000);
    
    info("Get and remove the most current item from queueA");
    String pollValue1 = (String) sharedData.pollFirst("queueA");
    
    info("Remove the most current item from queueA - Timeout after 5 seconds");
    String pollValue2 = (String) sharedData.pollFirst("queueA", 5000);
    
    info("Remove the oldest item from queueA");
    String pollValue1 = (String) sharedData.pollLast("queueA");
    
    info("Remove the oldest item from queueA - Timeout after 5 seconds");
    String pollValue2 = (String) sharedData.pollLast("queueA", 5000);
    
    info("Waiting for an existing value 100 in queueA");
    boolean isFound1 = sharedData.waitFor("queueA", 100);
    
    info("Waiting for an existing value 100 in queueA - timeout afer 5 seconds");
    boolean isFound2 = sharedData.waitFor("queueA", 100, 5000);
    
  3. Add other custom code to the script to use the data from the queue.

21.3.8 Clearing a Shared Data Queue

Clear queues when the script is finished using the data.

To clear a shared data queue:

  1. Open the Java Code view and insert the sharedData.clearQueue code with a the name of the queue to clear into the script where you want to clear the queue, as follows:

    info("Clear queueA");
    sharedData.clearQueue("queueA");
    

21.3.9 Destroying a Shared Queue

Destroy queues when the script is finished using the data. Destroying queues releases the queues' data and its listeners and release the memory that is allocated to a queue.

To destroy a shared data queue:

  1. Open the Java Code view and insert the sharedData.destroyQueue code with a the name of the queue to destroy into the script where you want to destroy the queue, as follows:

    info("Destroy queueA");
    sharedData.destroyQueue("queueA");
    

21.3.10 Creating a Shared Data Hash Map

To create a shared data hash map:

  1. Create an script project.

  2. Make sure the Shared Data Service is enabled, the password encryption, and connection parameters are specified as previously described.

  3. Open the Java Code view and insert the sharedData.createMap code with a life time value into the script where you want to create the hash map, as follows:

    info("Create mapA with life time of 10 minutes");
    sharedData.createMap("mapA", 10);
    

    The maximum number of hash maps is 1000. The maximum capacity of a hash map is 65535. If the maximum is exceeded, an exception occurs. Once the life time expires, the hash map is destroyed.

21.3.11 Inserting Data into a Shared Data Hash Map

The types of the "values" that can be put into a hash map are the same as for queues. See "Inserting Data into a Shared Data Queue" for a list of the data types.

To insert data into an existing hash map:

  1. Set up the shared data service and create a hash map as previously described.

  2. Open the Java Code view and insert the sharedData.putToMap code with a key and value into the script where you want to insert data into the hash map, as follows:

    int iterationNum = getIteration().getTotalIterationsCompleted() + 1;
    info("put key/value pair to an existing mapA");
    sharedData.putToMap("mapA", "key" + iterationNum, "value" + iterationNum);
    
    info("parameter type - String");
    sharedData.putToMap("mapA", "key", "value");
    String mapValue = (String) sharedData.getFromMap("mapA", "key");
    
    info("parameter type - list of Strings");
    ArrayList<String> listOfStr = new ArrayList<String>();
    listOfStr.add(0, "val1");
    listOfStr.add(1, "val2");
    sharedData.putToMap("mapA", "key", listOfStr);
    ArrayList<String> mapVal = (ArrayList<String>) sharedData.getFromMap("mapA", 
       "key");
    
    info("parameter type - boolean");
    sharedData.putToMap("mapA", "key", true);
    
    info("parameter type - int");
    sharedData.putToMap("mapA", "key", 10);
    
    info("parameter type - double");
    sharedData.putToMap("mapA", "key", 10.5);
    
    info("parameter type - long");
    sharedData.putToMap("mapA", "key", 100);
    

21.3.12 Getting Data from a Shared Data Hash Map

To get data from a hash map:

  1. Set up the shared data service, create a queue, and insert data to the hash map as previously described.

  2. Open the Java Code view and insert the Shared Data method(s) to use to get data into the script where you want to get data from the hash map. The Shared Data Service includes methods for getting the keys of the hash map and getting data and removing data from the hash map, as follows:

    info("Get all keys of mapA");
    String [] lsKey = sharedData.getKeysOfMap("mapA");
    
    info("Get key/value pair from mapA");
    String actualValue = (String) sharedData.getFromMap("mapA", "key");
    
    info("Get key/value pair from mapA - timeout after 5 seconds");
    String actualValue1 = (String) sharedData.getFromMap("mapA", "key", 5000);
    
    info("Remove key/value pair from mapA");
    String removeValue = (String) sharedData.removeFromMap("mapA", "key");
    
    info("Remove key/value pair from mapA - timeout after 5 seconds");
    String removeValue1 = (String) sharedData.removeFromMap("mapA", "key", 5000);
    
  3. Add other custom code to the script to use the data from the hash map.

21.3.13 Clearing a Shared Data Hash Map

Clear hash maps when the script is finished using the data.

To clear a shared data hash map:

  1. Open the Java Code view and insert the sharedData.clearMap code with a the name of the map to clear into the script where you want to clear the hash map, as follows:

    info("Clear mapA");
    sharedData.clearMap("mapA");
    

21.3.14 Destroying a Shared Data Hash Map

Destroy hash maps when the script is finished using the data. Destroying hash maps releases the map's data and its listeners and release the memory that is allocated to a map.

To destroy a shared data hash map:

  1. Open the Java Code view and insert the sharedData.destroyMap code with a the name of the map to destroy into the script where you want to destroy the hash map, as follows:

    info("Destroy mapA");
    sharedData.destroyMap("mapA");
    

21.4 Using The Shared Data API

The Shared Data Module includes a script Application Programming Interface (API) for Shared Data actions. You can use the Shared Data API to pass data between load testing scripts running as Virtual Users in Oracle Load Testing. The Shared Data can also be used to pass data between functional testing scripts running from the command line. Commands that are specific to the Shared Data Module are part of the "sharedData" class. The Shared Data service must be enabled separately for use with other types of scripts. You can also leverage other commands from other enabled classes (services) or general Java commands in your scripts.

Some examples of the Shared Data Module API include:

  • clearMap

  • clearQueue

  • createMap

  • createQueue

  • destroyMap

  • destroyQueue

  • getFromMap

  • getKeysOfMap

  • getLengthOfQueue

  • offerFirst

  • offerLast

  • peekFirst

  • peekLast

  • pollFirst

  • pollLast

  • putToMap

  • removeFromMap

  • setConnectionParameters

  • waitFor

The setConnectionParameters API method can be added using the script Tree View. Additional methods can be added using the Java Code view.