use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexTest method testDelete.
@Test
public void testDelete() {
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
index.boot(BlockRangeIndexMetadata.empty());
index.put(Sized.valueOf(3), Sized.valueOf("c"));
index.put(Sized.valueOf(2), Sized.valueOf("b"));
index.put(Sized.valueOf(1), Sized.valueOf("a"));
index.delete(Sized.valueOf(1), Sized.valueOf("a"));
assertTrue(index.search(Sized.valueOf(1)).isEmpty());
assertEquals(Sized.valueOf("b"), index.search(Sized.valueOf(2)).get(0));
assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
index.delete(Sized.valueOf(2), Sized.valueOf("b"));
assertTrue(index.search(Sized.valueOf(2)).isEmpty());
assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
index.delete(Sized.valueOf(3), Sized.valueOf("c"));
assertTrue(index.search(Sized.valueOf(3)).isEmpty());
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexTest method testDeleteAndUnload.
/**
* Verify that deleted entries stay deleted ever after a page unload
*
* @author diego.salvi
*/
@Test
public void testDeleteAndUnload() throws IOException {
/* Must be 1 to keep just one page in memory keeping to unload on every page load */
final PageReplacementPolicy policy = new RandomPageReplacementPolicy(1);
final IndexDataStorage<Sized<Integer>, Sized<String>> storage = new MemoryIndexDataStorage<>();
final BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, policy, storage);
index.boot(BlockRangeIndexMetadata.empty());
/* Add values until block split */
int elements;
for (elements = 0; index.getNumBlocks() < 2; elements++) {
index.put(Sized.valueOf(elements), Sized.valueOf("test_" + elements));
}
/* NumBlocks must be greater than 1 to permit unloading */
Assert.assertTrue(index.getNumBlocks() > 1);
/* Check every value existance */
for (int i = 0; i < elements; i++) {
List<Sized<String>> result = index.search(Sized.valueOf(i));
Assert.assertEquals(1, result.size());
}
/* Remove every value */
for (int i = 0; i < elements; i++) {
index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
}
/* Check every value non existance */
for (int i = 0; i < elements; i++) {
List<Sized<String>> result = index.search(Sized.valueOf(i));
Assert.assertEquals(0, result.size());
}
index.clear();
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexBench method testHuge.
@Test
public void testHuge() {
final int testSize = 1_000_000;
final int tenPerc = testSize / 10;
long _start = System.currentTimeMillis();
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(10000, new RandomPageReplacementPolicy(10000));
index.boot(BlockRangeIndexMetadata.empty());
for (int i = 0; i < testSize; i++) {
index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
if (i % tenPerc == 0) {
System.out.println("insert : " + (1 + i / tenPerc) * 10 + "%: " + i);
}
}
long _stop = System.currentTimeMillis();
System.out.println("time w: " + (_stop - _start));
System.out.println("num segments: " + index.getNumBlocks());
for (int i = 0; i < testSize; i++) {
List<Sized<String>> s = index.search(Sized.valueOf(i));
Assert.assertEquals(1, s.size());
Assert.assertEquals("test_" + i, s.get(0).dummy);
if (i % tenPerc == 0) {
System.out.println("search : " + (1 + i / tenPerc) * 10 + "%: " + i);
}
}
_start = _stop;
_stop = System.currentTimeMillis();
System.out.println("time r: " + (_stop - _start));
index.clear();
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexTest method testSimpleSplitInverse.
@Test
public void testSimpleSplitInverse() {
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, new RandomPageReplacementPolicy(10));
index.boot(BlockRangeIndexMetadata.empty());
index.put(Sized.valueOf(3), Sized.valueOf("c"));
index.put(Sized.valueOf(2), Sized.valueOf("b"));
index.put(Sized.valueOf(1), Sized.valueOf("a"));
dumpIndex(index);
assertEquals(Sized.valueOf("a"), index.search(Sized.valueOf(1)).get(0));
assertEquals(Sized.valueOf("b"), index.search(Sized.valueOf(2)).get(0));
assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
assertEquals(2, index.getNumBlocks());
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexTest method testMultiple.
@Test
public void testMultiple() {
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
index.boot(BlockRangeIndexMetadata.empty());
for (int i = 0; i < 10; i++) {
index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
}
for (int i = 0; i < 10; i++) {
List<Sized<String>> result = index.search(Sized.valueOf(i));
assertEquals(1, result.size());
assertEquals(Sized.valueOf("test_" + i), result.get(0));
}
for (int i = 0; i < 10; i++) {
index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
}
for (int i = 0; i < 10; i++) {
if (i == 6) {
System.out.println("QUI");
}
List<Sized<String>> result = index.search(Sized.valueOf(i));
System.out.println("result for " + i + " :" + result);
assertEquals(2, result.size());
assertEquals(Sized.valueOf("test_" + i), result.get(0));
assertEquals(Sized.valueOf("test_" + i), result.get(1));
}
List<Sized<String>> range = index.search(Sized.valueOf(3), Sized.valueOf(5));
assertEquals(6, range.size());
for (int i = 0; i < 10; i++) {
index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
}
for (int i = 0; i < 10; i++) {
List<Sized<String>> result = index.search(Sized.valueOf(i));
assertEquals(0, result.size());
}
}
Aggregations