net.openhft.chronicle.bytes.MethodReader Java Examples

The following examples show how to use net.openhft.chronicle.bytes.MethodReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TranslatorMain.java    From Chronicle-Queue-Demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    String pathfr = "queue-fr";
    SingleChronicleQueue queuefr = SingleChronicleQueueBuilder.binary(pathfr).build();
    MessageConsumer messageConsumer = queuefr.acquireAppender().methodWriter(MessageConsumer.class);

    MessageConsumer simpleTranslator = new SimpleTranslator(messageConsumer);

    String path_en = "queue-en";
    SingleChronicleQueue queue_en = SingleChronicleQueueBuilder.binary(path_en).build();
    MethodReader methodReader = queue_en.createTailer().methodReader(simpleTranslator);

    while (true) {
        if (!methodReader.readOne())
            Thread.sleep(10);
    }
}
 
Example #2
Source File: MessageHistoryTest.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
private void generateTestData(final ChronicleQueue inputQueue, final ChronicleQueue outputQueue) {
    final First first = inputQueue.acquireAppender()
            .methodWriterBuilder(First.class)
            .recordHistory(true)
            .get();
    first.say("one");
    first.say("two");
    first.say("three");

    final LoggingFirst loggingFirst =
            new LoggingFirst(outputQueue.acquireAppender().
                    methodWriterBuilder(Second.class).build());

    final MethodReader reader = inputQueue.createTailer().
            methodReaderBuilder().build(loggingFirst);

    assertTrue(reader.readOne());
    assertTrue(reader.readOne());

    // roll queue file
    clock.addAndGet(TimeUnit.DAYS.toMillis(2));

    assertTrue(reader.readOne());
    assertFalse(reader.readOne());
}
 
Example #3
Source File: DumpDecodedMain.java    From Chronicle-Queue-Demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    try (ChronicleQueue queue2 = ChronicleQueue.singleBuilder("out").sourceId(2).build()) {
        long last = Long.MAX_VALUE / 2;
        MethodReader methodReader = queue2.createTailer("dump")
                .methodReader(new EventHandler());
        System.out.println("Started");
        while (true) {
            long now = System.currentTimeMillis();
            if (methodReader.readOne()) {
                last = now;
            } else {
                // stop if nothing for 2.5 seconds.
                if (now > last + 2500)
                    break;
                Thread.yield();
            }
        }
    }
    System.out.println(".. Finished");
    System.exit(0);
}
 
Example #4
Source File: MessageHistoryTest.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAccessMessageHistoryWhenTailerIsMovedToEnd() {
    try (final ChronicleQueue inputQueue = createQueue(inputQueueDir, 1);
         final ChronicleQueue outputQueue = createQueue(outputQueueDir, 2)) {
        generateTestData(inputQueue, outputQueue);

        final ExcerptTailer tailer = outputQueue.createTailer();
        tailer.direction(TailerDirection.BACKWARD).toEnd();

        final ValidatingSecond validatingSecond = new ValidatingSecond();
        final MethodReader validator = tailer.methodReader(validatingSecond);

        assertTrue(validator.readOne());
        assertTrue(validatingSecond.messageHistoryPresent());
    }
}
 
Example #5
Source File: JDBCService.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
void runLoop() {
    try {
        JDBCResult result = out.acquireAppender()
                .methodWriterBuilder(JDBCResult.class)
                .recordHistory(true)
                .get();
        JDBCComponent js = new JDBCComponent(connectionSupplier, result);
        MethodReader reader = in.createTailer().afterLastWritten(out).methodReader(js);
        Pauser pauser = Pauser.millis(1, 10);
        while (!isClosed()) {
            if (reader.readOne())
                pauser.reset();
            else
                pauser.pause();
        }
    } catch (Throwable t) {
        LOGGER.warn("Run loop exited", t);
    }
}
 
Example #6
Source File: EventLoopServiceWrapper.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
@Override
public boolean action() throws InvalidEventHandlerException {
    if (isClosed()) {
        Closeable.closeQuietly(serviceImpl);
        Closeable.closeQuietly(serviceIn);
        Closeable.closeQuietly(outputQueue);
        Closeable.closeQuietly(inputQueues);
        throw new InvalidEventHandlerException();
    }

    boolean busy = false;
    for (MethodReader reader : serviceIn) {
        busy |= reader.readOne();
    }
    return busy;
}
 
