ConsulRegistry extends CommandFailbackRegistry implements Closable { @Override protected List<URL> discoverService(URL url) { String service = ConsulUtils.getUrlClusterInfo(url); String group = url.getGroup(); List<URL> serviceUrls = new ArrayList<URL>(); ConcurrentHashMap<String, List<URL>> serviceMap = serviceCache.get(group); if (serviceMap == null) { synchronized (group.intern()) { serviceMap = serviceCache.get(group); if (serviceMap == null) { ConcurrentHashMap<String, List<URL>> groupUrls = lookupServiceUpdate(group); updateServiceCache(group, groupUrls, false); serviceMap = serviceCache.get(group); } } } if (serviceMap != null) { serviceUrls = serviceMap.get(service); } return serviceUrls; } ConsulRegistry(URL url, MotanConsulClient client); ConcurrentHashMap<String, ConcurrentHashMap<URL, ServiceListener>> getServiceListeners(); ConcurrentHashMap<String, ConcurrentHashMap<URL, CommandListener>> getCommandListeners(); @Override void close();  }
@Test public void discoverService() throws Exception { registry.doRegister(serviceUrl); List<URL> urls = registry.discoverService(serviceUrl); Assert.assertFalse(urls.contains(serviceUrl)); registry.doAvailable(null); Thread.sleep(sleepTime); urls = registry.discoverService(serviceUrl); Assert.assertTrue(urls.contains(serviceUrl)); }