james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [13/13] james-project git commit: JAMES-2441 Run parallely (and statically when possible) docker containers and other heavy tasks.
Date Thu, 05 Jul 2018 02:01:35 GMT
JAMES-2441 Run parallely (and statically when possible) docker containers and other heavy tasks.


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

Branch: refs/heads/master
Commit: 9d023beae924f0d2b49ee1919e8160da840d45c2
Parents: 26df561
Author: benwa <btellier@linagora.com>
Authored: Wed Jul 4 14:50:12 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 5 09:00:27 2018 +0700

----------------------------------------------------------------------
 .../backends/es/EmbeddedElasticSearch.java      |  2 +-
 .../java/org/apache/james/util/Runnables.java   | 40 ++++++++++++++++++++
 .../james/user/ldap/LdapGenericContainer.java   | 10 +++++
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 25 ++++--------
 .../jmap/cassandra/CassandraJmapExtension.java  | 15 ++++++--
 server/queue/queue-rabbitmq/pom.xml             |  7 +++-
 .../DockerClusterRabbitMQExtension.java         | 30 +++++++++------
 7 files changed, 94 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
index b2146ab..19002b5 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
@@ -69,7 +69,7 @@ public class EmbeddedElasticSearch extends ExternalResource {
     }
 
     @Override
-    public void before() throws IOException {
+    public void before() {
         node = nodeBuilder().local(true)
             .settings(Settings.builder()
                 .put("path.home", folder.get().toAbsolutePath())

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
b/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
new file mode 100644
index 0000000..c199f31
--- /dev/null
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
+
+public class Runnables {
+    public static void runParallel(Runnable... runnables) {
+        FluentFutureStream.of(
+            Arrays.stream(runnables)
+                .map(runnable -> CompletableFuture.supplyAsync(toVoidSupplier(runnable))))
+            .join();
+    }
+
+    private static Supplier<Void> toVoidSupplier(Runnable runnable) {
+        return () -> {
+            runnable.run();
+            return null;
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
index 992b4bf..74e62d9 100644
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
+++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
@@ -78,6 +78,16 @@ public class LdapGenericContainer extends ExternalResource {
         this.container = container;
     }
 
+    @Override
+    protected void before() {
+        start();
+    }
+
+    @Override
+    protected void after() {
+        stop();
+    }
+
     public void start() {
         container.start();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
index e78f976..2fdbe54 100644
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
@@ -25,8 +25,8 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.plist.PropertyListConfiguration;
 import org.apache.james.core.MailAddress;
 import org.apache.james.domainlist.api.DomainList;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,24 +42,20 @@ public class ReadOnlyUsersLDAPRepositoryTest {
     private static final String PASSWORD = "secret";
     private static final String BAD_PASSWORD = "badpassword";
 
-    private LdapGenericContainer ldapContainer;
+    @ClassRule
+    public static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
+        .domain(DOMAIN)
+        .password(ADMIN_PASSWORD)
+        .build();
+
     private ReadOnlyUsersLDAPRepository ldapRepository;
     private DomainList domainList;
 
     @Before
     public void setup() {
-        startLdapContainer();
         domainList = mock(DomainList.class);
     }
 
-    private void startLdapContainer() {
-        ldapContainer = LdapGenericContainer.builder()
-                .domain(DOMAIN)
-                .password(ADMIN_PASSWORD)
-                .build();
-        ldapContainer.start();
-    }
-
     private void startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration)
throws Exception {
         ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
         ldapRepository.configure(ldapRepositoryConfiguration);
@@ -97,13 +93,6 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         return configuration;
     }
 
-    @After
-    public void tearDown() {
-        if (ldapContainer != null) {
-            ldapContainer.stop();
-        }
-    }
-
     @Test
     public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
         startUsersRepository(ldapRepositoryConfiguration());

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
index 5a0dd48..8a0b0cd 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
@@ -34,6 +34,7 @@ import org.apache.james.modules.TestESMetricReporterModule;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.core.configuration.Configuration;
+import org.apache.james.util.Runnables;
 import org.apache.james.util.scanner.SpamAssassinExtension;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
@@ -45,6 +46,8 @@ import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 import org.junit.rules.TemporaryFolder;
 
+import com.github.fge.lambdas.Throwing;
+
 public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallback,
     BeforeEachCallback, AfterEachCallback, ParameterResolver {
 
@@ -83,15 +86,19 @@ public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallba
     @Override
     public void beforeAll(ExtensionContext context) throws Exception {
         temporaryFolder.create();
-        cassandra.start();
-        elasticSearch.before();
+
+        Runnables.runParallel(
+            cassandra::start,
+            elasticSearch::before);
     }
 
     @Override
     public void afterAll(ExtensionContext context) {
         elasticSearch.after();
-        cassandra.stop();
-        temporaryFolder.delete();
+
+        Runnables.runParallel(
+            cassandra::stop,
+            elasticSearch::after);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/queue/queue-rabbitmq/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/pom.xml b/server/queue/queue-rabbitmq/pom.xml
index c2fff5b..06ba537 100644
--- a/server/queue/queue-rabbitmq/pom.xml
+++ b/server/queue/queue-rabbitmq/pom.xml
@@ -34,7 +34,12 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.james</groupId>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util-java8</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-util-java8</artifactId>
             <type>test-jar</type>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
index 000fef6..1f8cc0f 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
@@ -19,6 +19,7 @@
 package org.apache.james.queue.rabbitmq;
 
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.james.util.Runnables;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
@@ -27,6 +28,7 @@ import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 import org.testcontainers.containers.Network;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableList;
 import com.rabbitmq.client.Address;
 
@@ -39,7 +41,7 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback,
After
     private Network network;
 
     @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
+    public void beforeEach(ExtensionContext context) {
         String cookie = DigestUtils.sha1Hex("secret cookie here");
 
         network = Network.NetworkImpl.builder()
@@ -51,15 +53,20 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback,
After
         DockerRabbitMQ rabbitMQ2 = DockerRabbitMQ.withCookieAndNodeName(RABBIT_2, cookie,
"rabbit@rabbit2", network);
         DockerRabbitMQ rabbitMQ3 = DockerRabbitMQ.withCookieAndNodeName(RABBIT_3, cookie,
"rabbit@rabbit3", network);
 
-        rabbitMQ1.start();
-        rabbitMQ2.start();
-        rabbitMQ3.start();
+        Runnables.runParallel(
+            rabbitMQ1::start,
+            rabbitMQ2::start,
+            rabbitMQ3::start);
 
-        rabbitMQ2.join(rabbitMQ1);
-        rabbitMQ3.join(rabbitMQ1);
+        Runnables.runParallel(
+            Throwing.runnable(() -> rabbitMQ2.join(rabbitMQ1)),
+            Throwing.runnable(() -> rabbitMQ3.join(rabbitMQ1)));
 
-        rabbitMQ2.startApp();
-        rabbitMQ3.startApp();
+
+
+        Runnables.runParallel(
+            Throwing.runnable(rabbitMQ2::startApp),
+            Throwing.runnable(rabbitMQ3::startApp));
 
         cluster = new DockerRabbitMQCluster(rabbitMQ1, rabbitMQ2, rabbitMQ3);
     }
@@ -93,9 +100,10 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback,
After
         }
 
         public void stop() {
-            rabbitMQ1.stop();
-            rabbitMQ2.stop();
-            rabbitMQ3.stop();
+            Runnables.runParallel(
+                rabbitMQ1::stop,
+                rabbitMQ2::stop,
+                rabbitMQ3::stop);
         }
 
         public DockerRabbitMQ getRabbitMQ1() {


---------------------------------------------------------------------
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