因为开发那边在转 dubbo 服务,测试也需要了解相关知识,所以有了这篇
dubbo 源码中默认的是 Multicast 注册,但实际工作中是用 zookeeper 的
#配置文件更新内容:
dataDir=E:\\DevE\\zookeeper-3.4.12\\data
dataLogDir=E:\\DevE\\zookeeper-3.4.12\\log
在 dubbo 源码目录中有一个 demo 工程,dubbo-demo,使用 idea 打开
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.12</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
dubbo-provider
dubbo-consumer
查看结果日志,单机版 helloworld 已完成
安装 dubbo admin 主要方便查看管理 dubbo 服务
<!--server.xml-->
<Connector port="8123" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
至此环境搭建完成
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jollychic</groupId>
<artifactId>dubbo-test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<allure.version>1.5.4</allure.version>
<lombok.version>1.16.18</lombok.version>
<slf4j.version>1.7.25</slf4j.version>
<jsonpath.version>2.4.0</jsonpath.version>
<springframework.version>4.3.12.RELEASE</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.12</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-demo-provider</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
</dependencies>
</project>
<?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="app"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService" url="dubbo://127.0.0.1:20880" timeout="1000"/>
</beans>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/dubbo.xml"})
public class JunitDemo {
@Autowired
DemoService demoService;
@Test
public void testDemoService(){
demoService.sayHello("haha my test");
}
}
@ContextConfiguration(locations = {"classpath:/dubbo.xml"})
public class TestngDemo extends AbstractTestNGSpringContextTests {
@Autowired
private DemoService demoService;
@Test
public void testDemoService(){
demoService.sayHello("testng my test");
}
}
增加复制所有依赖包和 snapshot 包到目标位置:${project.build.directory}/lib
<jmeter.version>4.0</jmeter.version>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>${jmeter.version}</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!--<overWriteReleases>true</overWriteReleases>-->
<!--<overWriteSnapshots>true</overWriteSnapshots>-->
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="${project.build.directory}/lib">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
public class JmeterDemo extends AbstractJavaSamplerClient {
private static final ApplicationContext context = new ClassPathXmlApplicationContext("dubbo.xml");
private DemoService demoService;
@Override
public void setupTest(JavaSamplerContext arg0){
demoService = (DemoService) context.getBean("demoService");
}
@Override
public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
SampleResult sr = new SampleResult();
sr.sampleStart();
JSONObject result = demoService.sayHello("jmeter test");
System.out.println("result:" + result.toJSONString());
sr.setResponseData(result.get("result").toString(), "UTF-8");
sr.setSuccessful(true);
return sr;
}
}
public class JmeterDemoTest {
public static void main(String [] args){
JavaSamplerContext arg0 = new JavaSamplerContext(new Arguments());
JmeterDemo test = new JmeterDemo();
test.setupTest(arg0);
test.runTest(arg0);
}
}
# 更新jmeter配置文件
search_paths=E:/Workspace/dubbo-test/target/lib;
dubbo 源码及示例
dubbo admin 源码
dubbo admin 安装手册
tomcat 用户名密码修改
dubbo 基础运用 -- 英文
dubbo 用户手册