Search in sources :

Example 1 with BKClientClosedException

use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.

the class BookKeeperCloseTest method testCloseLedger.

/**
 * Test that closing a ledger using bookkeeper client which is closed should
 * throw ClientClosedException.
 */
@Test
public void testCloseLedger() throws Exception {
    BookKeeper bk = new BookKeeper(baseClientConf, zkc);
    LOG.info("Create ledger and add entries to it");
    LedgerHandle lh = createLedgerWithEntries(bk, 100);
    LedgerHandle lh2 = createLedgerWithEntries(bk, 100);
    LOG.info("Closing bookkeeper client");
    bk.close();
    try {
        lh.close();
        fail("should have failed, client is closed");
    } catch (BKClientClosedException e) {
    // correct
    }
    final CountDownLatch completeLatch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
    lh2.asyncClose(new CloseCallback() {

        public void closeComplete(int rccb, LedgerHandle lh, Object ctx) {
            rc.set(rccb);
            completeLatch.countDown();
        }
    }, null);
    LOG.info("Waiting to finish adding another entry asynchronously");
    assertTrue("Close ledger call should have completed", completeLatch.await(20, TimeUnit.SECONDS));
    assertEquals("Close ledger should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CloseCallback(org.apache.bookkeeper.client.AsyncCallback.CloseCallback) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with BKClientClosedException

use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.

the class BookKeeperCloseTest method testReadLedgerEntry.

/**
 * Test that reading entry from a ledger using bookkeeper client which is
 * closed should throw ClientClosedException.
 */
@Test
public void testReadLedgerEntry() throws Exception {
    BookKeeper bk = new BookKeeper(baseClientConf, zkc);
    LOG.info("Create ledger and add entries to it");
    int numOfEntries = 100;
    LedgerHandle lh = createLedgerWithEntries(bk, numOfEntries);
    LOG.info("Closing bookkeeper client");
    restartBookieSlow();
    bk.close();
    try {
        lh.readEntries(0, numOfEntries - 1);
        fail("should have failed, client is closed");
    } catch (BKClientClosedException e) {
    // correct
    }
    final CountDownLatch readLatch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
    ReadCallback cb = new ReadCallback() {

        @Override
        public void readComplete(int rccb, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx) {
            rc.set(rccb);
            readLatch.countDown();
        }
    };
    lh.asyncReadEntries(0, numOfEntries - 1, cb, readLatch);
    LOG.info("Waiting to finish reading the entries asynchronously");
    assertTrue("Read entry ledger call should have completed", readLatch.await(20, TimeUnit.SECONDS));
    assertEquals("Read entry ledger should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
Also used : Enumeration(java.util.Enumeration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) ReadCallback(org.apache.bookkeeper.client.AsyncCallback.ReadCallback) Test(org.junit.Test)

Example 3 with BKClientClosedException

use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.

the class BookKeeperCloseTest method testDeleteLedger.

/**
 * Test that deleting a ledger using bookkeeper client which is closed
 * should throw ClientClosedException.
 */
@Test
public void testDeleteLedger() throws Exception {
    BookKeeper bk = new BookKeeper(baseClientConf, zkc);
    LOG.info("Create ledger and add entries to it");
    LedgerHandle lh = createLedgerWithEntries(bk, 100);
    LOG.info("Closing bookkeeper client");
    bk.close();
    try {
        bk.deleteLedger(lh.getId());
        fail("should have failed, client is closed");
    } catch (BKClientClosedException e) {
    // correct
    }
    // using async, because this could trigger an assertion
    final AtomicInteger returnCode = new AtomicInteger(0);
    final CountDownLatch openLatch = new CountDownLatch(1);
    AsyncCallback.DeleteCallback cb = new AsyncCallback.DeleteCallback() {

        public void deleteComplete(int rc, Object ctx) {
            returnCode.set(rc);
            openLatch.countDown();
        }
    };
    bk.asyncDeleteLedger(lh.getId(), cb, openLatch);
    LOG.info("Waiting to delete the ledger asynchronously");
    assertTrue("Delete call should have completed", openLatch.await(20, TimeUnit.SECONDS));
    assertEquals("Delete should not have succeeded through closed bkclient!", BKException.Code.ClientClosedException, returnCode.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with BKClientClosedException

use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.

the class BookKeeperCloseTest method testAddLedgerEntry.

/**
 * Test that adding entry to a ledger using bookkeeper client which is
 * closed should throw ClientClosedException.
 */
@Test
public void testAddLedgerEntry() throws Exception {
    BookKeeper bk = new BookKeeper(baseClientConf, zkc);
    LOG.info("Create ledger and add entries to it");
    LedgerHandle lh = createLedgerWithEntries(bk, 1);
    LOG.info("Closing bookkeeper client");
    restartBookieSlow();
    bk.close();
    try {
        lh.addEntry("foobar".getBytes());
        fail("should have failed, client is closed");
    } catch (BKClientClosedException e) {
    // correct
    }
    final CountDownLatch completeLatch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
    lh.asyncAddEntry("foobar".getBytes(), new AddCallback() {

        public void addComplete(int rccb, LedgerHandle lh, long entryId, Object ctx) {
            rc.set(rccb);
            completeLatch.countDown();
        }
    }, null);
    LOG.info("Waiting to finish adding another entry asynchronously");
    assertTrue("Add entry to ledger call should have completed", completeLatch.await(20, TimeUnit.SECONDS));
    assertEquals("Add entry to ledger should not have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AddCallback(org.apache.bookkeeper.client.AsyncCallback.AddCallback) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with BKClientClosedException

use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.

the class BookKeeperCloseTest method testReadLastConfirmed.

/**
 * Test that readlastconfirmed entry from a ledger using bookkeeper client
 * which is closed should throw ClientClosedException.
 */
@Test
public void testReadLastConfirmed() throws Exception {
    BookKeeper bk = new BookKeeper(baseClientConf, zkc);
    LOG.info("Create ledger and add entries to it");
    LedgerHandle lh = createLedgerWithEntries(bk, 100);
    LOG.info("Closing bookkeeper client");
    // make all bookies slow
    restartBookieSlow();
    restartBookieSlow();
    restartBookieSlow();
    bk.close();
    final CountDownLatch readLatch = new CountDownLatch(1);
    final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
    AsyncCallback.ReadLastConfirmedCallback cb = new AsyncCallback.ReadLastConfirmedCallback() {

        @Override
        public void readLastConfirmedComplete(int rccb, long lastConfirmed, Object ctx) {
            rc.set(rccb);
            readLatch.countDown();
        }
    };
    lh.asyncReadLastConfirmed(cb, readLatch);
    LOG.info("Waiting to finish reading last confirmed entry asynchronously");
    assertTrue("ReadLastConfirmed call should have completed", readLatch.await(20, TimeUnit.SECONDS));
    assertEquals("ReadLastConfirmed should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
    try {
        lh.readLastConfirmed();
        fail("should have failed, client is closed");
    } catch (BKClientClosedException e) {
    // correct
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) Test(org.junit.Test)

Aggregations

BKClientClosedException (org.apache.bookkeeper.client.BKException.BKClientClosedException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Test (org.junit.Test)7 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 IOException (java.io.IOException)1 Enumeration (java.util.Enumeration)1 CompletionException (java.util.concurrent.CompletionException)1 AddCallback (org.apache.bookkeeper.client.AsyncCallback.AddCallback)1 CloseCallback (org.apache.bookkeeper.client.AsyncCallback.CloseCallback)1 CreateCallback (org.apache.bookkeeper.client.AsyncCallback.CreateCallback)1 ReadCallback (org.apache.bookkeeper.client.AsyncCallback.ReadCallback)1 BKException (org.apache.bookkeeper.client.BKException)1 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)1 LastConfirmedAndEntry (org.apache.bookkeeper.client.api.LastConfirmedAndEntry)1 LedgerEntries (org.apache.bookkeeper.client.api.LedgerEntries)1 ReadHandle (org.apache.bookkeeper.client.api.ReadHandle)1