完成提交订单这个dubbo接口的Java脚本编辑,开发提供的内容:
1、具体的方法及参数
接口类:com.gome.coupon.interfaces.dubbo.IPromotionAndCouponManager
方法:commitPromotionAndCoupon(String orderIds, List<CommitCouponsAndPromotionParam> list)
参数:参数1:"", 参数2:将附件提交订单.json转成List< CommitCouponsAndPromotionParam >
2、提交订单.json
[ { "couponCodes": [], "discount": 10, "products": [ { "amount": 101, "apportion": -5.4, "brandId": "480001", "catagoryInfo": { "oneCategory": "cat18000001", "threeCategory": "cat18000771", "twoCategory": "cat18000041" }, "commerceItemId": "2512755755", "discount": 0, "id": "8003756105", "promIdSet": [], "promotionId": "231883", "quantity": 1 }, { "amount": 86, "apportion": -4.6, "brandId": "480001", "catagoryInfo": { "oneCategory": "cat18000001", "threeCategory": "cat18000771", "twoCategory": "cat18000041" }, "commerceItemId": "2512755751", "discount": 0, "id": "8003756107", "promIdSet": [], "promotionId": "231883", "quantity": 1 } ], "promIdSet": [ "231883" ], "shippingGroupId": "2569605509", "shopNo": "80007143", "userId": "202693184" } ]
3、服务消费配置
<dubbo:application name="npop_logistics_query" owner="dongchao" />
<dubbo:protocol name="dubbo" port="-1"/>
<dubbo:registry address="zookeeper://10.58.57.58:2181?backup=10.58.57.54:2181,10.58.57.48:2181" id="defaultZookeeperAddress" />
<dubbo:reference id="promotionAndCouponManager" interface="com.gome.coupon.interfaces.dubbo.IPromotionAndCouponManager" registry="defaultZookeeperAddress " group="npop-coupon-front" check="false" timeout="6000"/>
<dubbo:reference id="couponAndBatchManager" interface="com.gome.coupon.interfaces.dubbo.ICouponAndBatchManager" registry="defaultZookeeperAddress " group="npop-coupon-front" check="false" timeout="6000"/>
4、服务引用Jar包
<dependency>
<artifactId>promotion-interfaces</artifactId>
<version>1.0.9-SNAPSHOT</version>
<name>promotion-interfaces</name>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
操作步骤:
1、spring-dubbo-consumer.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://code.alibabatech.com/schema/dubbo 8 http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 9 10 <dubbo:application name="npop_logistics_query" owner="dongchao" /> 11 <dubbo:protocol name="dubbo" port="-1"/> 12 <dubbo:registry address="zookeeper://10.58.57.58:2181?backup=10.58.57.54:2181,10.58.57.48:2181" id="defaultZookeeperAddress" /> 13 14 <dubbo:reference id="promotionAndCouponManager" interface="com.gome.coupon.interfaces.dubbo.IPromotionAndCouponManager" registry="defaultZookeeperAddress " group="npop-coupon-front" check="false" timeout="6000"/> 15 <dubbo:reference id="couponAndBatchManager" interface="com.gome.coupon.interfaces.dubbo.ICouponAndBatchManager" registry="defaultZookeeperAddress " group="npop-coupon-front" check="false" timeout="6000"/> 16 </beans>
2、pop.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <!-- <groupId>com.gome.pop</groupId> 5 <artifactId>pop-external-commom</artifactId> 6 <packaging>war</packaging> 7 <version>1.0.4-SNAPSHOT</version> 8 <name>pop-external-commom Maven Webapp</name> 9 <url>http://maven.apache.org</url>--> 10 11 <groupId>load.coo8.coupon</groupId> 12 <artifactId>coo8.coupon</artifactId> 13 <version>1.0-SNAPSHOT</version> 14 15 <properties> 16 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 17 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 18 <spring.version>4.1.0.RELEASE</spring.version> 19 </properties> 20 21 22 <dependencies> 23 24 <dependency> 25 <groupId>com.gome.pop</groupId> 26 <artifactId>pop-common</artifactId> 27 <version>STABLE-1.0.18</version> 28 <exclusions> 29 <exclusion> 30 <groupId>com.101tec</groupId> 31 <artifactId>zkclient</artifactId> 32 </exclusion> 33 <exclusion> 34 <groupId>org.jboss.netty</groupId> 35 <artifactId>netty</artifactId> 36 </exclusion> 37 <exclusion> 38 <groupId>org.slf4j</groupId> 39 <artifactId>jcl-over-slf4j</artifactId> 40 </exclusion> 41 <exclusion> 42 <groupId>cglib</groupId> 43 <artifactId>cglib</artifactId> 44 </exclusion> 45 <exclusion> 46 <artifactId>coupon-interfaces-simple</artifactId> 47 <groupId>coupon-interfaces</groupId> 48 </exclusion> 49 </exclusions> 50 </dependency> 51 <dependency> 52 <groupId>com.gome.npop</groupId> 53 <artifactId>promotion-interfaces</artifactId> 54 <version>1.0.9-SNAPSHOT</version> 55 <exclusions> 56 <exclusion> 57 <artifactId>*</artifactId> 58 <groupId>*</groupId> 59 </exclusion> 60 </exclusions> 61 </dependency> 62 63 64 65 <!--spring相关配置--> 66 <dependency> 67 <groupId>org.springframework</groupId> 68 <artifactId>spring-core</artifactId> 69 <version>${spring.version}</version> 70 </dependency> 71 <dependency> 72 <groupId>org.springframework</groupId> 73 <artifactId>spring-aop</artifactId> 74 <version>${spring.version}</version> 75 </dependency> 76 <dependency> 77 <groupId>org.springframework</groupId> 78 <artifactId>spring-beans</artifactId> 79 <version>${spring.version}</version> 80 </dependency> 81 <dependency> 82 <groupId>org.springframework</groupId> 83 <artifactId>spring-context</artifactId> 84 <version>${spring.version}</version> 85 </dependency> 86 <dependency> 87 <groupId>org.springframework</groupId> 88 <artifactId>spring-expression</artifactId> 89 <version>${spring.version}</version> 90 </dependency> 91 <dependency> 92 <groupId>org.springframework</groupId> 93 <artifactId>spring-tx</artifactId> 94 <version>${spring.version}</version> 95 </dependency> 96 97 <!--zookeeper--> 98 <dependency> 99 <groupId>com.github.sgroschupf</groupId> 100 <artifactId>zkclient</artifactId> 101 <version>0.1</version> 102 </dependency> 103 104 <dependency> 105 <groupId>org.apache.zookeeper</groupId> 106 <artifactId>zookeeper</artifactId> 107 <version>3.4.6</version> 108 </dependency> 109 110 <dependency> 111 <groupId>com.alibaba</groupId> 112 <artifactId>dubbo</artifactId> 113 <version>2.5.5.cat-SNAPSHOT</version> 114 <exclusions> 115 <exclusion> 116 <groupId>org.springframework</groupId> 117 <artifactId>spring</artifactId> 118 </exclusion> 119 <exclusion> 120 <groupId>org.glassfish.grizzly</groupId> 121 <artifactId>grizzly-framework</artifactId> 122 </exclusion> 123 </exclusions> 124 </dependency> 125 126 <!--打印日志使用slf4j 而不是log4j--> 127 <dependency> 128 <groupId>org.slf4j</groupId> 129 <artifactId>slf4j-api</artifactId> 130 <version>1.6.1</version> 131 </dependency> 132 133 134 135 <!--junit--> 136 <dependency> 137 <groupId>junit</groupId> 138 <artifactId>junit</artifactId> 139 <version>4.10</version> 140 <scope>test</scope> 141 </dependency> 142 143 144 145 <dependency> 146 <groupId>junit</groupId> 147 <artifactId>junit</artifactId> 148 <version>3.8.1</version> 149 <scope>test</scope> 150 </dependency> 151 152 <!--fastjson 阿里巴巴公司开源的速度最快的Json和对象转换工具--> 153 <dependency> 154 <groupId>com.alibaba</groupId> 155 <artifactId>fastjson</artifactId> 156 <version>1.2.6</version> 157 </dependency> 158 159 <!--jmeter--> 160 <dependency> 161 <groupId>org.apache.jmeter</groupId> 162 <artifactId>ApacheJMeter_java</artifactId> 163 <version>2.13</version> 164 <exclusions> 165 <exclusion> 166 <groupId>d-haven-managed-pool</groupId> 167 <artifactId>d-haven-managed-pool</artifactId> 168 </exclusion> 169 170 <exclusion> 171 <groupId>commons-math3</groupId> 172 <artifactId>commons-math3</artifactId> 173 </exclusion> 174 175 <exclusion> 176 <groupId>commons-pool2</groupId> 177 <artifactId>commons-pool2</artifactId> 178 </exclusion> 179 180 <exclusion> 181 <groupId>commons-collections</groupId> 182 <artifactId>commons-collections</artifactId> 183 </exclusion> 184 </exclusions> 185 <!--打包时注释放开--> 186 <scope>provided</scope> 187 </dependency> 188 189 </dependencies> 190 191 <!--构建项目--> 192 <build> 193 <plugins> 194 <plugin> 195 <groupId>org.apache.maven.plugins</groupId> 196 <artifactId>maven-compiler-plugin</artifactId> 197 <version>2.4</version> 198 <configuration> 199 <source>1.5</source> 200 <target>1.5</target> 201 </configuration> 202 </plugin> 203 <plugin> 204 <groupId>org.apache.maven.plugins</groupId> 205 <artifactId>maven-shade-plugin</artifactId> 206 <version>2.3</version> 207 <executions> 208 <execution> 209 <phase>package</phase> 210 <goals> 211 <goal>shade</goal> 212 </goals> 213 <configuration> 214 <filters> 215 <filter> 216 <artifact>*:*</artifact> 217 <excludes> 218 <exclude>META-INF/*.SF</exclude> 219 <exclude>META-INF/*.DSA</exclude> 220 <exclude>META-INF/*.RSA</exclude> 221 </excludes> 222 </filter> 223 </filters> 224 <transformers> 225 <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 226 <resource>META-INF/spring.handlers</resource> 227 </transformer> 228 <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 229 <resource>META-INF/spring.schemas</resource> 230 </transformer> 231 </transformers> 232 </configuration> 233 </execution> 234 </executions> 235 </plugin> 236 </plugins> 237 </build> 238 239 240 </project>
打包时候四个注意点:
a>以下的过滤不要忘记加
1 <plugins> 2 <plugin> 3 <groupId>org.apache.maven.plugins</groupId> 4 <artifactId>maven-compiler-plugin</artifactId> 5 <version>2.4</version> 6 <configuration> 7 <source>1.5</source> 8 <target>1.5</target> 9 </configuration> 10 </plugin> 11 <plugin> 12 <groupId>org.apache.maven.plugins</groupId> 13 <artifactId>maven-shade-plugin</artifactId> 14 <version>2.3</version> 15 <executions> 16 <execution> 17 <phase>package</phase> 18 <goals> 19 <goal>shade</goal> 20 </goals> 21 <configuration> 22 <filters> 23 <filter> 24 <artifact>*:*</artifact> 25 <excludes> 26 <exclude>META-INF/*.SF</exclude> 27 <exclude>META-INF/*.DSA</exclude> 28 <exclude>META-INF/*.RSA</exclude> 29 </excludes> 30 </filter> 31 </filters> 32 <transformers> 33 <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 34 <resource>META-INF/spring.handlers</resource> 35 </transformer> 36 <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 37 <resource>META-INF/spring.schemas</resource> 38 </transformer> 39 </transformers> 40 </configuration> 41 </execution> 42 </executions> 43 </plugin> 44 </plugins>
b>加上如下内容
1 <exclusions> 2 <exclusion> 3 <artifactId>coupon-interfaces-simple</artifactId>
4 <groupId>coupon-interfaces</groupId> 5 </exclusion> 6 </exclusions>
c>过滤以下包里面和依赖无关的其他所有文件
1 <dependency> 2 <groupId>com.gome.npop</groupId> 3 <artifactId>promotion-interfaces</artifactId> 4 <version>1.0.9-SNAPSHOT</version> 5 <exclusions> 6 <exclusion> 7 <artifactId>*</artifactId> 8 <groupId>*</groupId> 9 </exclusion> 10 </exclusions> 11 </dependency>
d>打包的时候注意将下面的注释放开,是jmeter里面的。
<!--打包时注释放开-->
<scope>provided</scope>
3、ContextGetBean.class
1 // 2 // Source code recreated from a .class file by IntelliJ IDEA 3 // (powered by Fernflower decompiler) 4 // 5 6 package com.gome.test.load; 7 8 import org.springframework.context.support.ClassPathXmlApplicationContext; 9 10 public class ContextGetBean { 11 private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:spring-dubbo-consumer.xml"}); 12 13 public ContextGetBean() { 14 } 15 16 public static void ContextGetBean() { 17 context.start(); 18 } 19 20 public static Object getBean(String classpath, String beanName) { 21 return context.getBean(beanName); 22 } 23 }
4、OrderTest.class
1 // 2 // Source code recreated from a .class file by IntelliJ IDEA 3 // (powered by Fernflower decompiler) 4 // 5 6 package com.gome.test.load; 7 8 import com.coo8.common.util.JsonUtil; 9 import com.gome.coupon.interfaces.dubbo.IPromotionAndCouponManager; 10 import com.gome.coupon.model.cartBean.CommitCouponsAndPromotionParam; 11 import com.gome.coupon.model.cartBean.ResultDO; 12 import com.gome.test.load.ContextGetBean; 13 import java.io.BufferedReader; 14 import java.io.File; 15 import java.io.FileInputStream; 16 import java.io.InputStreamReader; 17 import java.util.ArrayList; 18 import java.util.List; 19 import org.apache.jmeter.config.Arguments; 20 import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; 21 import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; 22 import org.apache.jmeter.samplers.SampleResult; 23 24 public class OrderTest extends AbstractJavaSamplerClient { 25 private IPromotionAndCouponManager iPromotionAndCouponManager; 26 private Arguments params; 27 28 public OrderTest() { 29 } 30 31 public void setupTest(JavaSamplerContext arg0) { 32 this.iPromotionAndCouponManager = (IPromotionAndCouponManager)ContextGetBean.getBean("classpath:spring-dubbo-consumer.xml", "promotionAndCouponManager"); 33 } 34 35 public void teardownTest(JavaSamplerContext arg0) { 36 } 37 38 public Arguments getDefaultParameters() { 39 this.params = new Arguments(); 40 String orderIds = ""; 41 String filePath = "C:\\Users\\zhaichao.DS\\Desktop\\dubbo接口测试\\购物券需求压测数据和接口文档\\提交订单.txt"; 42 this.params.addArgument("orderIds", orderIds); 43 this.params.addArgument("filePath", filePath); 44 return this.params; 45 } 46 47 public SampleResult runTest(JavaSamplerContext arg0) { 48 String orderIds = arg0.getParameter("orderIds"); 49 String filePath = arg0.getParameter("filePath"); 50 new ArrayList(); 51 String listStr = this.ReadFile(filePath); 52 List ProjectList = this.getListParam(listStr, CommitCouponsAndPromotionParam.class); 53 ResultDO rd = this.iPromotionAndCouponManager.commitPromotionAndCoupon(orderIds, ProjectList); 54 SampleResult sr = new SampleResult(); 55 sr.sampleStart(); 56 57 try { 58 if(rd != null && rd.isSuccess()) { 59 this.getLogger().info("一切正常!"); 60 sr.setSuccessful(true); 61 } else { 62 this.getLogger().info(rd.getErrorMsg()); 63 sr.setSuccessful(false); 64 } 65 } catch (Exception var9) { 66 sr.setSuccessful(false); 67 var9.getStackTrace(); 68 this.getLogger().error("抛出异常如下:" + var9); 69 } 70 71 sr.sampleEnd(); 72 return sr; 73 } 74 75 public static void main(String[] args) { 76 OrderTest orderTest = new OrderTest(); 77 Arguments paras = orderTest.getDefaultParameters(); 78 JavaSamplerContext javaSamplerContext = new JavaSamplerContext(paras); 79 orderTest.setupTest(javaSamplerContext); 80 orderTest.runTest(javaSamplerContext); 81 orderTest.teardownTest(javaSamplerContext); 82 } 83 84 public <T> List<T> getListParam(String jsonStr, Class targClass) { 85 new ArrayList(); 86 List list = JsonUtil.toObjArray(jsonStr, targClass); 87 return list; 88 } 89 90 public String ReadFile(String filePath) { 91 String line1 = ""; 92 93 try { 94 String e1 = "GBK"; 95 File file = new File(filePath); 96 if(file.isFile() && file.exists()) { 97 InputStreamReader reader = new InputStreamReader(new FileInputStream(file)); 98 BufferedReader br = new BufferedReader(reader); 99 String line = ""; 100 101 for(line1 = line1 + br.readLine(); line != null; line1 = line1 + line) { 102 line = br.readLine(); 103 } 104 } 105 } catch (Exception var8) { 106 var8.printStackTrace(); 107 } 108 109 this.getLogger().info(line1); 110 return line1.substring(0, line1.length() - 4); 111 } 112 }