一、新建一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