Search in sources :

Example 46 with ExcerptAppender

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

the class QueueInspectorTest method shouldIndicateNoProcessIdWhenDocumentIsComplete.

@Test
public void shouldIndicateNoProcessIdWhenDocumentIsComplete() throws IOException {
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).testBlockSize().build()) {
        final QueueInspector inspector = new QueueInspector(queue);
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(37L, ValueOut::int64);
        try (final DocumentContext ctx = appender.writingDocument()) {
            ctx.wire().write("foo").int32(17L);
        }
        final int writingThreadId = inspector.getWritingThreadId();
        assertThat(writingThreadId, is(not(OS.getProcessId())));
        assertThat(QueueInspector.isValidThreadId(writingThreadId), is(false));
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Example 47 with ExcerptAppender

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

the class QueueInspectorTest method shouldDetermineWritingProcessIdWhenDocumentIsNotComplete.

@Test
public void shouldDetermineWritingProcessIdWhenDocumentIsNotComplete() throws IOException {
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpDir.newFolder()).testBlockSize().build()) {
        final QueueInspector inspector = new QueueInspector(queue);
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(37L, ValueOut::int64);
        try (final DocumentContext ctx = appender.writingDocument()) {
            ctx.wire().write("foo").int32(17L);
            final int writingThreadId = inspector.getWritingThreadId();
            assertThat(writingThreadId, is(Affinity.getThreadId()));
            assertThat(QueueInspector.isValidThreadId(writingThreadId), is(true));
        }
    }
}
Also used : ValueOut(net.openhft.chronicle.wire.ValueOut) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) Test(org.junit.Test)

Example 48 with ExcerptAppender

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

the class RollAtEndOfCycleTest method shouldAppendToExistingQueueFile.

@Test
public void shouldAppendToExistingQueueFile() throws Exception {
    try (final SingleChronicleQueue queue = createQueue()) {
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(1, (w, i) -> {
            w.int32(i);
        });
        final ExcerptTailer tailer = queue.createTailer();
        try (final DocumentContext context = tailer.readingDocument()) {
            assertTrue(context.isPresent());
        }
        assertQueueFileCount(queue.path.toPath(), 1);
        assertFalse(tailer.readingDocument().isPresent());
        appender.writeDocument(2, (w, i) -> {
            w.int32(i);
        });
        assertQueueFileCount(queue.path.toPath(), 1);
        try (final DocumentContext context = tailer.readingDocument()) {
            assertTrue(context.isPresent());
        }
    }
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 49 with ExcerptAppender

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

the class RollAtEndOfCycleTest method shouldRollAndAppendToNewFile.

@Test
public void shouldRollAndAppendToNewFile() throws Exception {
    try (final SingleChronicleQueue queue = createQueue()) {
        final ExcerptAppender appender = queue.acquireAppender();
        appender.writeDocument(1, (w, i) -> {
            w.int32(i);
        });
        final ExcerptTailer tailer = queue.createTailer();
        try (final DocumentContext context = tailer.readingDocument()) {
            assertTrue(context.isPresent());
        }
        assertQueueFileCount(queue.path.toPath(), 1);
        clock.addAndGet(TimeUnit.SECONDS.toMillis(2));
        assertFalse(tailer.readingDocument().isPresent());
        appender.writeDocument(2, (w, i) -> {
            w.int32(i);
        });
        assertQueueFileCount(queue.path.toPath(), 2);
        try (final DocumentContext context = tailer.readingDocument()) {
            assertTrue(context.isPresent());
        }
        final ExcerptTailer newTailer = queue.createTailer();
        int totalCount = 0;
        while (true) {
            final DocumentContext context = newTailer.readingDocument();
            if (context.isPresent() && context.isData()) {
                assertTrue(context.wire().read().int32() != 0);
                totalCount++;
            } else if (!context.isPresent()) {
                break;
            }
        }
        assertThat(totalCount, is(2));
    }
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 50 with ExcerptAppender

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

the class RollCycleRetrieverTest method shouldRetrieveCorrectRollCycleFromExistingQueueFile.

@Test
public void shouldRetrieveCorrectRollCycleFromExistingQueueFile() throws Exception {
    final File queuePath = tempDir(RollCycleRetrieverTest.class.getSimpleName() + System.nanoTime());
    final SingleChronicleQueueBuilder builder = builder(queuePath, WIRE_TYPE).testBlockSize().rollCycle(ROLL_CYCLE);
    try (final SingleChronicleQueue queue = builder.build()) {
        final ExcerptAppender appender = queue.acquireAppender();
        try (final DocumentContext context = appender.writingDocument()) {
            context.wire().write("foo").text("bar");
        }
    }
    assertThat(getRollCycle(queuePath.toPath(), WIRE_TYPE, builder.blockSize()).isPresent(), is(true));
    assertThat(getRollCycle(queuePath.toPath(), WIRE_TYPE, builder.blockSize()).get(), is(ROLL_CYCLE));
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) Test(org.junit.Test)

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