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 2018/07/05 08:38:40 UTC

[incubator-servicecomb-java-chassis] branch master updated (964a411 -> 1a4a1dd)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from 964a411  [SCB-713] Required client test code added
     new bd44d93  [SCB-712]Do not register service path to service center when not necessary
     new 1a4a1dd  [SCB-712]fix Unit test fail

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../core/definition/loader/SchemaLoader.java       | 12 ++++++++--
 .../servicecomb/core/unittest/UnitTestMeta.java    |  6 +----
 core/src/main/resources/microservice.yaml          |  2 +-
 .../schema/TestProducerSchemaFactory.java          |  6 +----
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../client/ConsumerTestsAfterBootup.java}          | 25 +++++++++++++-------
 ...ryHolder.java => ProducerTestsAfterBootup.java} | 27 +++++++++++-----------
 .../src/main/resources/microservice.yaml           |  1 +
 .../src/test/resources/test1.yaml                  |  2 +-
 .../src/test/resources/test2.yaml                  |  2 +-
 .../demo/pojo/test/PojoIntegrationTestBase.java    |  2 +-
 .../servicecomb/serviceregistry/api/Const.java     |  2 ++
 17 files changed, 56 insertions(+), 43 deletions(-)
 copy demo/{demo-crossapp/crossapp-client/src/main/java/org/apache/servicecomb/demo/crossapp/CrossappBootListener.java => demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java} (61%)
 rename demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/{ProducerSchemaFactoryHolder.java => ProducerTestsAfterBootup.java} (82%)


[incubator-servicecomb-java-chassis] 01/02: [SCB-712]Do not register service path to service center when not necessary

Posted by li...@apache.org.
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/incubator-servicecomb-java-chassis.git

commit bd44d93d373f96a6a56452db94a71deac97dc3b3
Author: bao.liu <ba...@huawei.com>
AuthorDate: Tue Jul 3 21:08:02 2018 +0800

    [SCB-712]Do not register service path to service center when not necessary
---
 .../core/definition/loader/SchemaLoader.java       | 12 +++++-
 .../servicecomb/core/unittest/UnitTestMeta.java    |  6 +--
 core/src/main/resources/microservice.yaml          |  2 +-
 .../schema/TestProducerSchemaFactory.java          |  6 +--
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../src/main/resources/microservice.yaml           |  2 +-
 .../springmvc/client/ConsumerTestsAfterBootup.java | 43 ++++++++++++++++++++++
 ...ryHolder.java => ProducerTestsAfterBootup.java} | 27 +++++++-------
 .../src/main/resources/microservice.yaml           |  1 +
 .../src/test/resources/test1.yaml                  |  2 +-
 .../src/test/resources/test2.yaml                  |  2 +-
 .../servicecomb/serviceregistry/api/Const.java     |  2 +
 16 files changed, 81 insertions(+), 34 deletions(-)

diff --git a/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java b/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
index 29b03da..aa612c3 100644
--- a/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
+++ b/core/src/main/java/org/apache/servicecomb/core/definition/loader/SchemaLoader.java
@@ -40,6 +40,8 @@ import org.springframework.core.io.Resource;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 
+import com.netflix.config.DynamicPropertyFactory;
+
 import io.swagger.models.Swagger;
 
 @Component
@@ -100,12 +102,18 @@ public class SchemaLoader {
 
     microserviceMeta.regSchemaMeta(schemaMeta);
 
-    putSelfBasePathIfAbsent(microserviceName, swagger.getBasePath());
+    addSchemaPath2Microservice(microserviceName, swagger.getBasePath());
 
     return schemaMeta;
   }
 
-  public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
+  void addSchemaPath2Microservice(String microserviceName, String basePath) {
+    if (DynamicPropertyFactory.getInstance().getBooleanProperty(Const.REGISTER_SERVICE_PATH, false).get()) {
+      putSelfBasePathIfAbsent(microserviceName, basePath);
+    }
+  }
+
+  void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
     if (basePath == null || basePath.length() == 0) {
       return;
     }
diff --git a/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java b/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
index fd1eece..8d9c5b5 100644
--- a/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
+++ b/core/src/main/java/org/apache/servicecomb/core/unittest/UnitTestMeta.java
@@ -67,11 +67,7 @@ public class UnitTestMeta {
 
   private ConsumerSchemaFactory consumerSchemaFactory;
 
-  private SchemaLoader schemaLoader = new SchemaLoader() {
-    @Override
-    public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
-    }
-  };
+  private SchemaLoader schemaLoader = new SchemaLoader();
 
   private ServiceRegistry serviceRegistry;
 
