Search in sources :

Example 1 with LineProtoSender

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);
            }
        }
    });
}
Also used : RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) StringSink(com.questdb.std.str.StringSink) WriterPool(com.questdb.cairo.pool.WriterPool) CountDownLatch(java.util.concurrent.CountDownLatch) Worker(com.questdb.mp.Worker) Job(com.questdb.mp.Job) LineProtoSender(com.questdb.cutlass.client.LineProtoSender)

Aggregations

WriterPool (com.questdb.cairo.pool.WriterPool)1 LineProtoSender (com.questdb.cutlass.client.LineProtoSender)1 Job (com.questdb.mp.Job)1 Worker (com.questdb.mp.Worker)1 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)1 StringSink (com.questdb.std.str.StringSink)1 CountDownLatch (java.util.concurrent.CountDownLatch)1