Search in sources :

Example 16 with ChronicleQueue

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

the class SingleChronicleQueueCloseTest method testTailAfterClose.

@Test
public void testTailAfterClose() {
    final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(getTmpDir(), WireType.BINARY).build();
    final ExcerptAppender appender = queue.acquireAppender();
    appender.writeDocument(w -> w.write(TestKey.test).int32(1));
    queue.close();
    try {
        appender.writeDocument(w -> w.write(TestKey.test).int32(2));
        Assert.fail();
    } catch (IllegalStateException e) {
    // ok
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Test(org.junit.Test)

Example 17 with ChronicleQueue

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

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

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

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

the class Queue36Test method testTail.

@Test
public void testTail() throws IOException {
    File basePath = getTmpDir();
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath).testBlockSize().build()) {
        checkNoFiles(basePath);
        ExcerptTailer tailer = queue.createTailer();
        checkNoFiles(basePath);
        tailer.toStart();
        checkNoFiles(basePath);
        assertFalse(tailer.readDocument(d -> {
        }));
        checkNoFiles(basePath);
    }
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) ChronicleQueueTestBase(net.openhft.chronicle.queue.ChronicleQueueTestBase) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) 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