Search in sources :

Example 11 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method xd_333.

@Test
public void xd_333() throws IOException {
    rnd = new Random(0);
    final ByteIterable value = value("value");
    tm = createMutableTree(false, 1);
    final TreeSet<String> keys = new TreeSet<>();
    for (int i = 0; i < 15; ++i) {
        final String key = rndString();
        tm.put(key(key), value);
        keys.add(key);
    }
    /*final long address = saveTree();
        reopen();
        final ITree t = openTree(address, false);*/
    testCursorOrder(keys);
}
Also used : Random(jetbrains.exodus.util.Random) TreeSet(java.util.TreeSet) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Test(org.junit.Test)

Example 12 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method testInsertDeletes2.

@Test
public void testInsertDeletes2() {
    final ByteIterable value = value("value");
    final Set<String> keys = new HashSet<>();
    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.iterator().next();
            keys.remove(obsoleteKey);
            Assert.assertTrue(tm.delete(key(obsoleteKey)));
        }
    }
    testCursorOrder(new TreeSet<>(keys));
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet) Test(org.junit.Test)

Example 13 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method testGetSearchKeyRange4.

@Test
public void testGetSearchKeyRange4() throws IOException {
    tm = createMutableTree(false, 1);
    final ByteIterable v = value("0");
    tm.put(key("aaaa"), v);
    tm.put(key("aaab"), v);
    tm.put(key("aaba"), v);
    Cursor c = tm.openCursor();
    c.getSearchKeyRange(key("aaac"));
    assertEquals(key("aaba"), c.getKey());
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 14 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method failingGetNextAndGetPrevDontInvalidateKeyValue2.

@Test
@TestFor(issues = "XD-619")
public void failingGetNextAndGetPrevDontInvalidateKeyValue2() {
    tm = createMutableTree(false, 1);
    final int treeSize = 10000;
    for (int i = 0; i < treeSize; ++i) {
        tm.put(kv(i, Integer.toString(i)));
    }
    try (Cursor cursor = tm.openCursor()) {
        ByteIterable key = null;
        while (cursor.getNext()) {
            key = cursor.getKey();
        }
        Assert.assertEquals(key(treeSize - 1), key);
        Assert.assertEquals(key(treeSize - 1), cursor.getKey());
        cursor.getNext();
        cursor.getNext();
        Assert.assertEquals(key(treeSize - 1), cursor.getKey());
        cursor.getPrev();
        Assert.assertEquals(key(treeSize - 2), cursor.getKey());
    }
    try (Cursor cursor = tm.openCursor()) {
        ByteIterable key = null;
        while (cursor.getPrev()) {
            key = cursor.getKey();
        }
        Assert.assertEquals(key(0), key);
        Assert.assertEquals(key(0), cursor.getKey());
        cursor.getPrev();
        cursor.getPrev();
        Assert.assertEquals(key(0), cursor.getKey());
        cursor.getNext();
        Assert.assertEquals(key(1), cursor.getKey());
    }
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test) TestFor(jetbrains.exodus.TestFor)

Example 15 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreePutTest method testPutRight3.

@Test
public void testPutRight3() {
    tm = createMutableTree(false, 1);
    final int count = 10000;
    for (int i = 0; i < count; ++i) {
        tm.putRight(IntegerBinding.intToCompressedEntry(i), IntegerBinding.intToCompressedEntry(i));
        if (i % 32 == 0) {
            final long address = saveTree();
            tm = openTree(address, false).getMutableCopy();
        }
    }
    final long address = saveTree();
    tm = openTree(address, false).getMutableCopy();
    final ITreeCursor cursor = tm.openCursor();
    for (int i = 0; i < count; ++i) {
        Assert.assertTrue(cursor.getNext());
        final ByteIterable key = cursor.getKey();
        final ByteIterable value = cursor.getValue();
        Assert.assertTrue(key.compareTo(value) == 0);
        Assert.assertEquals(i, IntegerBinding.readCompressed(key.iterator()));
    }
    cursor.close();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Aggregations

ByteIterable (jetbrains.exodus.ByteIterable)86 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)45 Test (org.junit.Test)26 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)15 Nullable (org.jetbrains.annotations.Nullable)11 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)8 Cursor (jetbrains.exodus.env.Cursor)7 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)7 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)6 Store (jetbrains.exodus.env.Store)4 TreeSet (java.util.TreeSet)3 Transaction (jetbrains.exodus.env.Transaction)3 Exchange (com.persistit.Exchange)2 ExodusException (jetbrains.exodus.ExodusException)2 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)2 Pair (jetbrains.exodus.core.dataStructures.Pair)2 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)2 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)2 PersistentStoreTransaction (jetbrains.exodus.entitystore.PersistentStoreTransaction)2 Loggable (jetbrains.exodus.log.Loggable)2