Search in sources :

Example 1 with NamedThreadFactory

use of net.openhft.chronicle.threads.NamedThreadFactory 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)

Aggregations

IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)1 ChronicleQueueTestBase (net.openhft.chronicle.queue.ChronicleQueueTestBase)1 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)1 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)1 NamedThreadFactory (net.openhft.chronicle.threads.NamedThreadFactory)1 WireType (net.openhft.chronicle.wire.WireType)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1