[
https://issues.apache.org/jira/browse/SCB-297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16340397#comment-16340397
]
ASF GitHub Bot commented on SCB-297:
------------------------------------
liubao68 closed pull request #529: [SCB-297] The local cache is not update when
the server reboots betwe…
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/529
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/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 8a712bb22..f26ee057b 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 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 @@ protected MicroserviceVersionRule
createAndInitMicroserviceVersionRule(String st
@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 void
onMicroserviceInstanceChanged(MicroserviceInstanceChangedEvent chang
// 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 770318cfc..be1e8c7e1 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.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;
@@ -289,7 +290,53 @@ void setInstances(List<MicroserviceInstance>
pulledInstances, String rev) {
};
microserviceVersions.safeSetInstances(null, null);
-
+
Assert.assertEquals(1, pendingPullCount.get());
}
+
+ public void checkIsEventAccept(MicroserviceKey key, boolean expected) {
+
+ MicroserviceInstanceChangedEvent changeEvent = new
MicroserviceInstanceChangedEvent();
+ changeEvent.setKey(key);
+ boolean isEventAccept = microserviceVersions.isEventAccept(changeEvent);
+ Assert.assertEquals(expected, isEventAccept);
+ }
+
+ @Test
+ public void testIsEventAccept() {
+ MicroserviceKey key = new MicroserviceKey();
+
+ key.setAppId(appId);
+ key.setServiceName(microserviceName);
+ checkIsEventAccept(key, true);
+
+ key.setServiceName("falseMicroserviceName");
+ checkIsEventAccept(key, false);
+
+ key.setAppId("falseAppId");
+ checkIsEventAccept(key, false);
+
+ key.setServiceName(microserviceName);
+ checkIsEventAccept(key, false);
+
+
+ key.setAppId(appId);
+ key.setServiceName(appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
+
+ microserviceVersions =
+ new MicroserviceVersions(appManager, appId, appId +
Const.APP_SERVICE_SEPARATOR + microserviceName);
+ checkIsEventAccept(key, true);
+
+ microserviceVersions =
+ new MicroserviceVersions(appManager, "falseAppId", appId +
Const.APP_SERVICE_SEPARATOR + microserviceName);
+ checkIsEventAccept(key, false);
+
+ microserviceVersions = new MicroserviceVersions(appManager, "falseAppId",
+ "false" + appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
+ checkIsEventAccept(key, false);
+
+ microserviceVersions =
+ new MicroserviceVersions(appManager, appId, "false" + appId +
Const.APP_SERVICE_SEPARATOR + microserviceName);
+ checkIsEventAccept(key, false);
+ }
}
----------------------------------------------------------------
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]
> the local cache is not updated when the server reboots at the situation of
> accross application
> ------------------------------------------------------------------------------------------------
>
> Key: SCB-297
> URL: https://issues.apache.org/jira/browse/SCB-297
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Java-Chassis
> Reporter: laijianbin
> Assignee: laijianbin
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)