Search in sources :

Example 6 with Sized

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();
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) PageReplacementPolicy(herddb.core.PageReplacementPolicy) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 7 with Sized

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());
    }
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 8 with Sized

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());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 9 with Sized

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());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 10 with Sized

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());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Aggregations

Sized (herddb.utils.Sized)28 RandomPageReplacementPolicy (herddb.core.RandomPageReplacementPolicy)26 Test (org.junit.Test)26 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 Holder (herddb.utils.Holder)5 Entry (java.util.Map.Entry)5 PageReplacementPolicy (herddb.core.PageReplacementPolicy)4 ExecutorService (java.util.concurrent.ExecutorService)4 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Map (java.util.Map)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 ClockProPolicy (herddb.core.ClockProPolicy)1 Block (herddb.index.brin.BlockRangeIndex.Block)1 RandomString (herddb.utils.RandomString)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Future (java.util.concurrent.Future)1