use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class BTreeReclaimTest method testSkipDupTree.
@Test
public void testSkipDupTree() {
/* int p;
int u; */
long rootAddress = initDup(/* p = */
10, /* u = */
100);
tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
final ByteIterable key = key(5);
final ILeafNode savedLeaf = getTree().getRoot().get(key);
Assert.assertNotNull(savedLeaf);
final long oldAddress = savedLeaf.getAddress();
tm.delete(key);
tm.delete(key(6));
getTreeMutable().put(key(6), value("v6#0"));
rootAddress = saveTree();
tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(oldAddress);
/* Loggable loggable = iter.next();
while (loggable.getType() != BTree.DUP_INTERNAL) {
loggable = iter.next();
}
Assert.assertTrue(loggable.getAddress() < savedLeaf.getAddress()); // some dup tree stored before our leaf */
Assert.assertTrue(tm.reclaim(iter.next(), iter));
final AddressIterator addressIterator = getTreeAddresses(getTree());
while (addressIterator.hasNext()) {
final long address = addressIterator.next();
isAffected(log.read(address), key, (BTreeTraverser) addressIterator.getTraverser());
RandomAccessLoggable loggable = log.read(address);
if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, key, BTreeTraverser.getTraverserNoDup(addressIterator))) {
assertAffected(getTreeMutable(), getTree(), loggable, key);
}
}
/* rootAddress = saveTree();
checkTree(tm = (t = new BTree(log, rootAddress, getTreeMutable().getBalancePolicy(), true, 1)).getMutableCopy(), p, u).run(); */
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class BTreeReclaimTest method testLeafSimpleRemove.
@Test
public void testLeafSimpleRemove() {
tm = new BTreeEmpty(log, createTestSplittingPolicy(), false, 1).getMutableCopy();
getTreeMutable().put(kv(0, "thing"));
getTreeMutable().put(kv(1, "nothing"));
getTreeMutable().put(kv(2, "something"));
getTreeMutable().put(kv(3, "jumping"));
getTreeMutable().put(kv(4, "dumping"));
getTreeMutable().put(kv(5, "rambling"));
getTreeMutable().put(kv(6, "plumbing"));
long rootAddress = saveTree();
t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1);
final ByteIterable key = key(0);
final ILeafNode savedLeaf = getTree().getRoot().get(key);
Assert.assertNotNull(savedLeaf);
final long savedLeafAddress = savedLeaf.getAddress();
tm = getTree().getMutableCopy();
tm.delete(key(1));
rootAddress = saveTree();
tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy();
final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeafAddress);
Assert.assertTrue(tm.reclaim(iter.next(), iter));
System.out.println(tm.getExpiredLoggables().getSize());
final AddressIterator addressIterator = getTreeAddresses(getTree());
while (addressIterator.hasNext()) {
final long address = addressIterator.next();
isAffected(log.read(address), key, (BTreeTraverser) addressIterator.getTraverser());
}
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class TreeCursorNoDuplicatesTest method testOrderedInserts.
@Test
public void testOrderedInserts() {
final ByteIterable value = value("value");
final TreeSet<String> keys = new TreeSet<>();
for (int i = 0; i < 10000; ++i) {
keys.add(rndString());
}
tm = createMutableTree(false, 1);
for (final String key : keys) {
Assert.assertTrue(tm.add(key(key), value));
}
testCursorOrder(keys);
tm = createMutableTree(false, 1);
for (final String key : keys.descendingSet()) {
Assert.assertTrue(tm.add(key(key), value));
}
testCursorOrder(keys);
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class TreeCursorNoDuplicatesTest method testInsertDeletes.
@Test
public void testInsertDeletes() {
final ByteIterable value = value("value");
final TreeSet<String> keys = new TreeSet<>();
tm = createMutableTree(false, 1);
for (int i = 0; i < 10000; ++i) {
final String key = rndString();
if (keys.add(key)) {
Assert.assertTrue(tm.add(key(key), value));
}
if (keys.size() > 1000) {
final String obsoleteKey = keys.first();
keys.remove(obsoleteKey);
Assert.assertTrue(tm.delete(key(obsoleteKey)));
}
}
testCursorOrder(keys);
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class EnvironmentTestsBase method assertNotNullStringValues.
protected void assertNotNullStringValues(final Store store, final String... values) {
env.executeInTransaction(txn -> {
try (Cursor cursor = store.openCursor(txn)) {
int i = 0;
while (cursor.getNext()) {
final ByteIterable valueEntry = cursor.getValue();
Assert.assertNotNull(valueEntry);
final String value = values[i++];
Assert.assertEquals(value, StringBinding.entryToString(valueEntry));
}
}
});
}
Aggregations