18 SharedData Module

This chapter provides a complete listing and reference for the methods in the OpenScript SharedDataService Class of SharedData Module Application Programming Interface (API).

18.1 SharedDataService API Reference

The following section provides an alphabetical listing of the methods in the OpenScript SharedDataService API.

18.1.1 Alphabetical Command Listing

The following table lists the SharedDataService API methods in alphabetical order.

Table 18-1 List of SharedDataService Methods

Method Description

sharedData.clearMap

Removes all mappings from a hash map.

sharedData.clearQueue

Removes all of the elements from a queue.

sharedData.createMap

Creates a hash map with the name and the life time.

sharedData.createQueue

Creates a queue with the specified name and life time.

sharedData.destroyMap

Removes all mappings and their data listeners from a hash map.

sharedData.destroyQueue

Removes all of the elements and their data listeners from a queue.

sharedData.getFromMap

Returns the value to which the specified key is mapped in a hash map, or blocked until the default timeout if the map contains no mapping for this key.

sharedData.getKeysOfMap

Returns all of the keys contained in a hash map.

sharedData.getLengthOfQueue

Get the length of the queue.

sharedData.offerFirst

Inserts the specified element at the front of the specified queue.

sharedData.offerLast

Inserts the specified element at the end of the specified queue.

sharedData.peekFirst

Retrieves but does not remove the first element of the specified queue, or blocked until the default timeout if the queue is empty.

sharedData.peekLast

Retrieves but does not remove last element of the specified queue, or blocked until the default timeout if the queue is empty.

sharedData.pollFirst

Retrieves and removes the first element of the specified queue, or blocked until the default timeout if the queue is empty.

sharedData.pollLast

Retrieves and removes the last element of the specific queue, or blocked until the default timeout if the queue is empty.

sharedData.putToMap

Associates the specified value with the specified key in a session hash map.

sharedData.removeFromMap

Removes the mapping for this key from a map if present.

sharedData.setConnectionParameters

Sets the connection parameters for the shared data service.

sharedData.waitFor

Waits for the specific value to be added to the queue until the default timeout.


The following sections provide detailed reference information for each method and enum in the SharedDataService Class of SharedData Module Application Programming Interface.


sharedData.clearMap

Removes all mappings from a hash map.

Format

The sharedData.clearMap method has the following command format(s):

sharedData.clearMap(name);

Command Parameters

name

a String specifying the name of the map.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Clears the hash map named "mapA".

sharedData.clearMap("mapA");

sharedData.clearQueue

Removes all of the elements from a queue.

Format

The sharedData.clearQueue method has the following command format(s):

sharedData.clearQueue(name);

Command Parameters

name

a String specifying the name of the queue.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Clears the Queue named "queueA".

sharedData.clearQueue("queueA");

sharedData.createMap

Creates a hash map with the name and the life time.

If the hash map already exists, update its life time with the new life time value.

Format

The sharedData.createMap method has the following command format(s):

sharedData.createMap(name, lifeTime);

Command Parameters

name

a String specifying the name of the hash map to be created.

lifeTime

the life time the hash map will live. Its unit is minutes.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Creates the hash map named "mapA" with a life time of 10 minutes.

sharedData.createMap("mapA", 10);

sharedData.createQueue

Creates a queue with the specified name and life time.

If the queue already exists, update its life time with the new life time value.

Format

The sharedData.createQueue method has the following command format(s):

sharedData.createQueue(name, lifeTime);

Command Parameters

name

a String specifying the name of the queue to be created.

lifeTime

the life time the queue will live. Its unit is minutes.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Creates the Queue named "queueA" with a life time of 10 minutes.

sharedData.createQueue("queueA", 10);

sharedData.destroyMap

Removes all mappings and their data listeners from a hash map.

Format

The sharedData.destroyMap method has the following command format(s):

sharedData.destroyMap(name);

Command Parameters

name

a String specifying the name of the map.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Destroys the hash map named "mapA".

sharedData.destroyMap("mapA");

sharedData.destroyQueue

Removes all of the elements and their data listeners from a queue.

Format

The sharedData.destroyQueue method has the following command format(s):

sharedData.destroyQueue(name);

Command Parameters

name

a String specifying the name of the queue.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Destroys the Queue named "queueA".

sharedData.destroyQueue("queueA");

sharedData.getFromMap

Returns the value to which the specified key is mapped in a hash map, or blocked until the default timeout if the map contains no mapping for this key.

The default "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.getFromMap method has the following command format(s):

sharedData.getFromMap(name, key);

