use of org.apache.dubbo.remoting.etcd.ChildListener in project dubbo by alibaba.
the class JEtcdClientTest method test_watch_when_delete_path.
@Test
public void test_watch_when_delete_path() throws InterruptedException {
String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
String child = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers/demoService1";
final CountDownLatch notNotified = new CountDownLatch(1);
ChildListener childListener = (parent, children) -> {
Assertions.assertEquals(0, children.size());
notNotified.countDown();
};
client.createEphemeral(child);
client.addChildListener(path, childListener);
client.delete(child);
Assertions.assertTrue(notNotified.await(10, TimeUnit.SECONDS));
client.removeChildListener(path, childListener);
}
use of org.apache.dubbo.remoting.etcd.ChildListener in project dubbo by alibaba.
the class JEtcdClientTest method test_watch_then_unwatch.
@Test
public void test_watch_then_unwatch() throws InterruptedException {
String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
String child = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers/demoService2";
final CountDownLatch notNotified = new CountDownLatch(1);
final CountDownLatch notTwiceNotified = new CountDownLatch(2);
final Holder notified = new Holder();
ChildListener childListener = (parent, children) -> {
Assertions.assertEquals(1, children.size());
Assertions.assertEquals(child.substring(child.lastIndexOf("/") + 1), children.get(0));
notNotified.countDown();
notTwiceNotified.countDown();
notified.getAndIncrease();
};
client.addChildListener(path, childListener);
client.createEphemeral(child);
Assertions.assertTrue(notNotified.await(15, TimeUnit.SECONDS));
client.removeChildListener(path, childListener);
client.delete(child);
Assertions.assertFalse(notTwiceNotified.await(5, TimeUnit.SECONDS));
Assertions.assertEquals(1, notified.value);
client.delete(child);
}
use of org.apache.dubbo.remoting.etcd.ChildListener in project dubbo by alibaba.
the class JEtcdClientTest method test_watch_on_unrecoverable_connection.
@Test
public void test_watch_on_unrecoverable_connection() throws InterruptedException {
String path = "/dubbo/com.alibaba.dubbo.demo.DemoService/providers";
JEtcdClient.EtcdWatcher watcher = null;
try {
ChildListener childListener = (parent, children) -> {
Assertions.assertEquals(path, parent);
};
client.addChildListener(path, childListener);
watcher = client.getChildListener(path, childListener);
watcher.watchRequest.onError(Status.ABORTED.withDescription("connection error").asRuntimeException());
watcher.watchRequest.onNext(watcher.nextRequest());
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("call was cancelled"));
}
}
use of org.apache.dubbo.remoting.etcd.ChildListener in project dubbo by alibaba.
the class EtcdRegistry method doUnsubscribe.
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
ConcurrentMap<NotifyListener, ChildListener> listeners = etcdListeners.get(url);
if (listeners != null) {
ChildListener etcdListener = listeners.remove(listener);
if (etcdListener != null) {
if (ANY_VALUE.equals(url.getServiceInterface())) {
String root = toRootPath();
etcdClient.removeChildListener(root, etcdListener);
} else {
// maybe url has many subscribed paths
for (String path : toUnsubscribedPath(url)) {
etcdClient.removeChildListener(path, etcdListener);
}
}
}
if (listeners.isEmpty()) {
etcdListeners.remove(url);
}
}
}
Aggregations