Search in sources :

Example 6 with FlakyTest

use of org.apache.bookkeeper.test.annotations.FlakyTest 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

FlakyTest (org.apache.bookkeeper.test.annotations.FlakyTest)6 HashMap (java.util.HashMap)5 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)5 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)5 BookieServer (org.apache.bookkeeper.proto.BookieServer)5 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BKIllegalOpException (org.apache.bookkeeper.client.BKException.BKIllegalOpException)1 ZkLedgerUnderreplicationManager (org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager)1