sharedData.getFromMap(name, key, timeout);

Command Parameters

name

a String specifying the name of the hash map

key

a String specifying the key with which the specified value is to be associated.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

the value to which the specified key is mapped, or null if the map contains no mapping for this key.

Example

Returns the value of "key1" in the hash map named "mapA". Timeout after 5 seconds.

String actualValue = (String) sharedData.getFromMap("mapA", "key1", 5000);

sharedData.getKeysOfMap

Returns all of the keys contained in a hash map.

Format

The sharedData.getKeysOfMap method has the following command format(s):

sharedData.getKeysOfMap(name);

Command Parameters

name

a String specifying the name of the hash map.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

all of the keys contained in a hash map.

Example

Returns the values of the keys in the hash map named "mapA".

String [] lsKey = sharedData.getKeysOfMap("mapA");
for (int i=0; i\<lsKey.length; i++) {
 String key = "key" + i;
 String value = lsKey[i];
 info(key + " is " + value);
}

sharedData.getLengthOfQueue

Get the length of the queue.

The "timeout" is set in the playback settings whose default value is 20 seconds.

Format

The sharedData.getLengthOfQueue method has the following command format(s):

sharedData.getLengthOfQueue(name);

sharedData.getLengthOfQueue(name, timeout);

Command Parameters

name

a String specifying the name of the queue.

timeout

a long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

The length of the queue.

Example

Returns the length of the queue named "queueA". Timeour after 5 seconds.

int queueLength = sharedData.getLengthOfQueue("queueA", 5000);
info("Length of queueA is " + queueLength);

sharedData.offerFirst

Inserts the specified element at the front of the specified queue.

If the queue does not exist, a new one with the name will be created with a default life time of 20 minutes.

Format

The sharedData.offerFirst method has the following command format(s):

sharedData.offerFirst(name, value);

Command Parameters

name

a String specifying the name of the queue that the value will be put into.

value

a Serializable value to be put into a queue.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Inserts the different data type elements at the front of "queueA".

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);
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);

sharedData.offerLast

Inserts the specified element at the end of the specified queue.

If the queue does not exist, a new one with the name will be created with a default life time of 20 minutes.

Format

The sharedData.offerLast method has the following command format(s):

sharedData.offerLast(name, value);

Command Parameters

name

a String specifying the name of the queue that the value will be put into.

value

a Serializable value to be put into the queue.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Inserts the different data type elements at the end of "queueA".

info("parameter type - String");
sharedData.offerLast("queueA", "value");
info("parameter type - list of Strings");
ArrayList<String> listOfStr = new ArrayList<String>();
listOfStr.add(0, "val1");
listOfStr.add(1, "val2");
sharedData.offerLast("queueA", listOfStr);
info("parameter type - boolean");
sharedData.offerLast("queueA", true);
info("parameter type - int");
sharedData.offerLast("queueA", 10);
info("parameter type - double");
sharedData.offerLast("queueA", 10.5);
info("parameter type - long");
sharedData.offerLast("queueA", 100);

sharedData.peekFirst

Retrieves but does not remove the first element of the specified queue, or blocked until the default timeout if the queue is empty.

The "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.peekFirst method has the following command format(s):

sharedData.peekFirst(name);

sharedData.peekFirst(name, timeout);

Command Parameters

name

a String specifying the name of the queue.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

null if the queue is empty or the queue does not exist.

Example

Retrieves but does not remove the first element of "queueA". Timeout after 5 seconds.

String queueValue = (String) sharedData.peekFirst("queueA", 5000);

sharedData.peekLast

Retrieves but does not remove last element of the specified queue, or blocked until the default timeout if the queue is empty.

The "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.peekLast method has the following command format(s):

sharedData.peekLast(name);

sharedData.peekLast(name, timeout);

Command Parameters

name

a String specifying the name of the queue.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

null if the queue is empty or the queue does not exist.

Example

Retrieves but does not remove the last element of "queueA". Timeout after 5 seconds.

String queueValue = (String) sharedData.peekLast("queueA", 5000);

sharedData.pollFirst

Retrieves and removes the first element of the specified queue, or blocked until the default timeout if the queue is empty.

The "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.pollFirst method has the following command format(s):

sharedData.pollFirst(name);

sharedData.pollFirst(name, timeout);

Command Parameters

name

a String specifying the name of the queue.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

null if the queue is empty or the queue does not exist.

Example

Retrieves and removes the first element of "queueA". Timeout after 5 seconds.

String pollValue = (String) sharedData.pollFirst("queueA", 5000);

sharedData.pollLast

