github abstracta/jmeter-java-dsl v0.10
0.10

latest releases: v1.29, v1.28.1, v1.28...
3 years ago

Thanks to the contribution of @MrThreepwood is now easier to use dynamically generated urls, bodies & header values in http requests. Here is an example:

import static org.assertj.core.api.Assertions.assertThat;
import static us.abstracta.jmeter.javadsl.JmeterDsl.*;

import java.io.IOException;
import java.time.Duration;
import org.apache.jmeter.threads.JMeterVariables;
import org.eclipse.jetty.http.MimeTypes.Type;
import org.junit.jupiter.api.Test;

public class PerformanceTest {

  @Test
  public void testPerformance() throws IOException {
    TestPlanStats stats = testPlan(
        threadGroup(2, 10,
            httpSampler("http://my.service")
                .post(s -> buildRequestBody(s.vars), Type.TEXT_PLAIN)
        )
    ).run();
    assertThat(stats.overall().elapsedTimePercentile99()).isLessThan(Duration.ofSeconds(5));
  }

  public static String buildRequestBody(JMeterVariables vars) {
    String countVarName = "REQUEST_COUNT";
    Integer countVar = (Integer) vars.getObject(countVarName);
    int count = countVar != null ? countVar + 1 : 1;
    vars.putObject(countVarName, count);
    return "MyBody" + count;
  }

}

Warning: This alternative, as in the case of JSR223 pre & post processors using Java code, only works when using embedded JMeter engine. There is no support for using it with exported JMX files in JMeter GUI, or BlazeMeter. If you need such support prefer using a JSR223 pre processor with script specified as string (Groovy script).

Additionally, this version includes some minor non backwards compatible changes:

  • Change regex extractor target field enum names to be more explicit and avoid confusion.
  • Rename Jsr223PostProcessorScript, Jsr223PostProcessorScriptVars, Jsr223PreProcessorScript, Jsr223PreProcessorScriptVars to shorter forms to avoid verbosity on users code.

Finally, useDebugRun() method has been added to BlazeMeterEngine to allow running small tests in BlazeMeter without consuming credits, to verify that test plans properly work in BlazeMeter.

Don't miss a new jmeter-java-dsl release

NewReleases is sending notifications on new releases.