You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2018/07/12 15:37:41 UTC

[03/11] james-project git commit: JAMES-2464 ConcurrentTestRunner should use a builder

JAMES-2464 ConcurrentTestRunner should use a builder

This allows:
 - Removing the confusion between threadCount & operationCount
 - Allow a default value for operationCount (1)


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/68e03ede
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/68e03ede
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/68e03ede

Branch: refs/heads/master
Commit: 68e03edea6c088cdb454f5277c694054e1ae4e9a
Parents: 751e4fc
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 11 10:10:21 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 12 10:50:53 2018 +0700

----------------------------------------------------------------------
 .../CassandraMailboxMapperConcurrencyTest.java  |  12 +-
 .../QuotaThresholdMailingIntegrationTest.java   |   5 +-
 .../store/mail/model/MessageIdMapperTest.java   |  16 ++-
 .../store/mail/model/MessageMapperTest.java     |  16 ++-
 .../mailbox/tika/CachingTextExtractorTest.java  |   7 +-
 .../processor/base/UidMsnConverterTest.java     |  25 ++--
 .../protocols/smtp/AbstractSMTPServerTest.java  |  15 +-
 .../utils/InMemoryMailRepositoryStoreTest.java  |   6 +-
 .../util/concurrency/ConcurrentTestRunner.java  |  46 +++++-
 .../concurrency/ConcurrentTestRunnerTest.java   | 142 +++++++++----------
 .../api/MailRepositoryUrlStoreContract.java     |  13 +-
 .../mailrepository/MailRepositoryContract.java  |   8 +-
 .../org/apache/james/jmap/ProvisioningTest.java |   5 +-
 .../DefaultMailboxesProvisioningFilterTest.java |   7 +-
 14 files changed, 190 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
index cceb4f3..8f99a59 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
@@ -67,8 +67,10 @@ public class CassandraMailboxMapperConcurrencyTest {
 
     @Test
     public void saveShouldBeThreadSafe() throws Exception {
-        boolean termination = new ConcurrentTestRunner(THREAD_COUNT, OPERATION_COUNT,
-            (a, b) -> testee.save(new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY)))
+        boolean termination = ConcurrentTestRunner.builder()
+            .threadCount(THREAD_COUNT)
+            .operationCount(OPERATION_COUNT)
+            .build((a, b) -> testee.save(new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY)))
             .run()
             .awaitTermination(1, TimeUnit.MINUTES);
 
@@ -83,8 +85,10 @@ public class CassandraMailboxMapperConcurrencyTest {
 
         mailbox.setName("newName");
 
-        boolean termination = new ConcurrentTestRunner(THREAD_COUNT, OPERATION_COUNT,
-            (a, b) -> testee.save(mailbox))
+        boolean termination = ConcurrentTestRunner.builder()
+            .threadCount(THREAD_COUNT)
+            .operationCount(OPERATION_COUNT)
+            .build((a, b) -> testee.save(mailbox))
             .run()
             .awaitTermination(1, TimeUnit.MINUTES);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
index 2dbc69b..964570c 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
@@ -211,8 +211,9 @@ public interface QuotaThresholdMailingIntegrationTest {
                 .gracePeriod(GRACE_PERIOD)
                 .build());
 
-        new ConcurrentTestRunner(10, 1, (threadNb, step) ->
-            testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW)))
+        ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .build((threadNb, step) -> testee.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW)))
             .run()
             .awaitTermination(1, TimeUnit.MINUTES);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
