JMeter adding Java requests and if controllers

Source: Internet
Author: User

The new project uses JMeter to do performance testing, import the jar package written by others, found if the controller and Java request, but I do not understand what the script is doing, had to grope.

Java requests that you write a runable jar package yourself, inherit the JMeter Abstractjavasamplercontext class, and then rewrite the Runtest method. The specific code is as follows.

The steps are as follows:

1. Open Eclipse, write the code, and export to runnable jar file (remember that jar file is not found in JMeter)

The default import code will not find the namespace, remember to import the JMeter lib jar in the properties->build path, as

2. Place the jar file in the Lib\ext in the JMeter, restart the jmeter, add a Java request such as thread group, and add the view results tree.

You can see the results of the execution.

But if the controller I have not set a successful, until I find the reason to continue to update.

Package Jmeter_sample;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 classPerformancetest extends abstractjavasamplerclient{Private Static LongStart =0; Private Static LongEnd =0; PrivateString A, B, result;  Public voidsetuptest (Javasamplercontext arg0) {Start=System.currenttimemillis (); }         Public voidteardowntest (Javasamplercontext arg0) {End=System.currenttimemillis (); System.err.println (" Cost Time"+ (End-start)/ +); }         PublicArguments getdefaultparameters () {Arguments args=NewArguments (); Args.addargument ("NUM1",""); Args.addargument ("num2",""); returnargs; }        Private Static intSumintAintb) {returnA +b;}  Publicsampleresult runtest (Javasamplercontext arg0) {Sampleresult SR=NewSampleresult (); A= Arg0.getparameter ("NUM1"); b= Arg0.getparameter ("num2"); Sr.setsamplelabel ("Hui"); Try{Sr.samplestart (); Result=string.valueof (SUM (Integer.parseint (a), Integer.parseint (b))); if(Result! =NULL&&result.length () >0) {Sr.setresponsedata ("The result is"+result,NULL);            Sr.setdatatype (Sampleresult.text); } sr.setsuccessful (true);        Sr.sampleend (); }        Catch(Exception e) {e.printstacktrace ();} returnSR; }         Public Static voidMain (string[] args) {System. out. Print ("Hello"); }}

JMeter adding Java requests and if controllers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.