Search in sources :

Example 21 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue 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)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)21 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)20 Test (org.junit.Test)20 File (java.io.File)16 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)14 MappedFile (net.openhft.chronicle.bytes.MappedFile)10 DocumentContext (net.openhft.chronicle.wire.DocumentContext)9 IOException (java.io.IOException)4 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)4 Ignore (org.junit.Ignore)4 ExecutorService (java.util.concurrent.ExecutorService)3 ChronicleQueueTestBase (net.openhft.chronicle.queue.ChronicleQueueTestBase)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)2 WireType (net.openhft.chronicle.wire.WireType)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2