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