Search in sources :

Example 16 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method testGetSearchBothRange2.

@Test
public void testGetSearchBothRange2() throws IOException {
    tm = getTreeMutable().getMutableCopy();
    getTreeMutable().put(key("10"), value("v10"));
    getTreeMutable().put(key("20"), value("v20"));
    getTreeMutable().put(key("30"), value("v30"));
    getTreeMutable().put(key("40"), value("v40"));
    getTreeMutable().put(key("50"), value("v50"));
    getTreeMutable().put(key("60"), value("v60"));
    Cursor c = getTreeMutable().openCursor();
    // miss
    assertEquals(null, c.getSearchBothRange(key("01"), value("v10")));
    // found
    assertEquals(value("v10"), c.getSearchBothRange(key("10"), value("v01")));
    // miss
    assertEquals(null, c.getSearchBothRange(key("20"), value("v21")));
    // check keep prev state
    assertEquals(key("10"), c.getKey());
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 17 with Cursor

use of jetbrains.exodus.env.Cursor 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 18 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class BTreeCursorDeleteTest method testDeleteCursorNoDuplicates1.

@Test
public void testDeleteCursorNoDuplicates1() throws IOException {
    tm = createMutableTree(false, 1);
    getTreeMutable().put(kv(1, "1"));
    Cursor c = tm.openCursor();
    assertTrue(c.getNext());
    assertTrue(c.deleteCurrent());
    assertFalse(c.deleteCurrent());
    assertFalse(c.getNext());
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 19 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class BTreeCursorDeleteTest method testDeleteCursorDuplicates1.

@Test
public void testDeleteCursorDuplicates1() throws IOException {
    tm = createMutableTree(true, 1);
    getTreeMutable().put(kv(1, "11"));
    getTreeMutable().put(kv(1, "12"));
    assertTrue(getTreeMutable().getRoot() instanceof BottomPageMutable);
    assertEquals(1, getTreeMutable().getRoot().getSize());
    assertTrue(getTreeMutable().getRoot().getKey(0) instanceof LeafNodeDupMutable);
    assertEquals(2, getTreeMutable().getRoot().getKey(0).getDupCount());
    Cursor c = getTreeMutable().openCursor();
    assertTrue(c.getNext());
    assertTrue(c.deleteCurrent());
    assertFalse(c.deleteCurrent());
    assertTrue(getTreeMutable().getRoot() instanceof BottomPageMutable);
    assertEquals(1, getTreeMutable().getRoot().getSize());
    assertTrue(getTreeMutable().getRoot().getKey(0) instanceof LeafNodeMutable);
    assertTrue(c.getNext());
    assertTrue(c.deleteCurrent());
    assertFalse(c.deleteCurrent());
    assertFalse(c.getNext());
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 20 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class VFSBlobVault method loadAllBlobs.

@NotNull
private static LongSet loadAllBlobs(@NotNull final PersistentEntityStoreImpl store, @NotNull final PersistentStoreTransaction txn) {
    final LongSet result = new PackedLongHashSet();
    final Transaction envTxn = txn.getEnvironmentTransaction();
    try (Cursor entityTypesCursor = store.getEntityTypesTable().getSecondIndexCursor(envTxn)) {
        while (entityTypesCursor.getNext()) {
            final int entityTypeId = IntegerBinding.compressedEntryToInt(entityTypesCursor.getKey());
            final BlobsTable blobs = store.getBlobsTable(txn, entityTypeId);
            final Store primary = blobs.getPrimaryIndex();
            try (Cursor blobsCursor = primary.openCursor(envTxn)) {
                while (blobsCursor.getNext()) {
                    final long blobId = LongBinding.compressedEntryToLong(blobsCursor.getValue());
                    result.add(blobId);
                }
            }
        }
        return result;
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) BlobsTable(jetbrains.exodus.entitystore.tables.BlobsTable) Store(jetbrains.exodus.env.Store) Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Cursor (jetbrains.exodus.env.Cursor)57 Test (org.junit.Test)46 ByteIterable (jetbrains.exodus.ByteIterable)7 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)6 NotNull (org.jetbrains.annotations.NotNull)4 Store (jetbrains.exodus.env.Store)3 Transaction (jetbrains.exodus.env.Transaction)3 File (java.io.File)2 TestFor (jetbrains.exodus.TestFor)2 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ComparableBinding (jetbrains.exodus.bindings.ComparableBinding)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 BlobsTable (jetbrains.exodus.entitystore.tables.BlobsTable)1 PropertyValue (jetbrains.exodus.entitystore.tables.PropertyValue)1 TreeCursorNoDuplicatesTest (jetbrains.exodus.tree.TreeCursorNoDuplicatesTest)1