Skip to content

Commit

Permalink
remove extra memory barrier in test asserting behaviour of memory bar…
Browse files Browse the repository at this point in the history
…riers
  • Loading branch information
epickrram committed Jun 14, 2017
1 parent eb7e0d6 commit f6271b8
Showing 1 changed file with 13 additions and 12 deletions.
Expand Up @@ -3463,30 +3463,31 @@ public void checkReferenceCountingWhenRollingAndCheckFileDeletion() throws IOExc
}
}


@Test
public void testWritingDocumentIsAtomic() {

ExecutorService executorService = Executors.newFixedThreadPool(8);
int maxCount = Short.MAX_VALUE;
final int threadCount = 8;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);

SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(getTmpDir()).build();
AtomicInteger counter = new AtomicInteger();
for (int i = 0; i < maxCount; i++) {
final int iterationsPerThread = Short.MAX_VALUE / 8;
final int totalIterations = iterationsPerThread * threadCount;
final int[] nonAtomicCounter = new int[] {0};
for (int i = 0; i < threadCount; i++) {
executorService.submit(() -> {
ExcerptAppender excerptAppender = queue.acquireAppender();
for (int j = 0; j < iterationsPerThread; j++) {
ExcerptAppender excerptAppender = queue.acquireAppender();

try (DocumentContext dc = excerptAppender.writingDocument()) {
int value = counter.getAndIncrement();
dc.wire().write("some key").int64(value);
try (DocumentContext dc = excerptAppender.writingDocument()) {
int value = nonAtomicCounter[0]++;
dc.wire().write("some key").int64(value);
}
}
});
}

ExcerptTailer tailer = queue.createTailer();
for (int expected = 0; expected < maxCount; expected++) {


for (int expected = 0; expected < totalIterations; expected++) {
for (; ; ) {
try (DocumentContext dc = tailer.readingDocument()) {
if (!dc.isPresent()) {
Expand Down

0 comments on commit f6271b8

Please sign in to comment.