@@ -0,0 +1,2521 @@
+package net.openhft.chronicle.queue.impl.single;%0A%0Aimport net.openhft.chronicle.queue.DirectoryUtils;%0Aimport net.openhft.chronicle.queue.ExcerptAppender;%0Aimport net.openhft.chronicle.wire.DocumentContext;%0Aimport org.junit.After;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0A%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A%0Apublic final class TailerSequenceRaceConditionTest %7B%0A    private final AtomicBoolean failedToMoveToEnd = new AtomicBoolean(false);%0A    private final ExecutorService threadPool = Executors.newFixedThreadPool(8);%0A%0A    @Ignore%0A    @Test%0A    public void shouldAlwaysBeAbleToTail() throws Exception %7B%0A        for (int i = 0; i %3C 10; i++) %7B%0A            final SingleChronicleQueue queue = createNewQueue();%0A            for (int j = 0; j %3C 4; j++) %7B%0A                threadPool.submit(() -%3E attemptToMoveToTail(queue));%0A            %7D%0A%0A            threadPool.submit(() -%3E appendToQueue(queue));%0A%0A            for (int j = 0; j %3C 4; j++) %7B%0A                threadPool.submit(() -%3E attemptToMoveToTail(queue));%0A            %7D%0A        %7D%0A%0A        threadPool.shutdown();%0A        assertThat(threadPool.awaitTermination(5L, TimeUnit.SECONDS), is(true));%0A        assertThat(failedToMoveToEnd.get(), is(false));%0A    %7D%0A%0A    @After%0A    public void tearDown() throws Exception %7B%0A        threadPool.shutdownNow();%0A    %7D%0A%0A    private void appendToQueue(final SingleChronicleQueue queue) %7B%0A        for (int i = 0; i %3C 31; i++) %7B%0A            final ExcerptAppender appender = queue.acquireAppender();%0A            if (queue.isClosed())%0A                return;%0A            try (final DocumentContext dc = appender.writingDocument()) %7B%0A                dc.wire().write(%22foo%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void attemptToMoveToTail(final SingleChronicleQueue queue) %7B%0A        final SingleChronicleQueueExcerpts.StoreTailer tailer =%0A                (SingleChronicleQueueExcerpts.StoreTailer) queue.createTailer();%0A        try %7B%0A            tailer.toEnd();%0A        %7D catch(IllegalStateException e) %7B%0A            e.printStackTrace();%0A            failedToMoveToEnd.set(true);%0A        %7D%0A    %7D%0A%0A    private SingleChronicleQueue createNewQueue() %7B%0A        return SingleChronicleQueueBuilder.%0A                binary(DirectoryUtils.tempDir(TailerSequenceRaceConditionTest.class.getSimpleName())).build();%0A    %7D%0A%7D%0A

add test that exhibits failure to reach end of existing queue