From 762303b94617e4febcf00f79e1c67050ae6f832d Mon Sep 17 00:00:00 2001 From: MajorHe1 <53824889+MajorHe1@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:14:30 +0800 Subject: [PATCH] [ISSUE #12970] Fix NamingMetadataManager.removeInstanceMetadata() error (#12971) * [ISSUE #12970] Fix NamingMetadataManager.removeInstanceMetadata() error fix #12970 * Update NamingMetadataManagerTest.java --- .../naming/core/v2/metadata/NamingMetadataManager.java | 2 +- .../naming/core/v2/metadata/NamingMetadataManagerTest.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 a4f34661d5..44ca8cbe82 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 ac6e6aed2f..99383753b1 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 +}