Search in sources :

Example 1 with LongList

use of io.questdb.std.LongList 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 2 with LongList

use of io.questdb.std.LongList 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 3 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntrinsicModelTest method assertShortInterval.

private static void assertShortInterval(String expected, String interval) throws SqlException {
    LongList out = new LongList();
    IntervalUtils.parseIntervalEx(interval, 0, interval.length(), 0, out, IntervalOperation.INTERSECT);
    IntervalUtils.applyLastEncodedIntervalEx(out);
    TestUtils.assertEquals(expected, intervalToString(out));
}
Also used : LongList(io.questdb.std.LongList)

Example 4 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntrinsicModelTest method testInvert.

@Test
public void testInvert() throws SqlException {
    final String intervalStr = "2018-01-10T10:30:00.000Z;30m;2d;2";
    LongList out = new LongList();
    IntervalUtils.parseIntervalEx(intervalStr, 0, intervalStr.length(), 0, out, IntervalOperation.INTERSECT);
    IntervalUtils.applyLastEncodedIntervalEx(out);
    IntervalUtils.invert(out);
    TestUtils.assertEquals("[{lo=, hi=2018-01-10T10:29:59.999999Z},{lo=2018-01-10T11:00:00.000001Z, hi=2018-01-12T10:29:59.999999Z},{lo=2018-01-12T11:00:00.000001Z, hi=294247-01-10T04:00:54.775807Z}]", intervalToString(out));
}
Also used : GriffinParserTestUtils.intervalToString(io.questdb.griffin.GriffinParserTestUtils.intervalToString) LongList(io.questdb.std.LongList) Test(org.junit.Test)

Example 5 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method testIsInListWithEvenNumberOfIntervals.

@Test
public void testIsInListWithEvenNumberOfIntervals() {
    LongList intervals = new LongList();
    add(intervals, 100, 102);
    add(intervals, 122, 124);
    Assert.assertFalse(IntervalUtils.isInIntervals(intervals, 99));
    Assert.assertTrue(IntervalUtils.isInIntervals(intervals, 101));
    Assert.assertFalse(IntervalUtils.isInIntervals(intervals, 103));
    Assert.assertTrue(IntervalUtils.isInIntervals(intervals, 123));
    Assert.assertFalse(IntervalUtils.isInIntervals(intervals, 125));
}
Also used : LongList(io.questdb.std.LongList) Test(org.junit.Test)

Aggregations

LongList (io.questdb.std.LongList)30 Test (org.junit.Test)25 LongTreeSet (io.questdb.griffin.engine.table.LongTreeSet)3 Rnd (io.questdb.std.Rnd)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 GriffinParserTestUtils.intervalToString (io.questdb.griffin.GriffinParserTestUtils.intervalToString)1 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 ObjList (io.questdb.std.ObjList)1 Random (java.util.Random)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1