How to write a JMeter test for a Java query

I need to do load testing in memory databases.

I want to use JMeter and, impressed, I need to write a class that implements JavaSamplerClient.

I just have no idea where to start. What the JMeter website offers helps me very little. This is my first time when I do something like this, and I got lost in a few days!

So, maybe you can help by explaining how the basics of how my class should be set up are? Do I need to import packages? Because whenever I try to say that it implements JavaSamplerClient, I get an error.

Could there also be a brief overview of how it all works? How does the method run as many times as specified in JMeter? Or what is really going on here?

+4
source share
2 answers

To use the java query in jmeter, you must create a java class that inherits from the JavaSamler client. for this you need to add two jar files and add them to the classpath if you are working with eclipse. these are two jar files: ApacheJMeter_core.jar and ApacheJMeter_java.jar Your class will look like this:

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
public class javaRequest extends AbstractJavaSamplerClient {

        @Override
        public void setupTest(JavaSamplerContext context){
        // TODO Auto-generated method stub

        super.setupTest(context);
        }
        @Override
        public Arguments getDefaultParameters() {
        // TODO Auto-generated method stub  


        }
        @Override
        public SampleResult runTest(JavaSamplerContext arg0) {
            // TODO Auto-generated method stub

            SampleResult result = new SampleResult();

                boolean success = true;

                result.sampleStart();

                // Write your test code here.

                //


                result.sampleEnd();

                result.setSuccessful(success);

                return result;

        }
        @Override
        public void teardownTest(JavaSamplerContext context){
            // TODO Auto-generated method stub
            driver.quit();
              String verificationErrorString = verificationErrors.toString();
              if (!"".equals(verificationErrorString)) {
                fail(verificationErrorString);
                System.out.println(verificationErrorString); 

              }
        super.teardownTest(context);
        }



}

for more information you can visit this link   http://www.javacodegeeks.com/2012/05/apache-jmeter-load-test-whatever-you.html/comment-page-1/#comment-8288 and this page too How to use CSV dataset with junit request validation in jmeter

+7
source

JavaSamplerClient, AbstractSamplerClient.

runTest().

JavaTest JavaTest:

  • /src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java
  • /src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java

JMeter download

, Java.

.

.jar /lib/ext JMeter. Java Request.

, .

+6

Source: https://habr.com/ru/post/1538017/


All Articles