Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space FUNCTDEV and version SVC2023.1

...

A load test component can be created by extending the SimRunnable class of the Load Test component Java API located in the com.parasoft.simulator.api package. SimRunnable stands for Simulator runnable. Simulator is the name for the Load Test container, which simulates multiple virtual user activities.

...

The component examples are located in the examples\dev\components folder of your SOAtest/Load Test installation. The simple-runnable-source.jar and the socket-runnable-source.jar archives contain the source, configuration, and build files for the components described in this tutorial. You will need to unjar these archives to the Load Test component projects directory, which must be created manually. 

...

To create a component projects directory outside the Load Test installation:

  1. Copy the simple-runnable-source.jar into the component projects directory and unjar the component source archive.
  2. Unjar the socket-runnable-source.jar into the SocketRunnable directory, which must be created manually. Each source directory contains a component-build.xml ANT build script.
  3. Open this file and make sure the load.test.install.root property is pointing to your SOAtest/Load Test installation directory.
  4. Change the load.test.jar.path property to point to the loadtest.jar file located in the <INSTALL><INSTALL-DIR>/plugins/com.parasoft.ptest.libs.web_<VERSION>/root directoryroot directory.

Creating a SimpleRunnable Load Test Component Project

...

  1. Open the New Project wizard, select Java Project, then click Next.
  2. Name the project SimpleRunnable.
  3. Choose Create project from existing source, select the SocketRunnable directory, then click Next.
  4. In the Source tab, make sure the default output folder is set to SocketRunnable/target/classes.
  5. Open the Libraries tab, click Add External Jar.
  6. Add the parasoft.jar and com.parasoft.api.jar files located in the <INSTALL><INSTALL-DIR>/plugins/com.parasoft.ptest.libs.web_<VERSION>/root root directory.
  7. In Eclipse, right-click component-build.xml and choose Run As> As > Ant Build to create the component .jar file.
Note
titleNotes

The components should be built with Java 1.5 JRE—preferably JRE, preferably with JRE 1.5.0_18.

The default target of the component-build.xml ANT script in each example project builds a component jar archive, which could be deployed to the Load Test as a custom or built-in component. If you use Eclipse to compile the component project as described here, remove the compile target dependency from the jar target of the component-build.xml script. 

Creating a SocketRunnable Load Test Component Project

The SocketRunnable component extends the SimpleRunnable component. Compile SimpleRunnable first and put the main.jar from the root directory of the SimpleRunnable project into the lib directory of the SocketRunnable project.

...

  1. Open the New Project wizard, select Java Project, then click Next.
  2. Choose Create project from existing source, select the SimpleRunnable directory, then click Next.
  3. In the Source tab, make sure the default output folder is set to SimpleRunnable/target/classes.
  4. Open the Libraries tab and click Add External Jar.
  5. Add the parasoft.jar and com.parasoft.api.jar files located in the <INSTALL>INSTALL-DIR>/plugins/com.parasoft.ptest.libs.web_<VERSION>/root directory. 
  6. In the Libraries tab, ensure that the lib/jtidy-r820.jar and lib/main.jar are on the project class path.
  7. In Eclipse, right-click component-build.xml and choose Run As> As > Ant Build to create the component .jar file.

...

  1. In the Load Test GUI, select the Profiles node of the Load Test Configuration tree.
  2. In the Project Configuration view, click Select.
  3. In the Select a Component Archive dialog, choose Local option, click Next, then select your load test component archive.
  4. Click Finish. A component deployment view will appear as shown below.
    Image Modified

If component validation failed, the error messages will be shown in the lower table of the Deployment view. 

...

  1. Place the component jar archive into the <INSTALL> <INSTALL-DIR>/plugins/com.parasoft.ptest.libs.web_<VERSION>/root/lt-components/built-in folder.

  2. Restart  Load Load Test.
  3. From the File menu, select Go to File > Customize Preferences. You will see your component deployment details in the built-in component deployment view as shown below.

    If a built-in component has been successfully deployed, it will be available in the Select Component Archive dialog in the Built-in drop down list as shown below:

    Image Modified

Using Load Test Component API

Javadoc documentation for the Load Test component API is available by selecting the API> Component API submenu from the Help menu of the going to Help > API > Component API on the Load Test application menu bar.