Example #7
Source File: EventLoopServiceWrapper.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
public EventLoopServiceWrapper(@NotNull ServiceWrapperBuilder<O> builder) {
    this.priority = builder.priority();
    outputQueue = ChronicleQueue.singleBuilder(builder.outputPath())
            .sourceId(builder.outputSourceId())
            .checkInterrupts(false)
            .build();
    serviceOut = outputQueue.acquireAppender()
            .methodWriterBuilder(builder.outClass())
            .recordHistory(builder.outputSourceId() != 0)
            .get();
    serviceImpl = builder.getServiceFunctions().stream()
            .map(f -> f.apply(serviceOut))
            .toArray();

    List<String> paths = builder.inputPath();
    serviceIn = new MethodReader[paths.size()];
    inputQueues = new ChronicleQueue[paths.size()];
    for (int i = 0; i < paths.size(); i++) {
        inputQueues[i] = ChronicleQueue.singleBuilder(paths.get(i))
                .sourceId(builder.inputSourceId())
                .build();
        serviceIn[i] = inputQueues[i].createTailer()
                .afterLastWritten(outputQueue)
                .methodReader(serviceImpl);
    }
    eventLoop = builder.eventLoop();
    eventLoop.addHandler(this);
    createdEventLoop = builder.createdEventLoop();
    if (createdEventLoop)
        eventLoop.start();
}
 
Example #8
Source File: MessageHistoryTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
public void chainedMessageHistory() {
    try (final ChronicleQueue inputQueue = createQueue(inputQueueDir, 1);
         final ChronicleQueue middleQueue = createQueue(middleQueueDir, 2);
         final ChronicleQueue outputQueue = createQueue(middleQueueDir, 3)) {
        generateTestData(inputQueue, middleQueue);

        MethodReader reader = middleQueue.createTailer().methodReader(outputQueue.methodWriter(First.class));
        for (int i = 0; i < 3; i++)
            assertTrue(reader.readOne());
        MethodReader reader2 = outputQueue.createTailer().methodReader((First) this::say3);
        for (int i = 0; i < 3; i++)
            assertTrue(reader2.readOne());
    }
}
 
Example #9
Source File: MessageHistoryTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAccessMessageHistory() {
    try (final ChronicleQueue inputQueue = createQueue(inputQueueDir, 1);
         final ChronicleQueue outputQueue = createQueue(outputQueueDir, 2)) {
        generateTestData(inputQueue, outputQueue);

        final ExcerptTailer tailer = outputQueue.createTailer();

        final ValidatingSecond validatingSecond = new ValidatingSecond();
        final MethodReader validator = tailer.methodReader(validatingSecond);

        assertTrue(validator.readOne());
        assertTrue(validatingSecond.messageHistoryPresent());
    }
}
 
Example #10
Source File: TestMethodWriterWithThreads.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("TODO FIX")
public void test() throws FileNotFoundException {

    File tmpDir = getTmpDir();
    try (final ChronicleQueue q = builder(tmpDir, WireType.BINARY).rollCycle(HOURLY).doubleBuffer(doubleBuffer).build()) {

        methodWriter = q.methodWriter(I.class);

        ExcerptTailer tailer = q.createTailer();
        MethodReader methodReader = tailer.methodReader(newReader());

        IntStream.range(0, 1000)
                .parallel()
                .forEach(i -> {
                    creates();
                    amends();
                    synchronized (methodReader) {
                        for (int j = 0; j < 2 && !fail.get(); )
                            if (methodReader.readOne())
                                j++;
                    }
                    if (fail.get())
                        fail();
                });

    } finally {
        if (fail.get()) {
            DumpQueueMain.dump(tmpDir.getAbsolutePath());
        }
    }
}
 
