use of com.questdb.cutlass.client.LineProtoSender 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);
}
}
});
}
Aggregations