james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/6] james-project git commit: MAILBOX-287 Adding connectivity tests for ClientProviderImpl
Date Tue, 28 Feb 2017 11:45:09 GMT
MAILBOX-287 Adding connectivity tests for ClientProviderImpl


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

Branch: refs/heads/master
Commit: 9de20759c968e943c4aca6b3059da1dbad304262
Parents: fbcfb02
Author: benwa <btellier@linagora.com>
Authored: Fri Feb 24 17:05:34 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 28 18:44:33 2017 +0700

----------------------------------------------------------------------
 backends-common/elasticsearch/pom.xml           | 17 ++++
 .../es/ClientProviderImplConnectionTest.java    | 89 ++++++++++++++++++++
 backends-common/pom.xml                         |  6 ++
 3 files changed, 112 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9de20759/backends-common/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/pom.xml b/backends-common/elasticsearch/pom.xml
index 0ffbdd8..5bdb565 100644
--- a/backends-common/elasticsearch/pom.xml
+++ b/backends-common/elasticsearch/pom.xml
@@ -166,6 +166,23 @@
                     <artifactId>slf4j-api</artifactId>
                 </dependency>
                 <dependency>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-simple</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-util-java8</artifactId>
+                    <scope>test</scope>
+                    <type>test-jar</type>
+                    <version>${project.version}</version>
+                </dependency>
+                <dependency>
+                    <groupId>org.testcontainers</groupId>
+                    <artifactId>testcontainers</artifactId>
+                    <version>1.1.7</version>
+                </dependency>
+                <dependency>
                     <groupId>nl.jqno.equalsverifier</groupId>
                     <artifactId>equalsverifier</artifactId>
                     <version>1.7.6</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9de20759/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
new file mode 100644
index 0000000..3ee7a1f
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplConnectionTest.java
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.backends.es;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.util.streams.SwarmGenericContainer;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jayway.awaitility.Awaitility;
+
+public class ClientProviderImplConnectionTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ClientProviderImplConnectionTest.class);
+    private static final String DOCKER_ES_IMAGE = "elasticsearch:2.2.1";
+
+    @Rule
+    public SwarmGenericContainer es1 = new SwarmGenericContainer(DOCKER_ES_IMAGE)
+        .withAffinityToContainer();
+
+    @Rule
+    public SwarmGenericContainer es2 = new SwarmGenericContainer(DOCKER_ES_IMAGE)
+        .withAffinityToContainer();
+
+    @Test
+    public void connectingASingleServerShouldWork() throws Exception {
+        Awaitility.await()
+            .atMost(1, TimeUnit.MINUTES)
+            .pollInterval(5, TimeUnit.SECONDS)
+            .until(() -> isConnected(ClientProviderImpl.forHost(es1.getIp(), 9300)));
+    }
+
+    @Test
+    public void connectingAClusterShouldWork() throws Exception {
+        Awaitility.await()
+            .atMost(1, TimeUnit.MINUTES)
+            .pollInterval(5, TimeUnit.SECONDS)
+            .until(() ->isConnected(
+                ClientProviderImpl.fromHostsString(
+                    es1.getIp() + ":" + 9300 + ","
+                    + es2.getIp() + ":" + 9300)));
+    }
+
+    @Test
+    public void connectingAClusterWithAFailedNodeShouldWork() throws Exception {
+        es2.stop();
+
+        Awaitility.await()
+            .atMost(1, TimeUnit.MINUTES)
+            .pollInterval(5, TimeUnit.SECONDS)
+            .until(() -> isConnected(
+                ClientProviderImpl.fromHostsString(
+                    es1.getIp() + ":" + 9300 + ","
+                    + es2.getIp() + ":" + 9300)));
+    }
+
+    private boolean isConnected(ClientProvider clientProvider) {
+        try (Client client = clientProvider.get()) {
+            client.prepareSearch()
+                .setQuery(QueryBuilders.existsQuery("any"))
+                .get();
+            return true;
+        } catch (Exception e) {
+            LOGGER.info("Caught exception while trying to connect", e);
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/9de20759/backends-common/pom.xml
----------------------------------------------------------------------
diff --git a/backends-common/pom.xml b/backends-common/pom.xml
index aaaaf3e..be1dd38 100644
--- a/backends-common/pom.xml
+++ b/backends-common/pom.xml
@@ -72,6 +72,12 @@
                 <artifactId>slf4j-api</artifactId>
                 <version>${slf4j.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-simple</artifactId>
+                <version>${slf4j.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
 
     </dependencyManagement>


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