use of org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback in project pulsar by yahoo.
the class ManagedLedgerTest method cursorReadsWithDiscardedEmptyLedgersStillListed.
@Test
public void cursorReadsWithDiscardedEmptyLedgersStillListed() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("entry-1".getBytes());
ledger.close();
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
ledger.addEntry("entry-2".getBytes());
final LedgerInfo l1info = ledger.getLedgersInfoAsList().get(0);
final LedgerInfo l2info = ledger.getLedgersInfoAsList().get(1);
ledger.close();
// Add the deleted ledger back in the meta-data to simulate an empty ledger that was deleted but not removed
// from the list of ledgers
final CountDownLatch counter = new CountDownLatch(1);
final MetaStore store = factory.getMetaStore();
store.getManagedLedgerInfo("my_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {
@Override
public void operationComplete(ManagedLedgerInfo result, Stat version) {
// Update the list
ManagedLedgerInfo.Builder info = ManagedLedgerInfo.newBuilder(result);
info.clearLedgerInfo();
info.addLedgerInfo(LedgerInfo.newBuilder().setLedgerId(l1info.getLedgerId()).build());
info.addLedgerInfo(l2info);
store.asyncUpdateLedgerIds("my_test_ledger", info.build(), version, new MetaStoreCallback<Void>() {
@Override
public void operationComplete(Void result, Stat version) {
counter.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
counter.countDown();
}
});
}
@Override
public void operationFailed(MetaStoreException e) {
counter.countDown();
}
});
// Wait for the change to be effective
counter.await();
// Delete the ledger and mantain it in the ledgers list
bkc.deleteLedger(l1info.getLedgerId());
// re-open
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
assertEquals(c1.getNumberOfEntries(), 1);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(ledger.getLedgersInfoAsList().size(), 2);
List<Entry> entries = c1.readEntries(10);
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
assertEquals(c1.hasMoreEntries(), false);
entries = c1.readEntries(1);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
}
Aggregations