System.setProperty("digestType", digestType.toString());
System.setProperty("passwd", "testPasswd");
BookKeeperAdmin admin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
LedgerHandle writelh = bkc.createLedger(digestType, "testPasswd".getBytes());
String tmp = "Foobar";
final int numEntries = 10;
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
InetSocketAddress bookieToKill
= writelh.getLedgerMetadata().getEnsemble(numEntries).get(0);
killBookie(bookieToKill);
// write entries to change ensemble
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
admin.recoverBookieData(bookieToKill, null);
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
LedgerHandle readlh = bkc.openLedger(writelh.getId(),
digestType, "testPasswd".getBytes());
try {
writelh.addEntry(tmp.getBytes());
LOG.error("Should have thrown an exception");
fail("Should have thrown an exception when trying to write");
} catch (BKException.BKLedgerFencedException e) {
// correct behaviour
}
readlh.close();
try {
writelh.close();
fail("Should fail trying to update metadata");
} catch (BKException.ZKException e) {
// correct behaviour