Performance test for the "Go" Java interface

Source: Internet
Author: User
Tags gettext

I've tried this week. Performance Testing, before testing the site's performance tests, JavaInterface Performance test is the first time, learned a lot, hereby share. The main use of the two performance testing tools, one is JMeter, one is LoadRunner。 Test methods for using JMeter: 1, download the Linux version of Jemeter, download the file contains two jar package, one is Apachejmeter_core.jar,apachejmter_java.jar. Place the two jars below the libraries of Eclipse's Java Build path. 2, create the script class, so that he inherits Abstractjavasamplerclient. The initial structure is
Private Sampleresult results;public void Setuptest (Javasamplercontext arg0) {results = new sampleresult ();} Public Arguments getdefaultparameters () {Arguments params = new Arguments (); return params;} The loop body of the test execution, which executes several times depending on the number of threads and the number of cycles, is similar to the action method in LoadRunner public Sampleresult runtest (Javasamplercontext arg0) { Results.samplestart (); Results.sampleend (); results.setsuccessful (true); return results;} The end method, which is actually run only once per thread, executes after the test method runs, similar to the end method in LoadRunner public void Teardowntest (Javasamplercontext arg0) {}
Put the business process that needs to be cycled into the Runtest method. The code is written as follows:
Package App;import http. Httpclient4;import http. Httpparameter;import http. Httpresp;import http. Jsonutil;import Java.io.ioexception;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.calendar;import Java.util.date;import Java.util.map;import Java.util.random;import Org.apache.commons.httpclient.httpclient;import Org.apache.commons.httpclient.httpexception;import Org.apache.commons.httpclient.methods.postmethod;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; Import Com.yeepay.g3.utils.common.encrypt.aes;import Com.yibao.utils.des3.rsa_encrypt;public class TheardTest Extends Abstractjavasamplerclient{private sampleresult results;public void Setuptest (Javasamplercontext arg0) { results = new Sampleresult ();} Public Arguments getdefaultparameters () {Arguments params = new Arguments ();return params;} public static String ramdonnum (int num) {Random rd = new Random (); StringBuilder sb = new StringBuilder (""); if (num <1) {return null;} else{for (int i=1;i<=num;i++) {int sr=rd.nextint (9); Sb.append (String.valueof (SR));} return sb.tostring ();}} public static void Testcreditpay () throws Parseexception{string Public_key=theardtest.testconsult (); HttpClient client = new HttpClient (); Postmethod method = new Postmethod ("Http://xxxxxxxx/xxxxxx/api/bankcard/credit/pay"); String Key=theardtest.ramdonnum (6); String Encryptkey = "0123456789" +key; String merchantaccount = "YB01000000078";//Minsheng string Cardno = "xxxxxxxxx"; String validthru= "xxx7"; String cvv2 = "6xx"; String phone = "13xxxxxx5431"; String orderId = "33hhkssseef3utyt2" +key; System.out.println (orderId); integer transtime = (int) (System.currenttimemillis ()/1000); integer currency = 156; String  amount = "50"; String ProductCatalog = "1"; String productName = "123"; String productdesc = "small Meatballs"; String Userip = "123.45.45.45"; String IdentiTyid = "a"; Integer identitytype = 6; String other = "eeee"; String data = "{\" merchantaccount\ ": \" "+ merchantaccount+" \ ", \" cardno\ ": \" "+ cardno+" \ ", \" validthru\ ": \" "+ Validthru + "\", \ "cvv2\": \ "" + cvv2+ "\", \ "phone\": \ "" + phone+ "\", \ "orderid\": \ "" + orderid+ "\", \ "transtime\": "+ transtime+", \ " Currency\ ":" + currency+ ", \" amount\ ":" + amount+ ", \" productcatalog\ ": \" "+ productcatalog+" \ ", \" productname\ ": \" "+ PR Oductname+ "\", \ "productdesc\": \ "" + productdesc+ "\", \ "userip\": \ "" + userip+ "\", \ "identityid\": \ "" + identityid+ "\", \ "Identitytype\": "+ identitytype+", \ "Other\": \ "" + other + "\"} ";d ata = aes.encrypttobase64 (data, encryptkey); try {meth Od.setparameter ("MerchantAccount", MerchantAccount), Method.setparameter ("Data", data); Method.setparameter (" Encryptkey ", Rsa_encrypt.encrypt (Encryptkey, Public_key)); Client.executemethod (method); System.out.println (Method.getstatusline ()); String respstr = method.getresponsebodyasstring (); System.out.println (RESPSTR); String result = Aes.decRyptFromBase64 (Respstr, Encryptkey); SYSTEM.OUT.PRINTLN (Result)//                  map<string auto-refund, OBJ ect> Mapjson=jsonutil.parse (Result), Object obj = Mapjson.get ("Yborderid"); String yborderid=obj.tostring (); SYSTEM.OUT.PRINTLN ("Serial number:" +yborderid); Theardtest.refundtesecase (Yborderid,merchantaccount,amount); Method.releaseconnection ();} catch (HttpException E) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Auto-gener Ated catch Blocke.printstacktrace ();} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}  
/*** Test Negotiation interface * @author shangwei* @return * @throws parseexception**/public static String Testconsult () throws ParseException {String URL = "Http://xxxxxxx/xxxxxx/consult"; HTTPCLIENT4 client =httpclient4.createdefault (); String data = "";D ate d = new Date (); Calendar now = Calendar.getinstance (); Now.settime (d); SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String Dateline=format.format (Now.gettime ()); System.out.println (Dateline);D ate Date = Format.parse (dateline); String dates=date.gettime ()/1000+ ""; SYSTEM.OUT.PRINTLN (dates); try {data = aes.encrypttobase64 (dates, "12345678901234HH");} catch (Exception e) { E.printstacktrace ();} Httpparameter parameter = new Httpparameter ();p arameter.add ("Data", data);p Arameter.add ("MerchantAccount", " YB01000000078 "); Httpresp resp = new Httpresp () try{resp=client.dopost (URL, parameter, "Utf-8"); String respstr= resp.gettext ("Utf-8"); System.out.println (RESPSTR); String aes=aes.decryptfrombase64 (respstr, "12345678901234HH"); System.out.println (AES); return AES;} catch (HttpException E) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Auto-gener Ated catch Blocke.printstacktrace ();} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} Client.shutdown (); return "error";} public static void Refundtesecase (String yborderid,string merchantaccount,string amount) throws ioexception{string url = "Http://xxxxxxxx/xxxxxxx/api/refund/direct"; HTTPCLIENT4 client =httpclient4.createdefault (); Httpparameter parameter = new Httpparameter ();p arameter.add ("MerchantAccount", MerchantAccount);p Arameter.add (" Merchantrefundid "," 093032323 ");p arameter.add (" Transorderid ", Yborderid);p arameter.add (" Amount ", amount); Httpresp Rep;try {rep = client.dopost (url, parameter, "Utf-8"); System.out.println (Rep.getstatuscode ()); System.out.println (Rep.gettext ("Utf-8"));} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}} The loop body of the test execution, which executes several times depending on the number of threads and the number of cycles, is similar to the action method in LoadRunner public SampleREsult runtest (Javasamplercontext arg0) {results.samplestart (); try {testcreditpay ();} catch (ParseException e) {//TODO Auto-generated catch Blocke.printstacktrace ();} Results.sampleend (); results.setsuccessful (true); return results;} The end method, which is actually run only once per thread, executes after the test method runs, similar to the end method in LoadRunner public void Teardowntest (Javasamplercontext arg0) {}}
   3, to write the class class and the class introduced into a jar packageand place it under the Lib/ext file for the Jemter file. Put the other jar packages that you used into the Lib folder. 4. After starting Jemter, create the Add thread group and add sampler Java request, if the previous step succeeds, the class name drop-down list will show the test code to hit the jar package.  After the operation Jemter to test it OK. Below share LoadRunner for performance testing and environment optimization.

Performance test for the "Go" Java interface

Related Article

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.