@@ -0,0 +1,3279 @@
+package net.openhft.chronicle.queue.impl.single;%0A%0Aimport net.openhft.chronicle.queue.DirectoryUtils;%0Aimport net.openhft.chronicle.queue.ExcerptAppender;%0Aimport net.openhft.chronicle.queue.ExcerptTailer;%0Aimport net.openhft.chronicle.queue.RollCycles;%0Aimport net.openhft.chronicle.wire.DocumentContext;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0A%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.TimeoutException;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0Aimport java.util.concurrent.atomic.AtomicLong;%0Aimport java.util.concurrent.locks.LockSupport;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0A@Ignore(%22WIP%22)%0Apublic final class DocumentOrderingTest %7B%0A    private final ExecutorService executorService = Executors.newCachedThreadPool();%0A    private final AtomicLong clock = new AtomicLong(System.currentTimeMillis());%0A    private final AtomicInteger counter = new AtomicInteger(0);%0A%0A    @Test%0A    public void codeWithinPriorDocumentMustExecuteBeforeSubsequentDocument() throws InterruptedException, ExecutionException, TimeoutException %7B%0A        try (final SingleChronicleQueue queue =%0A                     SingleChronicleQueueBuilder.binary(DirectoryUtils.tempDir(%22document-ordering%22)).%0A                             testBlockSize().rollCycle(RollCycles.TEST_SECONDLY).%0A                             timeProvider(clock::get).build()) %7B%0A%0A            final ExcerptAppender excerptAppender = queue.acquireAppender();%0A            final Future%3CBoolean%3E otherDocumentWriter;%0A            try (final DocumentContext documentContext = excerptAppender.writingDocument()) %7B%0A%0A                // move time to beyond the next cycle%0A                clock.addAndGet(TimeUnit.SECONDS.toMillis(2L));%0A%0A                otherDocumentWriter = executorService.submit(attemptToWriteDocument(queue));%0A%0A                // stall this thread, other thread should not be able to advance,%0A                // since this DocumentContext is still open%0A                LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(2L));%0A%0A                documentContext.wire().getValueOut().int32(counter.getAndIncrement());%0A            %7D%0A%0A            assertTrue(otherDocumentWriter.get(5L, TimeUnit.SECONDS));%0A%0A            final ExcerptTailer tailer = queue.createTailer();%0A            expectValue(0, tailer);%0A            expectValue(1, tailer);%0A        %7D%0A    %7D%0A%0A    private static void expectValue(final int expectedValue, final ExcerptTailer tailer) %7B%0A        try( final DocumentContext documentContext = tailer.readingDocument()) %7B%0A            assertTrue(documentContext.isPresent());%0A            assertEquals(expectedValue, documentContext.wire().getValueIn().int32());%0A        %7D%0A    %7D%0A%0A    private Callable%3CBoolean%3E attemptToWriteDocument(final SingleChronicleQueue queue) %7B%0A        return () -%3E %7B%0A            try (final DocumentContext documentContext = queue.acquireAppender().writingDocument()) %7B%0A                documentContext.wire().getValueOut().int32(counter.getAndIncrement());%0A            %7D%0A            return true;%0A        %7D;%0A    %7D%0A%7D

test documenting desired behaviour