[prev in list] [next in list] [prev in thread] [next in thread] 

List:       james-dev
Subject:    [4/6] james-project git commit: MAILBOX-287 Allow connection to an ES cluster
From:       btellier () apache ! org
Date:       2017-02-28 11:45:11
Message-ID: f87c0a834bdc497786f5781a0e47350f () git ! apache ! org
[Download RAW message or body]

MAILBOX-287 Allow connection to an ES cluster


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

Branch: refs/heads/master
Commit: 94f7a413a4824c0d814559f01ce8921a3188c7a1
Parents: 78426b8
Author: benwa <btellier@linagora.com>
Authored: Fri Feb 24 11:55:11 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 28 18:44:33 2017 +0700

----------------------------------------------------------------------
 backends-common/elasticsearch/pom.xml           |  11 ++
 .../james/backends/es/ClientProviderImpl.java   | 100 ++++++++--
 .../backends/es/ClientProviderImplTest.java     | 192 +++++++++++++++++++
 .../destination/conf/elasticsearch.properties   |   4 +
 .../destination/conf/elasticsearch.properties   |   4 +
 .../mailbox/ElasticSearchMailboxModule.java     |  37 +++-
 .../mailbox/ElasticSearchMailboxModuleTest.java |  71 +++++++
 .../apache/james/metric/es/ESReporterTest.java  |   2 +-
 8 files changed, 404 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/backends-common/elasticsearch/pom.xml
                
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/pom.xml \
b/backends-common/elasticsearch/pom.xml index 624ec16..0ffbdd8 100644
--- a/backends-common/elasticsearch/pom.xml
+++ b/backends-common/elasticsearch/pom.xml
@@ -130,6 +130,11 @@
                     <artifactId>james-server-util-java8</artifactId>
                 </dependency>
                 <dependency>
+                    <groupId>com.github.fge</groupId>
+                    <artifactId>throwing-lambdas</artifactId>
+                    <version>0.5.0</version>
+                </dependency>
+                <dependency>
                     <groupId>com.jayway.awaitility</groupId>
                     <artifactId>awaitility</artifactId>
                     <version>1.6.3</version>
@@ -160,6 +165,12 @@
                     <groupId>org.slf4j</groupId>
                     <artifactId>slf4j-api</artifactId>
                 </dependency>
+                <dependency>
+                    <groupId>nl.jqno.equalsverifier</groupId>
+                    <artifactId>equalsverifier</artifactId>
+                    <version>1.7.6</version>
+                    <scope>test</scope>
+                </dependency>
             </dependencies>
             <build>
                 <plugins>

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
                
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java \
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
 index 118d077..bc378c1 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
                
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
 @@ -19,30 +19,102 @@
 package org.apache.james.backends.es;
 
 import java.net.InetAddress;
-import java.net.UnknownHostException;
+import java.util.Objects;
 
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
 
