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-metadata-report-configcenter
Date Thu, 27 Jun 2019 06:44:36 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 3893ecf  integration test for dubbo-samples-metadata-report-configcenter
3893ecf is described below

commit 3893ecfb365990cc4557e525dc03742489f377b9
Author: Ian Luo <ian.luo@gmail.com>
AuthorDate: Thu Jun 27 14:43:21 2019 +0800

    integration test for dubbo-samples-metadata-report-configcenter
---
 .../pom.xml                                        | 397 +++++++--------------
 .../configcenter/MetadataConfigcenterConsumer.java |  28 +-
 .../configcenter/MetadataConfigcenterProvider.java |  37 +-
 .../metadatareport/configcenter/ZKTools.java       |  53 ++-
 .../metadatareport/configcenter/ZkUtil.java        |  39 --
 .../configcenter/action/AnnotationAction.java      |   4 +-
 .../configcenter/api/AnnotationService.java        |   3 -
 .../configcenter/impl/AnnotationServiceImpl.java   |   6 +-
 .../resources/spring/dubbo-consumer.properties     |   6 +-
 .../resources/spring/dubbo-provider.properties     |   8 +-
 .../metadatareport/configcenter/MetadataIT.java    | 170 +++++++++
 11 files changed, 378 insertions(+), 373 deletions(-)

diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/pom.xml b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/pom.xml
index 872f98f..aeac6e0 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/pom.xml
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/pom.xml
@@ -30,301 +30,176 @@
     <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.1</dubbo.version>
-        <dubbo.rpc.version>2.7.1</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>
-        <snakeyaml_version>1.20</snakeyaml_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>20831</dubbo.port>
+        <zookeeper.port>2181</zookeeper.port>
+        <main-class>org.apache.dubbo.samples.metadatareport.configcenter.MetadataConfigcenterProvider</main-class>
     </properties>
 
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.yaml</groupId>
-                <artifactId>snakeyaml</artifactId>
-                <version>${snakeyaml_version}</version>
-            </dependency>
-            <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>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-configcenter-zookeeper</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}:${zookeeper.port}</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-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterConsumer.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterConsumer.java
index e07b282..a684092 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterConsumer.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterConsumer.java
@@ -19,36 +19,27 @@
 
 package org.apache.dubbo.samples.metadatareport.configcenter;
 
-import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
-import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
 import org.apache.dubbo.samples.metadatareport.configcenter.action.AnnotationAction;
 import org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService;
+
 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 
