JEtcdClient extends AbstractEtcdClient<JEtcdClient.EtcdWatcher> { @Override public boolean put(String key, String value) { return clientWrapper.put(key, value); } JEtcdClient(URL url); @Override void doCreatePersistent(String path); @Override long doCreateEphemeral(String path); @Override boolean checkExists(String path); @Override EtcdWatcher createChildWatcherListener(String path, ChildListener listener); @Override List<String> addChildWatcherListener(String path, EtcdWatcher etcdWatcher); @Override void removeChildWatcherListener(String path, EtcdWatcher etcdWatcher); @Override List<String> getChildren(String path); @Override boolean isConnected(); @Override long createLease(long second); @Override long createLease(long ttl, long timeout, TimeUnit unit); @Override void delete(String path); @Override void revokeLease(long lease); @Override void doClose(); @Override String getKVValue(String key); @Override boolean put(String key, String value); @Override boolean putEphemeral(String key, String value); ManagedChannel getChannel();  }
@Test public void test_watch_when_modify() { String path = "/dubbo/config/jetcd-client-unit-test/configurators"; String endpoint = "http: CountDownLatch latch = new CountDownLatch(1); ByteSequence key = ByteSequence.from(path, UTF_8); Watch.Listener listener = Watch.listener(response -> { for (WatchEvent event : response.getEvents()) { Assertions.assertEquals("PUT", event.getEventType().toString()); Assertions.assertEquals(path, event.getKeyValue().getKey().toString(UTF_8)); Assertions.assertEquals("Hello", event.getKeyValue().getValue().toString(UTF_8)); latch.countDown(); } }); try (Client client = Client.builder().endpoints(endpoint).build(); Watch watch = client.getWatchClient(); Watch.Watcher watcher = watch.watch(key, listener)) { client.getKVClient().put(ByteSequence.from(path, UTF_8), ByteSequence.from("Hello", UTF_8)); latch.await(); } catch (Exception e) { Assertions.fail(e.getMessage()); } }