JAMES-2541 remove ConcurrentTestRunner.Builder.{build,run}

        These two methods are useless because we never create
        the Builder without building it and we never want to
        run without a timeout


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

Branch: refs/heads/master
Commit: 7134fcf41bc360b4686b63b910076fc6da3cdca3
Parents: d131ed0
Author: Matthieu Baechler <[email protected]>
Authored: Tue Sep 11 15:30:20 2018 +0200
Committer: Benoit Tellier <[email protected]>
Committed: Thu Oct 4 15:12:08 2018 +0700

----------------------------------------------------------------------
 .../util/concurrency/ConcurrentTestRunner.java  |   4 +-
 .../concurrency/ConcurrentTestRunnerTest.java   | 147 ++++++++-----------
 2 files changed, 62 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7134fcf4/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 eb24bb0..b0d474e 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
@@ -53,7 +53,7 @@ public class ConcurrentTestRunner {
         private final ConcurrentOperation operation;
         private Optional<Integer> operationCount;
 
-        public Builder(int threadCount, ConcurrentOperation operation) {
+        private Builder(int threadCount, ConcurrentOperation operation) {
             Preconditions.checkArgument(threadCount > 0, "Thread count should 
be strictly positive");
             Preconditions.checkNotNull(operation);
 
@@ -68,7 +68,7 @@ public class ConcurrentTestRunner {
             return this;
         }
 
-        public ConcurrentTestRunner build() {
+        private ConcurrentTestRunner build() {
             return new ConcurrentTestRunner(
                 threadCount,
                 operationCount.orElse(DEFAULT_OPERATION_COUNT),

http://git-wip-us.apache.org/repos/asf/james-project/blob/7134fcf4/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 4ca59d9..3e9902f 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
@@ -39,7 +39,7 @@ public class ConcurrentTestRunnerTest {
             ConcurrentTestRunner.builder()
                 .operation(NOOP)
                 .threadCount(-1)
-                .build())
+                .runSuccessfullyWithin(1, TimeUnit.SECONDS))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
@@ -59,7 +59,7 @@ public class ConcurrentTestRunnerTest {
             ConcurrentTestRunner.builder()
                 .operation(NOOP)
                 .threadCount(0)
-                .build())
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
@@ -79,33 +79,25 @@ public class ConcurrentTestRunnerTest {
             ConcurrentTestRunner.builder()
                 .operation(null)
                 .threadCount(1)
-                .build())
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
     public void awaitTerminationShouldNotThrowWhenFinished() {
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation(NOOP)
-            .threadCount(1)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() ->  ConcurrentTestRunner.builder()
+                .operation(NOOP)
+                .threadCount(1)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
     }
 
     @Test
     public void awaitTerminationShouldThrowWhenNotFinished() {
-        int sleepDelay = 50;
-
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> Thread.sleep(sleepDelay))
-            .threadCount(1)
-            .build()
-            .run();
-
-        assertThatThrownBy(() -> 
concurrentTestRunner.awaitTermination(sleepDelay / 2, TimeUnit.MILLISECONDS))
+        assertThatThrownBy(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> Thread.sleep(50))
+                .threadCount(1)
+                .runSuccessfullyWithin(25, TimeUnit.MILLISECONDS))
             .isInstanceOf(ConcurrentTestRunner.NotTerminatedException.class);
     }
 
@@ -113,15 +105,13 @@ public class ConcurrentTestRunnerTest {
     public void runShouldPerformAllOperations() {
         ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> queue.add(threadNumber + ":" + 
step))
-            .threadCount(2)
-            .operationCount(2)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> queue.add(threadNumber + 
":" + step))
+                .threadCount(2)
+                .operationCount(2)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
+
         assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
     }
 
@@ -129,59 +119,46 @@ public class ConcurrentTestRunnerTest {
     public void operationCountShouldDefaultToOne() {
         ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> queue.add(threadNumber + ":" + 
step))
-            .threadCount(2)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> queue.add(threadNumber + 
":" + step))
+                .threadCount(2)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
-        assertThat(queue).containsOnly("0:0", "1:0");
     }
 
     @Test
     public void runShouldNotThrowOnExceptions() {
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> {
-                throw new RuntimeException();
-            })
-            .threadCount(2)
-            .operationCount(2)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> {
+                    throw new RuntimeException();
+                })
+                .threadCount(2)
+                .operationCount(2)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
     }
 
     @Test
     public void noExceptionsShouldNotThrowWhenNoExceptionGenerated() throws 
Exception {
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
+        ConcurrentTestRunner.builder()
             .operation(NOOP)
             .threadCount(2)
             .operationCount(2)
-            .build()
-            .run();
-
-        concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS);
-
-        concurrentTestRunner.assertNoException();
+            .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, TimeUnit.MILLISECONDS)
+            .assertNoException();
     }
 
     @Test
     public void assertNoExceptionShouldThrowOnExceptions() throws Exception {
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> {
-                throw new RuntimeException();
-            })
-            .threadCount(2)
-            .operationCount(2)
-            .build()
-            .run();
-        concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS);
-
-        assertThatThrownBy(concurrentTestRunner::assertNoException)
+        assertThatThrownBy(() ->
+                ConcurrentTestRunner.builder()
+                    .operation((threadNumber, step) -> {
+                        throw new RuntimeException();
+                    })
+                    .threadCount(2)
+                    .operationCount(2)
+                    .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS)
+                    .assertNoException())
             .isInstanceOf(ExecutionException.class);
     }
 
@@ -189,18 +166,16 @@ public class ConcurrentTestRunnerTest {
     public void runShouldPerformAllOperationsEvenOnExceptions() {
         ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> {
-                queue.add(threadNumber + ":" + step);
-                throw new RuntimeException();
-            })
-            .threadCount(2)
-            .operationCount(2)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> {
+                    queue.add(threadNumber + ":" + step);
+                    throw new RuntimeException();
+                })
+                .threadCount(2)
+                .operationCount(2)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
+
         assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
     }
 
@@ -208,20 +183,18 @@ public class ConcurrentTestRunnerTest {
     public void runShouldPerformAllOperationsEvenOnOccasionalExceptions() {
         ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
 
-        ConcurrentTestRunner concurrentTestRunner = 
ConcurrentTestRunner.builder()
-            .operation((threadNumber, step) -> {
-                queue.add(threadNumber + ":" + step);
-                if ((threadNumber + step) % 2 == 0) {
-                    throw new RuntimeException();
-                }
-            })
-            .threadCount(2)
-            .operationCount(2)
-            .build()
-            .run();
-
-        assertThatCode(() -> 
concurrentTestRunner.awaitTermination(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
+        assertThatCode(() -> ConcurrentTestRunner.builder()
+                .operation((threadNumber, step) -> {
+                    queue.add(threadNumber + ":" + step);
+                    if ((threadNumber + step) % 2 == 0) {
+                        throw new RuntimeException();
+                    }
+                })
+                .threadCount(2)
+                .operationCount(2)
+                .runSuccessfullyWithin(DEFAULT_AWAIT_TIME, 
TimeUnit.MILLISECONDS))
             .doesNotThrowAnyException();
+
         assertThat(queue).containsOnly("0:0", "0:1", "1:0", "1:1");
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to