james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [07/10] james-project git commit: JAMES-2334 user one rabbit cluster across whole cluster test
Date Wed, 24 Oct 2018 01:51:33 GMT
JAMES-2334 user one rabbit cluster across whole cluster test


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

Branch: refs/heads/master
Commit: e7f28f0cf835ab59a62c87607892b72470826e02
Parents: 0c4c367
Author: duc <dtran@linagora.com>
Authored: Mon Oct 22 14:18:46 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Oct 24 08:48:27 2018 +0700

----------------------------------------------------------------------
 .../DockerClusterRabbitMQExtension.java         | 28 +++++++++++---------
 .../james/backend/rabbitmq/DockerRabbitMQ.java  |  4 ++-
 .../backend/rabbitmq/RabbitMQClusterTest.java   | 19 ++++++++++---
 3 files changed, 34 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e7f28f0c/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerClusterRabbitMQExtension.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerClusterRabbitMQExtension.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerClusterRabbitMQExtension.java
index b787239..05278ca 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerClusterRabbitMQExtension.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerClusterRabbitMQExtension.java
@@ -22,9 +22,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.UUID;
 
 import org.apache.james.util.Runnables;
-import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.ParameterContext;
@@ -37,7 +35,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.hash.Hashing;
 import com.rabbitmq.client.Address;
 
-public class DockerClusterRabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
AfterEachCallback, AfterAllCallback, ParameterResolver {
+public class DockerClusterRabbitMQExtension implements BeforeEachCallback, AfterEachCallback,
ParameterResolver {
 
     private static final String RABBIT_1 = "rabbit1";
     private static final String RABBIT_2 = "rabbit2";
@@ -48,8 +46,7 @@ public class DockerClusterRabbitMQExtension implements BeforeAllCallback,
Before
     private DockerRabbitMQ rabbitMQ2;
     private DockerRabbitMQ rabbitMQ3;
 
-    @Override
-    public void beforeAll(ExtensionContext extensionContext) throws Exception {
+    public void beforeAll() {
         String cookie = Hashing.sha256().hashString("secret cookie here", StandardCharsets.UTF_8).toString();
 
         network = Network.NetworkImpl.builder()
@@ -62,14 +59,13 @@ public class DockerClusterRabbitMQExtension implements BeforeAllCallback,
Before
         rabbitMQ2 = DockerRabbitMQ.withCookieAndHostName(RABBIT_2, clusterIdentity, cookie,
network);
         rabbitMQ3 = DockerRabbitMQ.withCookieAndHostName(RABBIT_3, clusterIdentity, cookie,
network);
 
-        Runnables.runParallel(
-            rabbitMQ1::start,
-            rabbitMQ2::start,
-            rabbitMQ3::start);
+        startDockerRabbits();
     }
 
     @Override
-    public void beforeEach(ExtensionContext context) {
+    public void beforeEach(ExtensionContext context) throws Exception {
+        startDockerRabbits();
+
         Runnables.runParallel(
             Throwing.runnable(() -> rabbitMQ2.join(rabbitMQ1)),
             Throwing.runnable(() -> rabbitMQ3.join(rabbitMQ1)));
@@ -78,12 +74,11 @@ public class DockerClusterRabbitMQExtension implements BeforeAllCallback,
Before
     }
 
     @Override
-    public void afterEach(ExtensionContext context) throws Exception {
+    public void afterEach(ExtensionContext context) {
         cluster.detach();
     }
 
-    @Override
-    public void afterAll(ExtensionContext extensionContext) throws Exception {
+    public void afterAll() throws Exception {
         cluster.stop();
         network.close();
     }
@@ -98,6 +93,13 @@ public class DockerClusterRabbitMQExtension implements BeforeAllCallback,
Before
         return cluster;
     }
 
+    private void startDockerRabbits() {
+        Runnables.runParallel(
+            rabbitMQ1::start,
+            rabbitMQ2::start,
+            rabbitMQ3::start);
+    }
+
     public static class DockerRabbitMQCluster {
 
         private final DockerRabbitMQ rabbitMQ1;

http://git-wip-us.apache.org/repos/asf/james-project/blob/e7f28f0c/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerRabbitMQ.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerRabbitMQ.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerRabbitMQ.java
index 47c99ea..10f36ab 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerRabbitMQ.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/DockerRabbitMQ.java
@@ -128,7 +128,9 @@ public class DockerRabbitMQ {
     }
 
     public void start() {
-        container.start();
+        if (!container.isRunning()) {
+            container.start();
+        }
     }
 
     public void stop() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/e7f28f0c/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
index 5e50b4b..bc374bf 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
@@ -39,12 +39,14 @@ import java.util.stream.IntStream;
 import org.apache.james.backend.rabbitmq.DockerClusterRabbitMQExtension.DockerRabbitMQCluster;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,7 +65,19 @@ class RabbitMQClusterTest {
 
     private static final String QUEUE = "queue";
 
-    @ExtendWith(DockerClusterRabbitMQExtension.class)
+    @RegisterExtension
+    static DockerClusterRabbitMQExtension testExtension = new DockerClusterRabbitMQExtension();
+
+    @BeforeAll
+    static void setup() {
+        testExtension.beforeAll();
+    }
+
+    @AfterAll
+    static void tearDown() throws Exception {
+        testExtension.afterAll();
+    }
+
     @Nested
     class ClusterSharing {
 
@@ -147,7 +161,6 @@ class RabbitMQClusterTest {
 
     }
 
-    @ExtendWith(DockerClusterRabbitMQExtension.class)
     @Nested
     class ClusterNodesFailure {
 


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


Mime
View raw message