创建JMeter Java采样器并获得多个响应时间

时间:2015-01-14 08:30:37

标签: java jmeter

我正在为扩展AbstractJavaSamplerClient类的EJB方法调用创建JMeter测试。我有几个方法调用必须按顺序完成,我想得到每个方法的响应时间。是否有可能让JMeter报告一个测试类的几个响应时间?我还没有办法做到这一点。

EDIT1: 所以我想从call1和call2获得单独的响应时间。

public class JavaRequestSamplerDemo extends AbstractJavaSamplerClient {

  @Override
  public SampleResult runTest(JavaSamplerContext ctx) {
    SampleResult sampleResult = new SampleResult();
    sampleResult.sampleStart();
    class.call1();
    class.call2();
    sampleResult.sampleEnd();
    sampleResult.setSuccessful(true);
    sampleResult.setResponseCodeOK();
    sampleResult.setResponseMessageOK();
    return sampleResult;
  }  
}

1 个答案:

答案 0 :(得分:3)

正如评论中所承诺的那样,试试这个:

public class JavaRequestSamplerDemo extends AbstractJavaSamplerClient {

@Override
public SampleResult runTest(JavaSamplerContext ctx) {
    SampleResult mainResult = new SampleResult();
    mainResult.sampleStart();

    SampleResult child = new SampleResult();
    child.sampleStart();
    class.call1();
    child.sampleEnd();
    // set the other properties of the 'child' SampleResult, such as successful etc here.

    mainResult.addSubResult(child);

    child = new SampleResult();
    child.sampleStart();
    class.call2();
    child.sampleEnd();
    // again, set the properties of this child appropriately (successful etc).

    mainResult.addSubResult(child);
    mainResult.setSuccessful(true);
    mainResult.setResponseCodeOK();
    mainResult.setResponseMessageOK();
    return mainResult;
    }  
}

注意,缺点是没有任何本机JMeter监听器支持SubResults。我写了一些,并在这个问题的答案中发布了一个例子:Jmeter Graph Listener for SampleResult.subResult