Search in sources :

Example 31 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleWriterTest method testWireMarshallingMapAndDTO.

@Test(timeout = 5000)
public void testWireMarshallingMapAndDTO() throws IOException {
    ChronicleWriter chronicleWriter = chronicleWriter(null, cw1, cw2);
    chronicleWriter.execute();
    try (ChronicleQueue queue = ChronicleQueue.singleBuilder(dir).build()) {
        StringBuilder sb = new StringBuilder();
        @NotNull MethodReader mr = queue.createTailer().methodReader(Mocker.intercepting(MyInterface.class, "*", sb::append));
        Assert.assertTrue(mr.readOne());
        Assert.assertTrue(mr.readOne());
        Assert.assertFalse(mr.readOne());
        Assert.assertEquals("*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\n" + "  age: 19,\n" + "  name: Henry\n" + "}\n" + "]*doit[!net.openhft.chronicle.queue.internal.writer.ChronicleWriterTest$DTO {\n" + "  age: 42,\n" + "  name: Percy\n" + "}\n" + "]", sb.toString());
    } finally {
        IOTools.deleteDirWithFiles(dir);
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) NotNull(org.jetbrains.annotations.NotNull) MethodReader(net.openhft.chronicle.bytes.MethodReader) Test(org.junit.Test)

Example 32 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class QueueWriteJitterMain method run.

protected void run() {
    MappedFile.warmup();
    String path = "test-q-" + Time.uniqueId();
    System.out.println("Writing to " + path);
    Thread pretoucher = new Thread(() -> {
        try (ChronicleQueue q = createQueue(path)) {
            ExcerptAppender appender = q.acquireAppender();
            while (true) {
                Thread.sleep(50);
                appender.pretouch();
            }
        } catch (InterruptedException ie) {
            if (running)
                ie.printStackTrace();
        }
    });
    pretoucher.setDaemon(true);
    pretoucher.start();
    Thread writer = new Thread(() -> {
        try (ChronicleQueue q = createQueue(path)) {
            ExcerptAppender appender = q.acquireAppender();
            while (running) {
                writeStarted = System.nanoTime();
                Jvm.safepoint();
                try (DocumentContext dc = appender.writingDocument(false)) {
                    Jvm.safepoint();
                    Bytes<?> bytes = dc.wire().bytes();
                    for (int i = 0; i < size; i += 8) bytes.writeLong(i);
                    Jvm.safepoint();
                }
                Jvm.safepoint();
                writeStarted = Long.MAX_VALUE;
                waitForNext(Math.min(100, sampleTime));
            }
        }
    });
    writer.setDaemon(true);
    writer.start();
    // give it time to start
    Jvm.pause(100);
    try (ChronicleQueue q = createQueue(path)) {
        ExcerptTailer tailer = q.createTailer();
        long start0 = System.currentTimeMillis();
        do {
            if (writeStarted < Long.MAX_VALUE) {
                // overflow exists loop
                while (writeStarted + sampleTime * 1000 > System.nanoTime()) Thread.yield();
                if (writeStarted < Long.MAX_VALUE) {
                    StackTraceElement[] stes = writer.getStackTrace();
                    if (!stes[1].getMethodName().equals("waitForNext")) {
                        StringBuilder sb = new StringBuilder();
                        sb.append(PROFILE_OF_THE_THREAD);
                        Jvm.trimStackTrace(sb, stes);
                        System.out.println(sb);
                    }
                }
            }
            try (DocumentContext dc = tailer.readingDocument()) {
                if (!dc.isPresent())
                    waitForNext(Math.min(100, sampleTime));
            }
            Thread.yield();
        } while (System.currentTimeMillis() < start0 + runTime * 1_000);
    }
    running = false;
    pretoucher.interrupt();
    IOTools.deleteDirWithFiles(path, 2);
}
Also used : ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext)

Example 33 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testLastWrittenIndexPerAppenderNoData.

@Test(expected = IllegalStateException.class)
public void testLastWrittenIndexPerAppenderNoData() {
    final File file = createTempFile("testLastWrittenIndexPerAppenderNoData");
    try {
        final ChronicleQueue chronicle = createQueue(file);
        final ExcerptAppender appender = chronicle.acquireAppender();
        appender.lastWrittenIndex();
    } finally {
        file.delete();
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) Test(org.junit.Test)

Example 34 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testLastWrittenIndexPerAppender.

@Test
public void testLastWrittenIndexPerAppender() {
    final File file = createTempFile("testLastWrittenIndexPerAppender");
    try {
        final ChronicleQueue chronicle = createQueue(file);
        final ExcerptAppender appender = chronicle.acquireAppender();
        appender.writeDocument(wire -> wire.write("key").text("test"));
        Assert.assertEquals(0, appender.lastWrittenIndex());
    } finally {
        file.delete();
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) Test(org.junit.Test)

Example 35 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class StagedPerformanceMain method runBenchmark.

private static void runBenchmark(int count, int interval, boolean warmup) {
    String run = Long.toString(System.nanoTime(), 36);
    WARMUP = warmup;
    DIR = PATH + "/run-" + run;
    new File(DIR).mkdirs();
    // every 60 seconds.
    REPORT_INTERVAL = (int) (60e9 / interval);
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(DIR + "/data").build()) {
        q0 = queue;
        List<Runnable> runnables = new ArrayList<>();
        runnables.add(() -> producer(count, interval));
        runnables.add(() -> firstStage());
        for (int s = 2; s <= STAGES; s++) {
            int finalS = s;
            runnables.add(() -> runStage(finalS));
        }
        runnables.stream().parallel().forEach(Runnable::run);
        Histogram latencies = new Histogram();
        reportLatenciesForStage(STAGES, latencies);
    }
    IOTools.deleteDirWithFiles(DIR, 3);
}
Also used : Histogram(net.openhft.chronicle.core.util.Histogram) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ArrayList(java.util.ArrayList) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)80 Test (org.junit.Test)59 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)37 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)37 File (java.io.File)36 DocumentContext (net.openhft.chronicle.wire.DocumentContext)21 ArrayList (java.util.ArrayList)16 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 MethodReader (net.openhft.chronicle.bytes.MethodReader)12 List (java.util.List)11 IOException (java.io.IOException)9 MappedFile (net.openhft.chronicle.bytes.MappedFile)8 Path (java.nio.file.Path)7 Bytes (net.openhft.chronicle.bytes.Bytes)7 Collections (java.util.Collections)6 RollCycles (net.openhft.chronicle.queue.RollCycles)6 NotNull (org.jetbrains.annotations.NotNull)6 ByteBuffer (java.nio.ByteBuffer)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)5 Histogram (net.openhft.chronicle.core.util.Histogram)5