EtcdServiceDiscovery extends AbstractServiceDiscovery implements EventListener<ServiceInstancesChangedEvent> { @Override public void update(ServiceInstance serviceInstance) throws RuntimeException { super.register(serviceInstance); try { String path = toPath(serviceInstance); etcdClient.putEphemeral(path, new Gson().toJson(serviceInstance)); services.add(serviceInstance.getServiceName()); } catch (Throwable e) { throw new RpcException("Failed to register " + serviceInstance + " to etcd " + etcdClient.getUrl() + ", cause: " + (OptionUtil.isProtocolError(e) ? "etcd3 registry may not be supported yet or etcd3 registry is not available." : e.getMessage()), e); } }  @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 testUpdate() throws Exception { DefaultServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTest34Service", "127.0.0.1", 8080); Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); etcdServiceDiscovery.register(serviceInstance); Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance)); serviceInstance.setPort(9999); etcdServiceDiscovery.update(serviceInstance); Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance)); }