




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、使用Loadrunner进行http接口压力测试业务描述:在业务系统里进行查询操作,查询的结果是通过请求http接口,从系统中处理并将结果以json字符串返回。使用Loadrunner对此类接口进行压力测试并记录相关的性能指标数据:1 .安装Loadrunner本次测试过程使用Loadrunner11.0版本。2 .部署环境1 .接口服务器一台;2 .用于运行Loadrunner的压力测试机1台或N台,在条件允许下,尽可能提供高配置的CPU和内存。3 .接口服务器和压力测试机建议应部署于同一个局域网内,否则测试过程和结果将受到网络带宽因素的影响无法顺利进行。三.编写测试脚本方法一.通过java
2、编写测试类,以jar包的方式引入Loadrunner进行测试。优点:便于解析接口响应结果,同时避免由于LR脚本编写不规范或配置问题,导致测试过程引发的未知错误。条件:运行loadrunner的机器需要安装jdk1.6的版本。1.编写java测试类:CTLPTest.java,如下代码1 packagecom;23 importjava.io.InputStream;4 .HttpURLConnection;5 .URL;6 importjava.util.Random;78 publicclassCTLPTest9 10 publicstaticvoidmain(Stringargs)11 1
3、2 CTLPTestlbs=newCTLPTest();13 StringltpUrl=lbs.ltpRequestUrl();14 System.out.println(ltpUrl);15 System.out.println(lbs.ltpRequest(ltpUrl);16 )1718 publicintltpRequest(StringltpRequestUrl)19 20 intreturnCount=-1;21 try22 23 URLurl=newURL(ltpRequestUrl);24 /http连接25 HttpURLConnectionhttp=(HttpURLConn
4、ection)url.openConnection();26 http.setUseCaches(false);27 http.connect();28 /获取http响应流29 InputStreamin=http.getInputStream();30 /解析响应流31 byteb=newbytein.available();32 in.read(b);33 /将响应流转换成字符串34 Stringres=newString(b);35根据实际情况,判断响应结果,并设置返回值36intof=res.indexOf("sucess");37if(of<0)38ret
5、urnCount=-1;39else40returnCount=1;4142catch(Exceptione)43returnCount=-1;4445returnreturnCount;464748publicStringltpRequestUrl()49StringBuilderparam=newStringBuilder("05:8055/CTLP/LtpRequest.json?Imsi=");50param.append("userid-1");51param.append("&appNa
6、me=LBS&Apikey=D39hr1FgplZSjV2eNVW71wvbYbl8Mip4");52 returnparam.toString();53 54 ViewCode2 .将测试类导出为jar包:LTPRequest.jar过程略.3 .Loadrunner创建java测试类解1LoadRunnerCmjuration-Help-LoflcRunnfrLauncherCne凯e/EditScriptsWhat'sri&.vinVuGenRunLoadTestsAnaty;eTe&tResultsLeadTestingprftventscos
7、tlyandpainfulperformsneeproblemsinproductionbydetectingbottriQ受beforeaav&tem酊upgradet&deployed.Bycreatingpredictionworkloadsor回svs.terrsinQAorstagingyouCanmessurgthepfirforrnanccofcritica<tustnesspracessasuncercadandpinpointbottlenecksfarrapidresnhution.HPsoftware'sLcadrunnerprcvHesco
8、mprehensivesupp-ertfDrthenr&sicsr.monprotacQlssrdteChfioInits-includngER.P/CRMW«b,JZEEj'.MET,XML.NfTvjirelessandstreamirgmedia-3Iiowing(Tgroupstousasingleproductforloadandperformancetotingofai:enterpriseappicationsImptementipganeffectiveleadtestingproces-swithHPsoftware'sLfladRumerh
9、elpsensurethatne;vcrupgradedapplicaticmeetser/iee屏丫出objectivesanddepto/toproductionwithnoperfernnance岳山口诧be.Enhanc&4supportfqrY.eb20andR14sppTJewAjaxTryGhentprotocolInrrrxiderncrnulatinffuseractivitywithinawebbro NewprSocMsforMcrcftoft5"triigIHacommunicattingoverHTTP. EnhanceddataformatBwor
10、t(eLg.JSCFeatureVideos:Cj.iIntrcducti。ntcAjaz丁uClientciotc31瑞didianfeJdaLafcrmatsupportinWeb匿3m廿网hiprMnsW匿JovdoverHTTPprotocolWhat'sNewInController EntsncecfSurvitRLevelAgreementsfcsscreen Controfc-rnowallowscustomizingtheisines&urenwntsTaaccommodateyourtesFeatureVideos-:国Servicelevelagreeme
11、ntpercenlile总up昌CLstcmizemonitordefaultcdunteriis-tWfiat'sNewinAnalysisEnhen。同rep«rtingcapabiiities;Fulycustamizablereporttemp-latfts>«TheabilitytomulomatiEllyg启力eraterepoFeatureVideos.:Learnmereatoutloadtestmg搭NewreportingcapabFiitifsPert9rmaric&ardLsstilityimpro.图2:创建java协议脚本1
12、朗HPVirtualUserGenerator-StartPag?:FieViewToofcWindowHelp,每十口/vIa:1-Startftecurd,.|:LiillTasks|JScript|口StartPag1%,LodRunrifir-VirfudlUs6rGeneratorWelcometotheVirtualUserGeneratorInaperformancetestingorapplicationmanagementenvir&rmentHPapplicationsreplacehumanus&rsworkingonphysicalmachineswit
13、h'rtual"users,orVusers.TheVirtualUserGfieratof(VuGen)worksonarecordand-playbackprincipleAsyouwalkthroughabusinessprcrfSsnnyourappiication.VuGenrecordsyouractionsandcreatesautomatedscriptswhichjiffTmthefoundationforyoirrbusinesstechnologyoptimization画回阿区NewScriptNew-g齿Ia巨匚生IMprutgol邂JavaOver
14、HTTP幻Web(HTTP.,HTML)jgpJaaVuserOpgn&cwE鼻cipt国LTPRequestJ=feeeeee耳LTPRequeslJjWIFtLOCALTEST1sWlFLTesi"图3:创建java协议脚本2图4:创建java协议脚本3HP*rtumlUserGenerator-noname2-JavaVuserFileEditViewInsertVuserActionsToolsWindowHelp奥»JavaFunction嗯.即;fjTasksI口SaiptJQf5tr1:Pag电1nonameZ-a炉aVuser|C1vuser-ini
15、tActionsyuserend/*LoadRiinn&rJavascript.(Build:_buiLd_nmnt)e:*ScriptDescrlptlon:*#/importIrapi.Ir;publicclassActions!publicintinit()throwsThrowable!return0;1Z/f&lld6fLEiltI-publicintactionC)throTSThxovatilereturn0;Avenelofactionpublicint3nd0throvsThrovablc!return0;/endofend图5:设置环境变量翔HPVirtua
16、lUserGenerator-VLS&rArtinsTool?WindowH囱pStartPagenonaine?-Javuser_inilCActions年'wiserendFileEdrtViewIrirt:且国-巴|q:JStartRecQfding.Ctri+R:ks口Scripta:RunF511IjIJStopPauseCtkF5script.(Build:_build_nujiibE蠡CampiIeShift十F5>n:&RunStep2VStepF10更PameterLEt.Ctrl+4_SonScriptforCorrelations5匚也for
17、Corretons(atCursor)CreateCorrelationCtgFEAlt+Fa3.nit()throwsThrowablejrn0;1白Run-TirneSettings-.图6:设置安装的jdk位置目录public1/"endpublicJ/endintaction0throwsThrowablereturn0;ofactionintcndOthrQwsThrwablcreturn0;ofendiuporput'liLoadE-unnerJ-avascript.CBuild:_hu士lH_ntmEier_)Run-timeSettingsGeneralhPa
18、cing卜LogThinkTimeAdditionalattributesi-MkcellaneouJavaEnyirerirftefttS&ttingjJaaEnvifanmentSettings:匚博野puthClasspathEntries:EC:Ma¥ri(*1.6L0_35MbElC:Mavai*16.0_35Mibdlioi明C:JavaW.6.0_35Miblools.iarClLasspath-JarvaVMUjcDefaultsAddJARorZIPfileorOnce!图8:编写脚本内容国1 packagecom;23 importjava.io.Inpu
19、tStream;4 .HttpURLConnection;5 .URL;67 publicclassCTLPTest8 publicstaticvoidmain(Stringargs)10 11 CTLPTestlbs=newCTLPTest();12 StringItpUrl=lbs.ltpRequestUrl();13 System.out.println(ltpUrl);14 System.out.println(lbs.ltpRequest(ltpUrl);15 1617 publicintltpRequest(StringltpRequestUrl)18 19 intreturnCo
20、unt=-1;20 try21 22 URLurl=newURL(ltpRequestUrl);23 /http连接24 HttpURLConnectionhttp=(HttpURLConnection)url.openConnection();25 http.setUseCaches(false);26 http.connect();27 /获取http响应流28 InputStreamin=http.getInputStream();29 /解析响应流30 byte口b=newbytein.available();31 in.read(b);32 /将响应流转换成字符串33 Stringr
21、es=newString(b);34 根据实际情况,判断响应结果,并设置返回值35 booleanof=res.contains(""state":1");36 if(of)37 returnCount=1;38 else39 returnCount=0;40 41catch(Exceptione)42returnCount=-1;43)44returnreturnCount;45)4647publicStringltpRequestUrl()48StringBuilderparam=newStringBuilder("http:/192.16
22、8.100.205:8055/CTLP/LtpRequest.json?Imsi=");49param.append("userid-1");50param.append("&appName=LBS&Apikey=D39hr1FgplZSjV2eNVW71wvbYbl8Mip4");51returnparam.toString();52)53)ViewCode图9:试运行,查看结果因HPVirtualG&nrator-LtpRequ9stScripL-ShrtPmgmLtpRequestRun(F5)vaVuserLBe
23、vuserjnif-Actionsq'vtjser_ef)dReplayLegStartingactionvuser_i.nit,Endingactionvuser_inLt.Running7user.Startingiteration1.Eartod.endedwith"Fas号"status(Duration:0.Q929).StartingactionActiQns.fQtify;TransactionLTPRequestTransactionLTPRequestndingactionActions.Endingiteration1.EndingVtiser.
24、Startingactionvuser_end.Endingactionvuser_end.VuserTerminated.说明:至此,完成了java脚本的编写和基本测试,接下来我们就可以使用loadrunner的进行压力测试了。四.压力测试图1:选择压力测试HPLoadRunner11.00LoodRunnerflewLoadRunnerLicenseZziagnosbcsforJ2ESetupCreate/EditScriptsRunLoadTestAnalyzeTestResultsVJhafsNewiEchancsdSLippor NewAiaxTni1emulatinouse) Mf
25、rv;protocciscommurncatth EnhanceddaLiLoadlG&*inGprerentscostlyandpainfulperformanceprnbi&ms-inproductKinBy。号悔ctingbottlenecks-bofni官审systemarupgradekdsplo/ed.Bycreatifigproductionworklaa-dsanITsystemsinQAorstaging,youcanmeasurethep-erfcrrnarceofcriticalbusinessprocessesunderbadandpiipontbottlenecksforrapdresolution.HPsoftware'sLuadRunnerprovidfscomprehtnsiveMpportfertilen»tccmmanprotocolan-dtoehnotogies-incMfciERP/CRM,胃它b.2EE*ET,XML,NEwirelessand.sLre«mmqmfrdifl-allowmqITqroupsIntroductionAdvanceddiSilverIghtprJa7acverP'-ir-i-irrtand-t-B
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 抖音火花MCN机构与KOL合作内容收益分成协议
- 影视特效化妆工作台租赁及配套材料供应协议
- 脑机接口技术在虚拟现实教育软件研发中的合作合同
- 渠道分销合作伙伴战略规划协议
- 留学中介服务及海外院校生活适应辅导协议
- 海上救援直升机停机坪租赁及救援服务支持合同
- 专业影视替身意外伤害赔偿补充合同范本
- 绿色农业连锁加盟合作协议书
- 基本农田保护与生态循环种植承包协议
- 共享办公空间品牌推广合作协议
- 和歌手合作合同协议
- 甘肃酒泉事业单位考试笔试含答案2024
- 七下生物考试试卷及答案
- 财产险试题库及答案
- 湖南新高考教学教研联盟暨长郡二十校联盟2025届高三年级第二次联考物理试题及答案
- 商品出库管理规范
- 2025山东烟台市蓬莱区城市建设投资集团有限公司招聘22人笔试参考题库附带答案详解
- 建筑劳务公司人事管理制度
- 应聘人员登记表
- 2024年山东省公共卫生临床中心招聘笔试真题
- 2025年全国二模日语试题及答案
评论
0/150
提交评论