Example #11
Source File: MethodReaderObjectReuseTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneOne() {
    ClassAliasPool.CLASS_ALIASES.addAlias(PingDTO.class);
    try (ChronicleQueue cq = SingleChronicleQueueBuilder.single(OS.TARGET + "/MethodReaderObjectReuseTest-" + System.nanoTime()).build()) {
        PingDTO.constructionExpected++;
        PingDTO pdtio = new PingDTO();
        PingDTO.constructionExpected++;
        Pinger pinger = cq.acquireAppender().methodWriter(Pinger.class);
        for (int i = 0; i < 5; i++) {
            pinger.ping(pdtio);
            assertEquals(PingDTO.constructionExpected, PingDTO.constructionCounter);
            pdtio.bytes.append("hi");
        }
        StringBuilder sb = new StringBuilder();
        PingDTO.constructionExpected++;
        MethodReader reader = cq.createTailer()
                .methodReader(
                        (Pinger) pingDTO -> sb.append("ping ").append(pingDTO));
        assertEquals(PingDTO.constructionExpected, PingDTO.constructionCounter);
        while (reader.readOne()) ;
        assertEquals("ping !PingDTO {\n" +
                "  bytes: \"\"\n" +
                "}\n" +
                "ping !PingDTO {\n" +
                "  bytes: hi\n" +
                "}\n" +
                "ping !PingDTO {\n" +
                "  bytes: hihi\n" +
                "}\n" +
                "ping !PingDTO {\n" +
                "  bytes: hihihi\n" +
                "}\n" +
                "ping !PingDTO {\n" +
                "  bytes: hihihihi\n" +
                "}\n", sb.toString());
    }
}
 
Example #12
Source File: MessageReaderWriterTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
    public void testWriteWhileReading() {
        ClassAliasPool.CLASS_ALIASES.addAlias(Message1.class);
        ClassAliasPool.CLASS_ALIASES.addAlias(Message2.class);

        File path1 = DirectoryUtils.tempDir("testWriteWhileReading1");
        File path2 = DirectoryUtils.tempDir("testWriteWhileReading2");

        try (ChronicleQueue queue1 = SingleChronicleQueueBuilder
                .binary(path1)
                .testBlockSize()
                .build();
             ChronicleQueue queue2 = SingleChronicleQueueBuilder
                     .binary(path2)
                     .testBlockSize()
                     .build()) {
            MethodReader reader2 = queue1.createTailer().methodReader(ObjectUtils.printAll(MessageListener.class));
            MessageListener writer2 = queue2.acquireAppender().methodWriter(MessageListener.class);
            MessageListener processor = new MessageProcessor(writer2);
            MethodReader reader1 = queue1.createTailer().methodReader(processor);
            MessageListener writer1 = queue1.acquireAppender().methodWriter(MessageListener.class);

            for (int i = 0; i < 3; i++) {
                // write a message
                writer1.method1(new Message1("hello"));
                writer1.method2(new Message2(234));

                // read those messages
                assertTrue(reader1.readOne());
                assertTrue(reader1.readOne());
                assertFalse(reader1.readOne());

                // read the produced messages
                assertTrue(reader2.readOne());
                assertTrue(reader2.readOne());
                assertFalse(reader2.readOne());
            }
//            System.out.println(queue1.dump());
        }
    }
 
Example #13
Source File: ChronicleQueueMethodsWithoutParameters.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Test
    public void test() {
        File file = getTmpDir();

        try (ChronicleQueue queue = ChronicleQueue.singleBuilder(file)
                .testBlockSize()
                .rollCycle(TEST_DAILY).build()) {

            SomeListener someListener = queue.acquireAppender().methodWriter(SomeListener.class);

            SomeManager someManager = new SomeManager();
            MethodReader reader = queue.createTailer().methodReader(someManager);

            LOG.debug("Writing to queue");
            someListener.methodWithOneParam(1);
            someListener.methodWithoutParams();

            LOG.debug("Reading from queue");
            assertTrue(reader.readOne());
            assertTrue(reader.readOne());
            assertFalse(reader.readOne());

            assertTrue(someManager.methodWithOneParamInvoked);       // one param method was invoked
            assertTrue(someManager.methodWithoutParamsInvoked);      // no params method was NOT invoked

//            LOG.warn(queue.dump());
        }
    }
 
