// Create enough ledgers to span over 4 ranges in the hierarchical ledger manager implementation
final int numLedgers = 30001;
createLedgers(numLedgers, createdLedgers);
final GarbageCollector garbageCollector =
new ScanAndCompareGarbageCollector(getLedgerManager(), activeLedgers);
GarbageCollector.GarbageCleaner cleaner = new GarbageCollector.GarbageCleaner() {
@Override
public void clean(long ledgerId) {
LOG.info("Cleaned {}", ledgerId);
cleaned.add(ledgerId);
}
};
SortedSet<Long> scannedLedgers = new TreeSet<Long>();
LedgerRangeIterator iterator = getLedgerManager().getLedgerRanges();
while (iterator.hasNext()) {
LedgerRange ledgerRange = iterator.next();
scannedLedgers.addAll(ledgerRange.getLedgers());
}
assertEquals(createdLedgers, scannedLedgers);
garbageCollector.gc(cleaner);
assertTrue("Should have cleaned nothing", cleaned.isEmpty());
long first = createdLedgers.first();
removeLedger(first);
garbageCollector.gc(cleaner);
assertEquals("Should have cleaned something", 1, cleaned.size());
assertEquals("Should have cleaned first ledger" + first, (long)first, (long)cleaned.get(0));
}