Skip to content

Instantly share code, notes, and snippets.

@ivankelly
Created April 2, 2019 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivankelly/65c999a1a3a280eea7e5b27e0a5a361b to your computer and use it in GitHub Desktop.
Save ivankelly/65c999a1a3a280eea7e5b27e0a5a361b to your computer and use it in GitHub Desktop.
ackage org.apache.bookkeeper.client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LongPollTest {
public static final Logger log = LoggerFactory.getLogger(LongPollTest.class);
public static void main(String[] args) throws Exception {
BookKeeper bkc = new BookKeeper("localhost:2181");
log.info("Writing");
LedgerHandle write = bkc.createLedger(1,1,1, BookKeeper.DigestType.CRC32, "foobar".getBytes());
for (int i = 0; i < 100; i++) {
write.addEntry("foobar".getBytes());
}
log.info("long pollin");
for (int i = 0; i < 100; i++) {
Thread t = new Thread(() -> {
try {
LedgerHandle read = bkc.openLedgerNoRecovery(write.getId(),
BookKeeper.DigestType.CRC32, "foobar".getBytes());
long lac = 0;
while (true) {
lac = read.readLastAddConfirmedAndEntryAsync(lac+1, 1, false).get().getLastAddConfirmed();
}
} catch (Throwable ex) {
log.error("Caught error", ex);
System.exit(-10);
}
});
t.start();
}
while (true) {
Thread.sleep(100);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment