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/03/20 11:54:36 UTC
[james-project] 28/33: JAMES-2666 Extract ElasticSearch docker
extension
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 9a339a85f82b924bf8427de67db7d9582b0ece03
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Mar 13 10:09:46 2019 +0700
JAMES-2666 Extract ElasticSearch docker extension
---
.../apache/james/DockerElasticSearchExtension.java | 60 ++++++++++++++++++++++
.../james/JamesServerWithRetryConnectionTest.java | 42 ++-------------
2 files changed, 63 insertions(+), 39 deletions(-)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java
new file mode 100644
index 0000000..a25e34c
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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 org.apache.james.backends.es.ElasticSearchConfiguration;
+import org.apache.james.util.Host;
+import org.apache.james.util.docker.SwarmGenericContainer;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+public class DockerElasticSearchExtension implements GuiceModuleTestExtension {
+ public static final int ELASTIC_SEARCH_PORT = 9300;
+ public static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
+
+ private final SwarmGenericContainer elasticSearchContainer;
+
+ public DockerElasticSearchExtension(SwarmGenericContainer elasticSearchContainer) {
+ this.elasticSearchContainer = elasticSearchContainer;
+ }
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) {
+ elasticSearchContainer.start();
+ }
+
+ @Override
+ public void afterEach(ExtensionContext extensionContext) {
+ elasticSearchContainer.stop();
+ }
+
+ @Override
+ public Module getModule() {
+ return binder -> binder.bind(ElasticSearchConfiguration.class)
+ .toInstance(getElasticSearchConfigurationForDocker());
+ }
+
+ private ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
+ return ElasticSearchConfiguration.builder()
+ .addHost(Host.from(elasticSearchContainer.getHostIp(), elasticSearchContainer.getMappedPort(ELASTIC_SEARCH_PORT)))
+ .build();
+ }
+}
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
index ce438e8..1126bed 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
@@ -20,6 +20,8 @@
package org.apache.james;
import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_HTTP_PORT;
+import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_PORT;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
@@ -32,67 +34,29 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-import org.apache.james.backends.es.ElasticSearchConfiguration;
import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.search.PDFTextExtractor;
import org.apache.james.modules.TestJMAPServerModule;
import org.apache.james.modules.protocols.ImapGuiceProbe;
-import org.apache.james.util.Host;
import org.apache.james.util.concurrent.NamedThreadFactory;
import org.apache.james.util.docker.Images;
import org.apache.james.util.docker.SwarmGenericContainer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.RegisterExtension;
-import com.google.inject.Module;
-
class JamesServerWithRetryConnectionTest {
- private static class DockerElasticSearchRegistrableExtension implements GuiceModuleTestExtension {
- private final SwarmGenericContainer elasticSearchContainer;
-
- private DockerElasticSearchRegistrableExtension(SwarmGenericContainer elasticSearchContainer) {
- this.elasticSearchContainer = elasticSearchContainer;
- }
-
- @Override
- public void beforeEach(ExtensionContext extensionContext) {
- elasticSearchContainer.start();
- }
-
- @Override
- public void afterEach(ExtensionContext extensionContext) {
- elasticSearchContainer.stop();
- }
-
- @Override
- public Module getModule() {
- return binder -> binder.bind(ElasticSearchConfiguration.class)
- .toInstance(getElasticSearchConfigurationForDocker());
- }
-
- private ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
- return ElasticSearchConfiguration.builder()
- .addHost(Host.from(elasticSearchContainer.getHostIp(), elasticSearchContainer.getMappedPort(ELASTIC_SEARCH_PORT)))
- .build();
- }
- }
-
private static final int LIMIT_TO_10_MESSAGES = 10;
private static final long WAITING_TIME = TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS);
- private static final int ELASTIC_SEARCH_PORT = 9300;
- private static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
-
private static SwarmGenericContainer elasticSearchContainer = new SwarmGenericContainer(Images.ELASTICSEARCH_2)
.withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT);
private static final DockerCassandraRule cassandraRule = new DockerCassandraRule();
@RegisterExtension
static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
- .extension(new DockerElasticSearchRegistrableExtension(elasticSearchContainer))
+ .extension(new DockerElasticSearchExtension(elasticSearchContainer))
.extension(new CassandraExtension(cassandraRule))
.server(configuration -> GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org