use of org.apache.bookkeeper.client.BKException.ZKException in project bookkeeper by apache.
the class ZKRegistrationClient method getChildren.
private CompletableFuture<Versioned<Set<BookieSocketAddress>>> getChildren(String regPath, Watcher watcher) {
CompletableFuture<Versioned<Set<BookieSocketAddress>>> future = FutureUtils.createFuture();
zk.getChildren(regPath, watcher, (rc, path, ctx, children, stat) -> {
if (Code.OK != rc) {
ZKException zke = new ZKException();
zke.fillInStackTrace();
future.completeExceptionally(zke);
return;
}
Version version = new LongVersion(stat.getCversion());
Set<BookieSocketAddress> bookies = convertToBookieAddresses(children);
future.complete(new Versioned<>(bookies, version));
}, null);
return future;
}
use of org.apache.bookkeeper.client.BKException.ZKException in project bookkeeper by apache.
the class TestZkRegistrationClient method testWatchBookiesFailure.
private void testWatchBookiesFailure(boolean isWritable) throws Exception {
int zkCallbackDelayMs = 100;
mockGetChildren(isWritable ? regPath : regReadonlyPath, true, Code.NONODE.intValue(), null, null, zkCallbackDelayMs);
CompletableFuture<Versioned<Set<BookieSocketAddress>>> listenerResult = new CompletableFuture<>();
RegistrationListener listener = bookies -> listenerResult.complete(bookies);
CompletableFuture<Void> watchFuture;
WatchTask watchTask;
if (isWritable) {
watchFuture = zkRegistrationClient.watchWritableBookies(listener);
watchTask = zkRegistrationClient.getWatchWritableBookiesTask();
} else {
watchFuture = zkRegistrationClient.watchReadOnlyBookies(listener);
watchTask = zkRegistrationClient.getWatchReadOnlyBookiesTask();
}
assertNotNull(watchTask);
assertEquals(1, watchTask.getNumListeners());
// trigger zkCallbackExecutor to execute getChildren callback
zkCallbackController.advance(Duration.ofMillis(zkCallbackDelayMs));
try {
result(watchFuture);
fail("Should fail to watch writable bookies if reg path doesn't exist");
} catch (ZKException zke) {
// expected
}
assertEquals(0, watchTask.getNumListeners());
assertTrue(watchTask.isClosed());
if (isWritable) {
assertNull(zkRegistrationClient.getWatchWritableBookiesTask());
} else {
assertNull(zkRegistrationClient.getWatchReadOnlyBookiesTask());
}
}
Aggregations