ConsulRegistry extends FailbackRegistry { @Override public List<URL> lookup(URL url) { if (url == null) { throw new IllegalArgumentException("lookup url == null"); } try { String service = url.getServiceKey(); Response<List<HealthService>> result = getHealthServices(service, -1, buildWatchTimeout(url)); if (result == null || result.getValue() == null || result.getValue().isEmpty()) { return new ArrayList<>(); } else { return convert(result.getValue(), url); } } catch (Throwable e) { throw new RpcException("Failed to lookup " + url + " from consul " + getUrl() + ", cause: " + e.getMessage(), e); } } ConsulRegistry(URL url); @Override void register(URL url); @Override void doRegister(URL url); @Override void unregister(URL url); @Override void doUnregister(URL url); @Override void subscribe(URL url, NotifyListener listener); @Override void doSubscribe(URL url, NotifyListener listener); @Override void unsubscribe(URL url, NotifyListener listener); @Override void doUnsubscribe(URL url, NotifyListener listener); @Override List<URL> lookup(URL url); @Override boolean isAvailable(); @Override void destroy();  }
@Test public void testLookup() throws InterruptedException { List<URL> lookup = consulRegistry.lookup(serviceUrl); assertThat(lookup.size(), is(0)); consulRegistry.register(serviceUrl); Thread.sleep(5000); lookup = consulRegistry.lookup(serviceUrl); assertThat(lookup.size(), is(1)); }