jmeter+java vuser+rmi+dubbo脚本
dubbo协议
package com.howbuy; import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.java.sampler.JavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.howbuy.acccenter.facade.trade.opentxacctwithtenpay.OpenTxAcctWithTenpayFacade; import com.howbuy.acccenter.facade.trade.opentxacctwithtenpay.OpenTxAcctWithTenpayRequest; import com.howbuy.common.facade.BaseResponse; public class lct_1_01OpenTxAcctWithTenpay implements JavaSamplerClient { static ClassPathXmlApplicationContext context; public Arguments getDefaultParameters() { Arguments params = new Arguments(); params.addArgument("setInvstType", "1"); params.addArgument("setCustName", "123"); params.addArgument("setIdType", "0"); params.addArgument("setIdNo", "342422198809044857"); params.addArgument("setMobile", "13120898767"); params.addArgument("setCorpAcctNo", "00113"); params.addArgument("setEmail", "353566002@qq.com"); params.addArgument("setPostCode", "0334"); params.addArgument("setAddress", "tttttt"); params.addArgument("setHomeTelNo", "021-3456788"); params.addArgument("setOutletCode", "W20151111"); params.addArgument("setDisCode", "LCT00K001"); params.addArgument("setTradeChannel", "2"); params.addArgument("setAppDt", "20160813"); params.addArgument("setAppTm", "093600"); params.addArgument("logs", "false"); return params; } public SampleResult runTest(JavaSamplerContext arg0) { SampleResult result = new SampleResult(); try { /* result.sampleStart(); */ context.start(); OpenTxAcctWithTenpayFacade qtcq = (OpenTxAcctWithTenpayFacade) context .getBean("OpenTxAcctWithTenpayFacade"); OpenTxAcctWithTenpayRequest request = new OpenTxAcctWithTenpayRequest(); request.setInvstType(arg0.getParameter("setInvstType")); request.setCustName(arg0.getParameter("setCustName")); request.setIdType(arg0.getParameter("setIdType")); request.setIdNo(arg0.getParameter("setIdNo")); request.setMobile(arg0.getParameter("setMobile")); request.setCorpAcctNo(arg0.getParameter("setCorpAcctNo")); request.setEmail(arg0.getParameter("setEmail")); request.setPostCode(arg0.getParameter("setPostCode")); request.setAddress(arg0.getParameter("setAddress")); request.setHomeTelNo(arg0.getParameter("setHomeTelNo")); request.setOutletCode(arg0.getParameter("setOutletCode")); request.setDisCode(arg0.getParameter("setDisCode")); request.setTradeChannel(arg0.getParameter("setTradeChannel"));// request.setAppDt(arg0.getParameter("setAppDt")); request.setAppTm(arg0.getParameter("setAppTm")); result.sampleStart(); //System.out.println(request.getIdNo()); //System.out.println("kaishi----"); BaseResponse response = qtcq.execute(request); String msg=request.getIdType()+request.getIdNo().substring(12,18); msg=response.toString()+msg; result.setResponseMessage(msg); //System.out.println("jieshu----"); result.setSuccessful(true); /*if (response.getReturnCode().equals("5220120")) result.setSuccessful(true); else { result.setSuccessful(false); }*/ /*if (response.getReturnCode().equals("0000000")) result.setSuccessful(true); else { result.setSuccessful(false); }*/ if (arg0.getParameter("logs").equals("true")) { System.out.println(arg0.getParameter("OperCode")); System.out.println(response); System.out.println(response.getReturnCode()); System.out.println(response.getDescription()); } /* * if (response.getReturnCode().equals("0000000")) * result.setSuccessful(true); else { result.setSuccessful(false); } */ } catch (Exception e) { System.out .println("=======================Exception Start======================="); System.out.println("Exception raise!!!"); System.out.println(e.getMessage()); result.setSuccessful(false); System.out .println("=======================Exception End======================="); } finally { result.sampleEnd(); } return result; } public void setupTest(JavaSamplerContext arg0) { context = new ClassPathXmlApplicationContext( new String[] { "xinggong-search-dubbo-consumber.xml" }); } public void teardownTest(JavaSamplerContext arg0) { } public static void main(String[] args) { } }
其中xml为:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 logger="slf4j"--> <dubbo:application name="lct" /> <!-- 使用zookeeper注册中心暴露服务地址 集群至少要1/2的节点存活 --> <!--<dubbo:registry address="zookeeper://192.168.221.31:2181" /> --> <dubbo:registry address="zookeeper://10.11.153.10:2181" /> <dubbo:consumer timeout="5000" /> <dubbo:reference id="OpenTxAcctWithTenpayFacade" interface="com.howbuy.acccenter.facade.trade.opentxacctwithtenpay.OpenTxAcctWithTenpayFacade"/> </beans>
RMI
package com.howbuy; import java.math.BigDecimal; import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.java.sampler.JavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.howbuy.hsb.hsbclient.HSBClient; import com.howbuy.hsb.txio.BaseTxResponse; import com.howbuy.txio.fds3.fund.trade.subsforlct.FundSubsForLctRequest; public class lct_1_02FundSubsForLctReques implements JavaSamplerClient { static ClassPathXmlApplicationContext context; public Arguments getDefaultParameters() { Arguments params = new Arguments(); params.addArgument("setAppCode", "20"); params.addArgument("setTradeChannel", "2"); params.addArgument("setRegionCode", "web"); params.addArgument("setOutletCode", "W20151111"); params.addArgument("setOperCode", "00"); params.addArgument("setOperatorNo", "43434"); params.addArgument("setDisCode", "LCT00K001"); params.addArgument("setExternalDealNo", "123456987946679861"); params.addArgument("setCustNo", "1101557447"); params.addArgument("setAppAmt", "2000"); params.addArgument("setCorpAcctNo", "00123"); params.addArgument("setFundCode", "530008"); params.addArgument("setAcceptRisk", "1"); params.addArgument("setAppDt", "20160819"); params.addArgument("setAppTm", "132700"); params.addArgument("setCustCertIdentity", "0042155"); params.addArgument("logs", "false"); return params; } public SampleResult runTest(JavaSamplerContext arg0) { SampleResult result = new SampleResult(); try { /* result.sampleStart(); */ FundSubsForLctRequest request = new FundSubsForLctRequest(); request.setAppCode(arg0.getParameter("setAppCode")); request.setTradeChannel(arg0.getParameter("setTradeChannel")); request.setRegionCode(arg0.getParameter("setRegionCode")); request.setOutletCode(arg0.getParameter("setOutletCode")); request.setOperCode(arg0.getParameter("setOperCode")); request.setOperatorNo(arg0.getParameter("setOperatorNo")); request.setDisCode(arg0.getParameter("setDisCode")); request.setExternalDealNo(arg0.getParameter("setExternalDealNo")); request.setCustNo(arg0.getParameter("setCustNo")); request.setAppAmt(new BigDecimal(arg0.getParameter("setAppAmt"))); request.setCorpAcctNo(arg0.getParameter("setCorpAcctNo")); request.setFundCode(arg0.getParameter("setFundCode")); request.setAcceptRisk(arg0.getParameter("setAcceptRisk"));// request.setAppDt(arg0.getParameter("setAppDt")); request.setAppTm(arg0.getParameter("setAppTm")); request.setCustCertIdentity(arg0.getParameter("setCustCertIdentity")); result.sampleStart();//事务开始 //System.out.println(request.getIdNo()); //System.out.println("kaishi----"); BaseTxResponse response = HSBClient.getInstance().callService( request, BaseTxResponse.class); result.setResponseMessage(response.toString()); //System.out.println("jieshu----"); result.setSuccessful(true); /*if (response.getReturnCode().equals("5220120")) result.setSuccessful(true); else { result.setSuccessful(false); }*/ /*if (response.getReturnCode().equals("0000000")) result.setSuccessful(true); else { result.setSuccessful(false); }*/ if (arg0.getParameter("logs").equals("true")) { //System.out.println(arg0.getParameter("OperCode")); System.out.println(response); System.out.println(response.getReturnCode()); System.out.println(response.getDescription()); } // if (response.getReturnCode().equals("0000000")) // result.setSuccessful(true); else { result.setSuccessful(false); } } catch (Exception e) { System.out .println("=======================Exception Start======================="); System.out.println("Exception raise!!!"); System.out.println(e.getMessage()); result.setSuccessful(false); System.out .println("=======================Exception End======================="); } finally { result.sampleEnd(); } return result; } public void setupTest(JavaSamplerContext arg0) { } public void teardownTest(JavaSamplerContext arg0) { } public static void main(String[] args) { } }
hsb.xml配置文档
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="myConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:globals.properties</value> </list> </property> <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean> <bean id="hsbClient" class="com.howbuy.hsb.hsbclient.HSBClient" /> <bean id="hsbServer" class="com.howbuy.hsb.hsbserver.HSBServer"/> <bean id="fdNetConfig" class="com.howbuy.hsb.txio.NetConfig"> <property name="recognizers"><value>20</value></property> <property name="communMode"><value>3</value></property> <property name="timeout"><value>0</value></property> <property name="ctxPath"><value>context/fds3/online-service.xml</value></property> <property name="local"><value>false</value></property> <!--<property name="ip"><value>192.168.221.62</value></property>--> <!--<property name="ip"><value>192.168.220.150</value></property>--> <property name="ip"><value>192.168.220.151</value></property> <property name="port"><value>13242</value></property> <property name="communPort"><value>13244</value></property> <!--<property name="port"><value>13022</value></property> <property name="communPort"><value>13024</value></property>--> <property name="endpointSelectionPolicy"><value>org.softamis.cluster4spring.support.invocation.ShuffleEndpointSelectionPolicy</value></property> </bean> </beans>