You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/06/09 02:25:33 UTC
[servicecomb-java-chassis] 01/03: [SCB-1944]create a demo to show
zero config work with schema discovery
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit eeb08e7750508cce64908b6fa80eeadc6f6f1143
Author: liubao <bi...@qq.com>
AuthorDate: Mon Jun 8 15:55:53 2020 +0800
[SCB-1944]create a demo to show zero config work with schema discovery
---
.../README.md | 17 ++
.../pom.xml | 28 +++-
.../servicecomb/demo/zeroconfig/Application.java | 14 --
.../{ServerTest.java => ClientServerEndpoint.java} | 63 +++----
.../demo/zeroconfig/IServerEndpoint.java} | 22 +--
.../src/main/resources/application.yml | 4 +-
.../pom.xml | 8 +
.../pom.xml | 184 +++++++++++++++++++++
.../servicecomb/demo/zeroconfig/Application.java | 0
.../servicecomb/demo/zeroconfig/ServerTest.java | 38 ++---
.../src/main/resources/application.yml | 4 +-
.../src/main/resources/logback.xml | 50 ++++++
.../src/main/resources/registry.yaml} | 24 ++-
.../demo/zeroconfig/ZeroConfigRegistryIT.java | 0
.../pom.xml | 9 +-
.../zeroconfig/ZeroConfigDiscovery.java | 3 +-
.../zeroconfig/ZeroConfigRegistration.java | 10 +-
.../zeroconfig/ZeroConfigRegistryConstants.java | 3 +-
.../server/ZeroConfigRegistryService.java | 4 +-
19 files changed, 349 insertions(+), 136 deletions(-)
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/README.md b/demo/demo-zeroconfig-schemadiscovery-registry/README.md
new file mode 100644
index 0000000..34c4da9
--- /dev/null
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/README.md
@@ -0,0 +1,17 @@
+# Introduction
+
+This demo tests zeroconfig.
+
+* server
+
+ run in docker
+
+* client
+
+ run in docker, and find server instances through zeroconfig, find schemas through
+ schema discovery
+
+* tests
+
+ integration tests run in host machine, find client instances through local,
+ and schemas from schema discovery.
\ No newline at end of file
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
index 44dd323..5dd52f4 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/pom.xml
@@ -33,24 +33,41 @@
</properties>
<dependencies>
<dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-spring-boot-starter-servlet</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-schema-discovery</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-zero-config</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
</dependency>
+
</dependencies>
<build>
<plugins>
<plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
<groupId>com.github.odavid.maven.plugins</groupId>
<artifactId>mixin-maven-plugin</artifactId>
<configuration>
<mixins>
<mixin>
<groupId>org.apache.servicecomb.demo</groupId>
- <artifactId>docker-run-config</artifactId>
+ <artifactId>docker-build-config</artifactId>
<version>${project.version}</version>
</mixin>
</mixins>
@@ -62,19 +79,18 @@
<profiles>
<profile>
<id>docker</id>
- <properties>
- <demo.service.name>demo-zeroconfig-schemadiscovery-registry-server</demo.service.name>
- </properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.commonjava.maven.plugins</groupId>
+ <artifactId>directory-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
-
-
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
index 388add8..40e2255 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
@@ -17,8 +17,6 @@
package org.apache.servicecomb.demo.zeroconfig;
-import org.apache.servicecomb.demo.CategorizedTestCaseRunner;
-import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.springboot2.starter.EnableServiceComb;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -31,17 +29,5 @@ public class Application {
public static void main(final String[] args) throws Exception {
new SpringApplicationBuilder().sources(Application.class).web(WebApplicationType.SERVLET)
.build().run(args);
-
- runTest();
-
- TestMgr.summary();
- if (!TestMgr.errors().isEmpty()) {
- throw new IllegalStateException("tests failed");
- }
- }
-
- private static void runTest() throws Exception {
- CategorizedTestCaseRunner
- .runCategorizedTestCase("demo-zeroconfig-schemadiscovery-registry-server");
}
}
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ClientServerEndpoint.java
similarity index 57%
copy from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
copy to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ClientServerEndpoint.java
index d508bbc..a1631c8 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ClientServerEndpoint.java
@@ -20,26 +20,35 @@ package org.apache.servicecomb.demo.zeroconfig;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.apache.servicecomb.demo.CategorizedTestCase;
-import org.apache.servicecomb.demo.TestMgr;
-import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
-import org.apache.servicecomb.registry.DiscoveryManager;
-import org.apache.servicecomb.registry.api.registry.Microservice;
-import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
-@Component
-public class ServerTest implements CategorizedTestCase {
+import javax.ws.rs.core.MediaType;
- RestTemplate template = RestTemplateBuilder.create();
-
- @Override
- public void testRestTransport() {
- testServerGetName();
- testGetAllMicroservice();
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.registry.DiscoveryManager;
+import org.apache.servicecomb.registry.api.registry.Microservice;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RestSchema(schemaId = "ClientServerEndpoint")
+@RequestMapping(path = "/register/url/prefix", produces = MediaType.APPLICATION_JSON)
+public class ClientServerEndpoint {
+ private static final Logger LOGGER
+ = LoggerFactory.getLogger(ClientServerEndpoint.class);
+
+ @RpcReference(microserviceName = "demo-zeroconfig-schemadiscovery-registry-server", schemaId = "ServerEndpoint")
+ private IServerEndpoint serverEndpoint;
+
+ @GetMapping(path = "/getName")
+ public String getName(@RequestParam(name = "name") String name) {
+ return serverEndpoint.getName(name);
}
- private void testGetAllMicroservice() {
+ @GetMapping(path = "/getRegisteredMicroservice")
+ public Set<String> getRegisteredMicroservice() {
List<Microservice> microserviceList = DiscoveryManager.INSTANCE.getAllMicroservices();
Set<String> names = new HashSet<>();
@@ -49,24 +58,6 @@ public class ServerTest implements CategorizedTestCase {
names.add(m.getServiceName());
}
}
- TestMgr.check(2, names.size());
- }
-
- private void testServerGetName() {
- // invoke demo-zeroconfig-schemadiscovery-registry-server
- TestMgr.check("2", template
- .getForObject(
- "cse://demo-zeroconfig-schemadiscovery-registry-server/register/url/prefix/getName?name=2",
- String.class));
- }
-
- @Override
- public void testHighwayTransport() throws Exception {
-
- }
-
- @Override
- public void testAllTransport() throws Exception {
-
+ return names;
}
-}
+}
\ No newline at end of file
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/IServerEndpoint.java
similarity index 65%
copy from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java
copy to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/IServerEndpoint.java
index f73ff8b..c038532 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/IServerEndpoint.java
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,23 +17,6 @@
package org.apache.servicecomb.demo.zeroconfig;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-import org.apache.servicecomb.demo.TestMgr;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ZeroConfigRegistryIT {
- @Before
- public void setUp() throws Exception {
- TestMgr.errors().clear();
- }
-
- @Test
- public void clientGetsNoError() throws Exception {
- Application.main(new String[0]);
-
- assertThat(TestMgr.errors().isEmpty(), is(true));
- }
+public interface IServerEndpoint {
+ String getName(String name);
}
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
index 32526c9..6bbfed6 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
@@ -28,4 +28,6 @@ servicecomb:
handler:
chain:
Consumer:
- default: loadbalance
\ No newline at end of file
+ default: loadbalance
+ rest:
+ address: 0.0.0.0:8082
\ No newline at end of file
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-server/pom.xml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-server/pom.xml
index 7edb45c..ed5a285 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-server/pom.xml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-server/pom.xml
@@ -41,6 +41,14 @@
<artifactId>java-chassis-spring-boot-starter-servlet</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-schema-discovery</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-zero-config</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
</dependency>
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/pom.xml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/pom.xml
new file mode 100644
index 0000000..ee853c8
--- /dev/null
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.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.
+ -->
+
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>demo-zeroconfig-schemadiscovery-registry-tests</artifactId>
+ <name>Java Chassis::Demo::ZeroConfig-SchemaDiscovery Registry Tests</name>
+ <parent>
+ <groupId>org.apache.servicecomb.demo</groupId>
+ <artifactId>demo-zeroconfig-schemadiscovery-registry</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <properties>
+ <demo.main>org.apache.servicecomb.demo.zeroconfig.Application</demo.main>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-spring-boot-starter-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-schema-discovery</artifactId>
+ </dependency>
+ <!-- TODO: include this module will cause zero config message broadcasting error, need first fix the bug
+ and then enable zero-config for this module.
+ NOTES: in integration tests enable zero config for this module is useless, because
+ server and client run in docker. Here just to remember this bug.
+ -->
+ <!--
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-zero-config</artifactId>
+ </dependency>
+ -->
+
+ <dependency>
+ <groupId>org.apache.servicecomb.demo</groupId>
+ <artifactId>demo-schema</artifactId>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>docker</id>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <configuration>
+ <images>
+ <image>
+ <name>demo-zeroconfig-schemadiscovery-registry-server:${project.version}</name>
+ <alias>demo-zeroconfig-schemadiscovery-registry-server</alias>
+ <run>
+ <env>
+ <JAR_PATH>/maven/demo-zeroconfig-schemadiscovery-registry-server-${project.version}.jar
+ </JAR_PATH>
+ </env>
+ <wait>
+ <log>watching microservice successfully</log>
+ <tcp>
+ <ports>
+ <port>8080</port>
+ </ports>
+ </tcp>
+ <time>120000</time>
+ </wait>
+ <ports>
+ <port>8080:8080</port>
+ </ports>
+ </run>
+ </image>
+
+ <image>
+ <name>demo-zeroconfig-schemadiscovery-registry-client:${project.version}</name>
+ <alias>demo-zeroconfig-schemadiscovery-registry-client</alias>
+ <run>
+ <env>
+ <JAR_PATH>/maven/demo-zeroconfig-schemadiscovery-registry-client-${project.version}.jar
+ </JAR_PATH>
+ </env>
+ <wait>
+ <log>watching microservice successfully</log>
+ <tcp>
+ <ports>
+ <port>8082</port>
+ </ports>
+ </tcp>
+ <time>120000</time>
+ </wait>
+ <ports>
+ <port>8082:8082</port>
+ </ports>
+ </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>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-default-properties</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>
+ project.properties.setProperty('docker.hostname', 'localhost')
+ log.info("Docker hostname is " + project.properties['docker.hostname'])
+ </source>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <argLine>${jacoco.failsafe.argLine}</argLine>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
+
+
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
similarity index 100%
copy from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
copy to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/java/org/apache/servicecomb/demo/zeroconfig/Application.java
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
similarity index 62%
rename from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
rename to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
index d508bbc..a68c1d2 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/java/org/apache/servicecomb/demo/zeroconfig/ServerTest.java
@@ -17,14 +17,11 @@
package org.apache.servicecomb.demo.zeroconfig;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+
import org.apache.servicecomb.demo.CategorizedTestCase;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
-import org.apache.servicecomb.registry.DiscoveryManager;
-import org.apache.servicecomb.registry.api.registry.Microservice;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@@ -40,33 +37,20 @@ public class ServerTest implements CategorizedTestCase {
}
private void testGetAllMicroservice() {
- List<Microservice> microserviceList = DiscoveryManager.INSTANCE.getAllMicroservices();
- Set<String> names = new HashSet<>();
-
- for (Microservice m : microserviceList) {
- if (m.getServiceName().equals("demo-zeroconfig-schemadiscovery-registry-client")
- || m.getServiceName().equals("demo-zeroconfig-schemadiscovery-registry-server")) {
- names.add(m.getServiceName());
- }
- }
- TestMgr.check(2, names.size());
- }
-
- private void testServerGetName() {
- // invoke demo-zeroconfig-schemadiscovery-registry-server
+ // invoke demo-zeroconfig-schemadiscovery-registry-client
TestMgr.check("2", template
.getForObject(
- "cse://demo-zeroconfig-schemadiscovery-registry-server/register/url/prefix/getName?name=2",
+ "cse://demo-zeroconfig-schemadiscovery-registry-client/register/url/prefix/getName?name=2",
String.class));
}
- @Override
- public void testHighwayTransport() throws Exception {
-
- }
-
- @Override
- public void testAllTransport() throws Exception {
-
+ @SuppressWarnings("rawTypes")
+ private void testServerGetName() {
+ // invoke demo-zeroconfig-schemadiscovery-registry-client
+ TestMgr.check("2", template
+ .getForObject(
+ "cse://demo-zeroconfig-schemadiscovery-registry-client"
+ + "/register/url/prefix/getRegisteredMicroservice",
+ List.class).size());
}
}
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/application.yml
similarity index 92%
copy from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
copy to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/application.yml
index 32526c9..541af06 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/application.yml
@@ -16,13 +16,13 @@
## ---------------------------------------------------------------------------
server:
- port: 8082
+ port: 8084
# java-chassis configurations
APPLICATION_ID: demo-zeroconfig-schemadiscovery-registry
service_description:
- name: demo-zeroconfig-schemadiscovery-registry-client
+ name: demo-zeroconfig-schemadiscovery-registry-tests
version: 0.0.2
servicecomb:
handler:
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/logback.xml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/logback.xml
new file mode 100644
index 0000000..0d627f2
--- /dev/null
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/logback.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<configuration scan="true">
+ <appender name="STDOUT-TRACING" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter -->
+ <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter">
+ <Marker>SERVICECOMB_MARKER</Marker>
+ <OnMismatch>DENY</OnMismatch>
+ <OnMatch>ACCEPT</OnMatch>
+ </filter>
+
+ <encoder>
+ <pattern>%d [%level] [%thread][%X{SERVICECOMB_TRACE_ID}] - %msg (%F:%L\)%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- If applicable, can use ch.qos.logback.classic.filter.MarkerFilter -->
+ <filter class="org.apache.servicecomb.foundation.logback.MarkerFilter">
+ <Marker>SERVICECOMB_MARKER</Marker>
+ <OnMismatch>ACCEPT</OnMismatch>
+ <OnMatch>DENY</OnMatch>
+ </filter>
+
+ <encoder>
+ <pattern>%d [%level] [%thread] - %msg (%F:%L\)%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT"/>
+ <appender-ref ref="STDOUT-TRACING"/>
+ </root>
+</configuration>
\ No newline at end of file
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/registry.yaml
similarity index 77%
copy from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
copy to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/registry.yaml
index 32526c9..2dc9fa4 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/main/resources/application.yml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/main/resources/registry.yaml
@@ -15,17 +15,13 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-server:
- port: 8082
-
-# java-chassis configurations
-
-APPLICATION_ID: demo-zeroconfig-schemadiscovery-registry
-service_description:
- name: demo-zeroconfig-schemadiscovery-registry-client
- version: 0.0.2
-servicecomb:
- handler:
- chain:
- Consumer:
- default: loadbalance
\ No newline at end of file
+demo-zeroconfig-schemadiscovery-registry-client:
+ - id: "001"
+ version: "0.0.2"
+ appid: demo-zeroconfig-schemadiscovery-registry
+ schemaIds:
+ - ClientServerEndpoint
+ - SchemaDiscoveryEndpoint
+ instances:
+ - endpoints:
+ - rest://localhost:8082
\ No newline at end of file
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java
similarity index 100%
rename from demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-client/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java
rename to demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/ZeroConfigRegistryIT.java
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/pom.xml b/demo/demo-zeroconfig-schemadiscovery-registry/pom.xml
index 7ad6aa6..7c9e2b4 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/pom.xml
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/pom.xml
@@ -30,6 +30,7 @@
<modules>
<module>demo-zeroconfig-schemadiscovery-registry-server</module>
<module>demo-zeroconfig-schemadiscovery-registry-client</module>
+ <module>demo-zeroconfig-schemadiscovery-registry-tests</module>
</modules>
<dependencies>
@@ -39,14 +40,6 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>registry-schema-discovery</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>registry-zero-config</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-test-scaffolding</artifactId>
<scope>compile</scope>
</dependency>
diff --git a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigDiscovery.java b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigDiscovery.java
index 3b3cfcf..5bf28d5 100644
--- a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigDiscovery.java
+++ b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigDiscovery.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
import org.apache.servicecomb.zeroconfig.client.ZeroConfigClient;
import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.ENABLED;
+import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.ORDER;
public class ZeroConfigDiscovery implements Discovery {
@@ -56,7 +57,7 @@ public class ZeroConfigDiscovery implements Discovery {
@Override
public int getOrder() {
- return 101;
+ return ORDER;
}
@Override
diff --git a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistration.java b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistration.java
index 1de0b82..6e49d6c 100644
--- a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistration.java
+++ b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistration.java
@@ -16,8 +16,11 @@
*/
package org.apache.servicecomb.zeroconfig;
-import com.netflix.config.DynamicPropertyFactory;
+import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.ENABLED;
+import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.ORDER;
+
import java.util.Collection;
+
import org.apache.servicecomb.registry.api.Registration;
import org.apache.servicecomb.registry.api.registry.BasePath;
import org.apache.servicecomb.registry.api.registry.Microservice;
@@ -29,7 +32,7 @@ import org.apache.servicecomb.zeroconfig.server.ServerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.servicecomb.zeroconfig.ZeroConfigRegistryConstants.ENABLED;
+import com.netflix.config.DynamicPropertyFactory;
public class ZeroConfigRegistration implements Registration {
@@ -75,7 +78,7 @@ public class ZeroConfigRegistration implements Registration {
@Override
public int getOrder() {
- return 101;
+ return ORDER;
}
@Override
@@ -118,5 +121,4 @@ public class ZeroConfigRegistration implements Registration {
public void addBasePath(Collection<BasePath> basePaths) {
zeroConfigClient.getSelfMicroservice().getPaths().addAll(basePaths);
}
-
}
diff --git a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistryConstants.java b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistryConstants.java
index 483f702..c720b7c 100644
--- a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistryConstants.java
+++ b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/ZeroConfigRegistryConstants.java
@@ -20,6 +20,8 @@ public interface ZeroConfigRegistryConstants {
String ENABLED = "servicecomb.zeroconfig.registry.enabled";
+ int ORDER = 101;
+
// MulticastSocket related
String GROUP = "225.0.0.0";
Integer PORT = 6666;
@@ -62,5 +64,4 @@ public interface ZeroConfigRegistryConstants {
String SERVICE_ID_SPLITER = "/";
String ENDPOINT_PREFIX_REST = "rest";
String ENDPOINT_PREFIX_HTTP = "http";
-
}
diff --git a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ZeroConfigRegistryService.java b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ZeroConfigRegistryService.java
index 6145241..7875fed 100644
--- a/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ZeroConfigRegistryService.java
+++ b/service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ZeroConfigRegistryService.java
@@ -52,8 +52,8 @@ public class ZeroConfigRegistryService {
LOGGER.info("ServiceId: {}, instanceId: {} already exists", serviceId, instanceId);
} else {
// register a new instance for the service
- LOGGER.info("Register a new instance for serviceId: {}, instanceId: {}", serviceId,
- instanceId);
+ LOGGER.info("Register a new instance for serviceId: {}, instanceId: {}, status: {}, name: {}", serviceId,
+ instanceId, newServerMicroserviceInstance.getStatus(), newServerMicroserviceInstance.getServiceName());
innerInstanceMap.put(instanceId, newServerMicroserviceInstance);
}
}