0
votes

Moderators, please read through once before marking it as a duplicate.

This is my first time creating a custom Sampler in JMeter. I am trying a simple query.

public class CustomJavaSampler extends AbstractJavaSamplerClient implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 5838315675279087366L;

    @Override
    public SampleResult runTest(JavaSamplerContext arg0) {

        SampleResult result = new SampleResult();
        result.sampleStart(); // start stopwatch

         JMeterVariables vars = JMeterContextService.getContext().getVariables();
        vars.putObject("search", "DoASearch");
        JMeterContextService.getContext().setVariables(vars);

        result.sampleEnd(); // stop stopwatch
        result.setSuccessful(true);
        result.setResponseMessage("Successfull");
        result.setResponseCodeOK(); // 200 code

        return result;
    }

}

I have created a jar and I've added it to the lib/ext folder in jmeter. But I am not able to see the class in Java Request sampler. I have enabled debug logs.

log_level.jmeter=DEBUG
log_level.jmeter.junit=DEBUG
log_level.jmeter.control=DEBUG
log_level.jmeter.testbeans=DEBUG
log_level.jmeter.engine=DEBUG
log_level.jmeter.threads=DEBUG
log_level.jmeter.gui=WARN
log_level.jmeter.testelement=DEBUG
log_level.jmeter.util=DEBUG
log_level.jmeter.util.classfinder=DEBUG
log_level.jmeter.test=DEBUG
log_level.jmeter.protocol.http=DEBUG
# For CookieManager, AuthManager etc:
log_level.jmeter.protocol.http.control=DEBUG
log_level.jmeter.protocol.ftp=WARN
log_level.jmeter.protocol.jdbc=DEBUG
log_level.jmeter.protocol.java=WARN
log_level.jmeter.testelements.property=DEBUG
log_level.jorphan=DEBUG

log_file=jmeter-debug.log

The complete jmeter log is http://pastebin.com/T39iUhFW

And also why is the log showing a "did not find" message for the /lib jars?

1

1 Answers

0
votes

Nothing is wrong with your code, CustomJavaSampler is displayed in Java Request classnames.

Java Custom Sampler

So perhaps it's something with your .jar file. Can you upload it somewhere so we could take a look? I guess it's samp.jar.

By the way, setting a variable is a very "light" operation which can be done via Beanshell Sampler which is almost Java compatible.

If you need to perform some load - next option is JSR223 Sampler and "groovy" which is a "balance" between simplicity and productivity so if you will need to make some changes in your code you won't have to recompile, replace jars, restart JMeter, etc.