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); jmeter.configure(testPlanTree); // run test jmeter.runTest();
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: java.net.ConnectException: Connection refused at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:631) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:228) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:214) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:238) at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:190) 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 jmeter.properties.
I started my slave like this:
where IP is of the Slave
PS If you run tests in GUI, run Master with the parameter as well: