dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject [dubbo-samples] branch master updated: integration test for dubbo-samples-multi-registry
Date Thu, 27 Jun 2019 09:32:48 GMT
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 f062b10  integration test for dubbo-samples-multi-registry
f062b10 is described below

commit f062b10569a94d14e9b9b73c07d76915398838fe
Author: Ian Luo <ian.luo@gmail.com>
AuthorDate: Thu Jun 27 17:31:30 2019 +0800

    integration test for dubbo-samples-multi-registry
---
 dubbo-samples-multi-registry/pom.xml               | 389 ++++++++-------------
 .../multi/registry/MultiRegistryConsumer.java      |  11 +-
 .../multi/registry/MultiRegistryProvider.java      |  11 +-
 .../samples/multi/registry/api/DemoService.java    |   2 +-
 .../samples/multi/registry/api/HelloService.java   |   2 +-
 .../resources/spring/multi-registry-consumer.xml   |  23 +-
 .../resources/spring/multi-registry-provider.xml   |  21 +-
 .../multi/registry/MultiRegistryServiceIT.java     |  87 +++++
 .../dubbo/samples/multi/registry/ZKTools.java      |  51 +++
 9 files changed, 312 insertions(+), 285 deletions(-)

diff --git a/dubbo-samples-multi-registry/pom.xml b/dubbo-samples-multi-registry/pom.xml
index 574ef69..7fcf361 100644
--- a/dubbo-samples-multi-registry/pom.xml
+++ b/dubbo-samples-multi-registry/pom.xml
@@ -29,291 +29,178 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
+        <dubbo.version>2.7.2</dubbo.version>
         <spring.version>4.3.16.RELEASE</spring.version>
