use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testIterateNoLedgers.
@Test
public void testIterateNoLedgers() throws Exception {
LedgerManager lm = getLedgerManager();
LedgerRangeIterator lri = lm.getLedgerRanges();
assertNotNull(lri);
if (lri.hasNext()) {
lri.next();
}
assertEquals(false, lri.hasNext());
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testRemovalOfNodeJustTraversed.
@Test
public void testRemovalOfNodeJustTraversed() throws Throwable {
if (baseConf.getLedgerManagerFactoryClass() != LongHierarchicalLedgerManagerFactory.class) {
return;
}
LedgerManager lm = getLedgerManager();
/* For LHLM, first two should be leaves on the same node, second should be on adjacent level 4 node
* Removing all 3 once the iterator hits the first should result in the whole tree path ending
* at that node disappearing. If this happens after the iterator stops at that leaf, it should
* result in a few NodeExists errors (handled silently) as the iterator fails back up the tree
* to the next path.
*/
Set<Long> toRemove = new TreeSet<>(Arrays.asList(3394498498348983841L, 3394498498348983842L, 3394498498348993841L));
long first = 2345678901234567890L;
// Nodes which should be listed anyway
Set<Long> mustHave = new TreeSet<>(Arrays.asList(first, 6334994393848474732L));
Set<Long> ids = new TreeSet<>();
ids.addAll(toRemove);
ids.addAll(mustHave);
for (Long id : ids) {
createLedger(lm, id, Optional.of(BKException.Code.OK));
}
Set<Long> found = new TreeSet<>();
LedgerRangeIterator lri = lm.getLedgerRanges();
while (lri.hasNext()) {
LedgerManager.LedgerRange lr = lri.next();
found.addAll(lr.getLedgers());
if (lr.getLedgers().contains(first)) {
for (long id : toRemove) {
removeLedger(lm, id, Optional.of(BKException.Code.OK));
}
toRemove.clear();
}
}
for (long id : mustHave) {
assertTrue(found.contains(id));
}
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method testSeveralContiguousLedgers.
@Test
public void testSeveralContiguousLedgers() throws Throwable {
LedgerManager lm = getLedgerManager();
Set<Long> ids = new TreeSet<>();
for (long i = 0; i < 2000; ++i) {
createLedger(lm, i, Optional.of(BKException.Code.OK));
ids.add(i);
}
LedgerRangeIterator lri = lm.getLedgerRanges();
assertNotNull(lri);
Set<Long> returnedIds = ledgerRangeToSet(lri);
assertEquals(ids, returnedIds);
Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
assertEquals("Comparing LedgersIds read asynchronously", ids, ledgersReadAsync);
}
use of org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator in project bookkeeper by apache.
the class LedgerManagerIteratorTest method validateEmptyL4PathSkipped.
@Test
public void validateEmptyL4PathSkipped() throws Throwable {
if (baseConf.getLedgerManagerFactoryClass() != LongHierarchicalLedgerManagerFactory.class) {
return;
}
LedgerManager lm = getLedgerManager();
Set<Long> ids = new TreeSet<>(Arrays.asList(2345678901234567890L, 3394498498348983841L, 6334994393848474732L, 7349370101927398483L));
for (Long id : ids) {
createLedger(lm, id, Optional.of(BKException.Code.OK));
}
String[] paths = { // Empty L4 path, must be skipped
"/ledgers/633/4994/3938/4948" };
for (String path : paths) {
ZkUtils.createFullPathOptimistic(zkc, path, "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
LedgerRangeIterator lri = lm.getLedgerRanges();
assertNotNull(lri);
Set<Long> returnedIds = ledgerRangeToSet(lri);
assertEquals(ids, returnedIds);
Set<Long> ledgersReadAsync = getLedgerIdsByUsingAsyncProcessLedgers(lm);
assertEquals("Comparing LedgersIds read asynchronously", ids, ledgersReadAsync);
lri = lm.getLedgerRanges();
int emptyRanges = 0;
while (lri.hasNext()) {
if (lri.next().getLedgers().isEmpty()) {
emptyRanges++;
}
}
assertEquals(0, emptyRanges);
}
Aggregations