From c8facc5ef6e9ab64e0331f5d0e25a6fb96f6bed0 Mon Sep 17 00:00:00 2001 From: zetas <356082462@qq.com> Date: Tue, 23 Jul 2019 20:06:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=86=8C=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E7=82=B9=E9=97=AE=E9=A2=98=20(#4293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #2545 --- .../registry/support/AbstractRegistryFactory.java | 2 +- .../support/AbstractRegistryFactoryTest.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) 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