use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexTest method testRemoveHead.
@Test
public void testRemoveHead() {
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
index.boot(BlockRangeIndexMetadata.empty());
index.boot(BlockRangeIndexMetadata.empty());
index.put(Sized.valueOf(1), Sized.valueOf("a"));
index.delete(Sized.valueOf(1), Sized.valueOf("a"));
List<Sized<String>> searchResult = index.search(Sized.valueOf(1));
assertTrue(searchResult.isEmpty());
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexStorageTest method testUnload.
@Test
public void testUnload() throws Exception {
PageReplacementPolicy policy = new RandomPageReplacementPolicy(10);
IndexDataStorage<Sized<Integer>, Sized<String>> storage = new MemoryIndexDataStorage<>();
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, policy, storage);
index.boot(BlockRangeIndexMetadata.empty());
for (int i = 0; i < 100; i++) {
index.put(Sized.valueOf(i), Sized.valueOf("a"));
}
BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint();
assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size());
for (int i = 0; i < 100; i++) {
assertEquals(Sized.valueOf("a"), index.search(Sized.valueOf(i)).get(0));
}
assertEquals(10, policy.size());
index.clear();
/* No pages should remain in memory after unload!! */
assertEquals(0, policy.size());
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BlockRangeIndexStorageTest method testNextBlockIdAfterReload.
@Test
public void testNextBlockIdAfterReload() throws Exception {
PageReplacementPolicy policy = new RandomPageReplacementPolicy(10);
IndexDataStorage<Sized<Integer>, Sized<Integer>> storage = new MemoryIndexDataStorage<>();
BlockRangeIndex<Sized<Integer>, Sized<Integer>> index = new BlockRangeIndex<>(1024, policy, storage);
index.boot(BlockRangeIndexMetadata.empty());
Sized<Integer> data = Sized.valueOf(1);
while (index.getNumBlocks() < 2) {
index.put(data, data);
}
/* Ensure that the second block has a negative blockId (so we have both positive and negative blockIds) */
assertTrue(index.getBlocks().lastEntry().getKey().blockId < 0);
BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint();
assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size());
BlockRangeIndex<Sized<Integer>, Sized<Integer>> indexAfterBoot = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10), storage);
indexAfterBoot.boot(metadata);
/* Ensure that current block id is correct even if was generated a negative blockId */
assertEquals(index.getCurrentBlockId(), indexAfterBoot.getCurrentBlockId());
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BLinkTest method testScanAndSplit.
@Test
public void testScanAndSplit() throws Exception {
long splitAt;
try (BLink<Sized<Long>, Long> blink = new BLink<>(1024L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), new DummyBLinkIndexDataStorage<>())) {
long l = 0;
while (blink.nodes() < 2) {
blink.insert(Sized.valueOf(l), l);
l++;
}
splitAt = l - 1;
}
try (BLink<Sized<Long>, Long> blink = new BLink<>(1024L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), new DummyBLinkIndexDataStorage<>())) {
long l = 0;
while (l < splitAt) {
System.out.println("insert " + l);
blink.insert(Sized.valueOf(l), l);
l++;
}
Stream<Entry<Sized<Long>, Long>> s = blink.scan(Sized.valueOf(0L), null);
long keyStream;
Iterator<Entry<Sized<Long>, Long>> i = s.iterator();
do {
keyStream = i.next().getValue();
System.out.println("read " + keyStream);
} while (keyStream < splitAt - 4);
System.out.println("insert " + splitAt);
blink.insert(Sized.valueOf(splitAt), splitAt);
while (i.hasNext()) {
long nowStream = i.next().getValue();
if (nowStream < keyStream) {
Assert.fail("Unordered!");
}
keyStream = nowStream;
System.out.println("read " + keyStream);
}
}
}
use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.
the class BLinkTest method testScanHeadNotExistent.
@Test
public void testScanHeadNotExistent() throws Exception {
BLinkIndexDataStorage<Sized<Long>, Long> storage = new DummyBLinkIndexDataStorage<>();
try (BLink<Sized<Long>, Long> blink = new BLink<>(2048L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), storage)) {
final long headNonExistent = 100;
final long inserts = 100;
for (long l = headNonExistent; l < inserts + headNonExistent; l++) {
blink.insert(Sized.valueOf(l), l);
}
BLinkMetadata<Sized<Long>> metadata = blink.checkpoint();
/* Require at least two nodes! */
assertNotEquals(1, metadata.nodes.size());
long offset = 10;
for (long l = 0; l < headNonExistent - offset; l++) {
Stream<Entry<Sized<Long>, Long>> stream = blink.scan(Sized.valueOf(l), Sized.valueOf(l + offset));
Holder<Long> h = new Holder<>(l);
Holder<Long> count = new Holder<>(0L);
StringBuilder builder = new StringBuilder();
/* Check each value */
stream.forEach(entry -> {
assertEquals(h.value, entry.getValue());
h.value++;
count.value++;
builder.append(entry.getValue()).append(", ");
});
assertEquals(0, (long) count.value);
}
}
}
Aggregations