[ISSUE #9816] check expected final state before remove redo data. (#9907)

* [ISSUE #9816] check expected final state before remove redo data.

* check expected final state before remove subscriber redo data.

* update NamingGrpcRedoServiceTest when test remove

* update NamingGrpcRedoService, set expect register status to false when subscribers deregister
This commit is contained in:
MajorHe1 2023-02-08 09:38:37 +08:00 committed by GitHub
parent 428e0bc668
commit 30954dc612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -177,8 +177,12 @@ public class NamingGrpcRedoService implements ConnectionEventListener {
* @param groupName group name * @param groupName group name
*/ */
public void removeInstanceForRedo(String serviceName, String groupName) { public void removeInstanceForRedo(String serviceName, String groupName) {
String key = NamingUtils.getGroupedName(serviceName, groupName);
synchronized (registeredInstances) { synchronized (registeredInstances) {
registeredInstances.remove(NamingUtils.getGroupedName(serviceName, groupName)); InstanceRedoData redoData = registeredInstances.get(key);
if (null != redoData && !redoData.isExpectedRegistered()) {
registeredInstances.remove(key);
}
} }
} }
@ -244,6 +248,7 @@ public class NamingGrpcRedoService implements ConnectionEventListener {
SubscriberRedoData redoData = subscribes.get(key); SubscriberRedoData redoData = subscribes.get(key);
if (null != redoData) { if (null != redoData) {
redoData.setUnregistering(true); redoData.setUnregistering(true);
redoData.setExpectedRegistered(false);
} }
} }
} }
@ -272,8 +277,12 @@ public class NamingGrpcRedoService implements ConnectionEventListener {
* @param cluster cluster * @param cluster cluster
*/ */
public void removeSubscriberForRedo(String serviceName, String groupName, String cluster) { public void removeSubscriberForRedo(String serviceName, String groupName, String cluster) {
String key = ServiceInfo.getKey(NamingUtils.getGroupedName(serviceName, groupName), cluster);
synchronized (subscribes) { synchronized (subscribes) {
subscribes.remove(ServiceInfo.getKey(NamingUtils.getGroupedName(serviceName, groupName), cluster)); SubscriberRedoData redoData = subscribes.get(key);
if (null != redoData && !redoData.isExpectedRegistered()) {
subscribes.remove(key);
}
} }
} }

View File

@ -156,6 +156,7 @@ public class NamingGrpcRedoServiceTest {
assertTrue(registeredInstances.isEmpty()); assertTrue(registeredInstances.isEmpty());
redoService.cacheInstanceForRedo(SERVICE, GROUP, new Instance()); redoService.cacheInstanceForRedo(SERVICE, GROUP, new Instance());
assertFalse(registeredInstances.isEmpty()); assertFalse(registeredInstances.isEmpty());
redoService.instanceDeregister(SERVICE, GROUP);
redoService.removeInstanceForRedo(SERVICE, GROUP); redoService.removeInstanceForRedo(SERVICE, GROUP);
assertTrue(registeredInstances.isEmpty()); assertTrue(registeredInstances.isEmpty());
} }
@ -221,6 +222,7 @@ public class NamingGrpcRedoServiceTest {
assertTrue(subscribes.isEmpty()); assertTrue(subscribes.isEmpty());
redoService.cacheSubscriberForRedo(SERVICE, GROUP, CLUSTER); redoService.cacheSubscriberForRedo(SERVICE, GROUP, CLUSTER);
assertFalse(subscribes.isEmpty()); assertFalse(subscribes.isEmpty());
redoService.subscriberDeregister(SERVICE, GROUP, CLUSTER);
redoService.removeSubscriberForRedo(SERVICE, GROUP, CLUSTER); redoService.removeSubscriberForRedo(SERVICE, GROUP, CLUSTER);
assertTrue(subscribes.isEmpty()); assertTrue(subscribes.isEmpty());
} }