Skip to content

Commit

Permalink
修复注册中心域名解析导致的单点问题 (#4293)
Browse files Browse the repository at this point in the history
Fix #2545
  • Loading branch information
356082462 authored and chickenlj committed Jul 23, 2019
1 parent 6702cbd commit c8facc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c8facc5

Please sign in to comment.