use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class ConcurrentTest method testOneToOneBatched.
@Test
public void testOneToOneBatched() throws BrokenBarrierException, InterruptedException {
final int cycle = 1024;
final int size = 1024 * cycle;
final RingQueue<Event> queue = new RingQueue<>(Event.FACTORY, cycle);
final SPSequence pubSeq = new SPSequence(cycle);
final SCSequence subSeq = new SCSequence();
pubSeq.then(subSeq).then(pubSeq);
CyclicBarrier barrier = new CyclicBarrier(2);
new Thread(() -> {
try {
barrier.await();
Rnd rnd = new Rnd();
for (int i = 0; i < size; ) {
long cursor = pubSeq.next();
if (cursor > -1) {
long available = pubSeq.available();
while (cursor < available && i < size) {
Event event = queue.get(cursor++);
event.value = rnd.nextInt();
i++;
}
pubSeq.done(cursor - 1);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
barrier.await();
int consumed = 0;
final Rnd rnd2 = new Rnd();
while (consumed < size) {
long cursor = subSeq.next();
if (cursor > -1) {
long available = subSeq.available();
while (cursor < available) {
Assert.assertEquals(rnd2.nextInt(), queue.get(cursor++).value);
consumed++;
}
subSeq.done(available - 1);
}
}
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class MinDoubleGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f double)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putDouble(0, rnd.nextDouble());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(0.0011075139045715332, record.getDouble(0), 0.0001);
}
}
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class MinDoubleGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f double)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
TableWriter.Row r = w.newRow();
r.append();
for (int i = 100; i > 10; i--) {
r = w.newRow();
r.putDouble(0, rnd.nextDouble());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(0.0011075139045715332, record.getDouble(0), 0.0001);
}
}
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class MinFloatGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f float)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putFloat(0, rnd.nextFloat());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(0.0011075139045715332, record.getFloat(0), 0.0001);
}
}
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class MinLongGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f long)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putLong(0, rnd.nextLong());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(-8968886490993754893L, record.getLong(0));
}
}
}
Aggregations