Search in sources :

Example 26 with Sized

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

Example 27 with Sized

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

Example 28 with Sized

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);
        }
    }
}
Also used : Sized(herddb.utils.Sized) Holder(herddb.utils.Holder) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Entry(java.util.Map.Entry) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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