Retrieves and removes the last element of the specific queue, or blocked until the default timeout if the queue is empty.

The "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.pollLast method has the following command format(s):

sharedData.pollLast(name);

sharedData.pollLast(name, timeout);

Command Parameters

name

a String specifying the name of the queue.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

null if the queue is empty or the queue does not exist.

Example

Retrieves and removes the last element of "queueA". Timeout after 5 seconds.

String pollValue = (String) sharedData.pollLast("queueA", 5000);

sharedData.putToMap

Associates the specified value with the specified key in a session hash map.

If the map previously contained a mapping for this key, the old value is replaced. If the hash map does not exist, a new one with the name will be created with a default life time of 20 minutes.

Format

The sharedData.putToMap method has the following command format(s):

sharedData.putToMap(name, key, value);

Command Parameters

name

a String specifying the name of the map

key

a String specifying the key with which the specified value is to be associated.

value

a Serializable value to be associated with the specified key.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Associates the value with the key in a session hash map.

info("parameter type - String");
sharedData.putToMap("mapA", "key", "value");
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);
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);

sharedData.removeFromMap

Removes the mapping for this key from a map if present.

Format

The sharedData.removeFromMap method has the following command format(s):

sharedData.removeFromMap(name, key);

sharedData.removeFromMap(name, key, timeout);

Command Parameters

name

a String specifying the name of the hash map.

key

a String specifying the key with which the specified value is to be associated.

timeout

a Long specifying the maximum time of getting blocked. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

previous value associated with the specified key.

Example

Returns the value of "key1" in the hash map named "mapA". Timeout after 5 seconds.

String removeValue1 = (String) sharedData.removeFromMap("mapA", "key1", 5000);

sharedData.setConnectionParameters

Sets the connection parameters for the shared data service.

The connection parameters can be specified using the Add option on the Script menu.

Format

The sharedData.setConnectionParameters method has the following command format(s):

sharedData.setConnectionParameters(address, userName, password);

Command Parameters

address

a String specifying the address of the Oracle Load Testing server to use for the Shared Data Service.

userName

a String specifying the username to use for authentication.

password

a String specifying the password to use for authentication.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Sets the connection parameters.

sharedData.setConnectionParameters("http://testserver2", "username",
   decrypt("vGXUWvDW/F7E6OSYUjRmsQ=="));     

sharedData.waitFor

Waits for the specific value to be added to the queue until the default timeout.

The "timeout" is set in the playback settings which has a default value of 20 seconds.

Format

The sharedData.waitFor method has the following command format(s):

sharedData.waitFor(queueName, desiredValue);

sharedData.waitFor(queueName, desiredValue, timeout);

Command Parameters

queueName

a String specifying the name of the queue.

desiredValue

a Serializable value that is expected to be added to the queue.

timeout

a Long specifying the maximum time of waiting. The unit is milliseconds.

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Returns

true if the value is in the queue, otherwise false.

Example

Waits for the specific value to be added to the queue. Timeout after 5 seconds.

info("parameter type - String");
Boolean isFound1 = sharedData.waitFor("queueA", "key1", 5000);
 if (!isFound1)
   warn("Can not find item 'Key1' in queueA");
 else
   info("Found item 'key1' in queueA");
info("parameter type - list of Strings");
ArrayList<String> listOfStr = new ArrayList<String>();
listOfStr.add(0, "val1");
listOfStr.add(1, "val2");
Boolean isFound2 = sharedData.waitFor("queueA", listOfStr, 5000);
 if (!isFound2)
   warn("Can not find item 'listOfStr' in queueA");
 else
   info("Found item of queue item 'listOfStr' in queueA");
info("parameter type - boolean");
Boolean isFound3 = sharedData.waitFor("queueA", true, 5000);
 if (!isFound3)
   warn("Can not find item 'true' in queueA");
 else
   info("Found item 'true' in queueA");
info("parameter type - int");
Boolean isFound4 = sharedData.waitFor("queueA", 10, 5000);
 if (!isFound4)
   warn("Can not find item '10' in queueA");
 else
   info("Found item '10' in queueA");
info("parameter type - double");
Boolean isFound5 = sharedData.waitFor("queueA", 10.5, 5000);
 if (!isFound5)
   warn("Can not find item '10.5' in queueA");
 else
   info("Found item '10.5' in queueA");
info("parameter type - long");
Boolean isFound6 = sharedData.waitFor("queueA", 100, 5000);
 if (!isFound6)
   warn("Can not find item '100' in queueA");
 else
   info("Found item '100' in queueA");