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/08/09 07:57:41 UTC
[dubbo-samples] branch master updated: integration test for
dubbo-samples-nacos-conditionrouter
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 dfbc303 integration test for dubbo-samples-nacos-conditionrouter
dfbc303 is described below
commit dfbc303c8248509ba77b352abfc4a46c1ab358f1
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Fri Aug 9 15:57:03 2019 +0800
integration test for dubbo-samples-nacos-conditionrouter
---
.../dubbo-samples-nacos-conditionrouter/README.md | 19 +++++++
.../dubbo-samples-nacos-conditionrouter/pom.xml | 25 +++++-----
.../dubbo/samples/governance/BasicConsumer.java | 13 ++---
.../dubbo/samples/governance/util/NacosUtils.java | 48 ++++++++++++++++++
.../src/main/resources/docker/docker-compose.yml | 10 ++++
.../main/resources/spring/dubbo-demo-consumer.xml | 4 +-
.../main/resources/spring/dubbo-demo-provider.xml | 6 +--
.../dubbo/samples/governance/DemoServiceIT.java | 58 ++++++++++++++++++++++
8 files changed, 157 insertions(+), 26 deletions(-)
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/README.md b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/README.md
new file mode 100644
index 0000000..c458be3
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/README.md
@@ -0,0 +1,19 @@
+## Steps to run the samples
+
+1. Start Nacos locally
+
+ ```
+ cd src/main/resources/docker
+ docker-compose up
+ ```
+
+2. Start two dubbo provider `org.apache.dubbo.samples.configcenter.BasicProvider`, make sure one has the system property `-Ddubbo.port=20880` and the other with `-Ddubbo.port=20881`
+
+3. Execute `org.apache.dubbo.samples.governance.util.NacosUtils` to publish routing rule.
+
+4. Run Dubbo consumer demo `org.apache.dubbo.samples.configcenter.BasicConsumer`, verify that standard ouput has the following content on the consumer side:
+
+ ```
+ result: Hello world, response from provider: 192.168.99.1:20880
+ result: Hello world again, response from provider: 192.168.99.1:20881
+ ```
\ No newline at end of file
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
index 5bdba5e..016bf6e 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
@@ -42,7 +42,7 @@
<java-image.name>openjdk:8</java-image.name>
<dubbo.port.1>20880</dubbo.port.1>
<dubbo.port.2>20881</dubbo.port.2>
- <zookeeper.port>2181</zookeeper.port>
+ <nacos.port>8848</nacos.port>
<main-class>org.apache.dubbo.samples.governance.BasicProvider</main-class>
</properties>
@@ -65,13 +65,6 @@
</dependency>
<dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-dependencies-zookeeper</artifactId>
- <version>${dubbo.version}</version>
- <type>pom</type>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
@@ -88,7 +81,7 @@
<profiles>
<profile>
- <id>dubbo-integration-test-disabled</id>
+ <id>dubbo-integration-test</id>
<build>
<plugins>
<plugin>
@@ -125,7 +118,7 @@
<DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
</environment>
<jvmFlags>
- <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+ <jvmFlag>-Dnacos.address=${dubbo-local-address}</jvmFlag>
</jvmFlags>
</container>
</configuration>
@@ -146,11 +139,19 @@
<configuration>
<images>
<image>
- <name>zookeeper:latest</name>
+ <name>nacos/nacos-server:latest</name>
<run>
<ports>
- <port>${zookeeper.port}:${zookeeper.port}</port>
+ <port>${nacos.port}:${nacos.port}</port>
</ports>
+ <wait>
+ <time>30000</time>
+ <log>Nacos started successfully in stand alone mode</log>
+ </wait>
+ <env>
+ <PREFER_HOST_MODE>hostname</PREFER_HOST_MODE>
+ <MODE>standalone</MODE>
+ </env>
</run>
</image>
<image>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
index 4ec8b0f..d0b0662 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -21,7 +21,6 @@ package org.apache.dubbo.samples.governance;
import org.apache.dubbo.samples.governance.api.DemoService;
import org.apache.dubbo.samples.governance.api.DemoService2;
-
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BasicConsumer {
@@ -33,14 +32,10 @@ public class BasicConsumer {
DemoService demoService = context.getBean("demoService", DemoService.class);
DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);
- while (true) {
- String hello = demoService.sayHello("world");
- System.out.println(hello);
-
- String hello2 = demoService2.sayHello("world again");
- System.out.println(hello2);
+ String hello = demoService.sayHello("world");
+ System.out.println("result: " + hello);
- Thread.sleep(200);
- }
+ String hello2 = demoService2.sayHello("world again");
+ System.out.println("result: " + hello2);
}
}
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/util/NacosUtils.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/util/NacosUtils.java
new file mode 100644
index 0000000..807f006
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/util/NacosUtils.java
@@ -0,0 +1,48 @@
+/*
+ * 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.governance.util;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.PropertyKeyConst;
+import com.alibaba.nacos.api.config.ConfigService;
+import org.apache.commons.io.IOUtils;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+public class NacosUtils {
+ public static void main(String[] args) throws Throwable {
+ writeAppRule();
+ }
+
+ public static void writeAppRule() throws Throwable {
+ String serverAddr = System.getProperty("nacos.address", "localhost");
+ String dataId = "governance-conditionrouter-consumer.condition-router";
+ String group = "dubbo";
+ Properties properties = new Properties();
+ properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
+ ConfigService configService = NacosFactory.createConfigService(properties);
+
+ try (InputStream is = NacosUtils.class.getClassLoader().getResourceAsStream("dubbo-routers-condition.yml")) {
+ String content = IOUtils.toString(is);
+ if (configService.publishConfig(dataId, group, content)) {
+ System.out.println("write " + dataId + ":" + group + " successfully.");
+ }
+ }
+ }
+}
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/docker/docker-compose.yml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/docker/docker-compose.yml
new file mode 100644
index 0000000..dafcdc4
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/docker/docker-compose.yml
@@ -0,0 +1,10 @@
+version: "2"
+services:
+ nacos:
+ image: nacos/nacos-server:latest
+ container_name: nacos-standalone
+ environment:
+ - PREFER_HOST_MODE=hostname
+ - MODE=standalone
+ ports:
+ - "8848:8848"
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
index 9226781..b787503 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -27,9 +27,9 @@
<dubbo:application name="governance-conditionrouter-consumer"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:registry address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center highest-priority="false" address="nacos://${nacos.address:127.0.0.1}:8848"/>
<dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService"/>
<dubbo:reference id="demoService2" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService2"/>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
index fed3425..0da07d1 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
@@ -27,11 +27,11 @@
<dubbo:application name="governance-conditionrouter-provider"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:registry address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <dubbo:protocol port="${dubbo.port:-1}"/>
+ <dubbo:protocol port="${dubbo.port:20880}"/>
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center highest-priority="false" address="nacos://${nacos.address:127.0.0.1}:8848"/>
<bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
<dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
new file mode 100644
index 0000000..64779ee
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
@@ -0,0 +1,58 @@
+/*
+ * 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.governance;
+
+import org.apache.dubbo.samples.governance.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService2;
+
+import org.apache.dubbo.samples.governance.util.NacosUtils;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+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 DemoServiceIT {
+ @Autowired
+ private DemoService demoService;
+
+ @Autowired
+ private DemoService2 demoService2;
+
+ @BeforeClass
+ public static void setUp() throws Throwable {
+ NacosUtils.writeAppRule();
+ Thread.sleep(2000);
+ }
+
+ @Test
+ public void testDemoService() throws Exception {
+ String result = demoService.sayHello("world");
+ Assert.assertTrue(result.contains("20880"));
+ }
+
+ @Test
+ public void testDemoService2() throws Exception {
+ String result = demoService2.sayHello("world");
+ Assert.assertTrue(result.contains("20881"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org