Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache JMeter
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.jmeter.protocol.java.sampler
Interface JavaSamplerClient

All Known Implementing Classes:
  AbstractJavaSamplerClient, JavaTest, SleepTest

    public interface JavaSamplerClient

This interface defines the interactions between the JavaSampler and external Java programs which can be executed by JMeter. Any Java class which wants to be executed as a JMeter test must implement this interface (either directly or indirectly through AbstractJavaSamplerClient).

JMeter will create one instance of a JavaSamplerClient implementation for each user/thread in the test. Additional instances may be created for internal use by JMeter (for example, to find out what parameters are supported by the client).

When the test is started, setupTest() will be called on each thread's JavaSamplerClient instance to initialize the client. Then runTest() will be called for each iteration of the test. Finally, teardownTest() will be called to allow the client to do any necessary clean-up.

The JMeter JavaSampler GUI allows a list of parameters to be defined for the test. These are passed to the various test methods through the `JavaSamplerContext`. A list of default parameters can be defined through the getDefaultParameters() method. These parameters and any default values associated with them will be shown in the GUI. Users can add other parameters as well.

When possible, Java tests should extend `AbstractJavaSamplerClient` rather than implementing JavaSamplerClient directly. This should protect your tests from future changes to the interface. While it may be necessary to make changes to the JavaSamplerClient interface from time to time (therefore requiring changes to any implementations of this interface), we intend to make this abstract class provide reasonable default implementations of any new methods so that subclasses do not necessarily need to be updated for new versions. Implementing JavaSamplerClient directly will continue to be supported for cases where extending this class is not possible (for example, when the client class is already a subclass of some other class).

See `SleepTest` for an example of how to implement this interface.

Version:
  $Revision: 674365 $

Method Summary
`Arguments` | `getDefaultParameters()` Provide a list of parameters which this test supports.
`SampleResult` | `runTest(JavaSamplerContext context)` Perform a single sample for each iteration.
`void` | `setupTest(JavaSamplerContext context)` Do any initialization required by this client.
`void` | `teardownTest(JavaSamplerContext context)` Do any clean-up required by this test at the end of a test run.

Method Detail

### setupTest

    void setupTest(JavaSamplerContext context)

  Do any initialization required by this client. 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.

  Parameters:
    `context` - the context to run with. This provides access to initialization parameters.

### runTest

    SampleResult runTest(JavaSamplerContext context)

  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.sampleEnd`to set the time that the test required to execute. It is also a good idea to set the sampleLabel and the successful flag.

  Parameters:
    `context` - the context to run with. This provides access to initialization parameters.
  Returns:
    a SampleResult giving the results of this sample.
  See Also:
    `SampleResult.sampleStart()`, `SampleResult.sampleEnd()`, `SampleResult.setSuccessful(boolean)`, `SampleResult.setSampleLabel(String)`

### teardownTest

    void teardownTest(JavaSamplerContext context)

  Do any clean-up required by this test at the end of a test run.

  Parameters:
    `context` - the context to run with. This provides access to initialization parameters.

### getDefaultParameters

    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.

  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.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache JMeter
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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