Search in sources :

Example 56 with ExcerptAppender

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

the class ToEndTest method toEndBeforeWriteTest.

@Test
public void toEndBeforeWriteTest() {
    File baseDir = DirectoryUtils.tempDir("toEndBeforeWriteTest");
    IOTools.shallowDeleteDirWithFiles(baseDir);
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(baseDir).testBlockSize().build()) {
        checkOneFile(baseDir);
        // if this appender isn't created, the tailer toEnd doesn't cause a roll.
        ExcerptAppender appender = queue.acquireAppender();
        checkOneFile(baseDir);
        ExcerptTailer tailer = queue.createTailer();
        checkOneFile(baseDir);
        ExcerptTailer tailer2 = queue.createTailer();
        checkOneFile(baseDir);
        tailer.toEnd();
        checkOneFile(baseDir);
        tailer2.toEnd();
        checkOneFile(baseDir);
    }
    System.gc();
    /*for (int i = 0; i < 10; i++) {
            final int j = i;
            appender.writeDocument(wire -> wire.write(() -> "msg").int32(j));
        }*/
    IOTools.shallowDeleteDirWithFiles(baseDir);
}
Also used : RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 57 with ExcerptAppender

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

the class Queue30Test method testMT.

@Ignore("Stress test - doesn't finish")
@Test
public void testMT() throws IOException, InterruptedException {
    try (final ChronicleQueue queue = SingleChronicleQueueBuilder.text(getTmpDir()).blockSize(640_000).build()) {
        ExecutorService exec = Executors.newCachedThreadPool(new NamedThreadFactory("stress"));
        Throwable[] tref = { null };
        Runnable r = () -> {
            try {
                final String name = Thread.currentThread().getName();
                final ExcerptAppender appender = queue.acquireAppender();
                for (int count = 0; !Thread.currentThread().isInterrupted(); count++) {
                    final int c = count;
                    appender.writeDocument(w -> w.write(() -> "thread").text(name).write(() -> "count").int32(c));
                    if (count % 10_000 == 0) {
                        LOGGER.info(name + "> " + count);
                    }
                }
            } catch (Throwable t) {
                tref[0] = t;
                exec.shutdown();
            }
        };
        for (int i = 0; i < 100; i++) exec.submit(r);
        exec.awaitTermination(10, TimeUnit.MINUTES);
        exec.shutdownNow();
        if (tref[0] != null)
            throw new AssertionError(tref[0]);
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) ChronicleQueueTestBase(net.openhft.chronicle.queue.ChronicleQueueTestBase) Ignore(org.junit.Ignore) NamedThreadFactory(net.openhft.chronicle.threads.NamedThreadFactory) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Test(org.junit.Test) IOException(java.io.IOException) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) WireType(net.openhft.chronicle.wire.WireType) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) NamedThreadFactory(net.openhft.chronicle.threads.NamedThreadFactory) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) ExecutorService(java.util.concurrent.ExecutorService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with ExcerptAppender

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

the class Queue30Test method testST.

@SuppressWarnings("InfiniteLoopStatement")
@Ignore("Stress test - doesn't finish")
@Test
public void testST() throws IOException {
    try (final ChronicleQueue queue = new SingleChronicleQueueBuilder(getTmpDir()).wireType(WireType.TEXT).blockSize(640_000).build()) {
        final String name = Thread.currentThread().getName();
        final ExcerptAppender appender = queue.acquireAppender();
        for (int count = 0; ; count++) {
            final int c = count;
            appender.writeDocument(w -> w.write(() -> "thread").text(name).write(() -> "count").int32(c));
            if (count % 50_000 == 0) {
                LOGGER.info(name + "> " + count);
            }
        }
    }
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with ExcerptAppender

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

the class ChronicleReaderTest method shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader.

@Test(timeout = 10_000L)
public void shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader() throws IOException, InterruptedException {
    Path path = DirectoryUtils.tempDir("shouldReadQueueWithDifferentRollCycleWhenCreatedAfterReader").toPath();
    path.toFile().mkdirs();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicLong recordsProcessed = new AtomicLong(0);
    final ChronicleReader reader = new ChronicleReader().withBasePath(path).withMessageSink(m -> {
        latch.countDown();
        recordsProcessed.incrementAndGet();
    });
    final AtomicReference<Throwable> readerException = new AtomicReference<>();
    final CountDownLatch executeLatch = new CountDownLatch(1);
    final Thread readerThread = new Thread(() -> {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                reader.execute();
                executeLatch.countDown();
            } catch (Throwable t) {
                readerException.set(t);
                throw t;
            }
        }
    });
    readerThread.start();
    assertTrue(executeLatch.await(5, TimeUnit.SECONDS));
    assertTrue(capturedOutput.isEmpty());
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).build()) {
        final ExcerptAppender excerptAppender = queue.acquireAppender();
        final MethodWriterBuilder<StringEvents> methodWriterBuilder = excerptAppender.methodWriterBuilder(StringEvents.class);
        methodWriterBuilder.recordHistory(true);
        final StringEvents events = methodWriterBuilder.build();
        for (int i = 0; i < 24; i++) {
            events.say(i % 2 == 0 ? "hello" : "goodbye");
        }
    }
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    while (recordsProcessed.get() < 10) {
        LockSupport.parkNanos(1L);
    }
    readerThread.interrupt();
    assertThat(readerException.get(), is(nullValue()));
}
Also used : Path(java.nio.file.Path) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) Test(org.junit.Test)

Example 60 with ExcerptAppender

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

the class RollEOFTest method createQueueAndWriteData.

private void createQueueAndWriteData(MutableTimeProvider timeProvider) {
    final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeProvider(timeProvider).build();
    ExcerptAppender excerptAppender = queue.acquireAppender();
    try (DocumentContext dc = excerptAppender.writingDocument(false)) {
        dc.wire().write(() -> "test").int64(0);
    }
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) DocumentContext(net.openhft.chronicle.wire.DocumentContext)

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