diff --git a/core/src/main/resources/microservice.yaml b/core/src/main/resources/microservice.yaml
index 9e415d6..c51b1de 100644
--- a/core/src/main/resources/microservice.yaml
+++ b/core/src/main/resources/microservice.yaml
@@ -15,6 +15,6 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: -500
+servicecomb-config-order: -500
 servicecomb:
   microserviceVersionFactory: org.apache.servicecomb.core.definition.PrivateMicroserviceVersionMetaFactory
diff --git a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index fc3a4a7..6500c64 100644
--- a/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++ b/core/src/test/java/org/apache/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -78,11 +78,7 @@ public class TestProducerSchemaFactory {
     producerArgsMapperFactory.setConverterMgr(converterMgr);
 
     MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
-    SchemaLoader schemaLoader = new SchemaLoader() {
-      @Override
-      public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
-      }
-    };
+    SchemaLoader schemaLoader = new SchemaLoader();
     CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
 
     producerSchemaFactory.setSwaggerEnv(swaggerEnv);
diff --git a/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml b/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
index a9ddcde..f06dd95 100644
--- a/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
+++ b/demo/demo-multiple/multiple-client/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 1000
+servicecomb-config-order: 1000
 a-server.name: merged-server
 b-server.name: merged-server
 APPLICATION_ID: multiple
diff --git a/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml b/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
index c3dd81b..94fb8d2 100644
--- a/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
+++ b/demo/demo-multiple/multiple-server/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 1000
+servicecomb-config-order: 1000
 APPLICATION_ID: multiple
 service_description:
   name: merged-server
diff --git a/demo/demo-schema/src/main/resources/microservice.yaml b/demo/demo-schema/src/main/resources/microservice.yaml
index 92b6959..d26c026 100644
--- a/demo/demo-schema/src/main/resources/microservice.yaml
+++ b/demo/demo-schema/src/main/resources/microservice.yaml
@@ -14,7 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-cse-config-order: -1
+servicecomb-config-order: -1
 
 cse:
   test:
diff --git a/demo/demo-server-servlet/src/main/resources/microservice.yaml b/demo/demo-server-servlet/src/main/resources/microservice.yaml
index 469a68e..cb4ae43 100644
--- a/demo/demo-server-servlet/src/main/resources/microservice.yaml
+++ b/demo/demo-server-servlet/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 100
+servicecomb-config-order: 100
 
 servicecomb:
   rest:
diff --git a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
index c6e5a22..0a7457f 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
+++ b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 1
+servicecomb-config-order: 1
 APPLICATION_ID: spring-boot-jaxrstest
 service_description:
   name: jaxrsClient
diff --git a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
index 76a3704..09c50e3 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
+++ b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-server/src/main/resources/microservice.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 1
+servicecomb-config-order: 1
 APPLICATION_ID: spring-boot-jaxrstest
 service_description:
   name: jaxrs
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java
new file mode 100644
index 0000000..d89f20d
--- /dev/null
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/ConsumerTestsAfterBootup.java
@@ -0,0 +1,43 @@
+package org.apache.servicecomb.demo.springmvc.client;
+/*
+ * 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.
+ */
+
+import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * Testing after bootup.
+ */
+@Component
+public class ConsumerTestsAfterBootup implements BootListener {
+  public void testRegisterPath() {
+    TestMgr.check(RegistryUtils.getMicroservice().getPaths().size(), 0);
+  }
+
+  @Override
+  public void onBootEvent(BootEvent event) {
+    if (event.getEventType() == BootListener.EventType.AFTER_REGISTRY) {
+      testRegisterPath();
+      if (!TestMgr.isSuccess()) {
+        TestMgr.summary();
+        throw new IllegalStateException("some tests are failed. ");
+      }
+    }
+  }
+}
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
similarity index 82%
rename from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
rename to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index 687273b..d2d201a 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -29,26 +29,24 @@ import org.springframework.stereotype.Component;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectWriter;
-import com.google.common.base.Charsets;
-import com.google.common.hash.Hashing;
 
 import io.swagger.models.Swagger;
 import io.swagger.util.Yaml;
 
 /**
- * Testing schemas generation should be same for each boot up and accommodate swagger.
+ * Testing after bootup.
  */
 @Component
