org.apache.jmeter.protocol.java.test

Class SleepTest

Implemented Interfaces:
Serializable, JavaSamplerClient

public class SleepTest
extends AbstractJavaSamplerClient
implements Serializable

The SleepTest class is a simple example class for a JMeter Java protocol client. The class implements the JavaSamplerClient interface.

During each sample, this client will sleep for some amount of time. The amount of time to sleep is determined from the two parameters SleepTime and SleepMask using the formula:

 totalSleepTime = SleepTime + (System.currentTimeMillis() % SleepMask)
 
Thus, the SleepMask provides a way to add a random component to the sleep time.
Version:
$Revision: 674365 $

Field Summary

static long
DEFAULT_SLEEP_MASK
The default value of the SleepMask parameter.
static long
DEFAULT_SLEEP_TIME
The default value of the SleepTime parameter, in milliseconds.

Constructor Summary

SleepTest()
Default constructor for SleepTest.

Method Summary

Arguments
getDefaultParameters()
Provide a list of parameters which this test supports.
SampleResult
runTest(JavaSamplerContext context)
Perform a single sample.
void
setupTest(JavaSamplerContext context)
Do any initialization required by this client.
void
teardownTest(JavaSamplerContext context)
Do any clean-up required by this test.

Methods inherited from class org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient

getDefaultParameters, getLogger, setupTest, teardownTest

Field Details

DEFAULT_SLEEP_MASK

public static final long DEFAULT_SLEEP_MASK
The default value of the SleepMask parameter.
Field Value:
1023L

DEFAULT_SLEEP_TIME

public static final long DEFAULT_SLEEP_TIME
The default value of the SleepTime parameter, in milliseconds.
Field Value:
1000L

Constructor Details

SleepTest

public SleepTest()
Default constructor for SleepTest. The Java Sampler uses the default constructor to instantiate an instance of the client class.

Method Details

getDefaultParameters

public Arguments getDefaultParameters()
Provide a list of parameters which this test supports. Any parameter names and associated values returned by this method will appear in the GUI by default so the user doesn't have to remember the exact names. The user can add other parameters which are not listed here. If this method returns null then no parameters will be listed. If the value for some parameter is null then that parameter will be listed in the GUI with an empty value.
Specified by:
getDefaultParameters in interface JavaSamplerClient
Overrides:
getDefaultParameters in interface AbstractJavaSamplerClient
Returns:
a specification of the parameters used by this test which should be listed in the GUI, or null if no parameters should be listed.

runTest

public SampleResult runTest(JavaSamplerContext context)
Perform a single sample. In this case, this method will simply sleep for some amount of time. Perform a single sample for each iteration. This method returns a SampleResult object. SampleResult has many fields which can be used. At a minimum, the test should use SampleResult.sampleStart and SampleResult.sampleEndto set the time that the test required to execute. It is also a good idea to set the sampleLabel and the successful flag.
Specified by:
runTest in interface JavaSamplerClient
Parameters:
context - the context to run with. This provides access to initialization parameters.
Returns:
a SampleResult giving the results of this sample.

setupTest

public void setupTest(JavaSamplerContext context)
Do any initialization required by this client. In this case, initialization consists of getting the values of the SleepTime and SleepMask parameters. It is generally recommended to do any initialization such as getting parameter values in the setupTest method rather than the runTest method in order to add as little overhead as possible to the test.
Specified by:
setupTest in interface JavaSamplerClient
Overrides:
setupTest in interface AbstractJavaSamplerClient
Parameters:
context - the context to run with. This provides access to initialization parameters.

teardownTest

public void teardownTest(JavaSamplerContext context)
Do any clean-up required by this test. In this case no clean-up is necessary, but some messages are logged for debugging purposes.
Specified by:
teardownTest in interface JavaSamplerClient
Overrides:
teardownTest in interface AbstractJavaSamplerClient
Parameters:
context - the context to run with. This provides access to initialization parameters.

Copyright © 1998-2010 Apache Software Foundation. All Rights Reserved.