乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      loadrunner腳本實例

       戰(zhàn)爭213 2015-01-19

      在做香港某個項目的時候,涉及到了接口之間性能測試,也就是A業(yè)務(wù)系統(tǒng)對外提供webservice接口,系統(tǒng)B調(diào)用webservice接口和A業(yè)務(wù)系統(tǒng)通信,需要對接口的各個操作進行壓力測試。


      由于是標(biāo)準(zhǔn)的webservice接口,我首先想到的就是使用java直接調(diào)用這些接口進行測試,因為loadrunner支持java Vuser這個強大的協(xié)議。


      下面選取了兩個操作的腳本進行總結(jié)分析:


      一、創(chuàng)建操作


      腳本如下:


      1. //前面這些import是需要的外部依賴組件,就是java調(diào)用webservice接口需要的一些jar包,不懂網(wǎng)上查下或者問問開發(fā)人員就知道了。注意,所需要的jar包請下載到loadrunner所在機器本地,然后在Run-time Setting中的ClassPath中導(dǎo)入這些需要的jar包;當(dāng)然ClassPath中也要記得導(dǎo)入本地JDK的bin/lib下面的dt.jar包和tools.jar包。  
      1. import lrapi.lr;  
      2. import java.io.File;  
      3. import java.io.IOException;  
      4. import java.rmi.RemoteException;  
      5. import javax.xml.rpc.ParameterMode;  
      6. import javax.xml.rpc.ServiceException;  
      7. import org.apache.axis.client.Call;  
      8. import org.apache.axis.client.Service;  
      9. import org.apache.axis.encoding.XMLType;  
      10. import org.apache.commons.io.FileUtils;  
      11. //加密發(fā)送出去的XML文件使用,因為腳本中發(fā)送出去的文件需要加密,所以這里要導(dǎo)入加密包  
      12. //import sun.misc.BASE64Decoder;  
      13. import sun.misc.BASE64Encoder;  
      14.   
      15. public class Actions  
      16. {  
      17.   
      18.     public int init() {  
      19.         return 0;  
      20.     }//end of init  
      21.   
      22.   
      23.     public int action() {  
      24.         //webservice的地址,A業(yè)務(wù)系統(tǒng)部署后對外發(fā)布的地址  
      25.         String endpoint = "http://192.168.0.116:8080/xxxu-webapp/ws/xxxxUService";  
      26.         String fileurl="d:\\test\\index.xml";//創(chuàng)建動作接收的主要業(yè)務(wù)數(shù)據(jù)內(nèi)容是一個XML文件格式的字符串,字符串的內(nèi)容需要由XML文件轉(zhuǎn)換而來;  
      27.                 String oparatorid="yyyy";//另外一個參數(shù),操作者用戶名,需要具有對應(yīng)接口操作的權(quán)限;  
      28.         try{  
      29.             //把本地的XML文件讀入轉(zhuǎn)換成字符串處理,下面一段完全是業(yè)務(wù)操作  
      30.             File xmlfile=new File(fileurl);  
      31.             String xmlstring1=FileUtils.readFileToString(xmlfile,"UTF-8");  
      32.             //替換字符串里面的指定值后進行參數(shù)化,每次提交的參數(shù)值都是不同的;  
      33.             String xmlstring2=xmlstring1.replaceAll("abcdefg","<NewParam_2>");  
      34.             //替換字符串后參數(shù)化,保證提交的合同能隨機存儲在不同的文件夾中;  
      35.             String xmlstring3=xmlstring2.replaceAll("departyue","<NewParam_3>");  
      36.             xmlstring3=xmlstring3.replaceAll("departady","<NewParam_4>");  
      37.             BASE64Encoder encoder = new BASE64Encoder();  
      38.             xmlstring3=encoder.encode(xmlstring3.getBytes("UTF-8"));  
      39.   
      40.                         //事務(wù)開始,java操作webservice  
      41.             lr.start_transaction("Createdoc01");  
      42.   
      43.             Service service=new Service();  
      44.             Call call=(Call)service.createCall();  
      45.             call.setTargetEndpointAddress(new  java.net.URL(endpoint));//指定webservice的地址  
      46.             call.setOperationName("createDoc");指定需要操作webservice中哪個操作  
      47.             call.addParameter("operatorID", XMLType.XSD_STRING, ParameterMode.IN);//<span style="color:#ff0000;">指定對應(yīng)操作需要的參數(shù)</span>  
      48.             call.addParameter("docXml", XMLType.XSD_STRING, ParameterMode.IN);  
      49.       
      50.             call.setReturnType(XMLType.XSD_LONG);//設(shè)置操作返回值的類型,需要搞清楚webservice對應(yīng)操作返回值是什么類型  
      51.             Long result=(Long)call.invoke(new Object[]{oparatorid,xmlstring3});//調(diào)用webservice  
      52.             System.out.println(result);  
      53.             if(result == 0){  
      54.                 System.out.println("ucontent 返回:"+result+"created sucessfull");  
      55.                 lr.end_transaction("Createdoc01", lr.PASS);  
      56.                 }  
      57.             else if(result == 1103){  
      58.                 System.out.println("ucontent 返回:"+result+" XML格式錯誤");  
      59.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      60.             else if(result == 1101){  
      61.                 System.out.println("ucontent 返回:"+result+" 當(dāng)前用戶不存在");  
      62.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      63.             else if(result == 1102){  
      64.                 System.out.println("ucontent 返回:"+result+" 當(dāng)前用戶權(quán)限不足");  
      65.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      66.             else if(result == 1201){  
      67.                 System.out.println("ucontent 返回:"+result+" 指定文檔類型不存在");  
      68.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      69.             else if(result == 1202){  
      70.                 System.out.println("ucontent 返回:"+result+" 指定的索引不存在");  
      71.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      72.             else if(result == 1301){  
      73.                 System.out.println("ucontent 返回:"+result+" 文檔重名");  
      74.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      75.             else if(result == 1302){  
      76.                 System.out.println("ucontent 返回:"+result+" 索引值轉(zhuǎn)換失敗");  
      77.                 lr.end_transaction("Createdoc01", lr.PASS);}  
      78.             else   
      79.                 {System.out.println("ucontent 返回:"+result+" 其它錯誤");  
      80.                 lr.end_transaction("Createdoc01", lr.FAIL);}  
      81.         } catch(Exception e){  
      82.             e.printStackTrace();  
      83.             System.out.println("created faild");  
      84.             }  
      85.         return 0;  
      86.     }//end of action  
      87.   
      88.   
      89.     public int end() {  
      90.         return 0;  
      91.     }//end of end  
      92. }  

      二、讀取操作


      1. import lrapi.lr;  
      2. import java.io.File;  
      3. import java.io.IOException;  
      4. import java.rmi.RemoteException;  
      5. import javax.xml.rpc.ParameterMode;  
      6. import javax.xml.rpc.ServiceException;  
      7. import org.apache.axis.client.Call;  
      8. import org.apache.axis.client.Service;  
      9. import org.apache.axis.encoding.XMLType;  
      10. import org.apache.commons.io.FileUtils;  
      11. import javax.xml.namespace.QName;  
      12. import org.apache.axis.encoding.ser.BeanDeserializerFactory;  
      13. import org.apache.axis.encoding.ser.BeanSerializerFactory;  
      14. //導(dǎo)入系統(tǒng)中中自定義的返回結(jié)果類  
      15. import com.xxx.dm6p.web.server.webservice.xxx.domain.Result;  
      16.   
      17.   
      18. public class Actions  
      19. {  
      20.   
      21.     public int init() {  
      22.         return 0;  
      23.     }//end of init  
      24.   
      25.   
      26.     public int action() {  
      27.         //webservice的地址   
      28.         String endpoint = "http://192.168.0.193:8080/dm6p-webapp/ws/xxxUContentService";  
      29.         //操作者的ID  
      30.         String oparatorid="yinzg";  
      31.         //文檔存在ucontent中的docid  
      32.         String docid="";  
      33.         try{  
      34.                 Service service=new Service();  
      35.                 Call call=(Call)service.createCall();  
      36.             QName qn = new QName("urn:xxxUContentService","ResultDoc");  
      37.             call.registerTypeMapping(Result.class,qn,new BeanSerializerFactory(Result.class,qn),  
      38.             new BeanDeserializerFactory(Result.class,qn));  
      39.   
      40.                 call.setTargetEndpointAddress(new  java.net.URL(endpoint));  
      41.             call.setOperationName("readDoc");  
      42.             call.addParameter("operatorID", XMLType.XSD_STRING, ParameterMode.IN);  
      43.             call.addParameter("docID", XMLType.XSD_STRING, ParameterMode.IN);  
      44.             call.setReturnClass(Result.class);  
      45.             Result res=(Result)call.invoke(new Object[]{oparatorid,docid});  
      46.             call.invoke(new Object[]{oparatorid,docid});  
      47.             //返回的是一個result,包含int結(jié)果碼、List<String>類型的ID列表,這個類型是系統(tǒng)自己定義,所以在import的時候需要導(dǎo)入包含該類型的包com.xxx.dm6p.web.server.webservice.xxx.domain.Result;  
      48.             int result_code=res.getCode();  
      49.             System.out.println(result_code);  
      50.                   
      51.             if(result_code == 0){  
      52.                 System.out.println("ucontent 返回:"+result_code+"created sucessfull");  
      53.                 System.out.println(res.getCode());  
      54.                 for(String docid: result.getDocIDs())  
      55.                     {System.out.println(docid);}  
      56.             }  
      57.             else if(result_code == 1101){  
      58.                 System.out.println("ucontent 返回:"+result_code+"當(dāng)前用戶不存在");}  
      59.             else if(result_code == 1102){  
      60.                 System.out.println("ucontent 返回:"+result_code+"當(dāng)前用戶沒有操作權(quán)限");}  
      61.             else if(result_code == 1303){  
      62.                 System.out.println("ucontent 返回:"+result_code+"指定的文檔不存在");}  
      63.             else System.out.println("ucontent 返回:"+result_code+"其它錯誤");   
      64.             } catch(Exception e){  
      65.             e.printStackTrace();  
      66.             System.out.println("操作失敗");  
      67.         }  
      68.   
      69.         return 0;  
      70.     }//end of action  
      71.   
      72.   
      73.     public int end() {  
      74.         return 0;  
      75.     }//end of end  
      76. }  







       


      使用java Vuser協(xié)議的幾點要求:


      1.不管什么系統(tǒng)要做性能測試,都必須對業(yè)務(wù)了解清楚,特別是需要開發(fā)涉及到一些接口和內(nèi)部操作的腳本,更需要對系統(tǒng)業(yè)務(wù),內(nèi)部結(jié)構(gòu),數(shù)據(jù)流向等了解的非常清楚;比如我編寫這個接口的測試腳本,我首先要清楚接口中方法需要的參數(shù)要求,參數(shù)傳入后系統(tǒng)怎么處理,最后返回什么結(jié)果等;


      2.懂一點簡單的java語言,當(dāng)然你不懂可以百度了!保證你寫的java腳本沒有性能問題;


      3.使用java Vuser協(xié)議要注意run-time setting的設(shè)置,包括classpath和java jvm,classpath保證腳本能正常運行,JVM保證客戶端的腳本能更好的運行;


      4.loadruner的分步運行也能調(diào)試java腳本,但是在專門的編譯工具上調(diào)試通過后再copy過來會更方便;


       


       



        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多