[ 
https://issues.apache.org/jira/browse/SCB-652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507789#comment-16507789
 ] 

ASF GitHub Bot commented on SCB-652:
------------------------------------

liubao68 closed pull request #757: [SCB-652] Fix schema register logic
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/757
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
index 22e4709cc..216167814 100644
--- 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
+++ 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/base/ServiceCombConstants.java
@@ -64,4 +64,8 @@
   String SERVICECOMB_ENV = "SERVICECOMB_ENV";
 
   String DEFAULT_SERVICECOMB_ENV = "";
+
+  String DEVELOPMENT_SERVICECOMB_ENV = "development";
+
+  String PRODUCTION_SERVICECOMB_ENV = "production";
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
index 321ff24a5..20306787a 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
@@ -40,6 +40,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Charsets;
+import com.google.common.hash.Hashing;
 import com.netflix.config.DynamicPropertyFactory;
 
 public final class RegistryUtils {
@@ -221,4 +223,8 @@ public static MicroserviceInstances 
findServiceInstances(String appId, String se
       String versionRule, String revision) {
     return serviceRegistry.findServiceInstances(appId, serviceName, 
versionRule, revision);
   }
+
+  public static String calcSchemaSummary(String schemaContent) {
+    return Hashing.sha256().newHasher().putString(schemaContent, 
Charsets.UTF_8).hash().toString();
+  }
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
index 184aac3ca..4ce3fb2ff 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/registry/MicroserviceInstance.java
@@ -55,6 +55,10 @@
 
   private HealthCheck healthCheck;
 
+  /**
+   * Will be abandoned, use {@link Microservice#environment} instead
+   */
+  @Deprecated
   private String environment;
 
   private String stage;
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
index 5e78abcd8..84c15169d 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImpl.java
@@ -31,6 +31,8 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.ws.rs.core.Response.Status;
+
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
@@ -40,6 +42,7 @@
 import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
 import org.apache.servicecomb.serviceregistry.api.response.HeartbeatResponse;
 import 
org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
+import org.apache.servicecomb.serviceregistry.client.http.Holder;
 import 
org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.version.Version;
 import org.apache.servicecomb.serviceregistry.version.VersionRule;
@@ -342,7 +345,7 @@ public String getSchema(String microserviceId, String 
schemaId) {
   }
 
   @Override
-  public List<GetSchemaResponse> getSchemas(String microserviceId) {
+  public Holder<List<GetSchemaResponse>> getSchemas(String microserviceId) {
     Microservice microservice = microserviceIdMap.get(microserviceId);
     if (microservice == null) {
       throw new IllegalArgumentException("Invalid serviceId, serviceId=" + 
microserviceId);
@@ -355,7 +358,9 @@ public String getSchema(String microserviceId, String 
schemaId) {
       schema.setSummary(Hashing.sha256().newHasher().putString(val, 
Charsets.UTF_8).hash().toString());
       schemas.add(schema);
     });
-    return schemas;
+    Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
+    resultHolder.setStatusCode(Status.OK.getStatusCode()).setValue(schemas);
+    return resultHolder;
   }
 
   @Override
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
index 9b2e1001e..4af6d7087 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/ServiceRegistryClient.java
@@ -27,6 +27,7 @@
 import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
 import org.apache.servicecomb.serviceregistry.api.response.HeartbeatResponse;
 import 
org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
+import org.apache.servicecomb.serviceregistry.client.http.Holder;
 import 
org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 
 public interface ServiceRegistryClient {
@@ -82,7 +83,7 @@
    *
    * 批量获取schemas内容
    */
-  List<GetSchemaResponse> getSchemas(String microserviceId);
+  Holder<List<GetSchemaResponse>> getSchemas(String microserviceId);
 
   /**
    *
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/Holder.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/Holder.java
new file mode 100644
index 000000000..e63911a93
--- /dev/null
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/Holder.java
@@ -0,0 +1,67 @@
+/*
+ * 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.servicecomb.serviceregistry.client.http;
+
+/**
+ * To carry the rest response information.
+ * @param <T> Type of response body
+ */
+public class Holder<T> {
+  T value;
+
+  int statusCode;
+
+  Throwable throwable;
+
+  public T getValue() {
+    return value;
+  }
+
+  public Holder<T> setValue(T value) {
+    this.value = value;
+    return this;
+  }
+
+  public int getStatusCode() {
+    return statusCode;
+  }
+
+  public Holder<T> setStatusCode(int statusCode) {
+    this.statusCode = statusCode;
+    return this;
+  }
+
+  public Throwable getThrowable() {
+    return throwable;
+  }
+
+  public Holder<T> setThrowable(Throwable throwable) {
+    this.throwable = throwable;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    final StringBuilder sb = new StringBuilder("Holder{");
+    sb.append("value=").append(value);
+    sb.append(", statusCode=").append(statusCode);
+    sb.append(", throwable=").append(throwable);
+    sb.append('}');
+    return sb.toString();
+  }
+}
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
index f379d9318..30f420072 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
@@ -27,11 +27,11 @@
 import java.util.concurrent.CountDownLatch;
 
 import javax.ws.rs.core.Response.Status;
-import javax.xml.ws.Holder;
 
 import org.apache.servicecomb.foundation.common.net.IpPort;
 import org.apache.servicecomb.foundation.common.utils.JsonUtils;
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.api.Const;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
@@ -60,8 +60,6 @@
 import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
-import com.google.common.hash.Hashing;
 
 import io.netty.handler.codec.http.HttpStatusClass;
 import io.vertx.core.Handler;
@@ -108,6 +106,7 @@ private void retry(RequestContext requestContext, 
Handler<RestResponse> response
         }
         return;
       }
+      holder.setStatusCode(response.statusCode());
       response.bodyHandler(
           bodyBuffer -> {
             if (cls.getName().equals(HttpClientResponse.class.getName())) {
@@ -115,6 +114,11 @@ private void retry(RequestContext requestContext, 
Handler<RestResponse> response
               countDownLatch.countDown();
               return;
             }
+            if (cls.equals(String.class)) {
+              holder.setValue((T) bodyBuffer.toString());
+              countDownLatch.countDown();
+              return;
+            }
 
             // no need to support 304 in this place
             if 
(!HttpStatusClass.SUCCESS.equals(HttpStatusClass.valueOf(response.statusCode())))
 {
@@ -131,6 +135,7 @@ private void retry(RequestContext requestContext, 
Handler<RestResponse> response
               holder.value =
                   JsonUtils.readValue(bodyBuffer.getBytes(), cls);
             } catch (Exception e) {
+              holder.setStatusCode(0).setThrowable(e);
               LOGGER.warn("read value failed and response message is {}",
                   bodyBuffer.toString());
             }
@@ -291,7 +296,7 @@ public boolean registerSchema(String microserviceId, String 
schemaId, String sch
     try {
       CreateSchemaRequest request = new CreateSchemaRequest();
       request.setSchema(schemaContent);
-      request.setSummary(Hashing.sha256().newHasher().putString(schemaContent, 
Charsets.UTF_8).hash().toString());
+      request.setSummary(RegistryUtils.calcSchemaSummary(schemaContent));
       byte[] body = JsonUtils.writeValueAsBytes(request);
 
       CountDownLatch countDownLatch = new CountDownLatch(1);
@@ -355,9 +360,10 @@ public String getSchema(String microserviceId, String 
schemaId) {
   }
 
   @Override
-  public List<GetSchemaResponse> getSchemas(String microserviceId) {
+  public Holder<List<GetSchemaResponse>> getSchemas(String microserviceId) {
     Holder<GetSchemasResponse> holder = new Holder<>();
     IpPort ipPort = ipPortManager.getAvailableAddress();
+    Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     // default not return schema content, just return summary!
@@ -372,11 +378,15 @@ public String getSchema(String microserviceId, String 
schemaId) {
           microserviceId,
           e);
     }
+    
resultHolder.setStatusCode(holder.getStatusCode()).setThrowable(holder.getThrowable());
     if (holder.value != null) {
-      return holder.value.getSchema() != null ? holder.value.getSchema() : 
holder.value.getSchemas();
+      return resultHolder.setValue(
+          holder.value.getSchema() != null ?
+              holder.value.getSchema() :
+              holder.value.getSchemas());
     }
 
-    return null;
+    return resultHolder;
   }
 
   @Override
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
index caa6141f1..9e7be8ae7 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
@@ -16,22 +16,27 @@
  */
 package org.apache.servicecomb.serviceregistry.task;
 
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.foundation.common.base.ServiceCombConstants;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
 import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.apache.servicecomb.serviceregistry.client.http.Holder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;
 
-import com.google.common.base.Charsets;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
-import com.google.common.hash.Hashing;
 
 public class MicroserviceRegisterTask extends AbstractRegisterTask {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(MicroserviceRegisterTask.class);
@@ -73,14 +78,15 @@ protected boolean doRegister() {
         microservice.getVersion(),
         microservice.getEnvironment());
     if (!StringUtils.isEmpty(serviceId)) {
-      // 已经注册过了,不需要重新注册
+      // This microservice has been registered, so we just use the serviceId 
gotten from service center
       microservice.setServiceId(serviceId);
       LOGGER.info(
-          "Microservice exists in service center, no need to register. id={} 
appId={}, name={}, version={}",
+          "Microservice exists in service center, no need to register. id=[{}] 
appId=[{}], name=[{}], version=[{}], env=[{}]",
           serviceId,
           microservice.getAppId(),
           microservice.getServiceName(),
-          microservice.getVersion());
+          microservice.getVersion(),
+          microservice.getEnvironment());
 
       if (!checkSchemaIdSet()) {
         return false;
@@ -89,24 +95,25 @@ protected boolean doRegister() {
       serviceId = srClient.registerMicroservice(microservice);
       if (StringUtils.isEmpty(serviceId)) {
         LOGGER.error(
-            "Registry microservice failed. appId={}, name={}, version={}",
+            "Registry microservice failed. appId=[{}], name=[{}], 
version=[{}], env=[{}]",
             microservice.getAppId(),
             microservice.getServiceName(),
-            microservice.getVersion());
+            microservice.getVersion(),
+            microservice.getEnvironment());
         return false;
       }
 
-      schemaIdSetMatch = true;
-      // 重新注册服务场景下,instanceId不应该缓存
+      // In re-register microservice case, the old instanceId should not be 
cached
       microservice.getInstance().setInstanceId(null);
 
       LOGGER.info(
-          "Registry Microservice successfully. id={} appId={}, name={}, 
version={}, schemaIds={}",
+          "Registry Microservice successfully. id=[{}] appId=[{}], name=[{}], 
version=[{}], schemaIds={}, env=[{}]",
           serviceId,
           microservice.getAppId(),
           microservice.getServiceName(),
           microservice.getVersion(),
-          microservice.getSchemas());
+          microservice.getSchemas(),
+          microservice.getEnvironment());
     }
 
     microservice.setServiceId(serviceId);
@@ -126,74 +133,207 @@ private boolean checkSchemaIdSet() {
     schemaIdSetMatch = existSchemas.equals(localSchemas);
 
     if (!schemaIdSetMatch) {
-      LOGGER.error(
-          "SchemaIds is different between local and service center. Please 
change microservice version. "
-              + "id={} appId={}, name={}, version={}, local schemaIds={}, 
service center schemaIds={}",
+      LOGGER.warn(
+          "SchemaIds is different between local and service center. "
+              + "serviceId=[{}] appId=[{}], name=[{}], version=[{}], env=[{}], 
local schemaIds={}, service center schemaIds={}",
           microservice.getServiceId(),
           microservice.getAppId(),
           microservice.getServiceName(),
           microservice.getVersion(),
+          microservice.getEnvironment(),
           localSchemas,
           existSchemas);
       return true;
     }
 
     LOGGER.info(
-        "SchemaIds is equals to service center. id={} appId={}, name={}, 
version={}, schemaIds={}",
+        "SchemaIds are equals to service center. serviceId=[{}], appId=[{}], 
name=[{}], version=[{}], env=[{}], schemaIds={}",
         microservice.getServiceId(),
         microservice.getAppId(),
         microservice.getServiceName(),
         microservice.getVersion(),
+        microservice.getEnvironment(),
         localSchemas);
     return true;
   }
 
   private boolean registerSchemas() {
-    List<GetSchemaResponse> existSchemas = 
srClient.getSchemas(microservice.getServiceId());
-    for (Entry<String, String> entry : microservice.getSchemaMap().entrySet()) 
{
-      String schemaId = entry.getKey();
-      String content = entry.getValue();
-      GetSchemaResponse existSchema = extractSchema(schemaId, existSchemas);
-      boolean exists = existSchema != null && existSchema.getSummary() != null;
-      LOGGER.info("schemaId [{}] exists {}", schemaId, exists);
-      if (!exists) {
-        if (!srClient.registerSchema(microservice.getServiceId(), schemaId, 
content)) {
-          return false;
-        }
-      } else {
-        String curSchemaSumary = existSchema.getSummary();
-        String schemaSummary = Hashing.sha256().newHasher().putString(content, 
Charsets.UTF_8).hash().toString();
-        if (!schemaSummary.equals(curSchemaSumary)) {
-          if 
(microservice.getInstance().getEnvironment().equalsIgnoreCase("development")) {
-            LOGGER.info(
-                "schemaId [{}]'s content changes and the current enviroment is 
development, so re-register it!",
-                schemaId);
-            if (!srClient.registerSchema(microservice.getServiceId(), 
schemaId, content)) {
-              return false;
-            }
-          } else {
-            throw new IllegalStateException("schemaId [" + schemaId
-                + "] exists in service center, but the content does not match 
the local content that means there are interface change "
-                + "and you need to increment microservice version before 
deploying. "
-                + "Or you can configure 
instance_description.environment=development to work in development enviroment 
and ignore this error");
-          }
-        }
+    Holder<List<GetSchemaResponse>> scSchemaHolder = 
srClient.getSchemas(microservice.getServiceId());
+    if (Status.OK.getStatusCode() != scSchemaHolder.getStatusCode()) {
+      LOGGER.error("failed to get schemas from service center, statusCode = 
[{}]", scSchemaHolder.getStatusCode());
+      return false;
+    }
+
+    Map<String, GetSchemaResponse> scSchemaMap = 
convertScSchemaMap(scSchemaHolder);
+    // CHECK: local > sc, local != sc
+    for (Entry<String, String> localSchemaEntry : 
microservice.getSchemaMap().entrySet()) {
+      if (!registerSchema(scSchemaMap, localSchemaEntry)) {
+        return false;
+      }
+    }
+
+    // CHECK: local < sc
+    checkRemainingSchema(scSchemaMap);
+
+    schemaIdSetMatch = true;
+    return true;
+  }
+
+  /**
+   * Check whether a local schema is equal to a sc schema.
+   * @return true if the local schema is equal to a sc schema, or be 
registered to sc successfully;
+   * false if schema is registered to sc but failed.
+   * @throws IllegalStateException The environment is not modifiable, and the 
local schema is different from sc schema
+   * or not exist in sc.
+   */
+  private boolean registerSchema(Map<String, GetSchemaResponse> scSchemaMap,
+      Entry<String, String> localSchemaEntry) {
+    GetSchemaResponse scSchema = scSchemaMap.get(localSchemaEntry.getKey());
+
+    boolean onlineSchemaExists = scSchema != null;
+    LOGGER.info("schemaId [{}] exists [{}], summary exists [{}]", 
localSchemaEntry.getKey(), onlineSchemaExists,
+        scSchema != null && scSchema.getSummary() != null);
+    if (!onlineSchemaExists) {
+      // local > sc
+      return registerNewSchema(localSchemaEntry);
+    }
+
+    scSchemaMap.remove(localSchemaEntry.getKey());
+
+    // local != sc
+    return compareAndReRegisterSchema(localSchemaEntry, scSchema);
+  }
+
+  /**
+   * Try to register a new schema to service center, or throw exception if 
cannot register.
+   * @param localSchemaEntry local schema to be registered.
+   * @return whether local schema is registered successfully.
+   * @throws IllegalStateException The environment is unmodifiable.
+   */
+  private boolean registerNewSchema(Entry<String, String> localSchemaEntry) {
+    // The ids of schemas are contained by microservice registry request, 
which means once a microservice
+    // is registered in the service center, the schemas that it contains are 
determined.
+    // If we get a microservice but cannot find the given schemaId in it's 
schemaId list, this means that
+    // the schemas of this microservice has been changed, and we should decide 
whether to register this new
+    // schema according to it's environment configuration.
+    if (onlineSchemaIsModifiable()) {
+      return registerSingleSchema(localSchemaEntry.getKey(), 
localSchemaEntry.getValue());
+    }
+
+    throw new IllegalStateException(
+        "There is a schema only existing in local microservice: [" + 
localSchemaEntry.getKey()
+            + "], which means there are interfaces changed. "
+            + "You need to increment microservice version before deploying, "
+            + "or you can configure service_description.environment="
+            + ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV
+            + " to work in development environment and ignore this error");
+  }
+
+  /**
+   * Compare schema summary and determine whether to re-register schema or 
throw exception.
+   * @param localSchemaEntry local schema
+   * @param scSchema schema in service center
+   * @return true if the two copies of schema are the same, or local schema is 
re-registered successfully,
+   * false if the local schema is re-registered to service center but failed.
+   * @throws IllegalStateException The two copies of schema are different and 
the environment is not modifiable.
+   */
+  private boolean compareAndReRegisterSchema(Entry<String, String> 
localSchemaEntry, GetSchemaResponse scSchema) {
+    String scSchemaSummary = getScSchemaSummary(scSchema);
+
+    if (null == scSchemaSummary) {
+      // cannot get scSchemaSummary, which means there is no schema content in 
sc, register schema directly
+      return registerSingleSchema(localSchemaEntry.getKey(), 
localSchemaEntry.getValue());
+    }
+
+    String localSchemaSummary = 
RegistryUtils.calcSchemaSummary(localSchemaEntry.getValue());
+    if (!localSchemaSummary.equals(scSchemaSummary)) {
+      if (onlineSchemaIsModifiable()) {
+        LOGGER.info(
+            "schema[{}]'s content is changed and the current environment is 
[{}], so re-register it!",
+            localSchemaEntry.getKey(), 
ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV);
+        return registerSingleSchema(localSchemaEntry.getKey(), 
localSchemaEntry.getValue());
       }
+
+      // env is not development, throw an exception and break the init 
procedure
+      throw new IllegalStateException(
+          "The schema(id=[" + localSchemaEntry.getKey()
+              + "]) content held by this instance and the service center is 
different. "
+              + "You need to increment microservice version before deploying. "
+              + "Or you can configure service_description.environment="
+              + ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV
+              + " to work in development environment and ignore this error");
     }
+
+    // summaries are the same
     return true;
   }
 
-  private GetSchemaResponse extractSchema(String schemaId, 
List<GetSchemaResponse> schemas) {
-    if (schemas == null || schemas.isEmpty()) {
-      return null;
+  /**
+   * Try to get or calculate scSchema summary.
+   * @return summary of scSchema,
+   * or null if there is no schema content in service center
+   */
+  private String getScSchemaSummary(GetSchemaResponse scSchema) {
+    String scSchemaSummary = scSchema.getSummary();
+    if (null != scSchemaSummary) {
+      return scSchemaSummary;
     }
-    GetSchemaResponse schema = null;
-    for (GetSchemaResponse tempSchema : schemas) {
-      if (tempSchema.getSchemaId().equals(schemaId)) {
-        schema = tempSchema;
-        break;
+
+    // if there is no online summery, query online schema content directly and 
calculate summary
+    String onlineSchemaContent = 
srClient.getSchema(microservice.getServiceId(), scSchema.getSchemaId());
+    if (null != onlineSchemaContent) {
+      scSchemaSummary = RegistryUtils.calcSchemaSummary(onlineSchemaContent);
+    }
+
+    return scSchemaSummary;
+  }
+
+  /**
+   * Check whether there are schemas remaining in service center but not exist 
in local microservice.
+   * @throws IllegalStateException There are schemas only existing in service 
center, and the environment is unmodifiable.
+   */
+  private void checkRemainingSchema(Map<String, GetSchemaResponse> 
scSchemaMap) {
+    if (!scSchemaMap.isEmpty()) {
+      // there are some schemas only exist in service center
+      if (!onlineSchemaIsModifiable()) {
+        // env is not development, throw an exception and break the init 
procedure
+        throw new IllegalStateException("There are schemas only existing in 
service center: " + scSchemaMap.keySet()
+            + ", which means there are interfaces changed. "
+            + "You need to increment microservice version before deploying, "
+            + "or if service_description.environment="
+            + ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV
+            + ", you can delete microservice information in service center and 
restart this instance.");
       }
+
+      // Currently nothing to do but print a warning
+      LOGGER.warn("There are schemas only existing in service center: {}, 
which means there are interfaces changed. "
+          + "It's recommended to increment microservice version before 
deploying.", scSchemaMap.keySet());
     }
-    return schema;
+  }
+
+  private boolean onlineSchemaIsModifiable() {
+    return 
ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV.equalsIgnoreCase(microservice.getEnvironment());
+  }
+
+  /**
+   * Register a schema directly.
+   * @return true if register success, otherwise false
+   */
+  private boolean registerSingleSchema(String schemaId, String content) {
+    return srClient.registerSchema(microservice.getServiceId(), schemaId, 
content);
+  }
+
+  private Map<String, GetSchemaResponse> 
convertScSchemaMap(Holder<List<GetSchemaResponse>> scSchemaHolder) {
+    Map<String, GetSchemaResponse> scSchemaMap = new HashMap<>();
+    List<GetSchemaResponse> scSchemaList = scSchemaHolder.getValue();
+    if (null == scSchemaList) {
+      return scSchemaMap;
+    }
+
+    for (GetSchemaResponse scSchema : scSchemaList) {
+      scSchemaMap.put(scSchema.getSchemaId(), scSchema);
+    }
+
+    return scSchemaMap;
   }
 }
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
index 88ba8bfcb..095aa8b2e 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
@@ -23,6 +23,8 @@
 import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
+import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
+import org.apache.servicecomb.serviceregistry.client.http.Holder;
 import 
org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
 import org.hamcrest.Matchers;
@@ -181,4 +183,12 @@ public void testGetServiceCenterInfo() {
     ServiceCenterInfo serviceCenterInfo = 
registryClient.getServiceCenterInfo();
     Assert.assertEquals("1.0.0", serviceCenterInfo.getVersion());
   }
+
+  @Test
+  public void testGetSchemas() {
+    Holder<List<GetSchemaResponse>> schemasHolder = 
registryClient.getSchemas("001");
+    Assert.assertEquals(200, schemasHolder.getStatusCode());
+    Assert.assertTrue(schemasHolder.getValue().isEmpty());
+  }
 }
+
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
index dd370e7cb..cd796fdd2 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
@@ -24,7 +24,6 @@
 import java.util.concurrent.CountDownLatch;
 
 import javax.ws.rs.core.Response.Status;
-import javax.xml.ws.Holder;
 
 import org.apache.log4j.Appender;
 import org.apache.log4j.Logger;
@@ -75,7 +74,7 @@ void httpDo(RequestContext requestContext, 
Handler<RestResponse> responseHandler
 
     new MockUp<CountDownLatch>() {
       @Mock
-      public void await() throws InterruptedException {
+      public void await() {
       }
     };
   }
@@ -310,12 +309,15 @@ void httpDo(RequestContext requestContext, 
Handler<RestResponse> responseHandler
             
"{\"schema\":[{\"schemaId\":\"metricsEndpoint\",\"summary\":\"c1188d709631a9038874f9efc6eb894f\"},{\"schemaId\":\"comment\",\"summary\":\"bfa81d625cfbd3a57f38745323e16824\"},"
                 + 
"{\"schemaId\":\"healthEndpoint\",\"summary\":\"96a0aaaaa454cfa0c716e70c0017fe27\"}]}",
             GetSchemasResponse.class);
+        holder.statusCode = 200;
         holder.value = schemasResp;
       }
     };
-    List<GetSchemaResponse> abc = oClient.getSchemas(microserviceId);
-    Assert.assertEquals(3, abc.size());
-    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", 
abc.get(1).getSummary());
+    Holder<List<GetSchemaResponse>> schemasHolder = 
oClient.getSchemas(microserviceId);
+    List<GetSchemaResponse> schemaResponses = schemasHolder.getValue();
+    Assert.assertEquals(200, schemasHolder.getStatusCode());
+    Assert.assertEquals(3, schemaResponses.size());
+    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", 
schemaResponses.get(1).getSummary());
   }
 
   @Test
@@ -330,12 +332,32 @@ void httpDo(RequestContext requestContext, 
Handler<RestResponse> responseHandler
             
"{\"schemas\":[{\"schemaId\":\"metricsEndpoint\",\"summary\":\"c1188d709631a9038874f9efc6eb894f\"},{\"schemaId\":\"comment\",\"summary\":\"bfa81d625cfbd3a57f38745323e16824\"},"
                 + 
"{\"schemaId\":\"healthEndpoint\",\"summary\":\"96a0aaaaa454cfa0c716e70c0017fe27\"}]}",
             GetSchemasResponse.class);
+        holder.statusCode = 200;
         holder.value = schemasResp;
       }
     };
-    List<GetSchemaResponse> abc = oClient.getSchemas(microserviceId);
-    Assert.assertEquals(3, abc.size());
-    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", 
abc.get(1).getSummary());
+    Holder<List<GetSchemaResponse>> schemasHolder = 
oClient.getSchemas(microserviceId);
+    List<GetSchemaResponse> schemas = schemasHolder.getValue();
+    Assert.assertEquals(200, schemasHolder.getStatusCode());
+    Assert.assertEquals(3, schemas.size());
+    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", 
schemas.get(1).getSummary());
+  }
+
+  @Test
+  public void getSchemasFailed() {
+    String microserviceId = "msId";
+
+    new MockUp<RestUtils>() {
+      @Mock
+      void httpDo(RequestContext requestContext, Handler<RestResponse> 
responseHandler) {
+        Holder<GetSchemasResponse> holder = 
Deencapsulation.getField(responseHandler, "arg$4");
+        holder.setStatusCode(Status.NOT_FOUND.getStatusCode());
+      }
+    };
+    Holder<List<GetSchemaResponse>> schemasHolder = 
oClient.getSchemas(microserviceId);
+    List<GetSchemaResponse> schemaResponses = schemasHolder.getValue();
+    Assert.assertEquals(404, schemasHolder.getStatusCode());
+    Assert.assertNull(schemaResponses);
   }
 
   @Test
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
index 7932d6893..a7944c83a 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/task/TestMicroserviceRegisterTask.java
@@ -24,6 +24,7 @@
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
 import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
+import org.apache.servicecomb.serviceregistry.client.http.Holder;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -82,12 +83,16 @@ public void testNewRegisterFailed(@Mocked 
ServiceRegistryClient srClient) {
 
   @Test
   public void testNewRegisterSuccess(@Mocked ServiceRegistryClient srClient) {
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200);
     new Expectations() {
       {
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = null;
         srClient.registerMicroservice((Microservice) any);
         result = "serviceId";
+        srClient.getSchemas("serviceId");
+        this.result = onlineSchemasHolder;
       }
     };
 
@@ -104,10 +109,23 @@ public void testNewRegisterSuccess(@Mocked 
ServiceRegistryClient srClient) {
     Assert.assertEquals(1, taskList.size());
   }
 
+  /**
+   * Local schemaId set is consistent with online schemaId set, and schema 
contents are not registered.
+   * This service instance try to register schema content but failed.
+   */
   @Test
   public void testRegisterSchemaFailed(@Mocked ServiceRegistryClient srClient) 
{
     microservice.addSchema("s1", "");
     microservice.addSchema("exist", "");
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200);
+    ArrayList<GetSchemaResponse> schemaResponses = new ArrayList<>();
+    onlineSchemasHolder.setValue(schemaResponses);
+    GetSchemaResponse schemaResponse = new GetSchemaResponse();
+    schemaResponse.setSchemaId("s1");
+    schemaResponses.add(schemaResponse);
+    schemaResponse.setSchemaId("exist");
+    schemaResponses.add(schemaResponse);
     new Expectations() {
       {
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
@@ -116,6 +134,8 @@ public void testRegisterSchemaFailed(@Mocked 
ServiceRegistryClient srClient) {
         result = "serviceId";
         srClient.registerSchema(anyString, anyString, anyString);
         result = false;
+        srClient.getSchemas("serviceId");
+        this.result = onlineSchemasHolder;
       }
     };
 
@@ -123,23 +143,35 @@ public void testRegisterSchemaFailed(@Mocked 
ServiceRegistryClient srClient) {
     registerTask.run();
 
     Assert.assertEquals(false, registerTask.isRegistered());
-    Assert.assertEquals(true, registerTask.isSchemaIdSetMatch());
+    Assert.assertEquals(false, registerTask.isSchemaIdSetMatch());
     Assert.assertEquals("serviceId", microservice.getServiceId());
     Assert.assertEquals("serviceId", 
microservice.getInstance().getServiceId());
     Assert.assertEquals(1, taskList.size());
   }
 
+  /**
+   * There is no microservice information in service center.
+   */
   @Test
   public void testRegisterSchemaSuccess(@Mocked ServiceRegistryClient 
srClient) {
-    microservice.addSchema("s1", "");
+    microservice.addSchema("s1", "s1Content");
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200);
+    ArrayList<GetSchemaResponse> schemaResponseList = new ArrayList<>();
+    onlineSchemasHolder.setValue(schemaResponseList);
+    GetSchemaResponse schemaResponse = new GetSchemaResponse();
+    schemaResponseList.add(schemaResponse);
+    schemaResponse.setSchemaId("s1");
     new Expectations() {
       {
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = null;
         srClient.registerMicroservice((Microservice) any);
         result = "serviceId";
-        srClient.registerSchema(anyString, anyString, anyString);
-        result = true;
+        srClient.getSchema("serviceId", "s1");
+        result = "s1Content";
+        srClient.getSchemas("serviceId");
+        result = onlineSchemasHolder;
       }
     };
 
@@ -155,12 +187,16 @@ public void testRegisterSchemaSuccess(@Mocked 
ServiceRegistryClient srClient) {
 
   @Test
   public void testAlreadyRegisteredSchemaIdSetMatch(@Mocked 
ServiceRegistryClient srClient) {
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200);
     new Expectations() {
       {
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
         result = microservice;
+        srClient.getSchemas("serviceId");
+        result = onlineSchemasHolder;
       }
     };
 
@@ -175,30 +211,33 @@ public void testAlreadyRegisteredSchemaIdSetMatch(@Mocked 
ServiceRegistryClient
     Assert.assertEquals(1, taskList.size());
   }
 
-  @Test
+  @Test(expected = IllegalStateException.class)
   public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked 
ServiceRegistryClient srClient) {
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
     otherMicroservice.addSchema("s1", "");
-
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200);
+    ArrayList<GetSchemaResponse> schemaResponseList = new ArrayList<>();
+    onlineSchemasHolder.setValue(schemaResponseList);
+    GetSchemaResponse schemaResponse = new GetSchemaResponse();
+
+    schemaResponseList.add(schemaResponse);
+    schemaResponse.setSchemaId("s1");
     new Expectations() {
       {
         srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
         result = "serviceId";
         srClient.getMicroservice(anyString);
         result = otherMicroservice;
+        srClient.getSchemas("serviceId");
+        result = onlineSchemasHolder;
       }
     };
 
     MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
     registerTask.run();
-
-    Assert.assertEquals(true, registerTask.isRegistered());
-    Assert.assertEquals(false, registerTask.isSchemaIdSetMatch());
-    Assert.assertEquals("serviceId", microservice.getServiceId());
-    Assert.assertEquals("serviceId", 
microservice.getInstance().getServiceId());
-    Assert.assertEquals(1, taskList.size());
   }
 
   @Test
@@ -229,7 +268,7 @@ public void 
testAlreadyRegisteredGetSchemaIdSetFailed(@Mocked ServiceRegistryCli
   @Test
   public void testReRegisteredSetForDev(@Mocked ServiceRegistryClient 
srClient) {
     ArchaiusUtils.resetConfig();
-    ArchaiusUtils.setProperty("instance_description.environment", 
"development");
+    ArchaiusUtils.setProperty("service_description.environment", 
"development");
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
@@ -240,6 +279,8 @@ public void testReRegisteredSetForDev(@Mocked 
ServiceRegistryClient srClient) {
     resp.setSchemaId("s1");
     resp.setSummary("c1188d709631a9038874f9efc6eb894f");
     list.add(resp);
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setStatusCode(200).setValue(list);
 
     new Expectations() {
       {
@@ -248,14 +289,14 @@ public void testReRegisteredSetForDev(@Mocked 
ServiceRegistryClient srClient) {
         srClient.getMicroservice(anyString);
         result = otherMicroservice;
         srClient.getSchemas(anyString);
-        result = list;
+        result = onlineSchemasHolder;
         srClient.registerSchema(microservice.getServiceId(), anyString, 
anyString);
         result = true;
       }
     };
 
     microservice.addSchema("s1", "");
-    microservice.getInstance().setEnvironment("development");
+    microservice.setEnvironment("development");
     MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
     registerTask.run();
 
@@ -265,18 +306,22 @@ public void testReRegisteredSetForDev(@Mocked 
ServiceRegistryClient srClient) {
     Assert.assertEquals(1, taskList.size());
   }
 
+  /**
+   * There is microservice information but no schema in service center.
+   */
   @Test
   public void testFirstRegisterForProd(@Mocked ServiceRegistryClient srClient) 
{
     Microservice otherMicroservice = new Microservice();
     otherMicroservice.setAppId(microservice.getAppId());
     otherMicroservice.setServiceName("ms1");
-    otherMicroservice.addSchema("s1", "");
+    otherMicroservice.addSchema("s1", null);
 
     List<GetSchemaResponse> list = new ArrayList<>();
     GetSchemaResponse resp = new GetSchemaResponse();
     resp.setSchemaId("s1");
-    resp.setSummary(null);
     list.add(resp);
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setValue(list).setStatusCode(200);
 
     new Expectations() {
       {
@@ -285,14 +330,16 @@ public void testFirstRegisterForProd(@Mocked 
ServiceRegistryClient srClient) {
         srClient.getMicroservice(anyString);
         result = otherMicroservice;
         srClient.getSchemas(anyString);
-        result = list;
-        srClient.registerSchema(microservice.getServiceId(), anyString, 
anyString);
+        result = onlineSchemasHolder;
+        srClient.getSchema("serviceId", "s1");
+        result = null;
+        srClient.registerSchema("serviceId", "s1", "s1Content");
         result = true;
       }
     };
 
-    microservice.addSchema("s1", "");
-    microservice.getInstance().setEnvironment("production");
+    microservice.addSchema("s1", "s1Content");
+    microservice.setEnvironment("production");
     MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
     registerTask.run();
 
@@ -302,6 +349,9 @@ public void testFirstRegisterForProd(@Mocked 
ServiceRegistryClient srClient) {
     Assert.assertEquals(1, taskList.size());
   }
 
+  /**
+   * There is schema in service center which is different from local schema.
+   */
   @Test(expected = IllegalStateException.class)
   public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient 
srClient) {
     Microservice otherMicroservice = new Microservice();
@@ -314,6 +364,8 @@ public void testReRegisteredSetForProd(@Mocked 
ServiceRegistryClient srClient) {
     resp.setSchemaId("s1");
     resp.setSummary("c1188d709631a9038874f9efc6eb894f");
     list.add(resp);
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setValue(list).setStatusCode(200);
 
     new Expectations() {
       {
@@ -322,13 +374,101 @@ public void testReRegisteredSetForProd(@Mocked 
ServiceRegistryClient srClient) {
         srClient.getMicroservice(anyString);
         result = otherMicroservice;
         srClient.getSchemas(anyString);
-        result = list;
+        result = onlineSchemasHolder;
       }
     };
 
     microservice.addSchema("s1", "");
-    microservice.getInstance().setEnvironment("prod");
+    microservice.setEnvironment("prod");
     MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
     registerTask.run();
   }
+
+  /**
+   * env = production and there are schemas only existing in service center
+   */
+  @Test(expected = IllegalStateException.class)
+  public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked 
ServiceRegistryClient srClient) {
+    Microservice otherMicroservice = new Microservice();
+    otherMicroservice.setAppId(microservice.getAppId());
+    otherMicroservice.setServiceName("ms1");
+    otherMicroservice.addSchema("s1", null);
+    otherMicroservice.addSchema("s2", null);
+
+    List<GetSchemaResponse> list = new ArrayList<>();
+    GetSchemaResponse resp = new GetSchemaResponse();
+    resp.setSchemaId("s1");
+    list.add(resp);
+    resp = new GetSchemaResponse();
+    resp.setSchemaId("s2");
+    list.add(resp);
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setValue(list).setStatusCode(200);
+
+    new Expectations() {
+      {
+        srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
+        result = "serviceId";
+        srClient.getMicroservice(anyString);
+        result = otherMicroservice;
+        srClient.getSchemas(anyString);
+        result = onlineSchemasHolder;
+        srClient.getSchema("serviceId", "s1");
+        result = null;
+        srClient.registerSchema("serviceId", "s1", "s1Content");
+        result = true;
+      }
+    };
+
+    microservice.addSchema("s1", "s1Content");
+    microservice.setEnvironment("production");
+    MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
+    registerTask.run();
+  }
+
+  @Test
+  public void testReRegisterForDevAndLocalSchemasAreLess(@Mocked 
ServiceRegistryClient srClient) {
+    Microservice otherMicroservice = new Microservice();
+    otherMicroservice.setAppId(microservice.getAppId());
+    otherMicroservice.setServiceName("ms1");
+    otherMicroservice.addSchema("s1", null);
+    otherMicroservice.addSchema("s2", null);
+
+    List<GetSchemaResponse> list = new ArrayList<>();
+    GetSchemaResponse resp = new GetSchemaResponse();
+    resp.setSchemaId("s1");
+    list.add(resp);
+    resp = new GetSchemaResponse();
+    resp.setSchemaId("s2");
+    list.add(resp);
+    Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
+    onlineSchemasHolder.setValue(list).setStatusCode(200);
+    Holder<String> removeSchemaResult = new Holder<>();
+    removeSchemaResult.setStatusCode(200);
+
+    new Expectations() {
+      {
+        srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
+        result = "serviceId";
+        srClient.getMicroservice(anyString);
+        result = otherMicroservice;
+        srClient.getSchemas(anyString);
+        result = onlineSchemasHolder;
+        srClient.getSchema("serviceId", "s1");
+        result = null;
+        srClient.registerSchema("serviceId", "s1", "s1Content");
+        result = true;
+      }
+    };
+
+    microservice.addSchema("s1", "s1Content");
+    microservice.setEnvironment("development");
+    MicroserviceRegisterTask registerTask = new 
MicroserviceRegisterTask(eventBus, srClient, microservice);
+    registerTask.run();
+
+    Assert.assertEquals(true, registerTask.isRegistered());
+    Assert.assertEquals(true, registerTask.isSchemaIdSetMatch());
+    Assert.assertEquals("serviceId", microservice.getServiceId());
+    Assert.assertEquals(1, taskList.size());
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Fix schema registry environment configuration
> ---------------------------------------------
>
>                 Key: SCB-652
>                 URL: https://issues.apache.org/jira/browse/SCB-652
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Java-Chassis
>            Reporter: YaoHaishi
>            Assignee: YaoHaishi
>            Priority: Major
>         Attachments: SchemaRegisterFlowChart.svg
>
>
> In schema registry, change environment config from 
> instance_description.environment to service_description.environment and 
> improve the registry logic.
> There is a flow chart in attatchments for reference: 
> [^SchemaRegisterFlowChart.svg] 
> If schema registry fails, the bootup procedure will be terminated or the 
> registry task will be rerun until the registry success.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to