Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does JMeter ​ develop a custom Sample

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "JMeter how to develop a custom Sample". In daily operation, I believe many people have doubts about how to develop a custom Sample in JMeter. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "JMeter how to develop a custom Sample". Next, please follow the editor to study!

View plaincopypackage com.alibaba.stress.load;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 LifecycleJMeterSampleextends AbstractJavaSamplerClient {@ Overridepublic Arguments getDefaultParameters () {System.out.println ("Get Parameter name! [getDefaultParameters] "); return super.getDefaultParameters ();} @ Overridepublic void setupTest (JavaSamplerContext context) {System.out.println (" [setupTest] "); super.setupTest (context);} @ Overridepublic void teardownTest (JavaSamplerContext context) {System.out.println (" [teardownTest] "); super.teardownTest (context);} @ Overridepublic SampleResult runTest (JavaSamplerContext ctx) {SampleResult result = new SampleResult (); result.sampleStart (); System.out.println (" [runTest] "); result.setSuccessful (true); result.sampleEnd (); return result }} [java] view plaincopypackage com.alibaba.stress.load; 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 LifecycleJMeterSample extends AbstractJavaSamplerClient {@ Override public Arguments getDefaultParameters () {System.out.println ("Get Parameter name! [getDefaultParameters] "); return super.getDefaultParameters ();} @ Override public void setupTest (JavaSamplerContext context) {System.out.println (" [setupTest] "); super.setupTest (context);} @ Override public void teardownTest (JavaSamplerContext context) {System.out.println (" [teardownTest] "); super.teardownTest (context) } @ Override public SampleResult runTest (JavaSamplerContext ctx) {SampleResult result = new SampleResult (); result.sampleStart (); System.out.println ("[runTest]"); result.setSuccessful (true); result.sampleEnd (); return result;}} [java] view plain copypackage com.alibaba.stress.load; 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 LifecycleJMeterSample extends AbstractJavaSamplerClient {@ Override public Arguments getDefaultParameters () {System.out.println ("Get Parameter name! [getDefaultParameters] "); return super.getDefaultParameters ();} @ Override public void setupTest (JavaSamplerContext context) {System.out.println (" [setupTest] "); super.setupTest (context);} @ Override public void teardownTest (JavaSamplerContext context) {System.out.println (" [teardownTest] "); super.teardownTest (context) } @ Override public SampleResult runTest (JavaSamplerContext ctx) {SampleResult result = new SampleResult (); result.sampleStart (); System.out.println ("[runTest]"); result.setSuccessful (true); result.sampleEnd (); return result;}}

Where AbstractJavaSamplerClient is obtained from ApacheJmeter_Java.jar. The class file you write is packaged with xxx.jar and put the Jar under lib/ext in the unzipped directory of Jmeter. Restart jmeter. Join the thread group and aggregate report two components at a time, and add a new Sample (Java Sample) before aggregating the report component.

Run the test. You can see the output of the console. Adjust the control of the number of threads in the thread group several times, we will find that the teardowntest and setupuptest methods in our custom class are executed against a thread in the thread group, and the number of calls to threads in the thread group actually refers to the number of runs of the runtest method. 5.Jmeter distributed testing (pros and cons) the following is how distributed testing is used, even if multiple machines are controlled by one machine to put pressure on the target machine. Since the methods on Linux and Windows are somewhat different, here's how to configure them under Linux.

First of all, the machine we control is called master, the broiler that produces pressure is called JmeterServer, and the system we test is called Target.

Step 1: start JmeterServer. We can find the jmeter-server script in the Jmeter/bin directory and run it. Of course, if you need to adjust the performance parameters such as the memory of the server generated by the test load, we modify the memory parameters in the script jmeter.

Step 2: modify the jmeter.properties file in the jmeter/bin directory on the Master machine, and modify the remote_hosts=localhost:1099,localhost:2010 as the actual IP of your own JmeterServer. If there are multiple, you can separate them with a comma.

Step 3: start master jmeter and choose to run the test script: run-> run remotely-- > select IP or run all remotes. JmeterServer will run the run script set on the Master machine.

At this point, the study on "how to develop a custom Sample by JMeter" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report