Search in sources :

Example 1 with BKIllegalOpException

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

the class BookieReadWriteTest method testLedgerHandle.

@Test
public void testLedgerHandle() throws Exception {
    // Create a ledger
    lh = bkc.createLedger(digestType, ledgerPassword);
    ledgerId = lh.getId();
    LOG.info("Ledger ID: " + lh.getId());
    long lac = writeNEntriesLastWriteSync(lh, 5);
    // doing addEntry with entryid using regular Ledgerhandle should fail
    CountDownLatch latch = new CountDownLatch(1);
    final int[] rcArray = { 0 };
    lh.asyncAddEntry(lac + 1, "".getBytes(), new AddCallback() {

        @Override
        public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
            CountDownLatch latch = (CountDownLatch) ctx;
            rcArray[0] = rc;
            latch.countDown();
        }
    }, latch);
    latch.await();
    if (rcArray[0] != BKException.Code.IllegalOpException) {
        Assert.fail("Test1 - addEntry with EntryID is expected to fail with IllegalOpException, " + "but it got following rc - " + KeeperException.Code.get(rcArray[0]));
    }
    // doing addEntry with entryid using regular Ledgerhandle should fail
    latch = new CountDownLatch(1);
    rcArray[0] = 0;
    lh.asyncAddEntry(lac + 1, "".getBytes(), 0, 0, new AddCallback() {

        @Override
        public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
            CountDownLatch latch = (CountDownLatch) ctx;
            rcArray[0] = rc;
            latch.countDown();
        }
    }, latch);
    latch.await();
    if (rcArray[0] != BKException.Code.IllegalOpException) {
        Assert.fail("Test2 - addEntry with EntryID is expected to fail with IllegalOpException," + "but it got following rc - " + KeeperException.Code.get(rcArray[0]));
    }
    // doing addEntry with entryid using regular Ledgerhandle should fail
    try {
        lh.addEntry(lac + 1, "".getBytes());
        Assert.fail("Test3 - addEntry with EntryID is expected to fail");
    } catch (BKIllegalOpException E) {
    }
    // doing addEntry with entryid using regular Ledgerhandle should fail
    try {
        lh.addEntry(lac + 1, "".getBytes(), 0, 0);
        Assert.fail("Test4 - addEntry with EntryID is expected to fail");
    } catch (BKIllegalOpException E) {
    }
    lh.close();
}
Also used : AddCallback(org.apache.bookkeeper.client.AsyncCallback.AddCallback) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BKIllegalOpException(org.apache.bookkeeper.client.BKException.BKIllegalOpException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with BKIllegalOpException

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

the class BookieDecommissionTest method testDecommissionBookie.

@FlakyTest("https://github.com/apache/bookkeeper/issues/502")
public void testDecommissionBookie() throws Exception {
    ZkLedgerUnderreplicationManager urLedgerMgr = new ZkLedgerUnderreplicationManager(baseClientConf, zkc);
    BookKeeperAdmin bkAdmin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
    int numOfLedgers = 2 * NUM_OF_BOOKIES;
    int numOfEntries = 2 * NUM_OF_BOOKIES;
    for (int i = 0; i < numOfLedgers; i++) {
        LedgerHandle lh = bkc.createLedger(3, 2, digestType, PASSWORD.getBytes());
        for (int j = 0; j < numOfEntries; j++) {
            lh.addEntry("entry".getBytes());
        }
        lh.close();
    }
    /*
         * create ledgers having empty segments (segment with no entries)
         */
    for (int i = 0; i < numOfLedgers; i++) {
        LedgerHandle emptylh = bkc.createLedger(3, 2, digestType, PASSWORD.getBytes());
        emptylh.close();
    }
    try {
        /*
             * if we try to call decommissionBookie for a bookie which is not
             * shutdown, then it should throw BKIllegalOpException
             */
        bkAdmin.decommissionBookie(bs.get(0).getLocalAddress());
        fail("Expected BKIllegalOpException because that bookie is not shutdown yet");
    } catch (BKIllegalOpException bkioexc) {
    // expected IllegalException
    }
    ServerConfiguration killedBookieConf = killBookie(1);
    /*
         * this decommisionBookie should make sure that there are no
         * underreplicated ledgers because of this bookie
         */
    bkAdmin.decommissionBookie(Bookie.getBookieAddress(killedBookieConf));
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    Iterator<Long> ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    if (ledgersToRereplicate.hasNext()) {
        while (ledgersToRereplicate.hasNext()) {
            Long ledgerId = ledgersToRereplicate.next();
            log.error("Ledger: {} is underreplicated which is not expected", ledgerId);
        }
        fail("There are not supposed to be any underreplicatedledgers");
    }
    killedBookieConf = killBookie(0);
    bkAdmin.decommissionBookie(Bookie.getBookieAddress(killedBookieConf));
    bkAdmin.triggerAudit();
    Thread.sleep(500);
    ledgersToRereplicate = urLedgerMgr.listLedgersToRereplicate(null);
    if (ledgersToRereplicate.hasNext()) {
        while (ledgersToRereplicate.hasNext()) {
            Long ledgerId = ledgersToRereplicate.next();
            log.error("Ledger: {} is underreplicated which is not expected", ledgerId);
        }
        fail("There are not supposed to be any underreplicatedledgers");
    }
    bkAdmin.close();
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BKIllegalOpException(org.apache.bookkeeper.client.BKException.BKIllegalOpException) ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) FlakyTest(org.apache.bookkeeper.test.annotations.FlakyTest)

Aggregations

BKIllegalOpException (org.apache.bookkeeper.client.BKException.BKIllegalOpException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AddCallback (org.apache.bookkeeper.client.AsyncCallback.AddCallback)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 ZkLedgerUnderreplicationManager (org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager)1 FlakyTest (org.apache.bookkeeper.test.annotations.FlakyTest)1 Test (org.junit.Test)1