-public class ProducerSchemaFactoryHolder implements BootListener {
-  private static final Logger LOGGER = LoggerFactory.getLogger(ProducerSchemaFactoryHolder.class);
+public class ProducerTestsAfterBootup implements BootListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ProducerTestsAfterBootup.class);
 
   private ObjectWriter writer = Yaml.pretty();
 
   @Autowired
   private ProducerSchemaFactory factory;
 
-  public void test() {
-    LOGGER.info("ProducerSchemaFactoryHolder testing start");
+  public void testSchemaNotChange() {
+    LOGGER.info("ProducerTestsAfterBootup testing start");
     SchemaMeta meta =
         factory.getOrCreateProducerSchema("customer-service",
             "test1",
@@ -58,13 +56,11 @@ public class ProducerSchemaFactoryHolder implements BootListener {
     TestMgr.check("07a48acef4cc1a7f2387d695923c49e98951a974e4f51cf1356d6878db48888f",
         RegistryUtils.calcSchemaSummary(codeFirst));
     TestMgr.check(codeFirst.length(), 899);
-
-    if (!TestMgr.isSuccess()) {
-      TestMgr.summary();
-      throw new IllegalStateException("schema not the same. ");
-    }
   }
 
+  public void testRegisterPath() {
+    TestMgr.check(RegistryUtils.getMicroservice().getPaths().size(), 9);
+  }
   private String getSwaggerContent(Swagger swagger) {
     try {
       return writer.writeValueAsString(swagger);
@@ -76,7 +72,12 @@ public class ProducerSchemaFactoryHolder implements BootListener {
   @Override
   public void onBootEvent(BootEvent event) {
     if (event.getEventType() == BootListener.EventType.AFTER_REGISTRY) {
-      test();
+      testSchemaNotChange();
+      testRegisterPath();
+      if (!TestMgr.isSuccess()) {
+        TestMgr.summary();
+        throw new IllegalStateException("some tests are failed. ");
+      }
     }
   }
 }
diff --git a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index 7098320..68fd39c 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -32,6 +32,7 @@ service_description:
 servicecomb:
   service:
     registry:
+      registerPath: true
       address: http://127.0.0.1:30100
       client:
         timeout:
diff --git a/foundations/foundation-config/src/test/resources/test1.yaml b/foundations/foundation-config/src/test/resources/test1.yaml
index 5a544a2..708d0e8 100644
--- a/foundations/foundation-config/src/test/resources/test1.yaml
+++ b/foundations/foundation-config/src/test/resources/test1.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: "1"
+servicecomb-config-order: "1"
 
 trace:
   handler:
diff --git a/foundations/foundation-config/src/test/resources/test2.yaml b/foundations/foundation-config/src/test/resources/test2.yaml
index a0aa390..dc00542 100644
--- a/foundations/foundation-config/src/test/resources/test2.yaml
+++ b/foundations/foundation-config/src/test/resources/test2.yaml
@@ -15,7 +15,7 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-cse-config-order: 0
+servicecomb-config-order: 0
 
 dsf:
   serializer:
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index 9f1d482..84e8424 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -182,4 +182,6 @@ public final class Const {
   public static final String INSTANCE_PUBKEY_PRO = "publickey";
 
   public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
+
+  public static final String REGISTER_SERVICE_PATH = "servicecomb.service.registry.registerPath";
 }


[incubator-servicecomb-java-chassis] 02/02: [SCB-712]fix Unit test fail

Posted by li...@apache.org.
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/incubator-servicecomb-java-chassis.git

commit 1a4a1dd1ba982827fb3d29db96faecf4fcab9cd8
Author: bao.liu <ba...@huawei.com>
AuthorDate: Wed Jul 4 11:12:52 2018 +0800

    [SCB-712]fix Unit test fail
---
 .../org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
index b67cd53..7eb6f43 100644
--- a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
+++ b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
@@ -68,7 +68,7 @@ public class PojoIntegrationTestBase {
 
     assertThat(result, is("Hello Message slow"));
     assertThat(elapsedTime,
-        is(both(greaterThan(5000L)).and(lessThan(6000L))));
+        is(both(greaterThan(4000L)).and(lessThan(7000L))));
   }
 
   @Test