Search in sources :

Example 1 with AddCallbackFuture

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());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) AddCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 2 with AddCallbackFuture

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();
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) AddCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture) Test(org.junit.Test)

Aggregations

AddCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ZooKeeperWatcherBase (org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1