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/06/18 12:22:18 UTC
[dubbo-samples] branch master updated: integration test for
dubbo-sampes-configcenter/dubbo-samples-configcenter-api
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 cdb3876 integration test for dubbo-sampes-configcenter/dubbo-samples-configcenter-api
new 8a90940 Merge branch 'master' of https://github.com/apache/incubator-dubbo-samples
cdb3876 is described below
commit cdb3876fa9cc2f3df21b2392635e35c00f8942b0
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Tue Jun 18 20:20:45 2019 +0800
integration test for dubbo-sampes-configcenter/dubbo-samples-configcenter-api
---
.../dubbo-samples-configcenter-api/pom.xml | 394 ++++++++-------------
.../java/org/apache/dubbo/samples/ZKTools.java | 21 +-
.../org/apache/dubbo/samples/api/DemoService.java | 3 -
.../dubbo/samples/provider/DemoServiceImpl.java | 29 --
.../samples/provider/GreetingsServiceImpl.java | 27 --
.../samples/provider/MultipleServiceProvider.java | 79 -----
.../apache/dubbo/samples/provider/Provider.java | 63 ----
.../dubbo/samples/server/DemoServiceImpl.java | 3 -
.../server/{Provider.java => Provider1.java} | 10 +-
...MultipleServiceProvider.java => Provider2.java} | 29 +-
.../src/main/resources/docker/docker-compose.yml | 10 +
.../org/apache/dubbo/samples/DemoServiceIT.java | 52 +++
.../apache/dubbo/samples/GreetingsServiceIT.java | 53 +++
13 files changed, 292 insertions(+), 481 deletions(-)
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/pom.xml b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/pom.xml
index d78582a..f27de9d 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/pom.xml
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/pom.xml
@@ -26,291 +26,187 @@
<artifactId>dubbo-samples-configcenter-api</artifactId>
-
<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>3.0.0-M3</maven-failsafe-plugin.version>
+ <image.name>${artifactId}:${dubbo.version}</image.name>
+ <dubbo.port>20880</dubbo.port>
+ <main-class>org.apache.dubbo.samples.server.Provider2</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>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
</dependency>
+
<dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <groupId>org.springframework</groupId>
+ <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>
+ <ports>
+ <port>${dubbo.port}</port>
+ </ports>
+ <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>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>
+ <external>
+ <type>compose</type>
+ <basedir>src/main/resources/docker</basedir>
+ <composeFile>docker-compose.yml</composeFile>
+ </external>
+ </image>
+ <image>
+ <name>${image.name}</name>
+ <run>
+ <ports>
+ <port>${dubbo.port}:${dubbo.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>check</goal>
+ <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-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/ZKTools.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/ZKTools.java
index b2ffb1e..aff867d 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/ZKTools.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/ZKTools.java
@@ -22,22 +22,17 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
-/**
- *
- */
public class ZKTools {
private static CuratorFramework client;
+ private static String zookeeperHost = "127.0.0.0";
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();
-
+ initClient();
generateDubboPropertiesForGlobal();
}
public static void generateDubboPropertiesForGlobal() {
- String str = "dubbo.registry.address=zookeeper://127.0.0.1:2181\n";
+ String str = "dubbo.registry.address=zookeeper://" + zookeeperHost + ":2181\n";
System.out.println(str);
@@ -52,6 +47,16 @@ public class ZKTools {
}
}
+ public static void setZookeeperHost(String host) {
+ zookeeperHost = host;
+ }
+
+ public static void initClient() {
+ client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
+ new ExponentialBackoffRetry(1000, 3));
+ client.start();
+ }
+
private static void setData(String path, String data) throws Exception {
client.setData().forPath(path, data.getBytes());
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/api/DemoService.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/api/DemoService.java
index 5fb553e..3fe0a9c 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/api/DemoService.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/api/DemoService.java
@@ -16,9 +16,6 @@
*/
package org.apache.dubbo.samples.api;
-/**
- *
- */
public interface DemoService {
String sayHello();
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java
deleted file mode 100644
index 2902273..0000000
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java
+++ /dev/null
@@ -1,29 +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.provider;
-
-import org.apache.dubbo.samples.api.DemoService;
-
-/**
- *
- */
-public class DemoServiceImpl implements DemoService {
- @Override
- public String sayHello() {
- return "Hello, you!";
- }
-}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
deleted file mode 100644
index d0d4448..0000000
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
+++ /dev/null
@@ -1,27 +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.provider;
-
-import org.apache.dubbo.samples.api.GreetingsService;
-
-public class GreetingsServiceImpl implements GreetingsService {
- @Override
- public String sayHi(String name) {
- return "hi, " + name;
- }
-}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java
deleted file mode 100644
index 8490d91..0000000
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java
+++ /dev/null
@@ -1,79 +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.provider;
-
-
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.ConfigCenterConfig;
-import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.config.ServiceConfig;
-import org.apache.dubbo.samples.api.DemoService;
-import org.apache.dubbo.samples.api.GreetingsService;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MultipleServiceProvider {
- private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
- private static ApplicationConfig application = new ApplicationConfig("api-dubbo-provider");
- private static RegistryConfig registry1 = new RegistryConfig();
- private static RegistryConfig registry2 = new RegistryConfig();
-
- static {
- configCenter.setExternalConfig(getExternalConfiguration());
- registry1.setAddress("zookeeper://127.0.0.1:2181");
- registry2.setAddress("zookeeper://127.0.0.1:2181");
- }
-
- public static void main(String[] args) throws Exception {
- ServiceConfig<GreetingsService> greetingsService = new ServiceConfig<>();
- greetingsService.setApplication(application);
- greetingsService.setConfigCenter(configCenter);
- greetingsService.setRegistries(Arrays.asList(registry1, registry2));
- greetingsService.setInterface(GreetingsService.class);
- greetingsService.setRef(new GreetingsServiceImpl());
- greetingsService.export();
-
- ServiceConfig<DemoService> demoService = new ServiceConfig<>();
- demoService.setApplication(application);
- demoService.setConfigCenter(configCenter);
- demoService.setInterface(DemoService.class);
- demoService.setRegistries(Arrays.asList(registry1, registry2));
- demoService.setRef(new DemoServiceImpl());
- demoService.export();
-
- System.out.println("Dubbo provider started successfully!");
- System.in.read();
- }
-
- /**
- * If you don't want to use ConfigCenter provided by dubbo, you can set external configuration to Dubbo directly.
- * In this sample, we created a Map instance manually and put a value into it, but in reality,
- * the external configurations will most likely being generated from other plugins in your system.
- */
- public static Map<String, String> getExternalConfiguration() {
- Map<String, String> dubboConfigurations = new HashMap<>();
- dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
- // you will need to add the configcenter address if you want to use the service governance features in 2.7, e.g., overrides and routers.
- // but notice it will not be used for gathering startup configurations.
- dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
-
- return dubboConfigurations;
- }
-}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java
deleted file mode 100644
index 6ca14bd..0000000
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java
+++ /dev/null
@@ -1,63 +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.provider;
-
-
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.ConfigCenterConfig;
-import org.apache.dubbo.config.ServiceConfig;
-import org.apache.dubbo.samples.api.GreetingsService;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Provider {
-
- private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
- private static ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-provider");
-
- static {
- configCenter.setExternalConfig(getExternalConfiguration());
- }
-
- public static void main(String[] args) throws Exception {
- ServiceConfig<GreetingsService> service = new ServiceConfig<>();
- service.setApplication(applicationConfig);
- service.setConfigCenter(configCenter);
- service.setInterface(GreetingsService.class);
- service.setRef(new GreetingsServiceImpl());
- service.export();
- System.out.println("Dubbo provider started successfully!");
- System.in.read();
- }
-
- /**
- * If you don't want to use ConfigCenter provided by dubbo, you can set external configuration to Dubbo directly.
- * In this sample, we created a Map instance manually and put a value into it, but in reality,
- * the external configurations will most likely being generated from other plugins in your system.
- */
- public static Map<String, String> getExternalConfiguration() {
- Map<String, String> dubboConfigurations = new HashMap<>();
- dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
- // you will need to add the configcenter address if you want to use the service governance features in 2.7, e.g., overrides and routers.
- // but notice it will not be used for gathering startup configurations.
- dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
-
- return dubboConfigurations;
- }
-}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/DemoServiceImpl.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/DemoServiceImpl.java
index 7ab4f2e..ed06547 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/DemoServiceImpl.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/DemoServiceImpl.java
@@ -18,9 +18,6 @@ package org.apache.dubbo.samples.server;
import org.apache.dubbo.samples.api.DemoService;
-/**
- *
- */
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello() {
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
similarity index 89%
rename from dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider.java
rename to dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
index e44e947..4ef486e 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
@@ -26,10 +26,10 @@ import org.apache.dubbo.samples.api.GreetingsService;
import java.util.HashMap;
import java.util.Map;
-public class Provider {
+public class Provider1 {
private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
- private static ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-provider");
+ private static ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-provider-1");
static {
configCenter.setExternalConfig(getExternalConfiguration());
@@ -42,7 +42,7 @@ public class Provider {
service.setInterface(GreetingsService.class);
service.setRef(new GreetingsServiceImpl());
service.export();
- System.out.println("Dubbo provider started successfully!");
+ System.out.println("dubbo service started");
System.in.read();
}
@@ -54,8 +54,8 @@ public class Provider {
public static Map<String, String> getExternalConfiguration() {
Map<String, String> dubboConfigurations = new HashMap<>();
dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
- // you will need to add the configcenter address if you want to use the service governance features in 2.7, e.g., overrides and routers.
- // but notice it will not be used for gathering startup configurations.
+ // you will need to add the configcenter address if you want to use the service governance features in 2.7,
+ // e.g., overrides and routers, but notice it will not be used for gathering startup configurations.
dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
return dubboConfigurations;
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/MultipleServiceProvider.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
similarity index 76%
rename from dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/MultipleServiceProvider.java
rename to dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
index f46786b..8f5328d 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/MultipleServiceProvider.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
@@ -25,27 +25,26 @@ import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.samples.api.DemoService;
import org.apache.dubbo.samples.api.GreetingsService;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
-public class MultipleServiceProvider {
+public class Provider2 {
private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
- private static ApplicationConfig application = new ApplicationConfig("api-dubbo-provider");
- private static RegistryConfig registry1 = new RegistryConfig();
- private static RegistryConfig registry2 = new RegistryConfig();
+ private static ApplicationConfig application = new ApplicationConfig("api-dubbo-provider-2");
+ private static RegistryConfig registry = new RegistryConfig();
+ private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
static {
configCenter.setExternalConfig(getExternalConfiguration());
- registry1.setAddress("zookeeper://127.0.0.1:2181");
- registry2.setAddress("zookeeper://127.0.0.1:2181");
+ registry.setAddress("zookeeper://" + zookeeperHost + ":2182");
}
public static void main(String[] args) throws Exception {
ServiceConfig<GreetingsService> greetingsService = new ServiceConfig<>();
greetingsService.setApplication(application);
greetingsService.setConfigCenter(configCenter);
- greetingsService.setRegistries(Arrays.asList(registry1, registry2));
+ greetingsService.setRegistry(registry);
greetingsService.setInterface(GreetingsService.class);
greetingsService.setRef(new GreetingsServiceImpl());
greetingsService.export();
@@ -54,12 +53,12 @@ public class MultipleServiceProvider {
demoService.setApplication(application);
demoService.setConfigCenter(configCenter);
demoService.setInterface(DemoService.class);
- demoService.setRegistries(Arrays.asList(registry1, registry2));
+ demoService.setRegistry(registry);
demoService.setRef(new DemoServiceImpl());
demoService.export();
- System.out.println("Dubbo provider started successfully!");
- System.in.read();
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
/**
@@ -69,10 +68,10 @@ public class MultipleServiceProvider {
*/
public static Map<String, String> getExternalConfiguration() {
Map<String, String> dubboConfigurations = new HashMap<>();
- dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
- // you will need to add the configcenter address if you want to use the service governance features in 2.7, e.g., overrides and routers.
- // but notice it will not be used for gathering startup configurations.
- dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
+ dubboConfigurations.put("dubbo.registry.address", "zookeeper://" + zookeeperHost + ":2181");
+ // you will need to add the config center address if you want to use the service governance features in 2.7,
+ // e.g., overrides and routers, but notice it will not be used for gathering startup configurations.
+ dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://" + zookeeperHost + ":2181");
return dubboConfigurations;
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/resources/docker/docker-compose.yml b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/resources/docker/docker-compose.yml
new file mode 100644
index 0000000..e92a4e8
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/resources/docker/docker-compose.yml
@@ -0,0 +1,10 @@
+version: "2"
+services:
+ zookeeper1:
+ image: "zookeeper:latest"
+ ports:
+ - "2181:2181"
+ zookeeper2:
+ image: "zookeeper:latest"
+ ports:
+ - "2182:2181"
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/DemoServiceIT.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/DemoServiceIT.java
new file mode 100644
index 0000000..5be4488
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/DemoServiceIT.java
@@ -0,0 +1,52 @@
+/*
+ * 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.config.ApplicationConfig;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.samples.api.DemoService;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class DemoServiceIT {
+ private static String zookeeperHost = "127.0.0.1";
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ zookeeperHost = System.getProperty("zookeeper.address", zookeeperHost);
+ ZKTools.setZookeeperHost(zookeeperHost);
+ ZKTools.initClient();
+ ZKTools.generateDubboPropertiesForGlobal();
+ }
+
+ @Test
+ public void test() throws Exception {
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer");
+ configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181");
+ ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
+ reference.setApplication(applicationConfig);
+ reference.setConfigCenter(configCenter);
+ reference.setInterface(DemoService.class);
+ DemoService demoService = reference.get();
+ Assert.assertEquals("Hello, you!", demoService.sayHello());
+ }
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/GreetingsServiceIT.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/GreetingsServiceIT.java
new file mode 100644
index 0000000..302f1b2
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/test/java/org/apache/dubbo/samples/GreetingsServiceIT.java
@@ -0,0 +1,53 @@
+/*
+ * 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.config.ApplicationConfig;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.samples.api.GreetingsService;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class GreetingsServiceIT {
+ private static String zookeeperHost = "127.0.0.1";
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ zookeeperHost = System.getProperty("zookeeper.address", zookeeperHost);
+ ZKTools.setZookeeperHost(zookeeperHost);
+ ZKTools.initClient();
+ ZKTools.generateDubboPropertiesForGlobal();
+ }
+
+ @Test
+ public void test() throws Exception {
+ ConfigCenterConfig configCenter = new ConfigCenterConfig();
+ ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer");
+ configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181");
+ ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
+ reference.setApplication(applicationConfig);
+ reference.setConfigCenter(configCenter);
+ reference.setInterface(GreetingsService.class);
+ GreetingsService greetingsService = reference.get();
+ String message = greetingsService.sayHi("dubbo");
+ Assert.assertEquals("hi, dubbo", message);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org