Example #14
Source File: OrderViewerMain.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    System.out.println("\nWaiting for messages");
    try (ChronicleQueue q = SingleChronicleQueueBuilder.binary("in").rollCycle(RollCycles.TEST8_DAILY).build()) {
        OMSIn logging = Mocker.logging(OMSIn.class, "read - ", System.out);
        MethodReader reader = q.createTailer().methodReader(logging);
        while (true) {
            if (!reader.readOne())
                Jvm.pause(50);
        }
    }
}
 
Example #15
Source File: ServiceWrapperBuilder.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@NotNull
public MethodReader outputReader(Object... impls) {
    ChronicleQueue queue = outputQueue();
    MethodReader reader = queue.createTailer().methodReader(impls);
    reader.closeIn(true);
    return reader;
}
 
Example #16
Source File: MethodReaderQueueEntryHandler.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(final WireIn wireIn, final Consumer<String> messageHandler) {
    MethodReader methodReader = wireIn.methodReader(Mocker.intercepting(mrInterface, "", s -> {
        long hn = wireIn.headerNumber();
        messageHandler.accept("header: " + hn + "\n" + s);
    }));
    while (methodReader.readOne()) {
        // read all
    }
}
 
Example #17
Source File: ResultGenerator.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        throw new IllegalArgumentException("Usage: <program> [resource-name]");
    }

    final ConfigParser configParser = new ConfigParser(args[0]);

    final List<StageConfig> allStageConfigs = configParser.getAllStageConfigs();
    final StageConfig lastStageConfig = allStageConfigs.
            get(allStageConfigs.size() - 1);
    Jvm.setExceptionHandlers((c, m, t) -> {
        System.out.println(m);
    }, (c, m, t) -> {
        System.out.println(m);
        if (t != null) {
            t.printStackTrace();
        }
    }, (c, m, t) -> System.out.println(m));
    try (final SingleChronicleQueue queue =
                 ChronicleQueue.singleBuilder(lastStageConfig.getOutputPath()).build();
         final Writer resultsWriter = new FileWriter("results.txt", false)) {
        final MethodReader methodReader = queue.createTailer().methodReader(new CapturingReceiver(resultsWriter));
        while (methodReader.readOne()) {
            // report
        }
    }
}
 
Example #18
Source File: StageMain.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
//        MlockAll.doMlockall();
        if (args.length != 2) {
            throw new IllegalArgumentException("Usage: <program> [resource-name] [stage-index]");
        }
        final ConfigParser configParser = new ConfigParser(args[0]);

        final StageConfig stageConfig = configParser.getStageConfig(Integer.parseInt(args[1]));
        final ExecutorService service = Executors.newFixedThreadPool(stageConfig.getStageIndices().size() + 1);
        service.submit(new PretoucherTask(outputQueue(stageConfig.getOutputPath(), UNSET_SOURCE),
                configParser.getPretouchIntervalMillis()));

        for (Integer index : stageConfig.getStageIndices()) {
            service.submit(() -> {
                final Stage stage = new Stage(createOutput(stageConfig.getOutputPath(), index + 1), index);
                final MethodReader reader = createReader(stageConfig.getInputPath(), stage);
                Thread.currentThread().setName("load.stage-consumer-" + index);
                boolean warnOnce = false;
                while (!Thread.currentThread().isInterrupted()) {
                    try {
                        reader.readOne();
                    } catch (Exception e) {
                        if (!warnOnce) {
                            e.printStackTrace();
                            warnOnce = true;
                        }
                    }
                }
            });
        }
    }
 
