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 2924c266bd7cc574b2c2cf58f92b979a52afb031 Author: Tran Tien Duc <[email protected]> AuthorDate: Wed May 15 16:07:39 2019 +0700 JAMES-2763 James should fail to start when having a non compatible ES server --- .../james/backends/es/DockerElasticSearch.java | 12 +++- .../apache/james/DockerElasticSearchExtension.java | 12 +++- ...esWithNonCompatibleElasticSearchServerTest.java | 68 ++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java index 10e6912..0d93b6a 100644 --- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java +++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java @@ -62,11 +62,21 @@ public class DockerElasticSearch { private final DockerGenericContainer eSContainer; public DockerElasticSearch() { - this.eSContainer = new DockerGenericContainer(Images.ELASTICSEARCH_2) + this(Images.ELASTICSEARCH_2); + } + + public DockerElasticSearch(String imageName) { + this.eSContainer = new DockerGenericContainer(imageName) .withExposedPorts(ES_HTTP_PORT, ES_TCP_PORT) .waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND)); } + public DockerElasticSearch withEnv(String key, String value) { + this.eSContainer + .withEnv(key, value); + return this; + } + public void start() { if (!eSContainer.isRunning()) { eSContainer.start(); 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 index aac65b5..bbee657 100644 --- 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 @@ -28,6 +28,16 @@ import com.google.inject.Module; public class DockerElasticSearchExtension implements GuiceModuleTestExtension { + private final DockerElasticSearch dockerElasticSearch; + + public DockerElasticSearchExtension() { + this(DockerElasticSearchSingleton.INSTANCE); + } + + public DockerElasticSearchExtension(DockerElasticSearch dockerElasticSearch) { + this.dockerElasticSearch = dockerElasticSearch; + } + @Override public void beforeEach(ExtensionContext extensionContext) { getDockerES().start(); @@ -55,6 +65,6 @@ public class DockerElasticSearchExtension implements GuiceModuleTestExtension { } public DockerElasticSearch getDockerES() { - return DockerElasticSearchSingleton.INSTANCE; + return dockerElasticSearch; } } diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java new file mode 100644 index 0000000..19caf35 --- /dev/null +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java @@ -0,0 +1,68 @@ +/**************************************************************** + * 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.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.james.backends.es.DockerElasticSearch; +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.util.docker.Images; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import com.google.inject.ProvisionException; + +class JamesWithNonCompatibleElasticSearchServerTest { + + private static final int LIMIT_MAX_MESSAGES = 10; + + static DockerElasticSearch dockerES6 = new DockerElasticSearch(Images.ELASTICSEARCH_6) + .withEnv("discovery.type", "single-node"); + + @RegisterExtension + static JamesServerExtension testExtension = new JamesServerBuilder() + .extension(new DockerElasticSearchExtension(dockerES6)) + .extension(new CassandraExtension()) + .server(configuration -> GuiceJamesServer.forConfiguration(configuration) + .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) + .overrideWith(new TestJMAPServerModule(LIMIT_MAX_MESSAGES))) + .disableAutoStart() + .build(); + + @AfterAll + static void afterAll() { + dockerES6.stop(); + } + + @Test + void jamesShouldStopWhenStartingWithANonCompatibleElasticSearchServer(GuiceJamesServer server) throws Exception { + assertThatThrownBy(server::start) + .isInstanceOf(ProvisionException.class); + + assertThat(server.isStarted()) + .isFalse(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
