0

我在 Jmeter 中有一个 java 请求,我为此编写了扩展 AbstractJavaSamplerClient 的代码并实现了我正在点击的重写方法,并且可以在远程机器的日志中看到响应但是我无法在视图结果树中看到响应并将响应保存到 jmeter 中的文件下面是运行测试代码片段,请告诉我如何在 Jmeter 中捕获 java 请求响应

public SampleResult runTest(JavaSamplerContext context) {

    System.out.println("run Test method actual method is called here..");
    XCardService xcardService = null;
    String urlString = context.getParameter( "rubyURL" );
    SampleResult result = new SampleResult();
    boolean success = true;
    result.sampleStart();
    //try with Junit
    String[] rubyURL = new String[1];
    rubyURL[0] = urlString;
    try {
        System.out.println("RubyUrl::"+rubyURL);
        xcardService = XCardFactory.getService(rubyURL, 165, appPassword, 5000);
    } catch (AuthenticationFailureException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IncompatibleVersionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceInitFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XCardTimeoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     DiagnosticContext dc = new ServerDiagnosticContext("Junit TestCase");
    try {
        System.out.println("xcardService::"+xcardService);
        AccountInfo account  = xcardService.getAccountInfo(dc, 1089765);
        System.out.println("getAccount Info ::"+account.toString());
    } catch (InvalidArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientNotAuthenticatedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XCardTimeoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XCardException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    result.sampleEnd();
    result.setSuccessful(success);
    System.out.println("Response Message:::"+result.getResponseMessage());
    return result;

}
4

1 回答 1

0

AbstractJavaSamplerClient 实现的一个很好的例子是 org.apache.jmeter.protocol.java.test.SleepTest。

http://www.javadocexamples.com/java_source/org/apache/jmeter/protocol/java/test/SleepTest.java.html

作为一般规则,我会将 result.sampleEnd(); 在 finally 块中。

于 2013-07-12T08:20:51.430 回答