Example #19
Source File: GarbageFreeMethodPublisher.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Override
    public void onEightyByteMessage(final EightyByteMessage message) {

        final ExcerptAppender appender = outputSupplier.get();
//        DebugTimestamps.operationStart(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
        @NotNull DocumentContext context = appender.writingDocument();
//        DebugTimestamps.operationEnd(DebugTimestamps.Operation.GET_WRITING_DOCUMENT);
        try {
            Wire wire = context.wire();
            // log write
//            DebugTimestamps.operationStart(DebugTimestamps.Operation.WRITE_EVENT);
            try {
                wire.write(MethodReader.HISTORY).marshallable(MessageHistory.get());
                final ValueOut valueOut = wire.writeEventName("onEightyByteMessage");
                valueOut.object(EightyByteMessage.class, message);
                wire.padToCacheAlign();
            } finally {
//                DebugTimestamps.operationEnd(DebugTimestamps.Operation.WRITE_EVENT);
            }
        } finally {

//            DebugTimestamps.operationStart(DebugTimestamps.Operation.CLOSE_CONTEXT);
            try {
                context.close();
            } finally {
//                DebugTimestamps.operationEnd(DebugTimestamps.Operation.CLOSE_CONTEXT);
            }
        }
    }
 
Example #20
Source File: BridgeMain.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    IOTools.deleteDirWithFiles("in", 2);
    IOTools.deleteDirWithFiles("out", 2);

    long events = 0, lastPrint = 0;
    try (ChronicleQueue queue = ChronicleQueue.singleBuilder("in").sourceId(1).build()) {
        try (ChronicleQueue queue2 = ChronicleQueue.singleBuilder("out").sourceId(2).build()) {

            Events out = queue2.methodWriterBuilder(Events.class).recordHistory(true).build();
            Events bridge = new BridgeEvents(out);
            MethodReader methodReader = queue.createTailer("bridge")
                    .methodReader(bridge);
            System.out.println("Started");
            long last = 0;
            while (running) {
                if (methodReader.readOne()) {
                    events++;
                } else {
                    long now = System.currentTimeMillis();
                    if (lastPrint != events && now > last + 250) {
                        System.out.println("events: " + events);
                        lastPrint = events;
                        last = now;
                    } else {
                        Thread.yield();
                    }
                }
            }
        }
    }
    System.out.println("... finished");
}
 
Example #21
Source File: OutputMain.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    String path = "queue-fr";
    SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).build();
    MessageConsumer messagePrinter = System.out::println;
    MethodReader methodReader = queue.createTailer().methodReader(messagePrinter);

    while (true) {
        if (!methodReader.readOne())
            Thread.sleep(10);
    }
}
 
Example #22
Source File: JDBCService.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@NotNull
public MethodReader createReader(JDBCResult result) {
    throwExceptionIfClosed();

    return out.createTailer().methodReader(result);
}
 
Example #23
Source File: HelloWorldTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Test
    @Ignore("TODO FIX")
    public void testWithAsQueueService() {
        // acts as three processes in one test
        // process A writes to the HelloWorld interface.
        // process B read fromt he HelloWorld interface and writes to the
        String input = OS.TARGET + "/input-" + System.nanoTime();
        String output = OS.TARGET + "/output-" + System.nanoTime();

        HelloReplier replier = createMock(HelloReplier.class);
        replier.reply("Hello April");
        replier.reply("Hello June");
        replay(replier);

        ServiceWrapperBuilder<HelloReplier> builder = ServiceWrapperBuilder
                .serviceBuilder(input, output, HelloReplier.class, HelloWorldImpl::new)
                .inputSourceId(1).outputSourceId(2);

        try (CloseableHelloWorld helloWorld = builder.inputWriter(CloseableHelloWorld.class);
             MethodReader replyReader = builder.outputReader(replier);
             ServiceWrapper helloWorldService = builder.get()) {

            helloWorld.hello("April");
            helloWorld.hello("June");

//            System.out.println(helloWorldService.inputQueues()[0].dump());
            for (int i = 0; i < 2; i++) {
                while (!replyReader.readOne()) {
                    Thread.yield();
                }
            }
//            System.out.println(helloWorldService.outputQueue().dump());
            verify(replier);
        } finally {
            builder.closeQueues();
            try {
                IOTools.deleteDirWithFiles(new File(input), 2);
                IOTools.deleteDirWithFiles(new File(output), 2);
            } catch (IORuntimeException e) {
                e.printStackTrace();
            }
        }
    }
 
