Search in sources :

Example 1 with LongTreeSet

use of io.questdb.griffin.engine.table.LongTreeSet in project questdb by bluestreak01.

the class LongTreeSetTest method testSimple.

@Test
public void testSimple() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (LongTreeSet set = new LongTreeSet(1024 * 1024, 1)) {
            doTestSimple(set);
            set.clear();
            doTestSimple(set);
        }
    });
}
Also used : LongTreeSet(io.questdb.griffin.engine.table.LongTreeSet) Test(org.junit.Test)

Example 2 with LongTreeSet

use of io.questdb.griffin.engine.table.LongTreeSet in project questdb by bluestreak01.

the class LongTreeSetTest method doTestSimple.

private void doTestSimple(LongTreeSet set) {
    Rnd rnd = new Rnd();
    LongList ll = new LongList();
    int n = 10000;
    for (int i = 0; i < n; i++) {
        long l = rnd.nextLong();
        set.put(l);
        ll.add(l);
    }
    ll.sort();
    int i = 0;
    LongTreeSet.TreeCursor cursor = set.getCursor();
    while (cursor.hasNext()) {
        long l = cursor.next();
        Assert.assertEquals(ll.getQuick(i++), l);
    }
    Assert.assertEquals(n, i);
    cursor.toTop();
    i = 0;
    while (cursor.hasNext()) {
        long l = cursor.next();
        Assert.assertEquals(ll.getQuick(i++), l);
    }
}
Also used : LongTreeSet(io.questdb.griffin.engine.table.LongTreeSet) Rnd(io.questdb.std.Rnd) LongList(io.questdb.std.LongList)

Example 3 with LongTreeSet

use of io.questdb.griffin.engine.table.LongTreeSet in project questdb by bluestreak01.

the class CairoEngineTest method testNextTableId.

@Test
public void testNextTableId() {
    try (CairoEngine engine = new CairoEngine(configuration);
        CairoEngine engineB = new CairoEngine(configuration)) {
        final LongList listA = new LongList();
        final LongList listB = new LongList();
        final CyclicBarrier startBarrier = new CyclicBarrier(2);
        final SOCountDownLatch haltLatch = new SOCountDownLatch();
        haltLatch.setCount(1);
        final AtomicInteger errors = new AtomicInteger();
        new Thread(() -> {
            try {
                startBarrier.await();
                for (int i = 0; i < 100; i++) {
                    listA.add(engine.getNextTableId());
                }
                haltLatch.countDown();
            } catch (InterruptedException | BrokenBarrierException e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }).start();
        try {
            startBarrier.await();
            for (int i = 0; i < 100; i++) {
                listB.add(engineB.getNextTableId());
            }
        } catch (InterruptedException | BrokenBarrierException e) {
            e.printStackTrace();
            errors.incrementAndGet();
        }
        haltLatch.await();
        try (LongTreeSet set = new LongTreeSet(4 * 2048, Integer.MAX_VALUE)) {
            // add both arrays to the set and asset that there are no duplicates
            for (int i = 0, n = listA.size(); i < n; i++) {
                Assert.assertTrue(set.put(listA.getQuick(i)));
            }
            for (int i = 0, n = listB.size(); i < n; i++) {
                Assert.assertTrue(set.put(listB.getQuick(i)));
            }
        }
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongTreeSet(io.questdb.griffin.engine.table.LongTreeSet) LongList(io.questdb.std.LongList) CyclicBarrier(java.util.concurrent.CyclicBarrier) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) Test(org.junit.Test)

Example 4 with LongTreeSet

use of io.questdb.griffin.engine.table.LongTreeSet in project questdb by bluestreak01.

the class LongTreeSetTest method testDuplicateValues.

@Test
public void testDuplicateValues() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (LongTreeSet set = new LongTreeSet(1024, 1)) {
            set.put(1);
            set.put(2);
            set.put(2);
            set.put(3);
            set.put(4);
            set.put(4);
            set.put(5);
            set.put(5);
            set.put(5);
            LongTreeSet.TreeCursor cursor = set.getCursor();
            LongList ll = new LongList();
            while (cursor.hasNext()) {
                ll.add(cursor.next());
            }
            TestUtils.assertEquals("[1,2,3,4,5]", ll.toString());
        }
    });
}
Also used : LongTreeSet(io.questdb.griffin.engine.table.LongTreeSet) LongList(io.questdb.std.LongList) Test(org.junit.Test)

Aggregations

LongTreeSet (io.questdb.griffin.engine.table.LongTreeSet)4 LongList (io.questdb.std.LongList)3 Test (org.junit.Test)3 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 Rnd (io.questdb.std.Rnd)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1