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/08 16:19:13 UTC
[dubbo-samples] branch master updated: add integration test for
dubbo-samples-nacos-registry
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 e0bf130 add integration test for dubbo-samples-nacos-registry
e0bf130 is described below
commit e0bf130adbe86cd9095bc3a330fb8e524c0788ff
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Fri Aug 9 00:18:45 2019 +0800
add integration test for dubbo-samples-nacos-registry
---
.../dubbo-samples-nacos-registry/README.md | 12 +++----
.../dubbo-samples-nacos-registry/pom.xml | 41 +++++++---------------
.../apache/dubbo/samples/ProviderBootstrap.java | 5 ++-
.../src/main/resources/docker/docker-compose.yml | 10 ++++++
.../resources/spring/dubbo-consumer.properties | 4 +--
.../resources/spring/dubbo-provider.properties | 4 +--
.../apache/dubbo/samples/GreetingServiceIT.java | 38 ++++++++++++++++++++
7 files changed, 73 insertions(+), 41 deletions(-)
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/README.md b/dubbo-samples-nacos/dubbo-samples-nacos-registry/README.md
index 0ec8b31..ee46ab9 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-registry/README.md
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/README.md
@@ -1,17 +1,15 @@
## Steps to run the samples
-1. Download nacos, go to https://github.com/alibaba/nacos/releases, and download the latest binary file.
-
-2. Start Nacos locally
+1. Start Nacos locally
```
- cd bin
- ./startup.sh -m standalone
+ cd src/main/resources/docker
+ docker-compose up
```
-3. Run Dubbo provider demo `org.apache.dubbo.samples.ProviderBootstrap.main`
+2. Run Dubbo provider demo `org.apache.dubbo.samples.ProviderBootstrap.main`
-4. Run Dubbo consumer demo `org.apache.dubbo.samples.ConsumerBootstrap.main`, verify that standard ouput has the following content on the consumer side:
+3. Run Dubbo consumer demo `org.apache.dubbo.samples.ConsumerBootstrap.main`, verify that standard ouput has the following content on the consumer side:
```
result: hello, nacos
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
index a5535b7..7c6bb94 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
@@ -40,9 +40,8 @@
<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.1>20880</dubbo.port.1>
- <dubbo.port.2>20881</dubbo.port.2>
- <zookeeper.port>2181</zookeeper.port>
+ <dubbo.port>20880</dubbo.port>
+ <nacos.port>8848</nacos.port>
<main-class>org.apache.dubbo.samples.ProviderBootstrap</main-class>
</properties>
@@ -65,13 +64,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 +80,7 @@
<profiles>
<profile>
- <id>dubbo-integration-test-disabled</id>
+ <id>dubbo-integration-test</id>
<build>
<plugins>
<plugin>
@@ -125,7 +117,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,24 +138,18 @@
<configuration>
<images>
<image>
- <name>zookeeper:latest</name>
+ <name>nacos/nacos-server:latest</name>
<run>
<ports>
- <port>${zookeeper.port}:${zookeeper.port}</port>
- </ports>
- </run>
- </image>
- <image>
- <name>${image.name}</name>
- <run>
- <ports>
- <port>${dubbo.port.1}:${dubbo.port.1}</port>
+ <port>${nacos.port}:${nacos.port}</port>
</ports>
<wait>
- <log>dubbo service started</log>
+ <time>30000</time>
+ <log>Nacos started successfully in stand alone mode</log>
</wait>
<env>
- <dubbo.port>${dubbo.port.1}</dubbo.port>
+ <PREFER_HOST_MODE>hostname</PREFER_HOST_MODE>
+ <MODE>standalone</MODE>
</env>
</run>
</image>
@@ -171,14 +157,11 @@
<name>${image.name}</name>
<run>
<ports>
- <port>${dubbo.port.2}:${dubbo.port.2}</port>
+ <port>${dubbo.port}:${dubbo.port}</port>
</ports>
<wait>
<log>dubbo service started</log>
</wait>
- <env>
- <dubbo.port>${dubbo.port.2}</dubbo.port>
- </env>
</run>
</image>
</images>
@@ -213,7 +196,7 @@
</goals>
<configuration>
<systemPropertyVariables>
- <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+ <nacos.address>${dubbo-local-address}</nacos.address>
</systemPropertyVariables>
<includes>
<include>**/*IT.java</include>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
index 3c640b6..2c04811 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
@@ -24,12 +24,15 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import java.util.concurrent.CountDownLatch;
+
public class ProviderBootstrap {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
context.start();
- System.in.read();
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
@Configuration
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/docker/docker-compose.yml b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/docker/docker-compose.yml
new file mode 100644
index 0000000..dafcdc4
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/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-registry/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-consumer.properties
index 5cc28f7..9d404e4 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-consumer.properties
@@ -17,6 +17,6 @@
#
#
-dubbo.application.name=demo-consumer
-dubbo.registry.address=nacos://localhost:8848
+dubbo.application.name=nacos-registry-demo-consumer
+dubbo.registry.address=nacos://${nacos.address:localhost}:8848
dubbo.consumer.timeout=3000
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties
index 5d65dce..cfd7476 100644
--- a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties
@@ -16,7 +16,7 @@
# limitations under the License.
#
#
-dubbo.application.name=demo-provider
-dubbo.registry.address=nacos://localhost:8848
+dubbo.application.name=nacos-registry-demo-provider
+dubbo.registry.address=nacos://${nacos.address:localhost}:8848
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/test/java/org/apache/dubbo/samples/GreetingServiceIT.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/test/java/org/apache/dubbo/samples/GreetingServiceIT.java
new file mode 100644
index 0000000..06b6628
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/test/java/org/apache/dubbo/samples/GreetingServiceIT.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.apache.dubbo.samples.action.GreetingServiceConsumer;
+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(classes = ConsumerBootstrap.ConsumerConfiguration.class)
+public class GreetingServiceIT {
+ @Autowired
+ private GreetingServiceConsumer service;
+
+ @Test
+ public void test() throws Exception {
+ Assert.assertEquals("hello, nacos", service.doSayHello("nacos"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org