Example #24
Source File: StoreTailerTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldConsiderSourceIdWhenDeterminingLastWrittenIndex() {
    try (ChronicleQueue firstInputQueue =
                 createQueue(dataDirectory, RollCycles.TEST_DAILY, 1, "firstInputQueue");
         // different RollCycle means that indicies are not identical to firstInputQueue
         ChronicleQueue secondInputQueue =
                 createQueue(dataDirectory, RollCycles.TEST_SECONDLY, 2, "secondInputQueue");
         ChronicleQueue outputQueue =
                 createQueue(dataDirectory, RollCycles.TEST_DAILY, 0, "outputQueue")) {

        final StringEvents firstWriter = firstInputQueue.acquireAppender()
                .methodWriterBuilder(StringEvents.class)
                .get();
        final HelloWorld secondWriter = secondInputQueue.acquireAppender()
                .methodWriterBuilder(HelloWorld.class)
                .get();

        // generate some data in the input queues
        firstWriter.onEvent("one");
        firstWriter.onEvent("two");

        secondWriter.hello("thirteen");
        secondWriter.hello("thirtyOne");

        final StringEvents eventSink = outputQueue.acquireAppender().
                methodWriterBuilder(StringEvents.class).recordHistory(true).get();

        final CapturingStringEvents outputWriter = new CapturingStringEvents(eventSink);
        final MethodReader firstMethodReader = firstInputQueue.createTailer().methodReader(outputWriter);
        final MethodReader secondMethodReader = secondInputQueue.createTailer().methodReader(outputWriter);

        // replay events from the inputs into the output queue
        assertTrue(firstMethodReader.readOne());
        assertTrue(firstMethodReader.readOne());
        assertTrue(secondMethodReader.readOne());
        assertTrue(secondMethodReader.readOne());

        // ensures that tailer is not moved to index from the incorrect source
        secondInputQueue.createTailer().afterLastWritten(outputQueue);
    }
}
 
Example #25
Source File: StageMain.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
private static MethodReader createReader(final Path path, final MethodDefinition impl) {
    final SingleChronicleQueue queue = outputQueue(path, UNSET_SOURCE);
    return queue.createTailer().methodReader(impl);
}
 
Example #26
Source File: JDBCServiceTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
private void doCreateTable(int repeats, int noUpdates) {
    for (int t = 0; t < repeats; t++) {
        long start = System.nanoTime(), written;
        File path1 = DirectoryUtils.tempDir("createTable1");
        File path2 = DirectoryUtils.tempDir("createTable2");
        File file = new File(OS.TARGET, "hsqldb-" + System.nanoTime());
        file.deleteOnExit();

        try (ChronicleQueue in = SingleChronicleQueueBuilder
                .binary(path1)
                .testBlockSize()
                .build();
             ChronicleQueue out = SingleChronicleQueueBuilder
                     .binary(path2)
                     .testBlockSize()
                     .build()) {

            JDBCService service = new JDBCService(in, out, () -> DriverManager.getConnection("jdbc:hsqldb:file:" + file.getAbsolutePath(), "SA", ""));

            JDBCStatement writer = service.createWriter();
            writer.executeUpdate("CREATE TABLE tableName (\n" +
                    "name VARCHAR(64) NOT NULL,\n" +
                    "num INT\n" +
                    ")\n");

            for (int i = 1; i < (long) noUpdates; i++)
                writer.executeUpdate("INSERT INTO tableName (name, num)\n" +
                        "VALUES (?, ?)", "name", i);

            written = System.nanoTime() - start;
            AtomicLong queries = new AtomicLong();
            AtomicLong updates = new AtomicLong();
            CountingJDBCResult countingJDBCResult = new CountingJDBCResult(queries, updates);
            MethodReader methodReader = service.createReader(countingJDBCResult);
            while (updates.get() < noUpdates) {
                if (!methodReader.readOne())
                    Thread.yield();
            }
            Closeable.closeQuietly(service);

            long time = System.nanoTime() - start;
            System.out.printf("Average time to write each update %.1f us, average time to perform each update %.1f us%n",
                    written / noUpdates / 1e3,
                    time / noUpdates / 1e3);
        } finally {
            try {
                IOTools.deleteDirWithFiles(path1, 2);
                IOTools.deleteDirWithFiles(path2, 2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}