Search in sources :

Example 31 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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 32 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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 33 with ExcerptAppender

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

Example 34 with ExcerptAppender

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

the class SingleChronicleQueueTest method testLastIndexPerChronicle.

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

Example 35 with ExcerptAppender

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

the class GarbageFreeMethodPublisher method onEightyByteMessage.

@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();
        // 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);
        }
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Wire(net.openhft.chronicle.wire.Wire) NotNull(org.jetbrains.annotations.NotNull)

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