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/01/26 01:24:38 UTC
[incubator-servicecomb-java-chassis] 01/02: [SCB-297] The local
cache is not update when the server reboots between different application
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 0c77d0b80b3e06f6060179fe459ee6dc366c42f5
Author: laijianbin <la...@huawei.com>
AuthorDate: Thu Jan 25 11:49:05 2018 +0800
[SCB-297] The local cache is not update when the server reboots between different application
---
.../consumer/MicroserviceVersions.java | 12 +++++++++---
.../consumer/TestMicroserviceVersions.java | 21 +++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
index 8a712bb..f26ee05 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.Const;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
import org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
@@ -195,11 +196,9 @@ public class MicroserviceVersions {
@Subscribe
public void onMicroserviceInstanceChanged(MicroserviceInstanceChangedEvent changedEvent) {
- if (!appId.equals(changedEvent.getKey().getAppId()) ||
- !microserviceName.equals(changedEvent.getKey().getServiceName())) {
+ if (!isEventAccept(changedEvent)) {
return;
}
-
// pull instances always replace old instances, not append
//
// pull result and watch event sequence is not defined even inside SC.
@@ -213,4 +212,11 @@ public class MicroserviceVersions {
// black/white config in SC changed, we must refresh all data from sc.
postPullInstanceEvent(TimeUnit.MILLISECONDS.toMillis(1));
}
+
+ protected boolean isEventAccept(MicroserviceInstanceChangedEvent changedEvent) {
+ return (appId.equals(changedEvent.getKey().getAppId()) &&
+ microserviceName.equals(changedEvent.getKey().getServiceName())) ||
+ microserviceName.equals(
+ changedEvent.getKey().getAppId() + Const.APP_SERVICE_SEPARATOR + changedEvent.getKey().getServiceName());
+ }
}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersions.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersions.java
index 770318c..1920bc3 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersions.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersions.java
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.api.Const;
import org.apache.servicecomb.serviceregistry.api.MicroserviceKey;
import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
@@ -292,4 +293,24 @@ public class TestMicroserviceVersions {
Assert.assertEquals(1, pendingPullCount.get());
}
+
+ @Test
+ public void testIsEventAccept(){
+ MicroserviceKey key = new MicroserviceKey();
+ key.setAppId(appId);
+ key.setServiceName(microserviceName);
+ MicroserviceInstanceChangedEvent changeEvent = new MicroserviceInstanceChangedEvent();
+ changeEvent.setKey(key);
+ boolean isEventAccept = microserviceVersions.isEventAccept(changeEvent);
+ Assert.assertEquals(true, isEventAccept);
+
+ microserviceVersions = new MicroserviceVersions(appManager, appId, appId+Const.APP_SERVICE_SEPARATOR+microserviceName);
+ key.setAppId(appId);
+ key.setServiceName(appId+Const.APP_SERVICE_SEPARATOR+microserviceName);
+ changeEvent.setKey(key);
+ boolean isEventAcceptWhenAccrossApp = microserviceVersions.isEventAccept(changeEvent);
+ Assert.assertEquals(true, isEventAcceptWhenAccrossApp);
+
+ }
+
}
--
To stop receiving notification emails like this one, please contact
liubao@apache.org.