diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java index 5bf35f7f629..d17c99b86bd 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java @@ -85,7 +85,7 @@ public Registry getRegistry(URL url) { url = url.setPath(RegistryService.class.getName()) .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY); - String key = url.toServiceString(); + String key = url.toServiceStringWithoutResolving(); // Lock the registry access process to ensure a single instance of the registry LOCK.lock(); try { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java index cb2a45473ff..15ef91efd98 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.registry.NotifyListener; import com.alibaba.dubbo.registry.Registry; import com.alibaba.dubbo.registry.RegistryFactory; - import junit.framework.Assert; import org.junit.Test; @@ -87,9 +86,15 @@ public void testRegistryFactoryCache() throws Exception { @Test public void testRegistryFactoryIpCache() throws Exception { - Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233")); - Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233")); - Assert.assertEquals(registry1, registry2); + String hostName = NetUtils.getLocalAddress().getHostName(); + String ip = NetUtils.getLocalAddress().getHostAddress(); + Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + hostName + ":2233")); + Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + ip + ":2233")); + if (hostName.equals(ip)) { + Assert.assertEquals(registry1, registry2); + } else { + Assert.assertNotSame(registry1, registry2); + } } @Test