Search in sources :

Example 61 with ExcerptAppender

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

the class SingleChronicleQueueTest method testReadAtIndexSingle.

@Test
public void testReadAtIndexSingle() {
    final File file = createTempFile("testReadAtIndexSingle");
    try {
        final DirectChronicleQueue chronicle = createQueue(file);
        final ExcerptAppender appender = chronicle.acquireAppender();
        // create 100 documents
        for (int i = 0; i < 100; i++) {
            final int j = i;
            appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
        }
        final ExcerptTailer tailer = chronicle.createTailer();
        tailer.index(5);
        StringBuilder sb = new StringBuilder();
        tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
        Assert.assertEquals("value=5", sb.toString());
    } finally {
        file.delete();
    }
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 62 with ExcerptAppender

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

the class SingleChronicleQueueTest method testSingleWire.

// *************************************************************************
// 
// *************************************************************************
@Test
public void testSingleWire() {
    final File file = createTempFile("testSingleWire");
    try {
        final ChronicleQueue chronicle = createQueue(file);
        final ExcerptAppender appender = chronicle.acquireAppender();
        appender.writeDocument(wire -> wire.write(() -> "FirstName").text("Steve"));
        appender.writeDocument(wire -> wire.write(() -> "Surname").text("Jobs"));
        StringBuilder first = new StringBuilder();
        StringBuilder surname = new StringBuilder();
        final ExcerptTailer tailer = chronicle.createTailer();
        tailer.readDocument(wire -> wire.read(() -> "FirstName").text(first));
        tailer.readDocument(wire -> wire.read(() -> "Surname").text(surname));
        Assert.assertEquals("Steve Jobs", first + " " + surname);
    } finally {
        file.delete();
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 63 with ExcerptAppender

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

the class PublisherMain method createOutput.

private static MethodDefinition createOutput(final Path path) {
    final SingleChronicleQueue queue = outputQueue(path);
    final ExcerptAppender appender = queue.acquireAppender();
    return new GarbageFreeMethodPublisher(() -> appender);
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)

Aggregations

ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)63 Test (org.junit.Test)55 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)34 File (java.io.File)33 DocumentContext (net.openhft.chronicle.wire.DocumentContext)28 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)21 MappedFile (net.openhft.chronicle.bytes.MappedFile)15 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)6 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)5 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)5 Ignore (org.junit.Ignore)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ValueOut (net.openhft.chronicle.wire.ValueOut)4 Wire (net.openhft.chronicle.wire.Wire)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 ExecutorService (java.util.concurrent.ExecutorService)3 Bytes (net.openhft.chronicle.bytes.Bytes)3 ChronicleQueueTestBase (net.openhft.chronicle.queue.ChronicleQueueTestBase)3