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 bt...@apache.org on 2019/06/10 04:15:59 UTC
[james-project] 06/06: JAMES-2551 Starting James before rabbitMQ
should be supported
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 54c31bec2679a4e84256294f72207a97ddfb86e4
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri May 24 10:31:55 2019 +0700
JAMES-2551 Starting James before rabbitMQ should be supported
James should await RabbitMQ start
---
.../james/CassandraRabbitMQJamesServerFixture.java | 6 +-
...RabbitMQJamesServerWithRetryConnectionTest.java | 76 ++++++++++++++++++++++
.../apache/james/modules/RabbitMQExtension.java | 5 ++
3 files changed, 86 insertions(+), 1 deletion(-)
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerFixture.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerFixture.java
index bc5836c..b351172 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerFixture.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerFixture.java
@@ -34,10 +34,14 @@ public class CassandraRabbitMQJamesServerFixture {
.overrideWith(JmapJamesServerContract.DOMAIN_LIST_CONFIGURATION_MODULE);
public static JamesServerBuilder baseExtensionBuilder() {
+ return baseExtensionBuilder(new RabbitMQExtension());
+ }
+
+ public static JamesServerBuilder baseExtensionBuilder(RabbitMQExtension rabbitMQExtension) {
return new JamesServerBuilder()
.extension(new DockerElasticSearchExtension())
.extension(new CassandraExtension())
- .extension(new RabbitMQExtension())
+ .extension(rabbitMQExtension)
.server(CONFIGURATION_BUILDER);
}
}
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/RabbitMQJamesServerWithRetryConnectionTest.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/RabbitMQJamesServerWithRetryConnectionTest.java
new file mode 100644
index 0000000..e44138e
--- /dev/null
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/RabbitMQJamesServerWithRetryConnectionTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.james;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.util.concurrent.NamedThreadFactory;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class RabbitMQJamesServerWithRetryConnectionTest {
+ private static final long WAITING_TIME = Duration.ofSeconds(10).toMillis();
+
+ private RabbitMQExtension rabbitMQExtension = new RabbitMQExtension();
+ private ScheduledExecutorService executorService;
+
+ @RegisterExtension
+ JamesServerExtension jamesServerExtension = CassandraRabbitMQJamesServerFixture
+ .baseExtensionBuilder(rabbitMQExtension)
+ .disableAutoStart()
+ .build();
+
+ @BeforeEach
+ void setUp() {
+ ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
+ executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
+ }
+
+ @AfterEach
+ void tearDown() {
+ executorService.shutdownNow();
+ }
+
+ @Test
+ void serverShouldStartAtDefault(GuiceJamesServer server) throws Exception {
+ server.start();
+
+ assertThat(server.isStarted()).isTrue();
+ }
+
+ @Test
+ void serverShouldRetryToConnectToRabbitMQWhenStartService(GuiceJamesServer server) throws Exception {
+ rabbitMQExtension.dockerRabbitMQ().pause();
+ executorService.schedule(() -> rabbitMQExtension.dockerRabbitMQ().unpause(), WAITING_TIME, TimeUnit.MILLISECONDS);
+
+ server.start();
+
+ assertThat(server.isStarted()).isTrue();
+ }
+}
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/RabbitMQExtension.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/RabbitMQExtension.java
index 095baca..6651549 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/RabbitMQExtension.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/RabbitMQExtension.java
@@ -20,6 +20,7 @@
package org.apache.james.modules;
import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.backend.rabbitmq.DockerRabbitMQ;
import org.junit.jupiter.api.extension.ExtensionContext;
import com.google.inject.Module;
@@ -42,4 +43,8 @@ public class RabbitMQExtension implements GuiceModuleTestExtension {
public Module getModule() {
return new TestRabbitMQModule(rabbitMQRule.dockerRabbitMQ());
}
+
+ public DockerRabbitMQ dockerRabbitMQ() {
+ return rabbitMQRule.dockerRabbitMQ();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org