Search in sources :

Example 1 with INode

use of jetbrains.exodus.tree.INode in project xodus by JetBrains.

the class BTreeDeleteSpecificTest method testDeleteNoDuplicatesBottomPage.

@Test
public void testDeleteNoDuplicatesBottomPage() throws IOException {
    tm = new BTreeEmpty(log, new BTreeBalancePolicy(16), false, 1).getMutableCopy();
    List<INode> res = new ArrayList<>();
    for (int i = 0; i < 64; i++) {
        final INode ln = kv(i, "v" + i);
        getTreeMutable().put(ln);
        res.add(ln);
    }
    dump(getTreeMutable());
    long a = saveTree();
    tm = new BTree(log, new BTreeBalancePolicy(16), a, false, 1).getMutableCopy();
    for (int i = 0; i < 64; i++) {
        tm.delete(key(i));
        res.remove(0);
        dump(getTreeMutable());
        assertMatchesIterator(tm, res);
    }
}
Also used : INode(jetbrains.exodus.tree.INode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with INode

use of jetbrains.exodus.tree.INode in project xodus by JetBrains.

the class BTreeDuplicatesExpiredAddressesTest method testDeleteSingleNoConvert.

@Test
public void testDeleteSingleNoConvert() throws IOException {
    tm = new BTreeEmpty(log, true, 1).getMutableCopy();
    getTreeMutable().put(kv(0, "value"));
    getTreeMutable().put(kv(0, "value2"));
    INode leafNode = kv(0, "value3");
    getTreeMutable().put(leafNode);
    // Expired: none
    checkExpiredAddress(tm, 0);
    long address = saveTree();
    t = new BTree(log, address, true, 1);
    tm = getTree().getMutableCopy();
    getTreeMutable().delete(leafNode.getKey(), leafNode.getValue());
    // Expired: root, dupTree, value3
    checkExpiredAddress(tm, 3);
    saveTree();
}
Also used : INode(jetbrains.exodus.tree.INode) Test(org.junit.Test)

Example 3 with INode

use of jetbrains.exodus.tree.INode in project xodus by JetBrains.

the class BTreeDuplicatesExpiredAddressesTest method testBulkDeleteByKey.

@Test
public void testBulkDeleteByKey() throws IOException {
    tm = new BTreeEmpty(log, createTestSplittingPolicy(), true, 1).getMutableCopy();
    ByteIterable[] keys = new ByteIterable[1000];
    for (int i = 0; i < 1000; i++) {
        INode node = kv(i, "value");
        getTreeMutable().put(node);
        getTreeMutable().put(kv(i, "value2"));
        getTreeMutable().put(kv(i, "value3"));
        getTreeMutable().put(kv(i, "value4"));
        getTreeMutable().put(kv(i, "value5"));
        getTreeMutable().put(kv(i, "value6"));
        getTreeMutable().put(kv(i, "value7"));
        getTreeMutable().put(kv(i, "value8"));
        keys[i] = node.getKey();
    }
    // Expired: none
    checkExpiredAddress(tm, 0);
    long address = saveTree();
    t = new BTree(log, address, true, 1);
    tm = getTree().getMutableCopy();
    long addresses = countNodes(getTreeMutable());
    for (int i = 0; i < 1000; i++) {
        tm.delete(keys[i]);
    }
    checkExpiredAddress(tm, addresses);
    saveTree();
}
Also used : INode(jetbrains.exodus.tree.INode) ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Example 4 with INode

use of jetbrains.exodus.tree.INode in project xodus by JetBrains.

the class BTreeDuplicatesExpiredAddressesTest method testBulkDeleteByKV.

@Test
public void testBulkDeleteByKV() throws IOException {
    tm = new BTreeEmpty(log, createTestSplittingPolicy(), true, 1).getMutableCopy();
    List<INode> leaves = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        INode[] nodes = new INode[5];
        nodes[0] = kv(i, "value");
        nodes[1] = kv(i, "value2");
        nodes[2] = kv(i, "value3");
        nodes[3] = kv(i, "value4");
        nodes[4] = kv(i, "value5");
        for (INode iLeafNode : nodes) {
            getTreeMutable().put(iLeafNode);
            leaves.add(iLeafNode);
        }
    }
    // Expired: none
    checkExpiredAddress(tm, 0);
    long address = saveTree();
    t = new BTree(log, address, true, 1);
    tm = getTree().getMutableCopy();
    long addresses = countNodes(getTreeMutable());
    for (INode leafNode : leaves) {
        getTreeMutable().delete(leafNode.getKey(), leafNode.getValue());
    }
    checkExpiredAddress(tm, addresses);
    saveTree();
}
Also used : INode(jetbrains.exodus.tree.INode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with INode

use of jetbrains.exodus.tree.INode in project xodus by JetBrains.

the class BTreeSimpleTest method testPutSaveGet.

@Test
public void testPutSaveGet() throws IOException {
    // put
    tm = new BTreeEmpty(log, false, 1).getMutableCopy();
    final INode ln1 = kv("1", "vadim");
    getTreeMutable().put(ln1);
    assertEquals(1, tm.getSize());
    assertEquals(true, tm.hasKey(key("1")));
    assertEquals(true, tm.hasPair(key("1"), value("vadim")));
    assertTrue(getTreeMutable().getRoot() instanceof BottomPageMutable);
    BottomPageMutable bpm = (BottomPageMutable) getTreeMutable().getRoot();
    assertEquals(1, bpm.size);
    assertEquals(ln1, bpm.keys[0]);
    assertEquals(Loggable.NULL_ADDRESS, bpm.keysAddresses[0]);
    assertMatchesIterator(tm, ln1);
    valueEquals("vadim", tm.get(key("1")));
    // save
    long newRootAddress = saveTree();
    valueEquals("vadim", tm.get(key("1")));
    // get
    t = new BTree(log, newRootAddress, false, 1);
    TreeAwareRunnable r = new TreeAwareRunnable() {

        @Override
        public void run() {
            assertEquals(1, t.getSize());
            assertEquals(true, tm.hasKey(key("1")));
            assertEquals(true, tm.hasPair(key("1"), value("vadim")));
            assertTrue(getTree().getRoot() instanceof BottomPage);
            BottomPage bp = (BottomPage) getTree().getRoot();
            assertEquals(1, bp.size);
            assertTrue(bp.getKeyAddress(0) != Loggable.NULL_ADDRESS);
            assertEquals(ln1, bp.get(key("1")));
            valueEquals("vadim", t.get(key("1")));
        }
    };
    r.run();
    // get after log reopen
    reopen();
    t = new BTree(log, newRootAddress, false, 1);
    r.run();
}
Also used : INode(jetbrains.exodus.tree.INode) Test(org.junit.Test)

Aggregations

INode (jetbrains.exodus.tree.INode)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)6 ByteIterable (jetbrains.exodus.ByteIterable)1