EtcdServiceDiscovery extends AbstractServiceDiscovery implements EventListener<ServiceInstancesChangedEvent> { @Override public List<ServiceInstance> getInstances(String serviceName) { List<String> children = etcdClient.getChildren(toParentPath(serviceName)); if (CollectionUtils.isEmpty(children)) { return Collections.EMPTY_LIST; } List<ServiceInstance> list = new ArrayList<>(children.size()); for (String child : children) { ServiceInstance serviceInstance = new Gson().fromJson(etcdClient.getKVValue(child), DefaultServiceInstance.class); list.add(serviceInstance); } return list; }  @Override void onEvent(ServiceInstancesChangedEvent event); @Override void initialize(URL registryURL); @Override void destroy(); @Override void register(ServiceInstance serviceInstance); @Override void update(ServiceInstance serviceInstance); @Override void unregister(ServiceInstance serviceInstance); @Override Set<String> getServices(); @Override void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener); @Override List<ServiceInstance> getInstances(String serviceName);  }
@Test public void testGetInstances() throws Exception { String serviceName = "EtcdTest77Service"; Assertions.assertTrue(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 8080)); etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 9809)); Assertions.assertFalse(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); List<String> r = convertToIpPort(etcdServiceDiscovery.getInstances(serviceName)); Assertions.assertTrue(r.contains("127.0.0.1:8080")); Assertions.assertTrue(r.contains("127.0.0.1:9809")); }