Skip to main content

JSR223 to Java.

Why Replacing JSR223 by Java.#

  1. Java can be edit easily with IDE and also debugged as simple as any java application.
  2. Using java we can use inheritance, and external library to reuse code and writing our library to be reused in future projects.
  3. Java has better performance tha groovy.
  4. Unit test.

Java Implementation.#

To Implement Java you can extends from AbstractJavaxxWrapper and implement execute method, depend on type of testElement, execute has the same input parameter as JSR223, expected the parameters witch is replaced by a map.

ClassTypeJSR223 equivalent
AbstractJavaSamplerWrapperSamplerJSR223Sampler
AbstractJavaAssertionWrapperAssertionJSR223Assertion
AbstractJavaPostProcessorWrapperPostProcessorJSR223PostProcessor
AbstractJavaPreProcessorWrapperPreProcessorJSR223PreProcessor
AbstractJavaTimerWrapperTimerJSR223Timer
AbstractJavaListenerWrapperListenerJSR223Listener

Extends#

JMC is based on lombok, each wrapper class should be annotated with :

@SuperBuilder(setterPrefix = "with", toBuilder = true)

@SuperBuilder(setterPrefix = "with", toBuilder = true)
public class TestJavaSampleListenerWrapperWithParametersKey
extends AbstractJavaListenerWrapper {
@Override
public void execute(
String label,
JMeterContext ctx,
JMeterVariables vars,
Properties props,
Map<String, String> parameters,
Logger log,
Sampler sampler,
SampleResult prev,
SampleEvent event) {
.....
}
/**
* @return list of valid parameters, null to not check validity.
*/
@Override
public List<String> getParametersKey() {
return null;
}
}

Parameters#

jmeter-debug-Intellij

Map#

tip

Map Parameters is preferable than attributes.

All JavaTest implementation can have parameter as Map < String,String > .

  1. addParameters(Map< String, String > parameters) : add list of key/value.
  2. addParameter(String name, String value) : add key/value.
  3. List< String > getParametersKey() : implement this method to validate parameters key: null to skip validation and empty list to not accept parameters.

Execute Method has the Parameters Map as arguments

Attributes (Beta)#

  1. Simple attribute (String,integer, boolean) can also be used for configuration.
  2. Complex attribute : complex attribute (List, Map , composed object, ..) can't be used to be persisted with JMX, but can be used during execution. All those attribute should be annotated with @JmcOmitField.
danger

Complex attribute should be skipped by annotation @JmcOmitField.