-/**
- * CallbackConsumer
- */
 public class MetadataConfigcenterConsumer {
 
     public static void main(String[] args) throws Exception {
         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
         context.start();
 
-
         printServiceData();
 
-        final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
+        AnnotationAction annotationAction = context.getBean("annotationAction", AnnotationAction.class);
         String hello = annotationAction.doSayHello("world");
-        System.out.println("result :" + hello);
-        System.in.read();
+        System.out.println("result: " + hello);
     }
 
     @Configuration
@@ -59,14 +50,13 @@ public class MetadataConfigcenterConsumer {
 
     }
 
-    private static void printServiceData() throws InterruptedException {
-        // get service data(consumer) from zookeeper.
-        ZookeeperClient zookeeperClient = ExtensionLoader.getExtensionLoader(ZookeeperTransporter.class).getExtension("curator").connect(new URL("zookeeper", "127.0.0.1", 2181));
+
+    private static void printServiceData() throws Exception {
         Thread.sleep(3000);
-        String data = zookeeperClient.getContent(ZkUtil.getNodePath(new MetadataIdentifier(AnnotationService.class.getName(), "1.1.1", "d-test", Constants.CONSUMER_SIDE, "metadatareport-configcenter-consumer")));
         System.out.println("*********************************************************");
-        System.out.println("Dubbo store consumer param into special store(as zk,redis) when configcenter:");
-        System.out.println(data);
+        System.out.println("service metadata:");
+        System.out.println(ZKTools.getMetadata("/dubbo", AnnotationService.class.getName(), "1.1.1", "d-test",
+                CommonConstants.CONSUMER_SIDE, "metadatareport-configcenter-consumer"));
         System.out.println("*********************************************************");
     }
 }
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterProvider.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterProvider.java
index 6e77b56..935bc08 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterProvider.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataConfigcenterProvider.java
@@ -20,34 +20,31 @@
 package org.apache.dubbo.samples.metadatareport.configcenter;
 
 
-import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.config.ProviderConfig;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
-import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
 import org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService;
+
 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 
-/**
- *
- */
+import java.util.concurrent.CountDownLatch;
+
 public class MetadataConfigcenterProvider {
 
     public static void main(String[] args) throws Exception {
-        EmbeddedZooKeeper embeddedZooKeeper = new EmbeddedZooKeeper(2181, false);
-        embeddedZooKeeper.start();
+        new EmbeddedZooKeeper(2181, false).start();
+        ZKTools.generateDubboProperties();
+
         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
         context.start();
-        // get service data(provider) from zookeeper .
+
         printServiceData();
-        System.in.read();
-        embeddedZooKeeper.stop();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
     }
 
     @Configuration
@@ -62,16 +59,12 @@ public class MetadataConfigcenterProvider {
         }
     }
 
-    private static void printServiceData() throws InterruptedException {
-        // get service data(provider) from zookeeper .
-        ZookeeperClient zookeeperClient = ExtensionLoader.getExtensionLoader(ZookeeperTransporter.class).getExtension("curator").connect(new URL("zookeeper", "127.0.0.1", 2181));
+    private static void printServiceData() throws Exception {
         Thread.sleep(3000);
-
-        String data = zookeeperClient.getContent(ZkUtil.getNodePath(new MetadataIdentifier(AnnotationService.class.getName(), "1.1.1", "d-test", Constants.PROVIDER_SIDE, "metadatareport-configcenter-provider")));
         System.out.println("*********************************************************");
-        System.out.println("Dubbo store metadata into special store(as zk,redis) when configcenter:");
-        System.out.println(data);
+        System.out.println("service metadata:");
+        System.out.println(ZKTools.getMetadata("/dubbo", AnnotationService.class.getName(), "1.1.1", "d-test",
+                CommonConstants.PROVIDER_SIDE, "metadatareport-configcenter-provider"));
         System.out.println("*********************************************************");
     }
-
 }
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZKTools.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZKTools.java
index 15003bb..7a55dce 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZKTools.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZKTools.java
@@ -17,31 +17,41 @@
 package org.apache.dubbo.samples.metadatareport.configcenter;
 
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
 
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.ExponentialBackoffRetry;
 
-/**
- *
- */
+import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
+
 public class ZKTools {
+    private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
     private static CuratorFramework client;
 
+    static {
+        initClient();
+    }
+
     public static void main(String[] args) throws Exception {
-        client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
-                new ExponentialBackoffRetry(1000, 3));
-        client.start();
+        generateDubboProperties();
+    }
 
-        //removeInterfaceData(AnnotationService.class);
+    public static void generateDubboProperties() {
         generateDubboPropertiesForGlobal();
         generateDubboPropertiesForProvider();
         generateDubboPropertiesForConsumer();
     }
 
+    private static void initClient() {
+        client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+    }
+
     public static void generateDubboPropertiesForGlobal() {
-        String str = "dubbo.registry.address=zookeeper://127.0.0.1:2181\n" +
-                "dubbo.metadata-report.address=zookeeper://127.0.0.1:2181\n" +
+        String str = "dubbo.registry.address=zookeeper://" + zookeeperHost + ":2181\n" +
+                "dubbo.metadata-report.address=zookeeper://" + zookeeperHost + ":2181\n" +
                 "#global config for consumer\n" +
                 "dubbo.consumer.timeout=6000\n" +
                 "#global config for provider\n" +
@@ -113,4 +123,29 @@ public class ZKTools {
         }
     }
 
+    public static String getMetadata(String root, String serviceInterface, String version, String group,
+                                     String side, String app) throws Exception {
+        String path = getNodePath(root, new MetadataIdentifier(serviceInterface, version, group, side, app));
+        return new String(client.getData().forPath(path));
+    }
+
+    public static String getNodePath(String root, MetadataIdentifier metadataIdentifier) {
+        return toRootDir(root) + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
+    }
+
+    private static String toRootDir(String root) {
+        if (root.equals(PATH_SEPARATOR)) {
+            return root;
+        }
+        return root + PATH_SEPARATOR;
+    }
+
+    private static void removeGlobalConfig() {
+        try {
+            client.delete().forPath("/dubbo/config/dubbo/dubbo.properties");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
 }
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZkUtil.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZkUtil.java
deleted file mode 100644
index 743cbbe..0000000
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/ZkUtil.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- *   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.metadatareport.configcenter;
-
-import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
-
-/**
- * 2018/11/8
- */
-public class ZkUtil {
-
-    static String toRootDir(String root) {
-        if (root.equals(Constants.PATH_SEPARATOR)) {
-            return root;
-        }
-        return root + Constants.PATH_SEPARATOR;
-    }
-
-    public static String getNodePath(MetadataIdentifier metadataIdentifier) {
-        return toRootDir("/dubbo") + metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH) + Constants.PATH_SEPARATOR + "service.data";
-    }
-}
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/action/AnnotationAction.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/action/AnnotationAction.java
index 9a21a5c..642bf56 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/action/AnnotationAction.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/action/AnnotationAction.java
@@ -21,11 +21,9 @@ package org.apache.dubbo.samples.metadatareport.configcenter.action;
 
 import org.apache.dubbo.config.annotation.Reference;
 import org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService;
+
 import org.springframework.stereotype.Component;
 
-/**
- * AnnotationAction
- */
 @Component("annotationAction")
 public class AnnotationAction {
 
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/api/AnnotationService.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/api/AnnotationService.java
index d2c4f0f..08b1a4d 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/api/AnnotationService.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/api/AnnotationService.java
@@ -19,9 +19,6 @@
 
 package org.apache.dubbo.samples.metadatareport.configcenter.api;
 
-/**
- * AsyncService
- */
 public interface AnnotationService {
 
     String sayHello(String name);
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/impl/AnnotationServiceImpl.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/impl/AnnotationServiceImpl.java
index 3c53732..37a1ca9 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/impl/AnnotationServiceImpl.java
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/java/org/apache/dubbo/samples/metadatareport/configcenter/impl/AnnotationServiceImpl.java
@@ -22,16 +22,12 @@ package org.apache.dubbo.samples.metadatareport.configcenter.impl;
 import org.apache.dubbo.config.annotation.Service;
 import org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService;
 
-/**
- * AsyncServiceImpl
- */
 @Service(version = "1.1.1", group = "d-test")
 public class AnnotationServiceImpl implements AnnotationService {
 
     @Override
     public String sayHello(String name) {
-        System.out.println("async provider received: " + name);
+        System.out.println("received: " + name);
         return "annotation: hello, " + name;
     }
-
 }
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-consumer.properties
index 5915e3b..d08d631 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-consumer.properties
@@ -17,8 +17,4 @@
 #
 #
 dubbo.application.name=metadatareport-configcenter-consumer
-dubbo.config-center.address=zookeeper://127.0.0.1:2181
-# The common part, for example registry, protocol can be stored under the global group in ConfigCenter
-#dubbo.registry.address=zookeeper://127.0.0.1:2181
-# The application specific part, can be stored under the app group in the ConfigCenter
-#dubbo.consumer.timeout=3000
+dubbo.config-center.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-provider.properties
index eb77253..c1ffb31 100644
--- a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-provider.properties
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/main/resources/spring/dubbo-provider.properties
@@ -17,11 +17,5 @@
 #
 #
 dubbo.application.name=metadatareport-configcenter-provider
-dubbo.config-center.address=zookeeper://127.0.0.1:2181
+dubbo.config-center.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
 dubbo.configCenter.configFile=dubbo.properties
-
-# The common part, for example registry, protocol can be stored under the global group in ConfigCenter
-# The application specific part, can be stored under the app group in the ConfigCenter
-#dubbo.registry.address=zookeeper://127.0.0.1:2181
-#dubbo.protocol.name=dubbo
-#dubbo.protocol.port=20880
diff --git a/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/test/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataIT.java b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/test/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataIT.java
new file mode 100644
index 0000000..2c67ba5
--- /dev/null
+++ b/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/src/test/java/org/apache/dubbo/samples/metadatareport/configcenter/MetadataIT.java
@@ -0,0 +1,170 @@
+/*
+ * 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.metadatareport.configcenter;
+
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.definition.model.MethodDefinition;
+import org.apache.dubbo.samples.metadatareport.configcenter.action.AnnotationAction;
+import org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService;
+
+import com.google.gson.Gson;
+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;
+
+import java.util.List;
+import java.util.Map;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {MetadataConfigcenterConsumer.ConsumerConfiguration.class})
+public class MetadataIT {
+    @Autowired
+    private AnnotationAction action;
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        Thread.sleep(2000);
+    }
+
+    /**
+     * <pre>
+     * {
+     *   "parameters": {
+     *     "side": "provider",
+     *     "release": "2.7.2",
+     *     "methods": "sayHello",
+     *     "deprecated": "false",
+     *     "dubbo": "2.0.2",
+     *     "threads": "100",
+     *     "interface": "org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService",
+     *     "threadpool": "fixed",
+     *     "version": "1.1.1",
+     *     "timeout": "5000",
+     *     "generic": "false",
+     *     "revision": "1.1.1",
+     *     "application": "metadatareport-configcenter-provider",
+     *     "dynamic": "true",
+     *     "register": "true",
+     *     "bean.name": "ServiceBean:org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService:1.1.1:d-test",
+     *     "group": "d-test",
+     *     "anyhost": "true"
+     *   },
+     *   "canonicalName": "org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService",
+     *   "codeSource": "file:/github/dubbo/incubator-dubbo-samples/dubbo-samples-metadata-report/dubbo-samples-metadata-report-configcenter/target/classes/",
+     *   "methods": [
+     *     {
+     *       "name": "sayHello",
+     *       "parameterTypes": [
+     *         "java.lang.String"
+     *       ],
+     *       "returnType": "java.lang.String"
+     *     }
+     *   ],
+     *   "types": [
+     *     {
+     *       "type": "int"
+     *     },
+     *     {
+     *       "type": "char"
+     *     },
+     *     {
+     *       "type": "java.lang.String",
+     *       "properties": {
+     *         "value": {
+     *           "type": "char[]"
+     *         },
+     *         "hash": {
+     *           "type": "int"
+     *         }
+     *       }
+     *     }
+     *   ]
+     * }
+     * </pre>
+     */
+    @Test
+    public void testProviderMetadata() throws Exception {
+        String result = ZKTools.getMetadata("/dubbo", AnnotationService.class.getName(), "1.1.1", "d-test",
+                CommonConstants.PROVIDER_SIDE, "metadatareport-configcenter-provider");
+        Gson gson = new Gson();
+        FullServiceDefinition definition = gson.fromJson(result, FullServiceDefinition.class);
+        Map<String, String> parameters = definition.getParameters();
+        Assert.assertEquals("provider", parameters.get("side"));
+        Assert.assertEquals("sayHello", parameters.get("methods"));
+        Assert.assertEquals("5000", parameters.get("timeout"));
+        Assert.assertEquals("1.1.1", parameters.get("version"));
+        Assert.assertEquals("d-test", parameters.get("group"));
+        Assert.assertEquals("100", parameters.get("threads"));
+        Assert.assertEquals("fixed", parameters.get("threadpool"));
+        Assert.assertEquals(AnnotationService.class.getCanonicalName(), parameters.get("interface"));
+        Assert.assertEquals("false", parameters.get("generic"));
+        Assert.assertEquals("metadatareport-configcenter-provider", parameters.get("application"));
+        Assert.assertEquals("true", parameters.get("dynamic"));
+        Assert.assertEquals("true", parameters.get("register"));
+        Assert.assertEquals("true", parameters.get("anyhost"));
+        Assert.assertEquals(AnnotationService.class.getCanonicalName(), definition.getCanonicalName());
+        List<MethodDefinition> methods = definition.getMethods();
+        Assert.assertEquals(1, methods.size());
+        MethodDefinition method = methods.get(0);
+        Assert.assertEquals("sayHello", method.getName());
+        String[] parameterTypes = method.getParameterTypes();
+        Assert.assertEquals(1, parameterTypes.length);
+        Assert.assertEquals("java.lang.String", parameterTypes[0]);
+        Assert.assertEquals("java.lang.String", method.getReturnType());
+    }
+
+    /**
+     * <pre>
+     * {
+     *   "side": "consumer",
+     *   "release": "2.7.2",
+     *   "methods": "sayHello",
+     *   "lazy": "false",
+     *   "dubbo": "2.0.2",
+     *   "interface": "org.apache.dubbo.samples.metadatareport.configcenter.api.AnnotationService",
+     *   "version": "1.1.1",
+     *   "timeout": "6666",
+     *   "revision": "1.1.1",
+     *   "application": "metadatareport-configcenter-consumer",
+     *   "sticky": "false",
+     *   "group": "d-test"
+     * }
+     * </pre>
+     */
+    @Test
+    public void testConsumerMetadata() throws Exception {
+        String result = ZKTools.getMetadata("/dubbo", AnnotationService.class.getName(), "1.1.1", "d-test",
+                CommonConstants.CONSUMER_SIDE, "metadatareport-configcenter-consumer");
+        Gson gson = new Gson();
+        Map<String, String> map = gson.fromJson(result, Map.class);
+        Assert.assertEquals("consumer", map.get("side"));
+        Assert.assertEquals("metadatareport-configcenter-consumer", map.get("application"));
+        Assert.assertEquals("sayHello", map.get("methods"));
+        Assert.assertEquals("false", map.get("lazy"));
+        Assert.assertEquals("false", map.get("sticky"));
+        Assert.assertEquals("1.1.1", map.get("version"));
+        Assert.assertEquals("d-test", map.get("group"));
+        Assert.assertEquals("6666", map.get("timeout"));
+        Assert.assertEquals(AnnotationService.class.getName(), map.get("interface"));
+    }
+}


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


Mime
View raw message