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


The following commit(s) were added to refs/heads/master by this push:
     new 0c67d8888 [SCB-2716]enable swagger override by default and allow 
microservcie i… (#3451)
0c67d8888 is described below

commit 0c67d888822300d2edc62b974e623ba9766e80ef
Author: liubao68 <[email protected]>
AuthorDate: Fri Nov 4 15:09:21 2022 +0800

    [SCB-2716]enable swagger override by default and allow microservcie i… 
(#3451)
---
 .../src/main/resources/microservice.yaml           |  2 +-
 demo/docker-run-config-edge/pom.xml                |  4 ++--
 .../registry/consumer/MicroserviceVersions.java    |  8 +++----
 .../config/ServiceRegistryConfigBuilder.java       |  7 +++---
 .../task/TestMicroserviceRegisterTask.java         | 25 ++++++++++++++++------
 5 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml 
b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
index 544cbcf1d..1813c3f10 100644
--- a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
+++ b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
@@ -29,7 +29,7 @@ servicecomb:
         enabled: true
         allowedHeaders: xxx
   rest:
-    address: 0.0.0.0:18080
+    address: 0.0.0.0:18090
     server:
       # for test case run in one core machine
       verticle-count: 1
diff --git a/demo/docker-run-config-edge/pom.xml 
b/demo/docker-run-config-edge/pom.xml
index f861e14e8..83839c38e 100644
--- a/demo/docker-run-config-edge/pom.xml
+++ b/demo/docker-run-config-edge/pom.xml
@@ -218,13 +218,13 @@
                     -->
                     <tcp>
                       <ports>
-                        <port>18080</port>
+                        <port>18090</port>
                       </ports>
                     </tcp>
                     <time>120000</time>
                   </wait>
                   <ports>
-                    <port>18080:18080</port>
+                    <port>18090:18090</port>
                   </ports>
                   <dependsOn>
                     <container>service-center</container>
diff --git 
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
 
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
index 6d0a94159..da5f99cb5 100644
--- 
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
+++ 
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceVersions.java
@@ -229,10 +229,10 @@ public class MicroserviceVersions {
       // clear cache
       versions.forEach((key, value) -> value.setInstances(new ArrayList<>()));
       for (Entry<String, List<MicroserviceInstance>> entry : 
mergedInstances.microserviceIdMap.entrySet()) {
-        // ensure microserviceVersion exists
-        versions.computeIfAbsent(entry.getKey(),
-            microserviceId -> createMicroserviceVersion(microserviceId, 
entry.getValue()))
-            .setInstances(entry.getValue());
+        // always update microservice versions, because we allow microservice 
info override, like schema info
+        MicroserviceVersion newVersion = 
createMicroserviceVersion(entry.getKey(), entry.getValue());
+        newVersion.setInstances(entry.getValue());
+        versions.put(entry.getKey(), newVersion);
       }
 
       for (MicroserviceVersionRule microserviceVersionRule : 
versionRules.values()) {
diff --git 
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
 
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
index 1ebb7212a..ae6b7fd08 100644
--- 
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
+++ 
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
@@ -223,13 +223,14 @@ class ServiceRegistryConfigBuilder {
     return times < 0 ? ServiceRegistryConfig.DEFAULT_CHECK_TIMES : times;
   }
 
-  // 配置项供开发测试使用,减少接口频繁变更情况下,需要修改版本号的工作量。
-  // 生产环境不能打开这个配置项,否则会导致网关、consumer等在provider之前启动的场景下,访问不到新增、更新的接口。
+  // Setting override schema to true, must also set 
OperationInstancesDiscoveryFilter false.
+  // Or when new version add some services, the gateway will not update its 
route and can not
+  // route to the target service.
   public boolean isAlwaysOverrideSchema() {
     DynamicBooleanProperty property =
         DynamicPropertyFactory.getInstance()
             
.getBooleanProperty("servicecomb.service.registry.instance.alwaysOverrideSchema",
-                false);
+                true);
     return property.get();
   }
 
diff --git 
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
 
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
index d1cabe096..aa0d1349c 100644
--- 
a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
+++ 
b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
@@ -32,13 +32,13 @@ import 
org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 
 import mockit.Expectations;
 import mockit.Mocked;
-import org.junit.jupiter.api.Assertions;
 
 public class TestMicroserviceRegisterTask {
   private EventBus eventBus;
@@ -225,7 +225,8 @@ public class TestMicroserviceRegisterTask {
   }
 
   @Test(expected = IllegalStateException.class)
-  public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked 
ServiceRegistryClient srClient) {
+  public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked 
ServiceRegistryClient srClient,
+      @Mocked ServiceRegistryConfig config) {
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
@@ -240,6 +241,8 @@ public class TestMicroserviceRegisterTask {
     schemaResponse.setSchemaId("s1");
     new Expectations() {
       {
+        config.isAlwaysOverrideSchema();
+        result = false;
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
@@ -366,7 +369,7 @@ public class TestMicroserviceRegisterTask {
    * There is schema in service center which is different from local schema.
    */
   @Test(expected = IllegalStateException.class)
-  public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient 
srClient) {
+  public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient 
srClient, @Mocked ServiceRegistryConfig config) {
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
@@ -382,6 +385,8 @@ public class TestMicroserviceRegisterTask {
 
     new Expectations() {
       {
+        config.isAlwaysOverrideSchema();
+        result = false;
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
@@ -401,7 +406,8 @@ public class TestMicroserviceRegisterTask {
    * env = production and there are schemas only existing in service center
    */
   @Test(expected = IllegalStateException.class)
-  public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked 
ServiceRegistryClient srClient) {
+  public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked 
ServiceRegistryClient srClient,
+      @Mocked ServiceRegistryConfig config) {
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
@@ -420,6 +426,8 @@ public class TestMicroserviceRegisterTask {
 
     new Expectations() {
       {
+        config.isAlwaysOverrideSchema();
+        result = false;
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
@@ -489,8 +497,8 @@ public class TestMicroserviceRegisterTask {
    * There is schema in service center which is different from local schema.
    */
   @Test
-  public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked 
ServiceRegistryClient srClient) {
-
+  public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked 
ServiceRegistryClient srClient,
+      @Mocked ServiceRegistryConfig config) {
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
@@ -506,6 +514,8 @@ public class TestMicroserviceRegisterTask {
 
     new Expectations() {
       {
+        config.isAlwaysOverrideSchema();
+        result = false;
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
@@ -602,7 +612,8 @@ public class TestMicroserviceRegisterTask {
       registerTask.run();
     } catch (IllegalStateException exception) {
       isIllegalException = true;
-      List<LoggingEvent> events = collector.getEvents().stream().filter(e -> 
MicroserviceRegisterTask.class.getName().equals(e.getLoggerName())).collect(Collectors.toList());
+      List<LoggingEvent> events = collector.getEvents().stream()
+          .filter(e -> 
MicroserviceRegisterTask.class.getName().equals(e.getLoggerName())).collect(Collectors.toList());
 
       Assertions.assertEquals("service center schema and local schema both are 
different:\n" +
           " service center schema:\n" +

Reply via email to