一、新建一maven项目(我弄的是新建模块,其余任意也行,就弄个消费者,提供者,service)java
二、新建一个myTest maven模块git
三、配置pom.xml文件(添加依赖、配置打包)github
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> </dependency>
<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency>
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency>
<dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.18.1-GA</version> </dependency>
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> <exclusions> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> <exclusion> <artifactId>jms</artifactId> <groupId>javax.jms</groupId> </exclusion> <exclusion> <artifactId>mail</artifactId> <groupId>javax.mail</groupId> </exclusion> </exclusions> </dependency>
<dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6.SEC03</version> </dependency>
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> </dependency>
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> </dependency>
<dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.6</version> <type>pom</type> </dependency>
<dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.4</version> </dependency>
<dependency> <groupId>org.apache.jmeter</groupId> <artifactId>ApacheJMeter_core</artifactId> <version>3.3</version> </dependency>
<dependency> <groupId>org.apache.jmeter</groupId> <artifactId>ApacheJMeter_java</artifactId> <version>3.3</version> </dependency>
其中、涉及跟jmeter打交道的包为(必须):spring
org.apache.jmeter.ApachJMeter_core
org.apache.jmeter.ApachJMeter_java
如下为pom.xml构建打包代码:apache
<build> <finalName>qgl_my_test_jar</finalName> <resources> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> <!-- 结合com.alibaba.dubbo.container.Main --> <resource> <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath> <directory>src/main/resources/spring</directory> <filtering>true</filtering> <includes> <include>spring-context.xml</include> </includes> </resource> </resources> <pluginManagement> <plugins> <!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引发冲突 --> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>copy-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore/> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <manifest> <mainClass>com.alibaba.dubbo.container.Main</mainClass> <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 --> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <type>jar</type> <includeTypes>jar</includeTypes> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>
四、在myTest/src/main/resources、新建一个applicationProvider.xmlapi
applicationProvider.xml内容以下:app
<?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: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://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
">
<!--应用名称 -->
<dubbo:application name="dubbo_test"/>
<!-- 注册地址 -->
<dubbo:registry address="127.0.0.1:22880"
register="false "/>
<!--dubbo:reference 这里主要编写接口的url地址,id=方法名称,接口路径,超时时间,是否检查,版本 -->
<dubbo:reference url="dubbo://10.0.xx.xx:22880" id="getxxxInfoByxx"
interface="com.xxx.xx.xx.xx.cc.xx.xaa" timeout="120000"
check="false" version="1.5" protocol="dubbo"/>
</beans>
五、编写消费者类:IMemberAccountBackgroundApieclipse
a、IMemberAccountBackgroundApi类须要继承AbstractJavaSamplerClient() //该类来自于pom.xml配置jmeter的依赖
b、编写方法:public SampleResult runTest(JavaSamplerContext args){maven
//必须得这么写,否则打包后,放到jmeter那边去后,不会识别ide
}
c、启动采样器和上下文
d、利用context.getBean("getxxxInfoByxx"),获取到xml中配置的id,而后new一个接口对象去接收
e、进入
IMemberAccountBackgroundApi,去找到对应的接口方法名称
好比我要测试经过ID进行数据查询的接口,以下:----------------------------------------------------------
把返回的对象进行打印处理,
而后对返回的结果进行判空处理,若是不为空则设置jmeter的数据类型为text
设置success=true
f、在类中写一个main方法进行测试,测试OK,则打包放到Jmeter中
六、调试成功的话,此时能够进入打包阶段了
a、如何打包:点击insetall(打包前,须要先清除clean操做,防止脏数据)
b、未打包这前,是没有terget文件夹的,下图为打包前
c、打包成功后,详情以下,tree型结构会增长terget
七、将打好的包找到,并放到jmeter下的lib目标与ext目录
八、启动Jmeter
可参考:https://github.com/dubbo/jmeter-plugins-dubbo/wiki/%E7%94%A8%E6%88%B7%E6%8C%87%E5%8D%97