-        <dubbo.version>2.7.0</dubbo.version>
-        <dubbo.rpc.version>2.7.0</dubbo.rpc.version>
-        <zookeeper.version>3.4.13</zookeeper.version>
-        <curator.version>4.0.1</curator.version>
-        <validation-api.version>1.1.0.Final</validation-api.version>
-        <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
-        <resteasy.version>3.0.19.Final</resteasy.version>
-        <curator-client.version>4.0.1</curator-client.version>
-        <swagger.version>1.5.19</swagger.version>
-        <tomcat.version>7.0.88</tomcat.version>
-        <servlet.version>3.0.1</servlet.version>
-        <maven_checkstyle_version>3.0.0</maven_checkstyle_version>
-        <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
-        <spring-boot.version>1.5.13.RELEASE</spring-boot.version>
+        <junit.version>4.12</junit.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>
+        <dubbo.port>20890</dubbo.port>
+        <zookeeper.port.1>2181</zookeeper.port.1>
+        <zookeeper.port.2>2182</zookeeper.port.2>
+        <main-class>org.apache.dubbo.samples.multi.registry.MultiRegistryProvider</main-class>
     </properties>
 
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework</groupId>
-                <artifactId>spring-framework-bom</artifactId>
-                <version>${spring.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <!-- Import dependency management from Spring Boot -->
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>${spring-boot.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>io.netty</groupId>
-                <artifactId>netty-all</artifactId>
-                <version>4.1.16.Final</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-bom</artifactId>
-                <version>${dubbo.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo</artifactId>
-                <version>${dubbo.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.thrift</groupId>
-                        <artifactId>libthrift</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-rpc-rest</artifactId>
-                <version>${dubbo.rpc.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.zookeeper</groupId>
-                <artifactId>zookeeper</artifactId>
-                <version>${zookeeper.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-framework</artifactId>
-                <version>${curator.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.validation</groupId>
-                <artifactId>validation-api</artifactId>
-                <version>${validation-api.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.hibernate</groupId>
-                <artifactId>hibernate-validator</artifactId>
-                <version>${hibernate-validator.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.jboss.resteasy</groupId>
-                <artifactId>resteasy-jackson-provider</artifactId>
-                <version>${resteasy.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-client</artifactId>
-                <version>${curator-client.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.servlet</groupId>
-                <artifactId>javax.servlet-api</artifactId>
-                <version>${servlet.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-core</artifactId>
-                <version>${tomcat.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-logging-juli</artifactId>
-                <version>${tomcat.version}</version>
-            </dependency>
-            <!-- swagger -->
-            <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-annotations</artifactId>
-                <version>${swagger.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-jaxrs</artifactId>
-                <version>${swagger.version}</version>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
     <dependencies>
         <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-framework</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>io.netty</groupId>
-                    <artifactId>netty</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.apache.zookeeper</groupId>
-                    <artifactId>zookeeper</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.zookeeper</groupId>
-            <artifactId>zookeeper</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
         </dependency>
+
         <dependency>
             <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-configcenter-zookeeper</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.netty</groupId>
-            <artifactId>netty-all</artifactId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>${dubbo.version}</version>
+            <type>pom</type>
         </dependency>
+
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
+            <artifactId>spring-test</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 
-    <build>
-        <pluginManagement>
-            <plugins>
-                <plugin>
-                    <groupId>org.springframework.boot</groupId>
-                    <artifactId>spring-boot-maven-plugin</artifactId>
-                    <version>${spring-boot.version}</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.7.0</version>
-                <configuration>
-                    <source>${source.level}</source>
-                    <target>${target.level}</target>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.rat</groupId>
-                <artifactId>apache-rat-plugin</artifactId>
-                <version>${apache-rat-plugin.version}</version>
-                <executions>
-                    <execution>
-                        <id>verify.rat</id>
-                        <phase>verify</phase>
-                        <goals>
-                            <goal>check</goal>
-                        </goals>
-                        <configuration>
-                            <excludes>
-                                <exclude>**/*.versionsBackup</exclude>
-                                <exclude>**/.idea/</exclude>
-                                <exclude>**/*.iml</exclude>
-                                <exclude>**/*.txt</exclude>
-                                <exclude>**/*.load</exclude>
-                                <exclude>**/*.flex</exclude>
-                                <exclude>**/*.fc</exclude>
-                                <exclude>**/*.javascript</exclude>
-                                <exclude>**/*.properties</exclude>
-                                <exclude>**/*.thrift</exclude>
-                                <exclude>**/*.sh</exclude>
-                                <exclude>**/*.bat</exclude>
-                                <exclude>**/*.md</exclude>
-                                <exclude>.git/</exclude>
-                                <exclude>.gitignore</exclude>
-                                <!-- ASF jenkins box puts the Maven repo in our root directory.
-->
-                                <exclude>.repository/</exclude>
-                                <exclude>**/.settings/*</exclude>
-                                <exclude>**/.classpath</exclude>
-                                <exclude>**/.project</exclude>
-                                <exclude>**/target/**</exclude>
-                                <exclude>**/*.log</exclude>
-                                <exclude>CODE_OF_CONDUCT.md</exclude>
-                                <exclude>.codecov.yml</exclude>
-                                <exclude>.travis.yml</exclude>
-                                <exclude>PULL_REQUEST_TEMPLATE.md</exclude>
-                                <exclude>CONTRIBUTING.md</exclude>
-                                <exclude>README.md</exclude>
-                                <exclude>**/codestyle/*</exclude>
-                                <exclude>**/resources/META-INF/**</exclude>
-                                <exclude>**/webapp/swagger/**</exclude>
-                                <exclude>**/org/apache/dubbo/samples/rpc/nativethrift/api/DemoService.java</exclude>
-                            </excludes>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
     <profiles>
         <profile>
-            <id>checkstyle</id>
-            <activation>
-                <jdk>[1.8,)</jdk>
-            </activation>
+            <id>dubbo-integration-test</id>
             <build>
                 <plugins>
                     <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-checkstyle-plugin</artifactId>
-                        <version>${maven_checkstyle_version}</version>
-                        <dependencies>
-                            <dependency>
-                                <groupId>com.puppycrawl.tools</groupId>
-                                <artifactId>checkstyle</artifactId>
-                                <version>8.9</version>
-                            </dependency>
-                        </dependencies>
+                        <groupId>org.apache.dubbo</groupId>
+                        <artifactId>dubbo-maven-address-plugin</artifactId>
+                        <version>1.0-SNAPSHOT</version>
                         <executions>
                             <execution>
-                                <id>checkstyle-validation</id>
-                                <phase>validate</phase>
+                                <goals>
+                                    <goal>local-address</goal>
+                                </goals>
                                 <configuration>
-                                    <configLocation>../codestyle/checkstyle.xml</configLocation>
-                                    <suppressionsLocation>../codestyle/checkstyle-suppressions.xml</suppressionsLocation>
-                                    <encoding>UTF-8</encoding>
-                                    <consoleOutput>true</consoleOutput>
-                                    <failOnViolation>true</failOnViolation>
+                                    <localAddress>dubbo-local-address</localAddress>
                                 </configuration>
+                                <phase>initialize</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>com.google.cloud.tools</groupId>
+                        <artifactId>jib-maven-plugin</artifactId>
+                        <version>${jib-maven-plugin.version}</version>
+                        <configuration>
+                            <from>
+                                <image>openjdk:8</image>
+                            </from>
+                            <to>
+                                <image>${image.name}</image>
+                            </to>
+                            <container>
+                                <mainClass>${main-class}</mainClass>
+                                <environment>
+                                    <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+                                </environment>
+                                <jvmFlags>
+                                    <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+                                </jvmFlags>
+                            </container>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>package</phase>
                                 <goals>
-                                    <goal>check</goal>
+                                    <goal>dockerBuild</goal>
                                 </goals>
                             </execution>
                         </executions>
                     </plugin>
+
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <version>${docker-maven-plugin.version}</version>
+                        <configuration>
+                            <images>
+                                <image>
+                                    <name>${image.name}</name>
+                                    <run>
+                                        <ports>
+                                            <port>${dubbo.port}:${dubbo.port}</port>
+                                            <port>${zookeeper.port.1}:${zookeeper.port.1}</port>
+                                            <port>${zookeeper.port.2}:${zookeeper.port.2}</port>
+                                        </ports>
+                                        <wait>
+                                            <log>dubbo service started</log>
+                                        </wait>
+                                    </run>
+                                </image>
+                            </images>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>start</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>${maven-failsafe-plugin.version}</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <systemPropertyVariables>
+                                        <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+                                    </systemPropertyVariables>
+                                    <includes>
+                                        <include>**/*IT.java</include>
+                                    </includes>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
                 </plugins>
             </build>
         </profile>
     </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
index 3f44863..f34ea1d 100644
--- a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
+++ b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
@@ -28,14 +28,15 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
 public class MultiRegistryConsumer {
 
     public static void main(String[] args) throws Exception {
-        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/multi-registry-consumer.xml"});
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/multi-registry-consumer.xml");
         context.start();
-        DemoService demoServiceFormDefault = (DemoService) context.getBean("demoServiceFormDefault");
// get remote service proxy
-        HelloService helloServiceFormShanghai = (HelloService) context.getBean("helloServiceFormShanghai");
// get remote service proxy
-        HelloService helloServiceFormBeijing = (HelloService) context.getBean("helloServiceFormBeijing");
// get remote service proxy
+
+        DemoService demoServiceFormDefault = (DemoService) context.getBean("demoServiceFormDefault");
+        HelloService helloServiceFormShanghai = (HelloService) context.getBean("helloServiceFormShanghai");
+        HelloService helloServiceFormBeijing = (HelloService) context.getBean("helloServiceFormBeijing");
+
         System.out.println(demoServiceFormDefault.get("service form default registry"));
         System.out.println(helloServiceFormShanghai.sayHello("service form shanghai registry"));
         System.out.println(helloServiceFormBeijing.sayHello("service form beijing registry"));
-        System.in.read();
     }
 }
diff --git a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
index c9c079e..993acd2 100644
--- a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
+++ b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryProvider.java
@@ -21,14 +21,19 @@ package org.apache.dubbo.samples.multi.registry;
 
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+import java.util.concurrent.CountDownLatch;
+
 
 public class MultiRegistryProvider {
 
-    public static void main(String[] args) throws Exception{
+    public static void main(String[] args) throws Exception {
         new EmbeddedZooKeeper(2181, false).start();
         new EmbeddedZooKeeper(2182, false).start();
-        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/multi-registry-provider.xml"});
+
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/multi-registry-provider.xml");
         context.start();
-        System.in.read(); // press any key to exit
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
     }
 }
diff --git a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
index 93d675a..10b7e3b 100644
--- a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
+++ b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/DemoService.java
@@ -22,5 +22,5 @@ package org.apache.dubbo.samples.multi.registry.api;
 
 public interface DemoService {
 
-    public String get(String name);
+    String get(String name);
 }
diff --git a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
index dfd44de..578ce97 100644
--- a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
+++ b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/api/HelloService.java
@@ -22,5 +22,5 @@ package org.apache.dubbo.samples.multi.registry.api;
 
 public interface HelloService {
 
-    public String sayHello(String name);
+    String sayHello(String name);
 }
diff --git a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer.xml
b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer.xml
index eca614c..a813ddb 100644
--- a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer.xml
+++ b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer.xml
@@ -18,24 +18,23 @@
 
 <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="multi-registry-consumer"/>
 
-    <!-- use multicast registry center to discover service -->
-    <dubbo:registry id="beijingRegistry" address="zookeeper://127.0.0.1:2181" default="false"/>
-    <dubbo:registry id="shanghaiRegistry" address="zookeeper://127.0.0.1:2182" />
+    <dubbo:registry id="beijingRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"
default="false"/>
+    <dubbo:registry id="shanghaiRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:2182"/>
 
-    <!-- generate proxy for the remote service, then demoService can be used in the same
way as the
-    local regular interface -->
     <dubbo:reference id="demoServiceFormDefault" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"/>
-    <dubbo:reference id="demoServiceFormBeijing" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"
registry="beijingRegistry"/>
-    <dubbo:reference id="helloServiceFormBeijing" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
registry="beijingRegistry"/>
-    <dubbo:reference id="helloServiceFormShanghai" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
registry="shanghaiRegistry"/>
+    <dubbo:reference id="demoServiceFormBeijing" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"
+                     registry="beijingRegistry"/>
+    <dubbo:reference id="helloServiceFormBeijing" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
+                     registry="beijingRegistry"/>
+    <dubbo:reference id="helloServiceFormShanghai" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
+                     registry="shanghaiRegistry"/>
 
 </beans>
 
diff --git a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-provider.xml
b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-provider.xml
index 93068ae..a5aea12 100644
--- a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-provider.xml
+++ b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-provider.xml
@@ -18,26 +18,23 @@
 
 <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="multi-registry-provider"/>
 
-    <!-- use multicast registry center to export service -->
-    <dubbo:registry id="beijingRegistry" address="zookeeper://127.0.0.1:2181" default="false"/>
-    <dubbo:registry id="shanghaiRegistry" address="zookeeper://127.0.0.1:2182" />
+    <dubbo:registry id="beijingRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"
default="false"/>
+    <dubbo:registry id="shanghaiRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:2182"/>
 
-    <!-- use dubbo protocol to export service on port 20880 -->
     <dubbo:protocol name="dubbo" port="20890"/>
 
-    <!-- service implementation, as same as regular local bean -->
     <bean id="helloService" class="org.apache.dubbo.samples.multi.registry.impl.HelloServiceImpl"/>
     <bean id="demoService" class="org.apache.dubbo.samples.multi.registry.impl.DemoServiceImpl"/>
 
-    <!-- declare the service interface to be exported -->
-    <dubbo:service interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
ref="helloService" registry="shanghaiRegistry,beijingRegistry" />
-    <dubbo:service interface="org.apache.dubbo.samples.multi.registry.api.DemoService"
ref="demoService" />
+    <dubbo:service interface="org.apache.dubbo.samples.multi.registry.api.HelloService"
ref="helloService"
+                   registry="shanghaiRegistry,beijingRegistry"/>
+    <dubbo:service interface="org.apache.dubbo.samples.multi.registry.api.DemoService"
ref="demoService"/>
 
-</beans>
\ No newline at end of file
+</beans>
diff --git a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
new file mode 100644
index 0000000..cdbe0f4
--- /dev/null
+++ b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
@@ -0,0 +1,87 @@
+/*
+ * 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.multi.registry;
+
+import org.apache.dubbo.samples.multi.registry.api.DemoService;
+import org.apache.dubbo.samples.multi.registry.api.HelloService;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.List;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/multi-registry-consumer.xml"})
+public class MultiRegistryServiceIT {
+    @Autowired
+    @Qualifier("demoServiceFormDefault")
+    private DemoService defaultDemoService;
+
+    @Autowired
+    @Qualifier("demoServiceFormBeijing")
+    private DemoService beijingDemoService;
+
+    @Autowired
+    @Qualifier("helloServiceFormBeijing")
+    private HelloService beijingHelloService;
+
+    @Autowired
+    @Qualifier("helloServiceFormShanghai")
+    private HelloService shanghaiHelloService;
+
+    @Test
+    public void testDefaultDemoService() throws Exception {
+        Assert.assertEquals("get: demo", defaultDemoService.get("demo"));
+    }
+
+    @Test
+    public void testBeijingDemoService() throws Exception {
+        Assert.assertEquals("get: beijing", beijingDemoService.get("beijing"));
+    }
+
+    @Test
+    public void testBeijingHelloService() throws Exception {
+        Assert.assertEquals("sayHello: beijing", beijingHelloService.sayHello("beijing"));
+    }
+
+    @Test
+    public void testShanghaiHelloService() throws Exception {
+        Assert.assertEquals("sayHello: shanghai", shanghaiHelloService.sayHello("shanghai"));
+    }
+
+    @Test
+    public void verifyProvidersFromBeijingRegistry() throws Exception {
+        List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class,
2181);
+        Assert.assertEquals(1, demoServiceProviders.size());
+        List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class,
2181);
+        Assert.assertEquals(1, helloServiceProviders.size());
+    }
+
+    @Test
+    public void verifyProvidersFromShanghaiRegistry() throws Exception {
+        List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class,
2182);
+        Assert.assertEquals(1, demoServiceProviders.size());
+        List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class,
2182);
+        Assert.assertEquals(1, helloServiceProviders.size());
+    }
+}
diff --git a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/ZKTools.java
b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/ZKTools.java
new file mode 100644
index 0000000..f03950d
--- /dev/null
+++ b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/ZKTools.java
@@ -0,0 +1,51 @@
+/*
+ * 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.multi.registry;
+
+import org.apache.dubbo.common.URL;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class ZKTools {
+    private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+    private static Map<Integer, CuratorFramework> clients = new HashMap<>();
+
+    private static CuratorFramework initClient(int port) {
+        if (!clients.containsKey(port)) {
+            CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperHost + ":"
+ port, 60 * 1000, 60 * 1000,
+                    new ExponentialBackoffRetry(1000, 3));
+            client.start();
+            clients.put(port, client);
+        }
+        return clients.get(port);
+    }
+
+    public static List<String> getProviders(Class clazz, int port) throws Exception
{
+        CuratorFramework client = initClient(port);
+        String path = "/dubbo/" + clazz.getName() + "/providers";
+        List<String> result = client.getChildren().forPath(path);
+        return result.stream().map(URL::decode).collect(Collectors.toList());
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Mime
View raw message