sijie commented on a change in pull request #775: Tests wait for client to see
started bookie
URL: https://github.com/apache/bookkeeper/pull/775#discussion_r153585139
##########
File path:
bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperTestClient.java
##########
@@ -50,13 +57,53 @@ public BookieClient getBookieClient() {
}
/**
- * Force a read to zookeeper to get list of bookies.
- *
- * @throws InterruptedException
- * @throws KeeperException
+ * Wait for the bookie to appear in any set
*/
- public void readBookiesBlocking()
- throws InterruptedException, BKException {
- bookieWatcher.readBookiesBlocking();
+ public CompletableFuture<?> waitForBookie(BookieSocketAddress b)
+ throws Exception {
+ return CompletableFuture.anyOf(
+ waitForReadOnlyBookie(b),
+ waitForWritableBookie(b));
+ }
+
+ public CompletableFuture<?> waitForReadOnlyBookie(BookieSocketAddress b)
+ throws Exception {
+ return waitForBookieInSet(b, false);
+ }
+
+ public CompletableFuture<?> waitForWritableBookie(BookieSocketAddress b)
+ throws Exception {
+ return waitForBookieInSet(b, true);
+ }
+
+ /**
+ * Wait for bookie to appear in either the writable set of bookies,
+ * or the read only set of bookies. Also ensure that it doesn't exist
+ * in the other set before completing.
+ */
+ private CompletableFuture<?> waitForBookieInSet(BookieSocketAddress b,
+ boolean writable) {
+ log.info("Wait for {} to become {}",
+ b, writable ? "writable" : "readonly");
+
+ CompletableFuture<Void> readOnlyFuture = new CompletableFuture<>();
+ CompletableFuture<Void> writableFuture = new CompletableFuture<>();
+
+ RegistrationListener readOnlyListener = (bookies) -> {
+ boolean contains = bookies.getValue().contains(b);
+ if ((!writable && contains) || (writable && !contains)) {
+ readOnlyFuture.complete(null);
+ }
+ };
+ RegistrationListener writableListener = (bookies) -> {
+ boolean contains = bookies.getValue().contains(b);
+ if ((writable && contains) || (!writable && !contains)) {
+ writableFuture.complete(null);
+ }
+ };
+
+ regClient.watchWritableBookies(writableListener);
+ regClient.watchReadOnlyBookies(readOnlyListener);
+ return CompletableFuture.allOf(writableFuture, readOnlyFuture);
Review comment:
I think CompletableFuture.allOf returns `CompletableFuture<Void>`. it would
be good for returning `CompletableFuture<Void>`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services