use of org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture in project bookkeeper by apache.
the class LedgerCloseTest method testAllWritesAreCompletedOnClosedLedger.
@Test
public void testAllWritesAreCompletedOnClosedLedger() throws Exception {
for (int i = 0; i < 100; i++) {
LOG.info("Iteration {}", i);
List<AddCallbackFuture> futures = new ArrayList<AddCallbackFuture>();
LedgerHandle w = bkc.createLedger(DigestType.CRC32, new byte[0]);
AddCallbackFuture f = new AddCallbackFuture(0L);
w.asyncAddEntry("foobar".getBytes(UTF_8), f, null);
f.get();
LedgerHandle r = bkc.openLedger(w.getId(), DigestType.CRC32, new byte[0]);
for (int j = 0; j < 100; j++) {
AddCallbackFuture f1 = new AddCallbackFuture(1L + j);
w.asyncAddEntry("foobar".getBytes(), f1, null);
futures.add(f1);
}
for (AddCallbackFuture f2 : futures) {
try {
f2.get(10, TimeUnit.SECONDS);
} catch (ExecutionException ee) {
// we don't care about errors
} catch (TimeoutException te) {
LOG.error("Error on waiting completing entry {} : ", f2.getExpectedEntryId(), te);
fail("Should succeed on waiting completing entry " + f2.getExpectedEntryId());
}
}
}
}
use of org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture in project bookkeeper by apache.
the class BookKeeperClientZKSessionExpiry method testSessionLossWhileWriting.
@Test
public void testSessionLossWhileWriting() throws Exception {
Thread expiryThread = new Thread() {
@Override
public void run() {
try {
while (true) {
Thread.sleep(5000);
long sessionId = bkc.getZkHandle().getSessionId();
byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd();
try {
ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000);
ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, watcher, sessionId, sessionPasswd);
zk.close();
} catch (Exception e) {
LOG.info("Error killing session", e);
}
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
}
}
};
expiryThread.start();
for (int i = 0; i < 3; i++) {
LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes());
for (int j = 0; j < 100; j++) {
lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null);
}
startNewBookie();
killBookie(0);
lh.addEntry("lastEntry".getBytes());
lh.close();
}
}
Aggregations