You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by il...@apache.org on 2019/07/10 06:51:35 UTC
[dubbo-samples] branch master updated: integration test for
dubbo-samples-metrics
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 8d5127e integration test for dubbo-samples-metrics
8d5127e is described below
commit 8d5127e2c9f4c65c47161faea7f9efaa6fa06da8
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Wed Jul 10 14:49:43 2019 +0800
integration test for dubbo-samples-metrics
---
dubbo-samples-metrics/pom.xml | 33 ++++++++----
.../dubbo/samples/metrics/MetricsConsumer.java | 5 +-
.../dubbo/samples/metrics/MetricsProvider.java | 8 +--
.../main/resources/spring/dubbo-demo-consumer.xml | 14 ++---
.../main/resources/spring/dubbo-demo-provider.xml | 18 +++----
.../dubbo/samples/metrics/MetricsServiceIT.java | 63 ++++++++++++++++++++++
6 files changed, 108 insertions(+), 33 deletions(-)
diff --git a/dubbo-samples-metrics/pom.xml b/dubbo-samples-metrics/pom.xml
index 392840e..c9fd3f3 100644
--- a/dubbo-samples-metrics/pom.xml
+++ b/dubbo-samples-metrics/pom.xml
@@ -32,14 +32,16 @@
<target.level>1.8</target.level>
<dubbo.version>2.7.2</dubbo.version>
<junit.version>4.12</junit.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
<jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
<image.name>${artifactId}:${dubbo.version}</image.name>
+ <java-image.name>openjdk:8</java-image.name>
<dubbo.port>20880</dubbo.port>
- <main-class>org.apache.dubbo.samples.basic.BasicProvider</main-class>
- <spring-test.version>4.3.16.RELEASE</spring-test.version>
+ <zookeeper.port>2181</zookeeper.port>
+ <main-class>org.apache.dubbo.samples.metrics.MetricsProvider</main-class>
</properties>
<dependencies>
@@ -49,8 +51,6 @@
<version>${dubbo.version}</version>
</dependency>
-
-<!-- dependency for metrics-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-monitor-default</artifactId>
@@ -64,6 +64,19 @@
<type>pom</type>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
@@ -101,10 +114,9 @@
</to>
<container>
<mainClass>${main-class}</mainClass>
- <ports>
- <port>${dubbo.port}</port>
- <port>2181</port>
- </ports>
+ <jvmFlags>
+ <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+ </jvmFlags>
<environment>
<DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
</environment>
@@ -131,7 +143,7 @@
<run>
<ports>
<port>${dubbo.port}:${dubbo.port}</port>
- <port>2181:2181</port>
+ <port>${zookeeper.port}:${zookeeper.port}</port>
</ports>
<wait>
<log>dubbo service started</log>
@@ -169,6 +181,9 @@
<goal>verify</goal>
</goals>
<configuration>
+ <systemPropertyVariables>
+ <dubbo.address>${dubbo-local-address}</dubbo.address>
+ </systemPropertyVariables>
<includes>
<include>**/*IT.java</include>
</includes>
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
index d8c7b5c..3fcba31 100644
--- a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.samples.metrics;
import org.apache.dubbo.samples.metrics.api.DemoService;
import org.apache.dubbo.samples.metrics.model.Result;
+
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MetricsConsumer {
@@ -25,7 +26,9 @@ public class MetricsConsumer {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
context.start();
- DemoService demoService = (DemoService) context.getBean("demoService");
+
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+
while (true) {
try {
Thread.sleep(3000);
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java
index 745056d..568f845 100644
--- a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java
@@ -18,15 +18,17 @@ package org.apache.dubbo.samples.metrics;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import java.util.concurrent.CountDownLatch;
+
public class MetricsProvider {
public static void main(String[] args) throws Exception {
new EmbeddedZooKeeper(2181, false).start();
- // wait for embedded zookeeper start completely.
- Thread.sleep(1000);
+
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
context.start();
+
System.out.println("dubbo service started");
- System.in.read();
+ new CountDownLatch(1).await();
}
}
diff --git a/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml
index b29fcad..ada8fe5 100644
--- a/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml
+++ b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -18,19 +18,15 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
- <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
- don't set it same as provider -->
- <dubbo:application name="demo-consumer"/>
+ <dubbo:application name="metrics-demo-consumer"/>
- <!-- use multicast registry center to discover service -->
- <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <!-- generate proxy for the remote service, then demoService can be used in the same way as the
- local regular interface -->
<dubbo:reference id="demoService" check="true" interface="org.apache.dubbo.samples.metrics.api.DemoService"/>
</beans>
diff --git a/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml
index 4281103..501f3af 100644
--- a/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml
@@ -18,25 +18,21 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
- <!-- provider's application name, used for tracing dependency relationship -->
- <dubbo:application name="demo-provider"/>
+ <dubbo:application name="metrics-provider"/>
- <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
- <dubbo:config-center address="zookeeper://127.0.0.1:2181" />
- <dubbo:metadata-report address="zookeeper://127.0.0.1:2181" />
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center address="zookeeper://${zookeepr.address:127.0.0.1}:2181" />
+ <dubbo:metadata-report address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
<dubbo:metrics port="20880" protocol="dubbo"/>
<dubbo:provider filter="metrics" />
-
- <!-- service implementation, as same as regular local bean -->
<bean id="demoService" class="org.apache.dubbo.samples.metrics.impl.DemoServiceImpl"/>
- <!-- declare the service interface to be exported -->
<dubbo:service interface="org.apache.dubbo.samples.metrics.api.DemoService" ref="demoService"/>
-
</beans>
diff --git a/dubbo-samples-metrics/src/test/java/org/apache/dubbo/samples/metrics/MetricsServiceIT.java b/dubbo-samples-metrics/src/test/java/org/apache/dubbo/samples/metrics/MetricsServiceIT.java
new file mode 100644
index 0000000..71fb2f8
--- /dev/null
+++ b/dubbo-samples-metrics/src/test/java/org/apache/dubbo/samples/metrics/MetricsServiceIT.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.samples.metrics;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.monitor.MetricsService;
+import org.apache.dubbo.samples.metrics.api.DemoService;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo-consumer.xml"})
+public class MetricsServiceIT {
+ private static String providerHost = System.getProperty("dubbo.address", "127.0.0.1");
+ private static int providerPort = Integer.getInteger("dubbo.port", 20880);
+
+ @Autowired
+ private DemoService demoService;
+
+ @Test
+ public void test() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ System.out.println("result: " + demoService.sayHello("dubbo"));
+ }
+
+ ReferenceConfig<MetricsService> reference = new ReferenceConfig<>();
+ reference.setApplication(new ApplicationConfig("metrics-demo-consumer"));
+ reference.setUrl("dubbo://" + providerHost + ":" + providerPort + "/" + MetricsService.class.getName());
+ reference.setInterface(MetricsService.class);
+ MetricsService service = reference.get();
+ String result = service.getMetricsByGroup("dubbo");
+ JSONArray metrics = (JSONArray) JSON.parse(result);
+ Assert.assertFalse(metrics.isEmpty());
+ for (int i = 0; i < metrics.size(); i++) {
+ String metric = (String) ((JSONObject) metrics.get(1)).get("metric");
+ Assert.assertTrue(metric.startsWith("dubbo.provider") || metric.startsWith("threadPool"));
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org