use of herddb.utils.Sized 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);
/* 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.utils.Sized 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));
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.lookUpRange(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());
}
}
use of herddb.utils.Sized 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.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.utils.Sized in project herddb by diennea.
the class BlockRangeIndexTest method testSimpleSplitSameKey.
@Test
public void testSimpleSplitSameKey() {
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, new RandomPageReplacementPolicy(10));
index.put(Sized.valueOf(1), Sized.valueOf("a"));
index.put(Sized.valueOf(1), Sized.valueOf("b"));
index.put(Sized.valueOf(1), Sized.valueOf("c"));
dumpIndex(index);
List<Sized<String>> searchResult = index.search(Sized.valueOf(1));
System.out.println("searchResult:" + searchResult);
assertEquals(3, searchResult.size());
assertEquals(Sized.valueOf("a"), searchResult.get(0));
assertEquals(Sized.valueOf("b"), searchResult.get(1));
assertEquals(Sized.valueOf("c"), searchResult.get(2));
assertEquals(2, index.getNumBlocks());
}
use of herddb.utils.Sized 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.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());
}
Aggregations