diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManager.java index a4f34661d59..44ca8cbe82b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManager.java @@ -151,7 +151,7 @@ public void removeInstanceMetadata(Service service, String metadataId) { if (null != instanceMetadataMapForService) { instanceMetadataMapForService.remove(metadataId); if (instanceMetadataMapForService.isEmpty()) { - serviceMetadataMap.remove(service); + instanceMetadataMap.remove(service); } } expiredMetadataInfos.remove(ExpiredMetadataInfo.newExpiredInstanceMetadata(service, metadataId)); diff --git a/naming/src/test/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManagerTest.java b/naming/src/test/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManagerTest.java index ac6e6aed2fd..99383753b1c 100644 --- a/naming/src/test/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManagerTest.java +++ b/naming/src/test/java/com/alibaba/nacos/naming/core/v2/metadata/NamingMetadataManagerTest.java @@ -170,6 +170,10 @@ void testRemoveInstanceMetadata() { Optional instanceMetadata = namingMetadataManager.getInstanceMetadata(service, METADATA_ID); assertFalse(instanceMetadata.isPresent()); + + Map> instanceMetadataSnapshot = namingMetadataManager.getInstanceMetadataSnapshot(); + + assertEquals(0, instanceMetadataSnapshot.size()); } @Test @@ -233,4 +237,4 @@ void testOnEvent() { namingMetadataManager.onEvent(clientDisconnectEvent); Mockito.verify(clientDisconnectEvent).getClient(); } -} \ No newline at end of file +}