-import com.google.common.base.Throwables;
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.consumers.ConsumerChainer;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
 
 public class ClientProviderImpl implements ClientProvider {
 
-    private final String host;
-    private final int port;
-    
-    public ClientProviderImpl(String host, int port) {
-        this.host = host;
-        this.port = port;
+    public static class Host {
+        private final String host;
+        private final int port;
+
+        public Host(String host, int port) {
+            Preconditions.checkNotNull(host, "Host address can not be null");
+            Preconditions.checkArgument(!host.isEmpty(), "Host address can not be \
empty"); +            Preconditions.checkArgument(isValidPort(port), "Port should be \
between ]0, 65535]"); +            this.host = host;
+            this.port = port;
+        }
+
+        public String getHost() {
+            return host;
+        }
+
+        public int getPort() {
+            return port;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof Host) {
+                Host that = (Host) o;
+
+                return Objects.equals(this.host, that.host)
+                    && Objects.equals(this.port, that.port);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(host, port);
+        }
+    }
+
+    public static ClientProviderImpl forHost(String address, Integer port) {
+        isValidPort(port);
+        return new ClientProviderImpl(ImmutableList.of(new Host(address, port)));
+    }
+
+    public static ClientProviderImpl fromHostsString(String hostsString) {
+        Preconditions.checkNotNull(hostsString, "HostString should not be null");
+        return new ClientProviderImpl(parseHosts(hostsString));
+    }
+
+    @VisibleForTesting
+    static ImmutableList<Host> parseHosts(String hostsString) {
+        return Splitter.on(',').splitToList(hostsString)
+                .stream()
+                .map(hostSting -> Splitter.on(':').splitToList(hostSting))
+                .map(hostParts -> {
+                    Preconditions.checkArgument(hostParts.size() == 2, "A host \
should be defined as a : separated pair of address and port"); +                    \
return new Host(hostParts.get(0), Integer.valueOf(hostParts.get(1))); +               \
}) +                .distinct()
+                .collect(Guavate.toImmutableList());
+    }
+
+    private static boolean isValidPort(Integer port) {
+        return port > 0 && port <= 65535;
+    }
+
+    private final ImmutableList<Host> hosts;
+
+    private ClientProviderImpl(ImmutableList<Host> hosts) {
+        Preconditions.checkArgument(!hosts.isEmpty(), "You should provide at least \
one host"); +        this.hosts = hosts;
     }
 
+
     public Client get() {
-        try {
-            return TransportClient.builder().build()
-                .addTransportAddress(new \
                InetSocketTransportAddress(InetAddress.getByName(host), port));
-        } catch (UnknownHostException e) {
-            throw Throwables.propagate(e);
-        }
+        TransportClient transportClient = TransportClient.builder().build();
+        ConsumerChainer<Host> consumer = Throwing.consumer(host -> transportClient
+            .addTransportAddress(
+                new InetSocketTransportAddress(
+                    InetAddress.getByName(host.getHost()),
+                    host.getPort())));
+        hosts.forEach(consumer.sneakyThrow());
+        return transportClient;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/backends-common/ela \
                sticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplTest.java
                
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplTest.java \
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplTest.java
 new file mode 100644
index 0000000..5d8f420
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ClientProviderImplTest.java
 @@ -0,0 +1,192 @@
+/****************************************************************
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.backends.es.ClientProviderImpl.Host;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class ClientProviderImplTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void fromHostsStringShouldThrowOnNullString() {
+        expectedException.expect(NullPointerException.class);
+
+        ClientProviderImpl.fromHostsString(null);
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnEmptyString() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("");
+    }
+
+    @Test
+    public void forHostShouldThrowOnNullHost() {
+        expectedException.expect(NullPointerException.class);
+
+        ClientProviderImpl.forHost(null, 9200);
+    }
+
+    @Test
+    public void forHostShouldThrowOnEmptyHost() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.forHost("", 9200);
+    }
+
+    @Test
+    public void forHostShouldThrowOnNegativePort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.forHost("localhost", -1);
+    }
+
+    @Test
+    public void forHostShouldThrowOnZeroPort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.forHost("localhost", 0);
+    }
+
+    @Test
+    public void forHostShouldThrowOnTooBigPort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.forHost("localhost", 65536);
+    }
+
+    @Test
+    public void fromHostsStringShouldEmptyAddress() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString(":9200");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnAbsentPort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowWhenTooMuchParts() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:9200:9200");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnEmptyPort() {
+        expectedException.expect(NumberFormatException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnInvalidPort() {
+        expectedException.expect(NumberFormatException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:invalid");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnNegativePort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:-1");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnZeroPort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:0");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowOnTooBigPort() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:65536");
+    }
+
+    @Test
+    public void fromHostsStringShouldThrowIfOneHostIsInvalid() {
+        expectedException.expect(IllegalArgumentException.class);
+
+        ClientProviderImpl.fromHostsString("localhost:9200,localhost");
+    }
+
+    @Test
+    public void parseHostsShouldParseMonoHost() {
+        assertThat(ClientProviderImpl.parseHosts("localhost:9200"))
+            .containsOnly(new Host("localhost", 9200));
+    }
+
+    @Test
+    public void parseHostsShouldParseMultiHosts() {
+        assertThat(ClientProviderImpl.parseHosts("localhost:9200,server:9155"))
+            .containsOnly(
+                new Host("localhost", 9200),
+                new Host("server", 9155));
+    }
+
+    @Test
+    public void parseHostsShouldSwallowDuplicates() {
+        assertThat(ClientProviderImpl.parseHosts("localhost:9200,localhost:9200"))
+            .containsOnly(
+                new Host("localhost", 9200));
+    }
+
+    @Test
+    public void parseHostsShouldNotSwallowSameAddressDifferentPort() {
+        assertThat(ClientProviderImpl.parseHosts("localhost:9200,localhost:9155"))
+            .containsOnly(
+                new Host("localhost", 9200),
+                new Host("localhost", 9155));
+    }
+
+
+
+    @Test
+    public void parseHostsShouldNotSwallowSamePortDifferentAddress() {
+        assertThat(ClientProviderImpl.parseHosts("localhost:9200,abcd:9200"))
+            .containsOnly(
+                new Host("localhost", 9200),
+                new Host("abcd", 9200));
+    }
+
+
+    @Test
+    public void hostShouldRespectBeanContract() {
+        EqualsVerifier.forClass(ClientProviderImpl.Host.class).verify();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/dockerfiles/run/guice/cassandra-ldap/destination/conf/elasticsearch.properties
                
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/elasticsearch.properties \
b/dockerfiles/run/guice/cassandra-ldap/destination/conf/elasticsearch.properties \
                index 06e1852..6d17382 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/elasticsearch.properties
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/elasticsearch.properties
@@ -22,6 +22,10 @@
 
 elasticsearch.masterHost=elasticsearch
 elasticsearch.port=9300
+
+# You can alternatively provide a list of hosts following this format :
+# elasticsearch.hosts=host1:9300,host2:9300
+
 elasticsearch.nb.shards=1
 elasticsearch.nb.replica=0
 elasticsearch.retryConnection.maxRetries=7

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/dockerfiles/run/guice/cassandra/destination/conf/elasticsearch.properties
                
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/elasticsearch.properties \
b/dockerfiles/run/guice/cassandra/destination/conf/elasticsearch.properties index \
                06e1852..6d17382 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/elasticsearch.properties
+++ b/dockerfiles/run/guice/cassandra/destination/conf/elasticsearch.properties
@@ -22,6 +22,10 @@
 
 elasticsearch.masterHost=elasticsearch
 elasticsearch.port=9300
+
+# You can alternatively provide a list of hosts following this format :
+# elasticsearch.hosts=host1:9300,host2:9300
+
 elasticsearch.nb.shards=1
 elasticsearch.nb.replica=0
 elasticsearch.retryConnection.maxRetries=7

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/server/container/gu \
ice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
                
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java \
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
 index bbea50a..6206222 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
                
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
 @@ -20,6 +20,7 @@
 package org.apache.james.modules.mailbox;
 
 import java.io.FileNotFoundException;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 
 import javax.inject.Singleton;
@@ -44,6 +45,8 @@ import org.apache.james.mailbox.tika.extractor.TikaTextExtractor;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.NoNodeAvailableException;
 
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
@@ -52,6 +55,7 @@ import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
 public class ElasticSearchMailboxModule extends AbstractModule {
 
     public static final String ES_CONFIG_FILE = FileSystem.FILE_PROTOCOL_AND_CONF + \
"elasticsearch.properties"; +    public static final String ELASTICSEARCH_HOSTS = \
                "elasticsearch.hosts";
     public static final String ELASTICSEARCH_MASTER_HOST = \
"elasticsearch.masterHost";  public static final String ELASTICSEARCH_PORT = \
"elasticsearch.port";  private static final int DEFAULT_CONNECTION_MAX_RETRIES = 7;
@@ -75,8 +79,8 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     protected Client provideClientProvider(FileSystem fileSystem, AsyncRetryExecutor \
executor) throws ConfigurationException, FileNotFoundException, ExecutionException, \
                InterruptedException {
         PropertiesConfiguration propertiesReader = new \
PropertiesConfiguration(fileSystem.getFile(ES_CONFIG_FILE));  
-        ClientProvider clientProvider = new \
                ClientProviderImpl(propertiesReader.getString(ELASTICSEARCH_MASTER_HOST),
                
-                propertiesReader.getInt(ELASTICSEARCH_PORT));
+        ClientProvider clientProvider = connectToCluster(propertiesReader);
+
         Client client = getRetryer(executor, propertiesReader)
                 .getWithRetry(ctx -> clientProvider.get()).get();
         IndexCreationFactory.createIndex(client,
@@ -90,6 +94,35 @@ public class ElasticSearchMailboxModule extends AbstractModule {
         return client;
     }
 
+    private static ClientProvider connectToCluster(PropertiesConfiguration \
propertiesReader) throws ConfigurationException { +        Optional<String> \
monoHostAddress = Optional.ofNullable(propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, \
null)); +        Optional<Integer> monoHostPort = \
Optional.ofNullable(propertiesReader.getInteger(ELASTICSEARCH_PORT, null)); +        \
Optional<String> multiHosts = \
Optional.ofNullable(propertiesReader.getString(ELASTICSEARCH_HOSTS, null)); +
+        validateHostsConfigurationOptions(monoHostAddress, monoHostPort, \
multiHosts); +
+        if (monoHostAddress.isPresent()) {
+            return ClientProviderImpl.forHost(monoHostAddress.get(), \
monoHostPort.get()); +        } else {
+            return ClientProviderImpl.fromHostsString(multiHosts.get());
+        }
+    }
+
+    @VisibleForTesting
+    static void validateHostsConfigurationOptions(Optional<String> monoHostAddress,
+                                                          Optional<Integer> \
monoHostPort, +                                                          \
Optional<String> multiHosts) throws ConfigurationException { +        if \
(monoHostAddress.isPresent() != monoHostPort.isPresent()) { +            throw new \
ConfigurationException(ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + " \
should be specified together"); +        }
+        if (multiHosts.isPresent() && monoHostAddress.isPresent()) {
+            throw new ConfigurationException("You should choose between mono host \
set up and " + ELASTICSEARCH_HOSTS); +        }
+        if (!multiHosts.isPresent() && !monoHostAddress.isPresent()) {
+            throw new ConfigurationException("You should specify either (" + \
ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + ") or " + \
ELASTICSEARCH_HOSTS); +        }
+    }
+
     private static AsyncRetryExecutor getRetryer(AsyncRetryExecutor executor, \
PropertiesConfiguration configuration) {  return executor
                 .withProportionalJitter()

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/server/container/gu \
ice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
                
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java \
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
 index 26e3cc5..dd22797 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
                
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
 @@ -19,14 +19,25 @@
 
 package org.apache.james.modules.mailbox;
 
+import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTICSEARCH_HOSTS;
 +import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTICSEARCH_MASTER_HOST;
 +import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTICSEARCH_PORT;
  import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.Optional;
+
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class ElasticSearchMailboxModuleTest {
 
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
     @Test
     public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() \
                {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
@@ -61,4 +72,64 @@ public class ElasticSearchMailboxModuleTest {
 
         assertThat(indexAttachments).isEqualTo(IndexAttachments.YES);
     }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenNoHostSpecify() \
throws Exception { +        expectedException.expect(ConfigurationException.class);
+        expectedException.expectMessage("You should specify either (" + \
ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + ") or " + \
ELASTICSEARCH_HOSTS); +
+        ElasticSearchMailboxModule.validateHostsConfigurationOptions(
+            Optional.empty(),
+            Optional.empty(),
+            Optional.empty());
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoAndMultiHostSpecified() \
throws Exception { +        expectedException.expect(ConfigurationException.class);
+        expectedException.expectMessage("You should choose between mono host set up \
and " + ELASTICSEARCH_HOSTS); +
+        ElasticSearchMailboxModule.validateHostsConfigurationOptions(
+            Optional.of("localhost"),
+            Optional.of(9200),
+            Optional.of("localhost:9200"));
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutPort() \
throws Exception { +        expectedException.expect(ConfigurationException.class);
+        expectedException.expectMessage(ELASTICSEARCH_MASTER_HOST + " and " + \
ELASTICSEARCH_PORT + " should be specified together"); +
+        ElasticSearchMailboxModule.validateHostsConfigurationOptions(
+            Optional.of("localhost"),
+            Optional.empty(),
+            Optional.empty());
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutAddress() \
throws Exception { +        expectedException.expect(ConfigurationException.class);
+        expectedException.expectMessage(ELASTICSEARCH_MASTER_HOST + " and " + \
ELASTICSEARCH_PORT + " should be specified together"); +
+        ElasticSearchMailboxModule.validateHostsConfigurationOptions(
+            Optional.empty(),
+            Optional.of(9200),
+            Optional.empty());
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldAcceptMonoHostConfiguration() \
throws Exception { +        \
ElasticSearchMailboxModule.validateHostsConfigurationOptions( +            \
Optional.of("localhost"), +            Optional.of(9200),
+            Optional.empty());
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldAcceptMultiHostConfiguration() \
throws Exception { +        \
ElasticSearchMailboxModule.validateHostsConfigurationOptions( +            \
Optional.empty(), +            Optional.empty(),
+            Optional.of("localhost:9200"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/94f7a413/server/container/me \
trics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
                
----------------------------------------------------------------------
diff --git a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java \
b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
 index fedc02d..f592ddc 100644
--- a/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
                
+++ b/server/container/metrics/metrics-es-reporter/src/test/java/org/apache/james/metric/es/ESReporterTest.java
 @@ -61,7 +61,7 @@ public class ESReporterTest {
 
     @Before
     public void setUp() {
-        clientProvider = new ClientProviderImpl(getContainerIp(), \
ES_APPLICATIVE_PORT); +        clientProvider = \
ClientProviderImpl.forHost(getContainerIp(), ES_APPLICATIVE_PORT);  \
                await().atMost(Duration.ONE_MINUTE)
             .until(() -> elasticSearchStarted(clientProvider));
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic