@Test(timeout = 60000)
public void testWatchMetadataRemoval() throws Exception {
LedgerManagerFactory factory = ReflectionUtils.newInstance(lmFactoryCls);
factory.initialize(baseConf, super.zkc, factory.getCurrentVersion());
LedgerManager manager = factory.newLedgerManager();
final ByteBuffer bbLedgerId = ByteBuffer.allocate(8);
final CountDownLatch createLatch = new CountDownLatch(1);
final CountDownLatch removeLatch = new CountDownLatch(1);
manager.createLedger( new LedgerMetadata(4, 2, 2, digestType, "fpj was here".getBytes()),
new BookkeeperInternalCallbacks.GenericCallback<Long>(){
@Override
public void operationComplete(int rc, Long result) {
bbLedgerId.putLong(result);
bbLedgerId.flip();
createLatch.countDown();
}
});
assertTrue(createLatch.await(2000, TimeUnit.MILLISECONDS));
final long createdLid = bbLedgerId.getLong();
manager.registerLedgerMetadataListener( createdLid,
new LedgerMetadataListener() {
@Override
public void onChanged( long ledgerId, LedgerMetadata metadata ) {
assertEquals(ledgerId, createdLid);
assertEquals(metadata, null);
removeLatch.countDown();
}
});
manager.removeLedgerMetadata( createdLid, Version.ANY,
new BookkeeperInternalCallbacks.GenericCallback<Void>() {
@Override
public void operationComplete(int rc, Void result) {
assertEquals(rc, BKException.Code.OK);