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