use of com.questdb.cairo.pool.WriterPool in project questdb by bluestreak01.
the class LinuxLineProtoReceiverTest method assertReceive.
private void assertReceive(ReceiverConfiguration receiverCfg, ReceiverFactory factory) throws Exception {
TestUtils.assertMemoryLeak(() -> {
final String expected = "colour\tshape\tsize\ttimestamp\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n" + "blue\tsquare\t3.400000000000\t1970-01-01T00:01:40.000Z\n";
CairoConfiguration cairoCfg = new DefaultCairoConfiguration(root);
try (WriterPool pool = new WriterPool(cairoCfg)) {
Job receiver = factory.createReceiver(receiverCfg, cairoCfg, pool);
try {
CountDownLatch workerHaltLatch = new CountDownLatch(1);
try (TableModel model = new TableModel(configuration, "tab", PartitionBy.NONE).col("colour", ColumnType.SYMBOL).col("shape", ColumnType.SYMBOL).col("size", ColumnType.DOUBLE).timestamp()) {
CairoTestUtils.create(model);
}
// warm writer up
try (TableWriter w = pool.get("tab")) {
w.warmUp();
}
ObjHashSet<Job> jobs = new ObjHashSet<>();
jobs.add(receiver);
Worker worker = new Worker(jobs, workerHaltLatch);
worker.start();
try (LineProtoSender sender = new LineProtoSender("127.0.0.1", receiverCfg.getPort(), 1400)) {
for (int i = 0; i < 10; i++) {
sender.metric("tab").tag("colour", "blue").tag("shape", "square").field("size", 3.4, 4).$(100000000);
}
sender.flush();
}
try (TableReader reader = new TableReader(cairoCfg, "tab")) {
int count = 1000000;
while (true) {
if (count-- > 0 && reader.size() < 10) {
reader.reload();
LockSupport.parkNanos(1);
} else {
break;
}
}
Assert.assertTrue(count > 0);
worker.halt();
Assert.assertTrue(workerHaltLatch.await(3, TimeUnit.SECONDS));
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
printer.print(reader.getCursor(), true, reader.getMetadata());
TestUtils.assertEquals(expected, sink);
}
} finally {
Misc.free(receiver);
}
}
});
}
use of com.questdb.cairo.pool.WriterPool in project questdb by bluestreak01.
the class CairoLineProtoParserTest method assertThat.
private void assertThat(String expected, String lines, CharSequence tableName, CairoConfiguration configuration) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (WriterPool pool = new WriterPool(configuration)) {
try (CairoLineProtoParser parser = new CairoLineProtoParser(configuration, pool)) {
byte[] bytes = lines.getBytes("UTF8");
int len = bytes.length;
long mem = Unsafe.malloc(len);
try {
for (int i = 0; i < len; i++) {
Unsafe.getUnsafe().putByte(mem + i, bytes[i]);
}
try (LineProtoLexer lexer = new LineProtoLexer(4096)) {
lexer.withParser(parser);
lexer.parse(mem, mem + len);
lexer.parseLast();
parser.commitAll();
}
} finally {
Unsafe.free(mem, len);
}
}
}
assertTable(expected, tableName);
});
}
use of com.questdb.cairo.pool.WriterPool in project questdb by bluestreak01.
the class LinuxLineProtoReceiverTest method assertConstructorFail.
private void assertConstructorFail(ReceiverConfiguration receiverCfg, ReceiverFactory factory) {
CairoConfiguration cairoCfg = new DefaultCairoConfiguration(root);
try (WriterPool pool = new WriterPool(cairoCfg)) {
try {
factory.createReceiver(receiverCfg, cairoCfg, pool);
Assert.fail();
} catch (CairoException ignore) {
}
}
}
Aggregations