Skip to content

Commit

Permalink
[improve][test] Clarify method signatures in Bookkeeper mock client (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzk1 authored Nov 14, 2024
1 parent 22cfa54 commit 0b0eef9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,38 @@ public BookieClient getBookieClient() {
return bookieClient;
}

public Future<?> waitForReadOnlyBookie(BookieId b)
public Future<?> waitForReadOnlyBookie(BookieId id)
throws Exception {
return waitForBookieInSet(b, false);
return waitForBookieInSet(id, false);
}

public Future<?> waitForWritableBookie(BookieId b)
public Future<?> waitForWritableBookie(BookieId id)
throws Exception {
return waitForBookieInSet(b, true);
return waitForBookieInSet(id, 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 Future<?> waitForBookieInSet(BookieId b,
private Future<?> waitForBookieInSet(BookieId id,
boolean writable) throws Exception {
log.info("Wait for {} to become {}",
b, writable ? "writable" : "readonly");
id, 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)) {
boolean containsId = bookies.getValue().contains(id);
if ((!writable && containsId) || (writable && !containsId)) {
readOnlyFuture.complete(null);
}
};
RegistrationListener writableListener = (bookies) -> {
boolean contains = bookies.getValue().contains(b);
if ((writable && contains) || (!writable && !contains)) {
boolean containsId = bookies.getValue().contains(id);
if ((writable && containsId) || (!writable && !containsId)) {
writableFuture.complete(null);
}
};
Expand All @@ -114,7 +114,7 @@ private Future<?> waitForBookieInSet(BookieId b,
return writableFuture
.thenCompose(ignored -> getMetadataClientDriver().getRegistrationClient().getReadOnlyBookies())
.thenCompose(readonlyBookies -> {
if (readonlyBookies.getValue().contains(b)) {
if (readonlyBookies.getValue().contains(id)) {
// if the bookie still shows up at readonly path, wait for it to disappear
return readOnlyFuture;
} else {
Expand All @@ -125,7 +125,7 @@ private Future<?> waitForBookieInSet(BookieId b,
return readOnlyFuture
.thenCompose(ignored -> getMetadataClientDriver().getRegistrationClient().getWritableBookies())
.thenCompose(writableBookies -> {
if (writableBookies.getValue().contains(b)) {
if (writableBookies.getValue().contains(id)) {
// if the bookie still shows up at writable path, wait for it to disappear
return writableFuture;
} else {
Expand All @@ -139,7 +139,7 @@ private Future<?> waitForBookieInSet(BookieId b,
* Force a read to zookeeper to get list of bookies.
*
* @throws InterruptedException
* @throws KeeperException
* @throws BKException
*/
public void readBookiesBlocking() throws InterruptedException, BKException {
bookieWatcher.initialBlockingBookieRead();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public OrderedExecutor getMainWorkerPool() {
}

@Override
public LedgerHandle createLedger(DigestType digestType, byte passwd[])
public LedgerHandle createLedger(DigestType digestType, byte[] passwd)
throws BKException, InterruptedException {
return createLedger(3, 2, digestType, passwd);
}

@Override
public LedgerHandle createLedger(int ensSize, int qSize, DigestType digestType, byte passwd[])
public LedgerHandle createLedger(int ensSize, int qSize, DigestType digestType, byte[] passwd)
throws BKException, InterruptedException {
return createLedger(ensSize, qSize, qSize, digestType, passwd);
}
Expand Down

0 comments on commit 0b0eef9

Please sign in to comment.