Search in sources :

Example 21 with ExcerptTailer

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

the class SingleChronicleQueueTest method testScanFromLastKnownIndex.

@Test
public void testScanFromLastKnownIndex() {
    final File file = createTempFile("testScanFromLastKnownIndex");
    try {
        final SingleChronicleQueue chronicle = (SingleChronicleQueue) createQueue(file);
        final ExcerptAppender appender = chronicle.acquireAppender();
        // create 100 documents
        for (int i = 0; i < 65; i++) {
            final int j = i;
            appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
        }
        // creates the indexes - index's 1 and 2 are created by the indexer
        new Indexer(chronicle).index();
        // create 100 documents
        for (long i = chronicle.lastIndex() + 1; i < 200; i++) {
            final long j = i;
            appender.writeDocument(wire -> wire.write(() -> "key").text("value=" + j));
        }
        final ExcerptTailer tailer = chronicle.createTailer();
        {
            int expected = 150;
            tailer.index(expected);
            StringBuilder sb = new StringBuilder();
            tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
            Assert.assertEquals("value=" + expected, sb.toString());
        }
        // read back earlier
        {
            int expected = 167;
            tailer.index(expected);
            StringBuilder sb = new StringBuilder();
            tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
            Assert.assertEquals("value=" + expected, sb.toString());
        }
    } finally {
        file.delete();
    }
}
Also used : BinaryWire(net.openhft.chronicle.wire.BinaryWire) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Arrays(java.util.Arrays) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ChronicleQueueBuilder(net.openhft.chronicle.queue.ChronicleQueueBuilder) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) IOException(java.io.IOException) Wire(net.openhft.chronicle.wire.Wire) File(java.io.File) TextWire(net.openhft.chronicle.wire.TextWire) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Assert(org.junit.Assert) Parameterized(org.junit.runners.Parameterized) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 22 with ExcerptTailer

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

the class SingleChronicleQueueTest method testReadAtIndexWithIndexesAtStart.

@Test
public void testReadAtIndexWithIndexesAtStart() {
    final File file = createTempFile("testReadAtIndexWithIndexesAtStart");
    try {
        final SingleChronicleQueue chronicle = (SingleChronicleQueue) 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));
        }
        new Indexer(chronicle).index();
        long index = 67;
        final ExcerptTailer tailer = chronicle.createTailer();
        tailer.index(index);
        StringBuilder sb = new StringBuilder();
        tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
        Assert.assertEquals("value=" + index, 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 23 with ExcerptTailer

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

the class SingleChronicleQueueTest method testSingleDirect.

@Test
public void testSingleDirect() {
    final File file = createTempFile("testSingleDirect");
    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();
        final StringBuilder sb = new StringBuilder();
        for (int j = 0; j < chronicle.lastIndex(); j++) {
            sb.setLength(0);
            tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
            Assert.assertEquals("value=" + j, 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 24 with ExcerptTailer

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

the class SingleChronicleQueueTest method testReadAtIndexWithIndexes.

@Test
public void testReadAtIndexWithIndexes() {
    final File file = createTempFile("testReadAtIndexWithIndexes");
    try {
        final SingleChronicleQueue chronicle = (SingleChronicleQueue) 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));
        }
        // creates the indexes
        new Indexer(chronicle).index();
        final ExcerptTailer tailer = chronicle.createTailer();
        tailer.index(67);
        StringBuilder sb = new StringBuilder();
        tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
        Assert.assertEquals("value=67", 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 25 with ExcerptTailer

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

the class SingleChronicleQueueTest method testReadAtIndex.

@Test
public void testReadAtIndex() {
    final File file = createTempFile("testReadAtIndex");
    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();
        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 100; i++) {
            tailer.index(i);
            sb.setLength(0);
            tailer.readDocument(wire -> wire.read(() -> "key").text(sb));
            Assert.assertEquals("value=" + i, 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)

Aggregations

ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)45 Test (org.junit.Test)39 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)34 File (java.io.File)24 DocumentContext (net.openhft.chronicle.wire.DocumentContext)22 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)15 MappedFile (net.openhft.chronicle.bytes.MappedFile)11 ArrayList (java.util.ArrayList)5 MethodReader (net.openhft.chronicle.bytes.MethodReader)5 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)5 IOException (java.io.IOException)4 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Bytes (net.openhft.chronicle.bytes.Bytes)3 ChronicleQueueTestBase (net.openhft.chronicle.queue.ChronicleQueueTestBase)3 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)3 Wire (net.openhft.chronicle.wire.Wire)3 ByteBuffer (java.nio.ByteBuffer)2 Future (java.util.concurrent.Future)2