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();
}
Aggregations