...

  • SimRunnableOutput run(PrivateContext context) –  The core functionality method of the component. Various container-specific variables are available through the PrivateContext passed as an argument to this method. See PrivateContext in the API docs for the list of available context variables.
  • String canRun() – This method is called by the container to ensure that the component is properly-configured and can be invoked. Check whether all component member variables are properly initialized. If not, return an error description. If the component is ready, return null. Returning a non-null error description will prevent Load Test from starting and the error string will display.
  • boolean done() – This method is called by the container after invoking the run() method of this class to determine whether the component has completed its activities. A component can emulate a multi-step user activity with each step followed by the Virtual User think time as configured in the load test Profile. In such a case, the run() method will be called more than once until the done() returns true. Returning false will cause the framework to retain the Virtual User to which the instance of this component class belongs and call its run() method again. Returning true will cause the Virtual User to which the instance of this component class belongs to be removed from the Virtual User pool.

    Info
    titleImportant - Releasing Virtual Users

    You eventually need to return true from the done() method in order to allow the Virtual Users to be removed from the pool. Once a Virtual User is removed from the pool, it will be replaced with a new Virtual User of the same profile if it is required by the load test Scenario. Releasing the Virtual Users is important because it allows the framework to follow the ups and downs of the scheduled virtual user or hit per second rate.

  • SimRunnable prototype() – This is a factory method. Each time a Virtual User is created by the container, it is assigned a new instance of the component class. When a component is deployed into the container, the container creates an instance of the component class, which serves as a prototype for creating component class objects that are assigned to Virtual Users during the load test. The framework calls the prototype() method of the component class to obtain copies of the component prototype and it lets the component decide how to make that copy. When implementing this method, make sure that all the necessary component member variables are copied to the newly created component instance. You can copy component class members by value or by reference:
    • When copying component class members by reference, be aware that these class members should be adequately protected against concurrent access or modification. If this becomes a problem, consider copying by value (deep copy).
    • When copying component class members by value (deep copy), keep in mind, that hundreds—possibly thousands—of Virtual Users (and therefore instances of this class) can simultaneously exist in the Load Test application while it runs the load test. The number of Virtual Users inside the application depends on the Load Test mode and the values scheduled in the load test Scenario. A load test component has too large of a memory footprint, it can cause the application to run out of memory. In this case, consider copying member variables by reference.
  • void onDeploy(DeploymentContext context) – This method is invoked by the container when a component archive gets deployed into the container. Various deployment-specific variables are available through the DeploymentContext passed as an argument to this method. The SimpleRunnable’s implementation of this method shows how to get access to the configuration (and other) files included into the component deployment.
  • void writeExternal() and void readExternal() – Methods that transfer component state to the remote machines.

...

Next, let’s look at the SimpleRunnable’s external configuration file. The source folder of the SimpleRunnable component contains two component configuration files: LongExecTime.cfg and ZeroExecTime.cfg. One of them is included into the component archive (see component-build.xml ANT script). 

When a component archive is deployed into the container, the archive is decompressed and the archive contents become available to the component via the DEPLOYMENT_BASE property of the DeploymentContext. The implementation of the onDeploy method of the SimpleRunnable class shows how the .cfg component configuration file is located and parsed to initialize an instance of SimpleRunnableConfiguration. If a load test configuration includes remote machines, the component archive is transferred to each remote machine before the beginning of the load test, after which each component is deployed. 

...

The lt-jar.xml component archive descriptor must be included into the root directory of each component archive. The descriptor must contain the class names of the main component class derived from the SimRunnable and the class name of the component output derived from SimRunnableOutput. See the lt-jar.xml files of the included components for the examples of the component archive descriptor file format.

...

  1. Add the execTimeMs parameter in the .cfg file.
  2. Run the component archive ANT build script.
  3. In the Load Test component view, click the Reload button.
  4. Rerun the load test. Note that the test execution time in the Statistics part of the load test report follows the configured execution time duration.


    The  execution execution statistics reflect the changes of the execTimeMs parameter of the component configuration file to 1200.

...

A component can provide its custom configuration view to the container by implementing the SimRunnableConfigViewProvider interface. The container will display this view in the Configuration tab of the Load Test Runnable component panel shown above. The container calls the getConfigView() method of the SimRunnableConfigViewProvider interface to get the configuration view of the component. In this example, the SocketRunnableView class implements the component configuration view. The SocketRunnableView class uses SocketTest*View classes located in com.parasoft.loadtest.component.example.socket.test.view package for individual SocketTest instance configuration.

...