0
votes

I created a custom JMeter Java sampler. It does what I expect it to do, however, I want to properly populate the SampleResult.

In particular, I want to set the Received KB/sec manually. Is there a way to do this with the SampleResult class or some other endpoint?

In the SampleResult class there is a setBytes and a setSentBytes method but no received bytes method: https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

1
Have you tried public int getBytes() ?NaveenKumar Namachivayam
I want to set it manually. If you build a custom Java sampler it does not automatically populate these fields. The getBytes would work if you use an existing sampler - not one that you have built yourself.rmoh21
can you show the sanitized version of your code (the part that formats SampleResult in particular)? I think getBytesAsLong() should work for you (getBytes() is actually depricated), but not sure what your previous comment meansKiril S.
So what I am doing is I am shelling out a docker command to pull an image. The shell process though does not necessarily return a response which gives me the bytes. However, I want to artificially induce that if the process completed successfully we download x number of bytes. From there JMeter can calculate the other stats for us.rmoh21

1 Answers

0
votes

Why don't you like setBytes()t method? As per the JavaDoc:

public void setBytes(long length)

In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput. The bytes are the bytes of the response data.

Parameters:

length - the number of bytes of the response data for this sample

I assume you're familiar with the How to Write a plugin for JMeter guide


Personally I am not a big fan of developing "samplers" as in 99.9% of cases the same can be implemented using JSR223 Test Elements and Groovy language, this way you won't have to spend additional time and effort for developing, supporting and troubleshooting the plugin as you can skip such phases as compilation, packaging, adding the new class to JMeter Classpath, restarting JMeter, etc. so JSR223 way is much faster and more convenient as you can develop the code directly in JMeter GUI.