index afafc1d..db3cd6e 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
@@ -677,8 +677,10 @@ public abstract class MessageIdMapperTest {
 
         int threadCount = 2;
         int updateCount = 10;
-        assertThat(new ConcurrentTestRunner(threadCount, updateCount,
-            (threadNumber, step) -> sut.setFlags(message1.getMessageId(),
+        assertThat(ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(updateCount)
+            .build((threadNumber, step) -> sut.setFlags(message1.getMessageId(),
                 ImmutableList.of(message1.getMailboxId()),
                 new Flags("custom-" + threadNumber + "-" + step),
                 FlagsUpdateMode.ADD)).run()
@@ -697,10 +699,12 @@ public abstract class MessageIdMapperTest {
         message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
         sut.save(message1);
 
-        final int threadCount = 4;
-        final int updateCount = 20;
-        assertThat(new ConcurrentTestRunner(threadCount, updateCount,
-            (threadNumber, step) -> {
+        int threadCount = 4;
+        int updateCount = 20;
+        assertThat(ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(updateCount)
+            .build((threadNumber, step) -> {
                 if (step  < updateCount / 2) {
                     sut.setFlags(message1.getMessageId(),
                         ImmutableList.of(message1.getMailboxId()),

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 5dc3105..a993d81 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -796,8 +796,10 @@ public abstract class MessageMapperTest {
 
         int threadCount = 2;
         int updateCount = 10;
-        assertThat(new ConcurrentTestRunner(threadCount, updateCount,
-            (threadNumber, step) -> messageMapper.updateFlags(benwaInboxMailbox,
+        assertThat(ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(updateCount)
+            .build((threadNumber, step) -> messageMapper.updateFlags(benwaInboxMailbox,
                 new FlagsUpdateCalculator(new Flags("custom-" + threadNumber + "-" + step), FlagsUpdateMode.ADD),
                 MessageRange.one(message1.getUid()))).run()
             .awaitTermination(1, TimeUnit.MINUTES))
@@ -814,10 +816,12 @@ public abstract class MessageMapperTest {
         Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(MapperProvider.Capabilities.THREAD_SAFE_FLAGS_UPDATE));
         saveMessages();
 
-        final int threadCount = 4;
-        final int updateCount = 20;
-        assertThat(new ConcurrentTestRunner(threadCount, updateCount,
-            (threadNumber, step) -> {
+        int threadCount = 4;
+        int updateCount = 20;
+        assertThat(ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(updateCount)
+            .build((threadNumber, step) -> {
                 if (step  < updateCount / 2) {
                     messageMapper.updateFlags(benwaInboxMailbox,
                         new FlagsUpdateCalculator(new Flags("custom-" + threadNumber + "-" + step), FlagsUpdateMode.ADD),

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
index e5b4d02..1cc2a40 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
@@ -185,10 +185,9 @@ public class CachingTextExtractorTest {
 
     @RepeatedTest(10)
     void concurrentValueComputationShouldNotLeadToDuplicatedBackendAccess() throws Exception {
-        int concurrentThreadCount = 10;
-        int operationCount = 1;
-        new ConcurrentTestRunner(concurrentThreadCount, operationCount,
-            (a, b) -> textExtractor.extractContent(INPUT_STREAM.get(), CONTENT_TYPE))
+        ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .build((a, b) -> textExtractor.extractContent(INPUT_STREAM.get(), CONTENT_TYPE))
             .run()
             .awaitTermination(1, TimeUnit.MINUTES);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/protocols/imap/src/test/java/org/apache/james/imap/processor/base/UidMsnConverterTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/UidMsnConverterTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/UidMsnConverterTest.java
index e793adc..9da76ae 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/UidMsnConverterTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/UidMsnConverterTest.java
@@ -365,14 +365,15 @@ public class UidMsnConverterTest {
 
     @Test
     public void addAndRemoveShouldLeadToMonoticMSNToUIDConversionWhenMixed() throws Exception {
-        final int initialCount = 1000;
+        int initialCount = 1000;
         for (int i = 1; i <= initialCount; i++) {
             testee.addUid(MessageUid.of(i));
         }
 
-        int threadCount = 2;
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, initialCount,
-            (threadNumber, step) -> {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(initialCount)
+            .build((threadNumber, step) -> {
                 if (threadNumber == 0) {
                     testee.remove(MessageUid.of(step + 1));
                 } else {
@@ -392,11 +393,13 @@ public class UidMsnConverterTest {
 
     @Test
     public void addShouldLeadToMonoticMSNToUIDConversionWhenConcurrent() throws Exception {
-        final int operationCount = 1000;
+        int operationCount = 1000;
         int threadCount = 2;
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> testee.addUid(MessageUid.of((threadNumber * operationCount) + (step + 1))));
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(operationCount)
+            .build((threadNumber, step) -> testee.addUid(MessageUid.of((threadNumber * operationCount) + (step + 1))));
         concurrentTestRunner.run();
         concurrentTestRunner.awaitTermination(10, TimeUnit.SECONDS);
 
@@ -410,14 +413,16 @@ public class UidMsnConverterTest {
 
     @Test
     public void removeShouldLeadToMonoticMSNToUIDConversionWhenConcurrent() throws Exception {
-        final int operationCount = 1000;
+        int operationCount = 1000;
         int threadCount = 2;
         for (int i = 1; i <= operationCount * (threadCount + 1); i++) {
             testee.addUid(MessageUid.of(i));
         }
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> testee.remove(MessageUid.of((threadNumber * operationCount) + (step + 1))));
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(operationCount)
+            .build((threadNumber, step) -> testee.remove(MessageUid.of((threadNumber * operationCount) + (step + 1))));
         concurrentTestRunner.run();
         concurrentTestRunner.awaitTermination(10, TimeUnit.SECONDS);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
index 966347e..e6891eb 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
@@ -99,13 +99,14 @@ public abstract class AbstractSMTPServerTest {
             server = createServer(createProtocol(hook));
             server.bind();
 
-            final ProtocolServer finalServer = server;
-            final InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
-            final String mailContent = CharStreams.toString(new InputStreamReader(ClassLoader.getSystemResourceAsStream("a50.eml"), StandardCharsets.US_ASCII));
-            int threadCount = 4;
-            int updateCount = 1;
-            assertThat(new ConcurrentTestRunner(threadCount, updateCount,
-                (threadNumber, step) -> send(finalServer, bindedAddress, mailContent)).run()
+            ProtocolServer finalServer = server;
+            InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
+            String mailContent = CharStreams.toString(new InputStreamReader(ClassLoader.getSystemResourceAsStream("a50.eml"), StandardCharsets.US_ASCII));
+
+            assertThat(ConcurrentTestRunner.builder()
+                .threadCount(4)
+                .build((threadNumber, step) -> send(finalServer, bindedAddress, mailContent))
+                .run()
                 .awaitTermination(1, TimeUnit.MINUTES))
                 .isTrue();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
index 5ad89e4..cb6cb00 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
@@ -240,10 +240,10 @@ public class InMemoryMailRepositoryStoreTest {
     public void selectShouldNotReturnDifferentResultsWhenUsedInAConcurrentEnvironment() throws Exception {
         MailRepositoryUrl url = MailRepositoryUrl.from("memory://repo");
         int threadCount = 10;
-        int operationCount = 1;
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNb, operationNb) -> repositoryStore.select(url)
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .build((threadNb, operationNb) -> repositoryStore.select(url)
                 .store(FakeMail.builder()
                     .name("name" + threadNb)
                     .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
index 23fd57c..0efb525 100644
--- a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
+++ b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
@@ -21,6 +21,7 @@ package org.apache.james.util.concurrency;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -35,7 +36,39 @@ import com.google.common.base.Preconditions;
 
 public class ConcurrentTestRunner {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentTestRunner.class);
+    public static final int DEFAULT_OPERATION_COUNT = 1;
+
+    public static class Builder {
+        private Optional<Integer> threadCount;
+        private Optional<Integer>  operationCount;
+
+        public Builder() {
+            threadCount = Optional.empty();
+            operationCount = Optional.empty();
+        }
+
+        public Builder threadCount(int threadCount) {
+            Preconditions.checkArgument(threadCount > 0, "Thread count should be strictly positive");
+            this.threadCount = Optional.of(threadCount);
+            return this;
+        }
+
+        public Builder operationCount(int operationCount) {
+            Preconditions.checkArgument(operationCount > 0, "Operation count should be strictly positive");
+            this.operationCount = Optional.of(operationCount);
+            return this;
+        }
+
+        public ConcurrentTestRunner build(BiConsumer operation) {
+            Preconditions.checkState(threadCount.isPresent(), "'threadCount' is compulsory");
+            Preconditions.checkNotNull(operation);
+
+            return new ConcurrentTestRunner(
+                threadCount.get(),
+                operationCount.orElse(DEFAULT_OPERATION_COUNT),
+                operation);
+        }
+    }
 
     public interface BiConsumer {
         void consume(int threadNumber, int step) throws Exception;
@@ -69,6 +102,12 @@ public class ConcurrentTestRunner {
         }
     }
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentTestRunner.class);
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
     private final int threadCount;
     private final int operationCount;
     private final CountDownLatch countDownLatch;
@@ -76,10 +115,7 @@ public class ConcurrentTestRunner {
     private final ExecutorService executorService;
     private final List<Future<?>> futures;
 
-    public ConcurrentTestRunner(int threadCount, int operationCount, BiConsumer biConsumer) {
-        Preconditions.checkArgument(threadCount > 0, "Thread count should be strictly positive");
-        Preconditions.checkArgument(operationCount > 0, "Operation count should be strictly positive");
-        Preconditions.checkNotNull(biConsumer);
+    private ConcurrentTestRunner(int threadCount, int operationCount, BiConsumer biConsumer) {
         this.threadCount = threadCount;
         this.operationCount = operationCount;
         this.countDownLatch = new CountDownLatch(threadCount);

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java b/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
index 4a03fe1..5eac926 100644
--- a/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
+++ b/server/container/util/src/test/java/org/apache/james/util/concurrency/ConcurrentTestRunnerTest.java
@@ -20,74 +20,64 @@
 package org.apache.james.util.concurrency;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class ConcurrentTestRunnerTest {
-
     public static final ConcurrentTestRunner.BiConsumer EMPTY_BI_CONSUMER = (threadNumber, step) -> { };
     public static final int DEFAULT_AWAIT_TIME = 100;
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     @Test
     public void constructorShouldThrowOnNegativeThreadCount() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        int operationCount = 1;
-        int threadCount = -1;
-        new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER);
+        assertThatThrownBy(() ->
+            ConcurrentTestRunner.builder()
+                .threadCount(-1))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void constructorShouldThrowOnNegativeOperationCount() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        int operationCount = -1;
-        int threadCount = 1;
-        new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER);
+        assertThatThrownBy(() ->
+            ConcurrentTestRunner.builder()
+                .operationCount(-1))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void constructorShouldThrowOnZeroThreadCount() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        int operationCount = 1;
-        int threadCount = 0;
-        new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER);
+        assertThatThrownBy(() ->
+            ConcurrentTestRunner.builder()
+                .threadCount(0))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void constructorShouldThrowOnZeroOperationCount() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        int operationCount = 0;
-        int threadCount = 1;
-        new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER);
+        assertThatThrownBy(() ->
+            ConcurrentTestRunner.builder()
+                .operationCount(0))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void constructorShouldThrowOnNullBiConsumer() {
-        expectedException.expect(NullPointerException.class);
-
-        int operationCount = 1;
-        int threadCount = 1;
-        new ConcurrentTestRunner(threadCount, operationCount, null);
+        assertThatThrownBy(() ->
+            ConcurrentTestRunner.builder()
+                .threadCount(1)
+                .build(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
     public void awaitTerminationShouldReturnTrueWhenFinished() throws Exception {
-        int operationCount = 1;
-        int threadCount = 1;
-
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER)
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(1)
+            .build(EMPTY_BI_CONSUMER)
             .run();
 
         assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
@@ -95,12 +85,11 @@ public class ConcurrentTestRunnerTest {
 
     @Test
     public void awaitTerminationShouldReturnFalseWhenNotFinished() throws Exception {
-        int operationCount = 1;
-        int threadCount = 1;
-        final int sleepDelay = 50;
+        int sleepDelay = 50;
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> Thread.sleep(sleepDelay))
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(1)
+            .build((threadNumber, step) -> Thread.sleep(sleepDelay))
             .run();
 
         assertThat(concurrentTestRunner.awaitTermination(sleepDelay / 2, TimeUnit.MILLISECONDS)).isFalse();
@@ -108,12 +97,12 @@ public class ConcurrentTestRunnerTest {
 
     @Test
     public void runShouldPerformAllOperations() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
-        final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
+        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> queue.add(threadNumber + ":" + step))
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build((threadNumber, step) -> queue.add(threadNumber + ":" + step))
             .run();
 
         assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
@@ -121,12 +110,24 @@ public class ConcurrentTestRunnerTest {
     }
 
     @Test
-    public void runShouldNotThrowOnExceptions() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
+    public void operationCountShouldDefaultToOne() throws Exception {
+        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .build((threadNumber, step) -> queue.add(threadNumber + ":" + step))
+            .run();
+
+        assertThat(concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)).isTrue();
+        assertThat(queue).containsOnly("0:0", "1:0");
+    }
+
+    @Test
+    public void runShouldNotThrowOnExceptions() throws Exception {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build((threadNumber, step) -> {
                 throw new RuntimeException();
             })
             .run();
@@ -136,10 +137,10 @@ public class ConcurrentTestRunnerTest {
 
     @Test
     public void noExceptionsShouldNotThrowWhenNoExceptionGenerated() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
-
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount, EMPTY_BI_CONSUMER)
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build(EMPTY_BI_CONSUMER)
             .run();
 
         concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS);
@@ -149,28 +150,27 @@ public class ConcurrentTestRunnerTest {
 
     @Test
     public void assertNoExceptionShouldThrowOnExceptions() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
-
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build((threadNumber, step) -> {
                 throw new RuntimeException();
             })
             .run();
         concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS);
 
-        expectedException.expect(ExecutionException.class);
-        concurrentTestRunner.assertNoException();
+        assertThatThrownBy(concurrentTestRunner::assertNoException)
+            .isInstanceOf(ExecutionException.class);
     }
 
     @Test
     public void runShouldPerformAllOperationsEvenOnExceptions() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
-        final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
+        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build((threadNumber, step) -> {
                 queue.add(threadNumber + ":" + step);
                 throw new RuntimeException();
             })
@@ -182,12 +182,12 @@ public class ConcurrentTestRunnerTest {
 
     @Test
     public void runShouldPerformAllOperationsEvenOnOccasionalExceptions() throws Exception {
-        int operationCount = 2;
-        int threadCount = 2;
-        final ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
+        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> {
+        ConcurrentTestRunner concurrentTestRunner = ConcurrentTestRunner.builder()
+            .threadCount(2)
+            .operationCount(2)
+            .build((threadNumber, step) -> {
                 queue.add(threadNumber + ":" + step);
                 if ((threadNumber + step) % 2 == 0) {
                     throw new RuntimeException();

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java b/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
index 8260deb..9bbe365 100644
--- a/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
+++ b/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
@@ -74,8 +74,10 @@ public interface MailRepositoryUrlStoreContract {
     default void addShouldWorkInConcurrentEnvironment(MailRepositoryUrlStore store) throws Exception {
         int operationCount = 10;
         int threadCount = 10;
-        ConcurrentTestRunner testRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (a, b) -> store.add(MailRepositoryUrl.from("proto://" + a + "/" + b)))
+        ConcurrentTestRunner testRunner = ConcurrentTestRunner.builder()
+            .threadCount(threadCount)
+            .operationCount(operationCount)
+            .build((a, b) -> store.add(MailRepositoryUrl.from("proto://" + a + "/" + b)))
             .run();
         testRunner.awaitTermination(1, TimeUnit.MINUTES);
         testRunner.assertNoException();
@@ -86,9 +88,10 @@ public interface MailRepositoryUrlStoreContract {
     @Test
     default void addShouldNotAddDuplicatesInConcurrentEnvironment(MailRepositoryUrlStore store) throws Exception {
         int operationCount = 10;
-        int threadCount = 10;
-        ConcurrentTestRunner testRunner = new ConcurrentTestRunner(threadCount, operationCount,
-            (a, b) -> store.add(MailRepositoryUrl.from("proto://" + b)))
+        ConcurrentTestRunner testRunner = ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .operationCount(operationCount)
+            .build((a, b) -> store.add(MailRepositoryUrl.from("proto://" + b)))
             .run();
         testRunner.awaitTermination(1, TimeUnit.MINUTES);
         testRunner.assertNoException();

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
index d56dee9..3ed562b 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
@@ -381,8 +381,6 @@ public interface MailRepositoryContract {
     default void storingAndRemovingMessagesConcurrentlyShouldLeadToConsistentResult() throws Exception {
         MailRepository testee = retrieveRepository();
         int nbKeys = 20;
-        int nbIterations = 10;
-        int threadCount = 10;
         ConcurrentHashMap.KeySetView<MailKey, Boolean> expectedResult = ConcurrentHashMap.newKeySet();
         List<Object> locks = IntStream.range(0, 10)
             .boxed()
@@ -412,8 +410,10 @@ public interface MailRepositoryContract {
                 new DistributionEntry<>(add, 0.25),
                 new DistributionEntry<>(remove, 0.75)));
 
-        new ConcurrentTestRunner(threadCount, nbIterations,
-            (a, b) -> distribution.sample().run())
+        ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .operationCount(10)
+            .build((a, b) -> distribution.sample().run())
             .run()
             .awaitTermination(1, TimeUnit.MINUTES);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ProvisioningTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ProvisioningTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ProvisioningTest.java
index e5d49a5..7194ad4 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ProvisioningTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ProvisioningTest.java
@@ -78,8 +78,9 @@ public abstract class ProvisioningTest {
     public void provisionMailboxesShouldNotDuplicateMailboxByName() throws Exception {
         String token = authenticateJamesUser(baseUri(jmapServer), USER, PASSWORD).serialize();
 
-        boolean termination = new ConcurrentTestRunner(10, 1,
-            (a, b) -> with()
+        boolean termination = ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .build((a, b) -> with()
                 .header("Authorization", token)
                 .body("[[\"getMailboxes\", {}, \"#0\"]]")
                 .post("/jmap"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/68e03ede/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
index 08522f1..ea0dd1f 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
@@ -89,10 +89,9 @@ public class DefaultMailboxesProvisioningFilterTest {
 
     @Test
     public void createMailboxesIfNeededShouldNotGenerateExceptionsInConcurrentEnvironment() throws Exception {
-        int threadCount = 10;
-        int operationCount = 1;
-        new ConcurrentTestRunner(threadCount, operationCount,
-            (threadNumber, step) -> testee.createMailboxesIfNeeded(session))
+        ConcurrentTestRunner.builder()
+            .threadCount(10)
+            .build((threadNumber, step) -> testee.createMailboxesIfNeeded(session))
             .run()
             .assertNoException()
             .awaitTermination(10, TimeUnit.SECONDS);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org