Repository: james-project Updated Branches: refs/heads/master ad5016e91 -> f7f01be21
JAMES-1760 Add container affinity in docker based tests Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f7f01be2 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f7f01be2 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f7f01be2 Branch: refs/heads/master Commit: f7f01be21a76cd299d83d9ed3ad4a26118024a05 Parents: ad5016e Author: Antoine Duprat <adup...@linagora.com> Authored: Wed Jun 15 09:24:04 2016 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Fri Jun 17 21:05:28 2016 +0200 ---------------------------------------------------------------------- mpt/impl/smtp/core/pom.xml | 7 ++- .../apache/james/mpt/smtp/ForwardSmtpTest.java | 4 +- mpt/pom.xml | 6 +++ server/container/util-java8/pom.xml | 7 ++- .../util/streams/SwarmGenericContainer.java | 50 ++++++++++++++++++++ server/pom.xml | 12 +++++ .../jmap-integration-testing-common/pom.xml | 16 ++++++- .../org/apache/james/jmap/ContainerTest.java | 4 +- 8 files changed, 99 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/mpt/impl/smtp/core/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/core/pom.xml b/mpt/impl/smtp/core/pom.xml index 4d49091..4cbc12b 100644 --- a/mpt/impl/smtp/core/pom.xml +++ b/mpt/impl/smtp/core/pom.xml @@ -148,6 +148,10 @@ <dependencies> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mpt-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>james-server-data-api</artifactId> </dependency> <dependency> @@ -156,7 +160,8 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> - <artifactId>apache-james-mpt-core</artifactId> + <artifactId>james-server-util-java8</artifactId> + <type>test-jar</type> </dependency> <dependency> <groupId>com.jayway.restassured</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java index bc3beaa..8b8776b 100644 --- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java +++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java @@ -29,6 +29,7 @@ import java.util.Locale; import javax.inject.Inject; import org.apache.james.mpt.script.AbstractSimpleScriptedTestProtocol; +import org.apache.james.util.streams.SwarmGenericContainer; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -50,7 +51,8 @@ public class ForwardSmtpTest extends AbstractSimpleScriptedTestProtocol { public static final String PASSWORD = "secret"; private final TemporaryFolder folder = new TemporaryFolder(); - private final GenericContainer fakeSmtp = new GenericContainer("weave/rest-smtp-sink:latest"); + private final GenericContainer fakeSmtp = new SwarmGenericContainer("weave/rest-smtp-sink:latest") + .withAffinityToContainer(); @Rule public final RuleChain chain = RuleChain.outerRule(folder).around(fakeSmtp); http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/mpt/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/pom.xml b/mpt/pom.xml index fbe5819..8919f4f 100644 --- a/mpt/pom.xml +++ b/mpt/pom.xml @@ -266,6 +266,12 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-util-java8</artifactId> + <version>${james.version}</version> + <type>test-jar</type> + </dependency> + <dependency> <groupId>org.apache.james.protocols</groupId> <artifactId>protocols-imap</artifactId> <version>${james-protocols.version}</version> http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/server/container/util-java8/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/util-java8/pom.xml b/server/container/util-java8/pom.xml index 3daa21f..5558bd2 100644 --- a/server/container/util-java8/pom.xml +++ b/server/container/util-java8/pom.xml @@ -29,8 +29,6 @@ </parent> <artifactId>james-server-util-java8</artifactId> - <packaging>bundle</packaging> - <name>Apache James :: Server :: Common Utilities :: Java 8</name> <profiles> @@ -148,6 +146,11 @@ <version>3.2.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java b/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java new file mode 100644 index 0000000..ddfb7f2 --- /dev/null +++ b/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java @@ -0,0 +1,50 @@ +/**************************************************************** + * 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.streams; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; + +import com.google.common.base.Strings; + +public class SwarmGenericContainer extends GenericContainer { + + private static final Logger LOGGER = LoggerFactory.getLogger(SwarmGenericContainer.class); + private static final String DOCKER_CONTAINER = "DOCKER_CONTAINER"; + + public SwarmGenericContainer(String dockerImageName) { + super(dockerImageName); + } + + public GenericContainer withAffinityToContainer() { + String container = System.getenv(DOCKER_CONTAINER); + if (Strings.isNullOrEmpty(container)) { + LOGGER.warn("'DOCKER_CONTAINER' environment variable not found, dockering without affinity"); + return this; + } + List<String> envVariables = getEnv(); + envVariables.add("affinity:container==" + container); + setEnv(envVariables); + return this; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/server/pom.xml ---------------------------------------------------------------------- diff --git a/server/pom.xml b/server/pom.xml index 28baa57..3d3dc98 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -187,6 +187,7 @@ <cassandra-unit.version>2.1.9.2</cassandra-unit.version> <assertj-1.version>1.7.1</assertj-1.version> <assertj-3.version>3.3.0</assertj-3.version> + <testcontainers-version>1.0.2</testcontainers-version> </properties> <dependencyManagement> @@ -757,6 +758,12 @@ <artifactId>james-server-util-java8</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-util-java8</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> <dependency> <groupId>org.apache.james</groupId> @@ -1501,6 +1508,11 @@ <artifactId>jetty-servlet</artifactId> <version>${jetty.version}</version> </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + <version>${testcontainers-version}</version> + </dependency> </dependencies> </dependencyManagement> http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml index 346cecb..6002d51 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml @@ -163,6 +163,12 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-util-java8</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> <!--$NO-MVN-MAN-VER$--> @@ -206,7 +212,7 @@ <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> - <version>1.0.2</version> + <scope>test</scope> </dependency> </dependencies> <build> @@ -261,6 +267,12 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-util-java8</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> <!--$NO-MVN-MAN-VER$--> @@ -304,7 +316,7 @@ <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> - <version>1.0.2</version> + <scope>test</scope> </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/james-project/blob/f7f01be2/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ContainerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ContainerTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ContainerTest.java index d1c0bc4..7c56e44 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ContainerTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ContainerTest.java @@ -26,13 +26,15 @@ import java.net.URISyntaxException; import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Response; import org.apache.http.client.utils.URIBuilder; +import org.apache.james.util.streams.SwarmGenericContainer; import org.junit.Rule; import org.junit.Test; import org.testcontainers.containers.GenericContainer; public class ContainerTest { - @Rule public GenericContainer container = new GenericContainer("nginx:1.7.1") + @Rule public GenericContainer container = new SwarmGenericContainer("nginx:1.7.1") + .withAffinityToContainer() .withExposedPorts(80); @Test --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org