use of herddb.utils.Sized in project herddb by diennea.
the class BLinkTest method testCheckpointAndRestore.
@Test
public void testCheckpointAndRestore() throws Exception {
String[] data = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
BLinkIndexDataStorage<Sized<String>, Long> storage = new DummyBLinkIndexDataStorage<>();
BLinkMetadata<Sized<String>> metadata;
try (BLink<Sized<String>, Long> blink = new BLink<>(2048L, new StringSizeEvaluator(), new RandomPageReplacementPolicy(3), storage)) {
for (int i = 0; i < data.length; ++i) {
blink.insert(Sized.valueOf(data[i]), i + 1L);
}
assertEquals(data.length, blink.size());
metadata = blink.checkpoint();
}
try (BLink<Sized<String>, Long> blinkFromMeta = new BLink<>(2048L, new StringSizeEvaluator(), new RandomPageReplacementPolicy(3), storage, metadata)) {
/* Require at least two nodes! */
assertNotEquals(1, metadata.nodes.size());
for (int i = 0; i < data.length; ++i) {
assertEquals(i + 1L, (long) blinkFromMeta.search(Sized.valueOf(data[i])));
}
assertEquals(data.length, blinkFromMeta.size());
}
}
use of herddb.utils.Sized in project herddb by diennea.
the class BLinkTest method testDelete.
@Test
public void testDelete() throws Exception {
final long inserts = 100000;
BLinkIndexDataStorage<Sized<Long>, Long> storage = new DummyBLinkIndexDataStorage<>();
try (BLink<Sized<Long>, Long> blink = new BLink<>(2048L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), storage)) {
for (long l = 0; l < inserts; l++) {
blink.insert(Sized.valueOf(l), l);
}
BLinkMetadata<Sized<Long>> metadata = blink.checkpoint();
/* Require at least two nodes! */
assertNotEquals(1, metadata.nodes.size());
for (long l = 0; l < inserts; l++) {
assertEquals(l, (long) blink.delete(Sized.valueOf(l)));
}
for (long l = 0; l < inserts; l++) {
assertEquals(null, blink.search(Sized.valueOf(l)));
}
}
}
use of herddb.utils.Sized in project herddb by diennea.
the class BLinkTest method testScan.
@Test
public void testScan() 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 inserts = 100;
for (long l = 0; l < inserts; 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 < inserts - 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(", ");
});
builder.setLength(builder.length() - 2);
System.out.println("start " + l + " end " + (l + offset) + " -> " + builder);
assertEquals(offset, (long) count.value);
}
}
}
Aggregations