Get results from JMeter remote test in Java

I´m trying to run JMeter tests directly from my Java code. The load should be produced via a JMeter server. In the code, I use a ClientJMeterEngine instance that connects to the JMeter daemon running on the server. This works so far, I can start and run my test. What I currently don´t understand is how to get the results from the test run after it has completed. My current code looks like this:

// create ClientJMeterEngine instance
ClientJMeterEngine jmeter = new ClientJMeterEngine("myHost:4000");
// load test
File file = new File("C:/myTest.jmx");
// configure test
HashTree testPlanTree = SaveService.loadTree(file); 
// run test

If I run the test using the StandardJMeterEngine object, I use a ResultCollector to get the results from my test runs. This works as expected. When I try to run the tests using the described server-based approach, I get the following exception on the machine where the server is running:

2016/03/15 09:24:35 ERROR - jmeter.samplers.BatchSampleSender: testEnded(host) java.rmi.ConnectException: Connection refused to host: myHost; nested exception is: Connection refused
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
    at sun.rmi.transport.tcp.TCPChannel.createConnection(
    at sun.rmi.transport.tcp.TCPChannel.newConnection(
    at sun.rmi.server.UnicastRef.invoke(
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(
    at com.sun.proxy.$Proxy1.processBatch(Unknown Source)

The server thus wants to call back to the client from which I start the test run. It fails, because I don´t have anything waiting for the remote call. I´ve worked my way through the JMeter source, but haven´t found an answer, what I need to do on my Java side to make this work.

EDIT In the meantime I´ve made some progress. What I´ve found is the following:

The client thread must be kept in state running, so the ResultCollector on the client can receive the results from the server. I now do this by "busy waiting" in my client Java code. The issue now is to know when the test execution on the server is finished, so I can also finish the client thread. The ResultCollector does have the capabilities to recognize the test is finished, but no public methods for this. The solution would be to extend the ResultCollector and override the testEnded method: This method sets a public boolean variable "testFinished" to true.

Though this feels a little bit "hacky". Does anybody have a better solution here?


I had the same problem and tried your solution with overriding testEnded() method of ResultCollector class. My test was endlessly waiting for response from remote JMeter slave server.

The actual problem is that remote server - Slave - succeed in replying of requests from Master at early stage. However, the connection dropped at some point and the test finished without receiving any report from a Slave. Slave is unable to start a new TCP connection, and can't send results when it is ready with his testing report as its hostname (IP) hasn't been set/sent to Master correctly.

Therefore, the solution is to start a Slave with the correct parameter in command line or in the

I started my slave like this:

c:\JMeter_new\apache-jmeter-3.1\bin>jmeter-server -Djava.rmi.server.hostname=IP

where IP is of the Slave

PS If you run tests in GUI, run Master with the parameter as well:

D:\JMeter_new\apache-jmeter-3.1\bin>jmeterw -Djava.rmi.server.hostname=IP_of_master

Need Your Help

Make iPad app fit in TV through HDMI

ipad television hdmi

I am working on an iPad application, and I have to give a demo on a television through HDMI, but iPad screen only appears in the middle of the TV screen.