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());
}
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());
}
}
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());
}
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());
}
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;
}
}
Aggregations