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);
}
});
}
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);
}
}
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)));
}
}
}
}
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());
}
});
}
Aggregations