public void testBookieRegistration() throws Exception {
File tmpDir = File.createTempFile("bookie", "test");
tmpDir.delete();
tmpDir.mkdir();
final ServerConfiguration conf = new ServerConfiguration()
.setZkServers(null).setJournalDirName(tmpDir.getPath())
.setAllowLoopback(true).setLedgerDirNames(new String[] { tmpDir.getPath() });
final String bkRegPath = conf.getZkAvailableBookiesPath() + "/"
+ InetAddress.getLocalHost().getHostAddress() + ":"
+ conf.getBookiePort();
MockBookie b = new MockBookie(conf);
b.zk = zkc;
b.testRegisterBookie(conf);
Stat bkRegNode1 = zkc.exists(bkRegPath, false);
Assert.assertNotNull("Bookie registration node doesn't exists!",
bkRegNode1);
// simulating bookie restart, on restart bookie will create new
// zkclient and doing the registration.
createNewZKClient();
b.zk = newzk;
// deleting the znode, so that the bookie registration should
// continue successfully on NodeDeleted event
new Thread() {
@Override
public void run() {
try {
Thread.sleep(conf.getZkTimeout() / 3);
zkc.delete(bkRegPath, -1);
} catch (Exception e) {
// Not handling, since the testRegisterBookie will fail
LOG.error("Failed to delete the znode :" + bkRegPath, e);
}