Skip to content

Commit

Permalink
update test assertion + name
Browse files Browse the repository at this point in the history
  • Loading branch information
epickrram committed Jan 3, 2018
1 parent ee1e1be commit 44b4617
Showing 1 changed file with 6 additions and 19 deletions.
Expand Up @@ -8,7 +8,6 @@
import net.openhft.chronicle.wire.ValueOut; import net.openhft.chronicle.wire.ValueOut;
import org.junit.After; import org.junit.After;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -47,9 +46,8 @@ public DocumentOrderingTest(final String testType, final boolean progressOnConte
this.progressOnContention = progressOnContention; this.progressOnContention = progressOnContention;
} }


@Ignore("WIP")
@Test @Test
public void queuedWriteInPreviousCycleShouldBeAppendedToNewCycle() throws Exception { public void queuedWriteInPreviousCycleShouldRespectTotalOrdering() throws Exception {
try (final SingleChronicleQueue queue = try (final SingleChronicleQueue queue =
builder(DirectoryUtils.tempDir("document-ordering"), 1_000L).build()) { builder(DirectoryUtils.tempDir("document-ordering"), 1_000L).build()) {
Assume.assumeFalse( Assume.assumeFalse(
Expand All @@ -67,8 +65,7 @@ public void queuedWriteInPreviousCycleShouldBeAppendedToNewCycle() throws Except
firstOpenDocument.wire().getValueOut().int32(counter.getAndIncrement()); firstOpenDocument.wire().getValueOut().int32(counter.getAndIncrement());


// start another record in the first cycle file // start another record in the first cycle file
// this will actually be written to the second cycle file, since it will wait for // this may be written to either the first or the second cycle file
// firstOpenDocument to be completed/timed out
final Future<RecordInfo> secondDocumentInFirstCycle = attemptToWriteDocument(queue); final Future<RecordInfo> secondDocumentInFirstCycle = attemptToWriteDocument(queue);


// move time to beyond the next cycle // move time to beyond the next cycle
Expand All @@ -77,17 +74,12 @@ public void queuedWriteInPreviousCycleShouldBeAppendedToNewCycle() throws Except
final Future<RecordInfo> otherDocumentWriter = attemptToWriteDocument(queue); final Future<RecordInfo> otherDocumentWriter = attemptToWriteDocument(queue);


firstOpenDocument.close(); firstOpenDocument.close();

secondDocumentInFirstCycle.get(5L, TimeUnit.SECONDS);
// assert that queued record (secondDocumentInFirstCycle) is actually written to the second cycle file
assertEquals(secondDocumentInFirstCycle.get(5L, TimeUnit.SECONDS).cycle,
otherDocumentWriter.get(5L, TimeUnit.SECONDS).cycle);

final ExcerptTailer tailer = queue.createTailer(); final ExcerptTailer tailer = queue.createTailer();
// discard first record // discard first record
tailer.readingDocument().close(); tailer.readingDocument().close();


// intermittently fails - cannot rely on ordering, only exclusivity // assert that records are committed in order

expectValue(0, tailer); expectValue(0, tailer);
expectValue(1, tailer); expectValue(1, tailer);
expectValue(2, tailer); expectValue(2, tailer);
Expand Down Expand Up @@ -253,15 +245,12 @@ private Future<RecordInfo> attemptToWriteDocument(final SingleChronicleQueue que
final CountDownLatch startedLatch = new CountDownLatch(1); final CountDownLatch startedLatch = new CountDownLatch(1);
final Future<RecordInfo> future = executorService.submit(() -> { final Future<RecordInfo> future = executorService.submit(() -> {
final int counterValue; final int counterValue;
DocumentContext outer;
startedLatch.countDown(); startedLatch.countDown();
try (final DocumentContext documentContext = queue.acquireAppender().writingDocument()) { try (final DocumentContext documentContext = queue.acquireAppender().writingDocument()) {
counterValue = counter.getAndIncrement(); counterValue = counter.getAndIncrement();
documentContext.wire().getValueOut().int32(counterValue); documentContext.wire().getValueOut().int32(counterValue);
outer = documentContext;
} }
final long index = outer.index(); return new RecordInfo(counterValue);
return new RecordInfo(counterValue, ROLL_CYCLE.toCycle(index));
}); });
assertTrue("Task did not start", startedLatch.await(1, TimeUnit.MINUTES)); assertTrue("Task did not start", startedLatch.await(1, TimeUnit.MINUTES));
return future; return future;
Expand All @@ -276,11 +265,9 @@ private SingleChronicleQueueBuilder builder(final File dir, final long timeoutMS


private static final class RecordInfo { private static final class RecordInfo {
private final int counterValue; private final int counterValue;
private final int cycle;


RecordInfo(final int counterValue, final int cycle) { RecordInfo(final int counterValue) {
this.counterValue = counterValue; this.counterValue = counterValue;
this.cycle = cycle;
} }
} }
} }

0 comments on commit 44b4617

Please sign in to comment.