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 2017/11/01 10:59:59 UTC

[01/15] james-project git commit: JAMES-2202 Configurable index name for ElasticSearch

Repository: james-project
Updated Branches:
  refs/heads/master 7c490edb8 -> b1f1077e8


JAMES-2202 Configurable index name for ElasticSearch


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

Branch: refs/heads/master
Commit: aebca5fbdd13755f7dc3b003081dc186751f64ac
Parents: 73deadf
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 10:26:31 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:53:02 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/backends/es/IndexName.java | 17 ++++++++
 .../MailboxElasticsearchConstants.java          |  2 +-
 .../search/ElasticSearchSearcher.java           | 21 +++++++---
 .../ElasticSearchIntegrationTest.java           | 15 ++++---
 .../host/ElasticSearchHostSystem.java           | 15 +++----
 .../smtp/host/CassandraJamesSmtpHostSystem.java |  2 +-
 .../mailbox/ElasticSearchMailboxModule.java     | 30 ++++++++++----
 .../apache/james/EmbeddedElasticSearchRule.java |  2 +-
 .../james/JamesCapabilitiesServerTest.java      |  2 +-
 .../james/modules/TestElasticSearchModule.java  | 10 ++---
 .../mailbox/ElasticSearchMailboxModuleTest.java | 41 ++++++++++++++++++++
 .../cassandra/cucumber/CassandraStepdefs.java   |  2 +-
 src/site/xdoc/server/config-elasticsearch.xml   |  2 +
 13 files changed, 124 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
index 8936bb2..4541f48 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.backends.es;
 
+import java.util.Objects;
+
 public class IndexName {
     private final String value;
 
@@ -29,4 +31,19 @@ public class IndexName {
     public String getValue() {
         return value;
     }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof IndexName) {
+            IndexName indexName = (IndexName) o;
+
+            return Objects.equals(this.value, indexName.value);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
index 4cf9bd1..9539e53 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
@@ -23,6 +23,6 @@ import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.TypeName;
 
 public interface MailboxElasticsearchConstants {
-    IndexName MAILBOX_INDEX = new IndexName("mailbox");
+    IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
     TypeName MESSAGE_TYPE = new TypeName("message");
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index f253001..330d363 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -25,9 +25,10 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.TypeName;
 import org.apache.james.backends.es.search.ScrollIterable;
 import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
 import org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants;
 import org.apache.james.mailbox.elasticsearch.query.QueryConverter;
 import org.apache.james.mailbox.elasticsearch.query.SortConverter;
@@ -57,18 +58,26 @@ public class ElasticSearchSearcher {
     private final int size;
     private final MailboxId.Factory mailboxIdFactory;
     private final MessageId.Factory messageIdFactory;
+    private final IndexName indexName;
+    private final TypeName typeName;
 
     @Inject
-    public ElasticSearchSearcher(Client client, QueryConverter queryConverter, MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory) {
-        this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory);
+    public ElasticSearchSearcher(Client client, QueryConverter queryConverter,
+                                 MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
+                                 IndexName indexName, TypeName typeName) {
+        this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, indexName, typeName);
     }
 
-    public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size, MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory) {
+    public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size,
+                                 MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
+                                 IndexName indexName, TypeName typeName) {
         this.client = client;
         this.queryConverter = queryConverter;
         this.size = size;
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
+        this.indexName = indexName;
+        this.typeName = typeName;
     }
 
     public Stream<MessageSearchIndex.SearchResult> search(Collection<MailboxId> mailboxIds, SearchQuery query,
@@ -86,8 +95,8 @@ public class ElasticSearchSearcher {
         return query.getSorts()
             .stream()
             .reduce(
-                client.prepareSearch(MailboxElasticsearchConstants.MAILBOX_INDEX.getValue())
-                    .setTypes(MailboxElasticsearchConstants.MESSAGE_TYPE.getValue())
+                client.prepareSearch(indexName.getValue())
+                    .setTypes(typeName.getValue())
                     .setScroll(TIMEOUT)
                     .addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID, JsonMessageConstants.MESSAGE_ID)
                     .setQuery(queryConverter.from(users, query))

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index bb6adb8..eaf7764 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -83,7 +83,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     private static final boolean IS_RECENT = true;
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
 
     @Rule
     public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
@@ -112,8 +112,8 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         Client client = NodeMappingFactory.applyMapping(
             IndexCreationFactory.createIndex(
                 new TestingClientProvider(embeddedElasticSearch.getNode()).get(),
-                MailboxElasticsearchConstants.MAILBOX_INDEX),
-            MailboxElasticsearchConstants.MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX),
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
 
@@ -125,11 +125,14 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
                     BATCH_SIZE,
-                    MailboxElasticsearchConstants.MAILBOX_INDEX,
+                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
                     MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.MESSAGE_TYPE),
+            new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
+                new InMemoryId.Factory(), messageIdFactory,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
-            new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE, new InMemoryId.Factory(), messageIdFactory),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
         storeMailboxManager = new InMemoryMailboxManager(
             mapperFactory,

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 12a854a..948acd8 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -82,7 +82,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
     public void beforeTest() throws Exception {
         super.beforeTest();
         this.tempDirectory = Files.createTempDirectory("elasticsearch");
-        this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticsearchConstants.MAILBOX_INDEX);
+        this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
         embeddedElasticSearch.before();
         initFields();
     }
@@ -95,19 +95,20 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
-            IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode()).get(), MailboxElasticsearchConstants.MAILBOX_INDEX),
-            MailboxElasticsearchConstants.MAILBOX_INDEX,
+            IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode()).get(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX),
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
-            MailboxMappingFactory.getMappingContent()
-        );
+            MailboxMappingFactory.getMappingContent());
 
         InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
         InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
 
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
             factory,
-            new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), MailboxElasticsearchConstants.MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
-            new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory),
+            new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
+            new ElasticSearchSearcher(client,
+                new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES));
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
index 97a5f55..7b958f2 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
@@ -83,7 +83,7 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory impleme
         inMemoryDNSService = new InMemoryDNSService();
         folder = new TemporaryFolder();
         folder.create();
-        embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticsearchConstants.MAILBOX_INDEX);
+        embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
         embeddedElasticSearch.before();
         jamesServer = createJamesServer();
         jamesServer.start();

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/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 f567d20..dee84b5 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
@@ -68,7 +68,6 @@ public class ElasticSearchMailboxModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        bind(IndexName.class).toInstance(MailboxElasticsearchConstants.MAILBOX_INDEX);
         bind(TypeName.class).toInstance(MailboxElasticsearchConstants.MESSAGE_TYPE);
         bind(ElasticSearchListeningMessageSearchIndex.class).in(Scopes.SINGLETON);
         bind(MessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class);
@@ -76,33 +75,48 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     }
 
     @Provides
+    protected IndexName provideIndexName(ElasticSearchConfiguration elasticSearchConfiguration) throws ConfigurationException {
+        try {
+            return Optional.ofNullable(elasticSearchConfiguration.getConfiguration()
+                .getString("elasticsearch.index.name"))
+                .map(IndexName::new)
+                .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+        } catch (FileNotFoundException e) {
+            LOGGER.info("Could not find ElasticSearch configuration file. Using default index {}", MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX.getValue());
+            return MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX;
+        }
+    }
+
+    @Provides
     @Singleton
-    protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration, AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException {
+    protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration,
+                                           IndexName indexName,
+                                           AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException {
         PropertiesConfiguration propertiesReader = elasticSearchConfiguration.getConfiguration();
         int maxRetries = propertiesReader.getInt("elasticsearch.retryConnection.maxRetries", DEFAULT_CONNECTION_MAX_RETRIES);
         int minDelay = propertiesReader.getInt("elasticsearch.retryConnection.minDelay", DEFAULT_CONNECTION_MIN_DELAY);
 
         return RetryExecutorUtil.retryOnExceptions(executor, maxRetries, minDelay, NoNodeAvailableException.class)
-            .getWithRetry(context -> connectToCluster(propertiesReader))
+            .getWithRetry(context -> connectToCluster(propertiesReader, indexName))
             .get();
     }
 
-    private Client createIndexAndMapping(Client client, PropertiesConfiguration propertiesReader) {
+    private Client createIndexAndMapping(Client client, IndexName indexName, PropertiesConfiguration propertiesReader) {
         IndexCreationFactory.createIndex(client,
-            MailboxElasticsearchConstants.MAILBOX_INDEX,
+            indexName,
             propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.shards", DEFAULT_NB_SHARDS),
             propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.replica", DEFAULT_NB_REPLICA));
         NodeMappingFactory.applyMapping(client,
-            MailboxElasticsearchConstants.MAILBOX_INDEX,
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
         return client;
     }
 
-    private Client connectToCluster(PropertiesConfiguration propertiesReader) throws ConfigurationException {
+    private Client connectToCluster(PropertiesConfiguration propertiesReader, IndexName indexName) throws ConfigurationException {
         LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
 
-        return createIndexAndMapping(createClient(propertiesReader), propertiesReader);
+        return createIndexAndMapping(createClient(propertiesReader), indexName, propertiesReader);
     }
 
     @Provides

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
index 8c300da..5bef22e 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
@@ -34,7 +34,7 @@ import com.google.inject.Module;
 public class EmbeddedElasticSearchRule implements GuiceModuleTestRule {
 
     private final TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX);
+    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
 
     private final RuleChain chain = RuleChain
         .outerRule(temporaryFolder)

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 48eca9d..383d781 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -45,7 +45,7 @@ public class JamesCapabilitiesServerTest {
 
     private GuiceJamesServer server;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
     private DockerCassandraRule cassandraServer = new DockerCassandraRule();
     
     @Rule

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index e9a89cd..7a984ec 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -19,8 +19,7 @@
 
 package org.apache.james.modules;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
+import javax.inject.Singleton;
 
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.IndexCreationFactory;
@@ -30,7 +29,8 @@ import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
 import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
 import org.elasticsearch.client.Client;
 
-import javax.inject.Singleton;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
 
 public class TestElasticSearchModule extends AbstractModule{
 
@@ -49,9 +49,9 @@ public class TestElasticSearchModule extends AbstractModule{
     @Singleton
     protected Client provideClientProvider() {
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
-        IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.MAILBOX_INDEX);
+        IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
         return NodeMappingFactory.applyMapping(client,
-            MailboxElasticsearchConstants.MAILBOX_INDEX,
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/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 dd22797..dc590a9 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
@@ -24,11 +24,14 @@ import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTI
 import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTICSEARCH_PORT;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.io.FileNotFoundException;
 import java.util.Optional;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.IndexName;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -39,6 +42,44 @@ public class ElasticSearchMailboxModuleTest {
     public ExpectedException expectedException = ExpectedException.none();
 
     @Test
+    public void provideIndexNameShouldRetrievedConfiguredIndexName() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String name = "name";
+        configuration.addProperty("elasticsearch.index.name", name);
+
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        IndexName indexName = testee.provideIndexName(() -> configuration);
+
+        assertThat(indexName)
+            .isEqualTo(new IndexName(name));
+    }
+
+    @Test
+    public void provideIndexNameShouldReturnDefaultIndexNameWhenNone() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        IndexName indexName = testee.provideIndexName(() -> configuration);
+
+        assertThat(indexName)
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    }
+
+    @Test
+    public void provideIndexNameShouldReturnDefaultIndexNameWhenError() throws ConfigurationException {
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        IndexName indexName = testee.provideIndexName(() -> {
+            throw new FileNotFoundException();
+        });
+
+        assertThat(indexName)
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    }
+
+    @Test
     public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.indexAttachments", true);

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index 066dc75..684bf3b 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -46,7 +46,7 @@ public class CassandraStepdefs {
 
     private final MainStepdefs mainStepdefs;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
     private DockerCassandraRule cassandraServer = CucumberCassandraSingleton.cassandraServer;
 
     @Inject

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/src/site/xdoc/server/config-elasticsearch.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-elasticsearch.xml b/src/site/xdoc/server/config-elasticsearch.xml
index c554e4c..94420c2 100644
--- a/src/site/xdoc/server/config-elasticsearch.xml
+++ b/src/site/xdoc/server/config-elasticsearch.xml
@@ -56,6 +56,8 @@
           <dd>Number of shards for index provisionned by James</dd>
           <dt><strong>elasticsearch.nb.replica</strong></dt>
           <dd>Number of replica for index provisionned by James</dd>
+          <dt><strong>elasticsearch.index.name</strong></dt>
+          <dd>Name of the index to use with Apache James. It will be created if missing.</dd>
           <dt><strong>elasticsearch.retryConnection.maxRetries</strong></dt>
           <dd>Number of retries when connecting the cluster</dd>
           <dt><strong>elasticsearch.retryConnection.minDelay</strong></dt>


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


[04/15] james-project git commit: JAMES-2202 All ElasticSearch operation should be performed on the Alias

Posted by bt...@apache.org.
JAMES-2202 All ElasticSearch operation should be performed on the Alias


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

Branch: refs/heads/master
Commit: e3e00e1ad2439668acb22e2bd451de85765149e4
Parents: deb93a7
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 11:52:46 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../james/backends/es/DeleteByQueryPerformer.java     | 14 +++++++-------
 .../james/backends/es/ElasticSearchIndexer.java       | 12 ++++++------
 .../james/backends/es/ElasticSearchIndexerTest.java   |  7 +++++--
 .../elasticsearch/search/ElasticSearchSearcher.java   | 14 +++++++-------
 .../elasticsearch/ElasticSearchIntegrationTest.java   |  6 +++---
 .../elasticsearch/host/ElasticSearchHostSystem.java   |  7 +++++--
 6 files changed, 33 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
index 6a44754..0ccea46 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
@@ -43,20 +43,20 @@ public class DeleteByQueryPerformer {
     private final Client client;
     private final ExecutorService executor;
     private final int batchSize;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, IndexName indexName, TypeName typeName) {
-        this(client, executor, DEFAULT_BATCH_SIZE, indexName, typeName);
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, AliasName aliasName, TypeName typeName) {
+        this(client, executor, DEFAULT_BATCH_SIZE, aliasName, typeName);
     }
 
     @VisibleForTesting
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, int batchSize, IndexName indexName, TypeName typeName) {
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, int batchSize, AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.executor = executor;
         this.batchSize = batchSize;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
 
@@ -66,7 +66,7 @@ public class DeleteByQueryPerformer {
 
     protected void doDeleteByQuery(QueryBuilder queryBuilder) {
         new ScrollIterable(client,
-            client.prepareSearch(indexName.getValue())
+            client.prepareSearch(aliasName.getValue())
                 .setTypes(typeName.getValue())
                 .setScroll(TIMEOUT)
                 .setNoFields()
@@ -80,7 +80,7 @@ public class DeleteByQueryPerformer {
         BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
         for (SearchHit hit : searchResponse.getHits()) {
             bulkRequestBuilder.add(client.prepareDelete()
-                .setIndex(indexName.getValue())
+                .setIndex(aliasName.getValue())
                 .setType(typeName.getValue())
                 .setId(hit.getId()));
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index 2716e89..d162a0c 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -88,14 +88,14 @@ public class ElasticSearchIndexer {
     
     private final Client client;
     private final DeleteByQueryPerformer deleteByQueryPerformer;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
-    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer, IndexName indexName, TypeName typeName) {
+    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer, AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.deleteByQueryPerformer = deleteByQueryPerformer;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
     
@@ -104,7 +104,7 @@ public class ElasticSearchIndexer {
         if (LOGGER.isDebugEnabled()) {
             LOGGER.debug("Indexing {}: {}", id, StringUtils.left(content, DEBUG_MAX_LENGTH_CONTENT));
         }
-        return client.prepareIndex(indexName.getValue(), typeName.getValue(), id)
+        return client.prepareIndex(aliasName.getValue(), typeName.getValue(), id)
             .setSource(content)
             .get();
     }
@@ -115,7 +115,7 @@ public class ElasticSearchIndexer {
             BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
             updatedDocumentParts.forEach(updatedDocumentPart -> bulkRequestBuilder.add(
                 client.prepareUpdate(
-                    indexName.getValue(),
+                    aliasName.getValue(),
                     typeName.getValue(),
                     updatedDocumentPart.getId())
                 .setDoc(updatedDocumentPart.getUpdatedDocumentPart())));
@@ -131,7 +131,7 @@ public class ElasticSearchIndexer {
             BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
             ids.forEach(id -> bulkRequestBuilder.add(
                 client.prepareDelete(
-                    indexName.getValue(),
+                    aliasName.getValue(),
                     typeName.getValue(),
                     id)));
             return Optional.of(bulkRequestBuilder.get());

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index 6855622..a4f9aca 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -43,6 +43,7 @@ public class ElasticSearchIndexerTest {
 
     private static final int MINIMUM_BATCH_SIZE = 1;
     private static final IndexName INDEX_NAME = new IndexName("index_name");
+    private static final AliasName ALIAS_NAME = new AliasName("alias_name");
     private static final TypeName TYPE_NAME = new TypeName("type_name");
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, INDEX_NAME);
@@ -57,17 +58,19 @@ public class ElasticSearchIndexerTest {
     public void setup() throws IOException {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(),
+            INDEX_NAME, ALIAS_NAME);
         DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider.get(),
             Executors.newSingleThreadExecutor(),
             MINIMUM_BATCH_SIZE,
-            INDEX_NAME,
+            ALIAS_NAME,
             TYPE_NAME) {
             @Override
             public void perform(QueryBuilder queryBuilder) {
                 doDeleteByQuery(queryBuilder);
             }
         };
-        testee = new ElasticSearchIndexer(clientProvider.get(), deleteByQueryPerformer, INDEX_NAME, TYPE_NAME);
+        testee = new ElasticSearchIndexer(clientProvider.get(), deleteByQueryPerformer, ALIAS_NAME, TYPE_NAME);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index 330d363..cc330e8 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -25,7 +25,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
-import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.TypeName;
 import org.apache.james.backends.es.search.ScrollIterable;
 import org.apache.james.mailbox.MessageUid;
@@ -58,25 +58,25 @@ public class ElasticSearchSearcher {
     private final int size;
     private final MailboxId.Factory mailboxIdFactory;
     private final MessageId.Factory messageIdFactory;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
     public ElasticSearchSearcher(Client client, QueryConverter queryConverter,
                                  MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
-                                 IndexName indexName, TypeName typeName) {
-        this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, indexName, typeName);
+                                 AliasName aliasName, TypeName typeName) {
+        this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, aliasName, typeName);
     }
 
     public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size,
                                  MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
-                                 IndexName indexName, TypeName typeName) {
+                                 AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.queryConverter = queryConverter;
         this.size = size;
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
 
@@ -95,7 +95,7 @@ public class ElasticSearchSearcher {
         return query.getSorts()
             .stream()
             .reduce(
-                client.prepareSearch(indexName.getValue())
+                client.prepareSearch(aliasName.getValue())
                     .setTypes(typeName.getValue())
                     .setScroll(TIMEOUT)
                     .addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID, JsonMessageConstants.MESSAGE_ID)

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index cab06e5..f32f895 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -126,13 +126,13 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
                     BATCH_SIZE,
-                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                     MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
         storeMailboxManager = new InMemoryMailboxManager(

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 2a90a99..cc6b435 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -108,10 +108,13 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
             factory,
-            new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
+            new ElasticSearchIndexer(client,
+                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client,
                 new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES));
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();


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


[10/15] james-project git commit: JAMES-2202 Solve bug when multiple hosts are passed to ElasticSearch configuration

Posted by bt...@apache.org.
JAMES-2202 Solve bug when multiple hosts are passed to ElasticSearch configuration


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

Branch: refs/heads/master
Commit: 76699b3cb4313ca2f73c4da758f328b68aa19a1f
Parents: 0480d7c
Author: benwa <bt...@linagora.com>
Authored: Thu Oct 26 09:44:48 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:55:12 2017 +0700

----------------------------------------------------------------------
 .../mailbox/ElasticSearchConfiguration.java     | 17 ++++++++----
 .../mailbox/ElasticSearchConfigurationTest.java | 29 ++++++++++++++++----
 .../main/java/org/apache/james/util/Host.java   |  2 +-
 3 files changed, 35 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/76699b3c/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index 3fc502f..e73ecc7 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.modules.mailbox;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -30,6 +32,7 @@ import org.apache.james.mailbox.elasticsearch.IndexAttachments;
 import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.util.Host;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 
@@ -52,6 +55,7 @@ public class ElasticSearchConfiguration {
     public static final int DEFAULT_NB_SHARDS = 1;
     public static final int DEFAULT_NB_REPLICA = 0;
     public static final int DEFAULT_PORT = 9300;
+    public static final Optional<Integer> DEFAULT_PORT_AS_OPTIONAL = Optional.of(DEFAULT_PORT);
 
     public static ElasticSearchConfiguration fromProperties(PropertiesConfiguration configuration) throws ConfigurationException {
         int nbShards = configuration.getInt(ELASTICSEARCH_NB_SHARDS, DEFAULT_NB_SHARDS);
@@ -95,8 +99,7 @@ public class ElasticSearchConfiguration {
             propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null));
         Optional<Integer> masterPort = Optional.ofNullable(
             propertiesReader.getInteger(ELASTICSEARCH_PORT, null));
-        Optional<String> multiHosts = Optional.ofNullable(
-            propertiesReader.getString(ELASTICSEARCH_HOSTS, null));
+        List<String> multiHosts = Arrays.asList(propertiesReader.getStringArray(ELASTICSEARCH_HOSTS));
 
         validateHostsConfigurationOptions(masterHost, masterPort, multiHosts);
 
@@ -105,21 +108,23 @@ public class ElasticSearchConfiguration {
                 Host.from(masterHost.get(),
                 masterPort.get()));
         } else {
-            return Host.parseHosts(multiHosts.get(), DEFAULT_PORT);
+            return multiHosts.stream()
+                .map(ipAndPort -> Host.parse(ipAndPort, DEFAULT_PORT_AS_OPTIONAL))
+                .collect(Guavate.toImmutableList());
         }
     }
 
     @VisibleForTesting
     static void validateHostsConfigurationOptions(Optional<String> masterHost,
                                                   Optional<Integer> masterPort,
-                                                  Optional<String> multiHosts) throws ConfigurationException {
+                                                  List<String> multiHosts) throws ConfigurationException {
         if (masterHost.isPresent() != masterPort.isPresent()) {
             throw new ConfigurationException(ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + " should be specified together");
         }
-        if (multiHosts.isPresent() && masterHost.isPresent()) {
+        if (!multiHosts.isEmpty() && masterHost.isPresent()) {
             throw new ConfigurationException("You should choose between mono host set up and " + ELASTICSEARCH_HOSTS);
         }
-        if (!multiHosts.isPresent() && !masterHost.isPresent()) {
+        if (multiHosts.isEmpty() && !masterHost.isPresent()) {
             throw new ConfigurationException("You should specify either (" + ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + ") or " + ELASTICSEARCH_HOSTS);
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/76699b3c/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
index 514f967..9c1a3fc 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
@@ -33,6 +33,8 @@ import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.util.Host;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public class ElasticSearchConfigurationTest {
 
     @Test
@@ -253,6 +255,21 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
+    public void getHostsShouldReturnConfiguredHostsWhenListIsUsed() throws ConfigurationException {
+        String hostname = "myHost";
+        String hostname2 = "myOtherHost";
+        int port = 2154;
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", hostname + "," + hostname2 + ":" + port);
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getHosts())
+            .containsOnly(Host.from(hostname, ElasticSearchConfiguration.DEFAULT_PORT),
+                Host.from(hostname2, port));
+    }
+
+    @Test
     public void getHostsShouldReturnConfiguredHosts() throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         String hostname = "myHost";
@@ -285,7 +302,7 @@ public class ElasticSearchConfigurationTest {
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.empty(),
                 Optional.empty(),
-                Optional.empty()))
+                ImmutableList.of()))
             .isInstanceOf(ConfigurationException.class)
             .hasMessage("You should specify either (" + ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST +
                 " and " + ElasticSearchConfiguration.ELASTICSEARCH_PORT +
@@ -298,7 +315,7 @@ public class ElasticSearchConfigurationTest {
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.of("localhost"),
                 Optional.of(9200),
-                Optional.of("localhost:9200")))
+                ImmutableList.of("localhost:9200")))
             .isInstanceOf(ConfigurationException.class)
             .hasMessage("You should choose between mono host set up and " + ElasticSearchConfiguration.ELASTICSEARCH_HOSTS);
     }
@@ -309,7 +326,7 @@ public class ElasticSearchConfigurationTest {
             ElasticSearchConfiguration.validateHostsConfigurationOptions(
                 Optional.of("localhost"),
                 Optional.empty(),
-                Optional.empty()))
+                ImmutableList.of()))
             .isInstanceOf(ConfigurationException.class)
             .hasMessage(ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST +
                 " and " + ElasticSearchConfiguration.ELASTICSEARCH_PORT + " should be specified together");
@@ -321,7 +338,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.empty(),
             Optional.of(9200),
-            Optional.empty()))
+            ImmutableList.of()))
         .isInstanceOf(ConfigurationException.class)
         .hasMessage(ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST + " and " +
             ElasticSearchConfiguration.ELASTICSEARCH_PORT + " should be specified together");
@@ -332,7 +349,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.of("localhost"),
             Optional.of(9200),
-            Optional.empty());
+            ImmutableList.of());
     }
 
     @Test
@@ -340,7 +357,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration.validateHostsConfigurationOptions(
             Optional.empty(),
             Optional.empty(),
-            Optional.of("localhost:9200"));
+            ImmutableList.of("localhost:9200"));
     }
 
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/76699b3c/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java b/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
index 4776f06..9adc41c 100644
--- a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
@@ -62,7 +62,7 @@ public class Host {
         return parse(ipAndPort, Optional.empty());
     }
 
-    private static Host parse(String ipAndPort, Optional<Integer> defaultPort) {
+    public static Host parse(String ipAndPort, Optional<Integer> defaultPort) {
         Preconditions.checkNotNull(ipAndPort);
         Preconditions.checkArgument(!ipAndPort.isEmpty());
 


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


[03/15] james-project git commit: JAMES-2202 Fix another typo

Posted by bt...@apache.org.
JAMES-2202 Fix another typo


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

Branch: refs/heads/master
Commit: fc927f0ac713d2a2710b0b1ad9bb584a268d48ca
Parents: 4f663b2
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 15:55:52 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../apache/james/modules/mailbox/ElasticSearchMailboxModule.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fc927f0a/server/container/guice/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 1939523..bab0ae3 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
@@ -109,7 +109,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
 
     @Provides
     @Singleton
-    protected Client provideClientProvider(ElasticSearchConfiguration configuration,
+    protected Client provideClient(ElasticSearchConfiguration configuration,
                                            IndexCreationFactory indexCreationFactory,
                                            AsyncRetryExecutor executor) throws ExecutionException, InterruptedException {
 


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


[07/15] james-project git commit: JAMES-2202 Handle a read and a write alias

Posted by bt...@apache.org.
JAMES-2202 Handle a read and a write alias

Code was bloating due to index and alias creation. I thus decided to:
 - Separate concerns of configuration parsing and injection
 - Make IndexCreationFatory a real factory


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

Branch: refs/heads/master
Commit: f3b6ac5db1f8fbbea401381a47651b9b0f1227cc
Parents: e3e00e1
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 13:40:35 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../james/backends/es/ClientProviderImpl.java   |   5 +
 .../backends/es/DeleteByQueryPerformer.java     |   2 +-
 .../backends/es/ElasticSearchConstants.java     |  25 ++
 .../james/backends/es/ElasticSearchIndexer.java |   5 +-
 .../james/backends/es/IndexCreationFactory.java |  65 +++-
 .../backends/es/ElasticSearchIndexerTest.java   |   6 +-
 .../backends/es/IndexCreationFactoryTest.java   |  10 +-
 .../backends/es/NodeMappingFactoryTest.java     |   5 +-
 .../backends/es/search/ScrollIterableTest.java  |   5 +-
 .../MailboxElasticsearchConstants.java          |   3 +-
 .../search/ElasticSearchSearcher.java           |   4 +-
 .../ElasticSearchIntegrationTest.java           |  15 +-
 .../host/ElasticSearchHostSystem.java           |  15 +-
 .../mailbox/ElasticSearchConfiguration.java     | 185 +++++++++-
 .../mailbox/ElasticSearchMailboxModule.java     | 141 +++-----
 .../apache/james/DockerElasticSearchRule.java   |  14 +-
 .../james/modules/TestElasticSearchModule.java  |   9 +-
 .../mailbox/ElasticSearchConfigurationTest.java | 347 +++++++++++++++++++
 .../mailbox/ElasticSearchMailboxModuleTest.java | 215 ------------
 .../main/java/org/apache/james/util/Host.java   |   3 +-
 src/site/xdoc/server/config-elasticsearch.xml   |   9 +-
 21 files changed, 723 insertions(+), 365 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/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 a56e056..6118739 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
@@ -42,6 +42,11 @@ public class ClientProviderImpl implements ClientProvider {
         return new ClientProviderImpl(Host.parseHosts(hostsString));
     }
 
+    public static ClientProviderImpl fromHosts(ImmutableList<Host> hosts) {
+        Preconditions.checkNotNull(hosts, "Hosts should not be null");
+        return new ClientProviderImpl(hosts);
+    }
+
     private static boolean isValidPort(Integer port) {
         return port > 0 && port <= 65535;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
index 0ccea46..6c8c2e3 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
@@ -47,7 +47,7 @@ public class DeleteByQueryPerformer {
     private final TypeName typeName;
 
     @Inject
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, AliasName aliasName, TypeName typeName) {
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService executor, @Named(ElasticSearchConstants.WRITE_ALIAS) AliasName aliasName, TypeName typeName) {
         this(client, executor, DEFAULT_BATCH_SIZE, aliasName, typeName);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConstants.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConstants.java
new file mode 100644
index 0000000..8830208
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConstants.java
@@ -0,0 +1,25 @@
+/****************************************************************
+ * 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;
+
+public interface ElasticSearchConstants {
+    String WRITE_ALIAS = "injectWriteAlias";
+    String READ_ALIAS = "injectReadAlias";
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index d162a0c..57dbc9e 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import java.util.Optional;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.apache.commons.lang3.StringUtils;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
@@ -92,7 +93,9 @@ public class ElasticSearchIndexer {
     private final TypeName typeName;
 
     @Inject
-    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer, AliasName aliasName, TypeName typeName) {
+    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer,
+                                @Named(ElasticSearchConstants.WRITE_ALIAS) AliasName aliasName,
+                                TypeName typeName) {
         this.client = client;
         this.deleteByQueryPerformer = deleteByQueryPerformer;
         this.aliasName = aliasName;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index 2eb9e1b..a4bcc84 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -22,6 +22,7 @@ package org.apache.james.backends.es;
 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 
 import java.io.IOException;
+import java.util.Optional;
 
 import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
 import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
@@ -31,6 +32,9 @@ import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
 public class IndexCreationFactory {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(IndexCreationFactory.class);
@@ -38,26 +42,55 @@ public class IndexCreationFactory {
     private static final int DEFAULT_NB_REPLICA = 0;
     public static final String CASE_INSENSITIVE = "case_insensitive";
 
-    public static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName, int nbShards, int nbReplica) {
-        try {
-            return createIndexAndAlias(client, indexName, aliasName, generateSetting(nbShards, nbReplica));
-        } catch (IOException e) {
-            LOGGER.error("Error while creating index : ", e);
-            return client;
-        }
+    private IndexName indexName;
+    private ImmutableList.Builder<AliasName> aliases;
+    private Optional<Integer> nbShards;
+    private Optional<Integer> nbReplica;
+
+    public IndexCreationFactory() {
+        indexName = null;
+        aliases = ImmutableList.builder();
+        nbShards = Optional.empty();
+        nbReplica = Optional.empty();
+    }
+
+    public IndexCreationFactory onIndex(IndexName indexName) {
+        Preconditions.checkNotNull(indexName);
+        this.indexName = indexName;
+        return this;
     }
 
-    public static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName) {
-        return createIndexAndAlias(client, indexName, aliasName, DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA);
+    public IndexCreationFactory addAlias(AliasName aliasName) {
+        Preconditions.checkNotNull(aliasName);
+        this.aliases.add(aliasName);
+        return this;
     }
 
-    private static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName, XContentBuilder settings) {
-        createIndexIfNeeded(client, indexName, settings);
-        createAliasIfNeeded(client, indexName, aliasName);
+    public IndexCreationFactory nbShards(int nbShards) {
+        this.nbShards = Optional.of(nbShards);
+        return this;
+    }
+
+    public IndexCreationFactory nbReplica(int nbReplica) {
+        this.nbReplica = Optional.of(nbReplica);
+        return this;
+    }
+
+    public Client createIndexAndAliases(Client client) {
+        Preconditions.checkNotNull(indexName);
+        try {
+            createIndexIfNeeded(client, indexName, generateSetting(
+                nbShards.orElse(DEFAULT_NB_SHARDS),
+                nbReplica.orElse(DEFAULT_NB_REPLICA)));
+            aliases.build()
+                .forEach(alias -> createAliasIfNeeded(client, indexName, alias));
+        } catch (IOException e) {
+            LOGGER.error("Error while creating index : ", e);
+        }
         return client;
     }
 
-    private static void createAliasIfNeeded(Client client, IndexName indexName, AliasName aliasName) {
+    private void createAliasIfNeeded(Client client, IndexName indexName, AliasName aliasName) {
         if (!aliasExist(client, aliasName)) {
             client.admin()
                 .indices()
@@ -67,7 +100,7 @@ public class IndexCreationFactory {
         }
     }
 
-    private static boolean aliasExist(Client client, AliasName aliasName) {
+    private boolean aliasExist(Client client, AliasName aliasName) {
         return client.admin()
             .indices()
             .aliasesExist(new GetAliasesRequest()
@@ -76,7 +109,7 @@ public class IndexCreationFactory {
             .exists();
     }
 
-    private static void createIndexIfNeeded(Client client, IndexName indexName, XContentBuilder settings) {
+    private void createIndexIfNeeded(Client client, IndexName indexName, XContentBuilder settings) {
         try {
             client.admin()
                 .indices()
@@ -89,7 +122,7 @@ public class IndexCreationFactory {
         }
     }
 
-    private static XContentBuilder generateSetting(int nbShards, int nbReplica) throws IOException {
+    private XContentBuilder generateSetting(int nbShards, int nbReplica) throws IOException {
         return jsonBuilder()
             .startObject()
                 .field("number_of_shards", nbShards)

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index a4f9aca..a3a6d9c 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -58,8 +58,10 @@ public class ElasticSearchIndexerTest {
     public void setup() throws IOException {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
-        IndexCreationFactory.createIndexAndAlias(clientProvider.get(),
-            INDEX_NAME, ALIAS_NAME);
+        new IndexCreationFactory()
+            .onIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(clientProvider.get());
         DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider.get(),
             Executors.newSingleThreadExecutor(),
             MINIMUM_BATCH_SIZE,

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
index dee1142..7735eb9 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
@@ -41,11 +41,17 @@ public class IndexCreationFactoryTest {
     @Before
     public void setUp() {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
-        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+        new IndexCreationFactory()
+            .onIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(clientProvider.get());
     }
 
     @Test
     public void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
-        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+        new IndexCreationFactory()
+            .onIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(clientProvider.get());
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
index 6aca8d7..1e0eb79 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
@@ -46,7 +46,10 @@ public class NodeMappingFactoryTest {
     @Before
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
-        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+        new IndexCreationFactory()
+            .onIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(clientProvider.get());
         NodeMappingFactory.applyMapping(clientProvider.get(),
             INDEX_NAME,
             TYPE_NAME,

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
index 4515f96..b296b8e 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
@@ -67,7 +67,10 @@ public class ScrollIterableTest {
     @Before
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
-        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+        new IndexCreationFactory()
+            .onIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(clientProvider.get());
         embeddedElasticSearch.awaitForElasticSearch();
         NodeMappingFactory.applyMapping(clientProvider.get(), INDEX_NAME, TYPE_NAME, getMappingsSources());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
index fb89b8e..e1d87c2 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
@@ -24,7 +24,8 @@ import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.TypeName;
 
 public interface MailboxElasticsearchConstants {
-    AliasName DEFAULT_MAILBOX_ALIAS = new AliasName("mailboxAlias");
+    AliasName DEFAULT_MAILBOX_WRITE_ALIAS = new AliasName("mailboxWriteAlias");
+    AliasName DEFAULT_MAILBOX_READ_ALIAS = new AliasName("mailboxReadAlias");
     IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
     TypeName MESSAGE_TYPE = new TypeName("message");
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index cc330e8..acf7baf 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -24,7 +24,9 @@ import java.util.Optional;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
+import org.apache.james.backends.es.ElasticSearchConstants;
 import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.TypeName;
 import org.apache.james.backends.es.search.ScrollIterable;
@@ -64,7 +66,7 @@ public class ElasticSearchSearcher {
     @Inject
     public ElasticSearchSearcher(Client client, QueryConverter queryConverter,
                                  MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
-                                 AliasName aliasName, TypeName typeName) {
+                                 @Named(ElasticSearchConstants.READ_ALIAS) AliasName aliasName, TypeName typeName) {
         this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, aliasName, typeName);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index f32f895..4e18134 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -110,10 +110,11 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     @Override
     protected void initializeMailboxManager() throws Exception {
         Client client = NodeMappingFactory.applyMapping(
-            IndexCreationFactory.createIndexAndAlias(
-                new TestingClientProvider(embeddedElasticSearch.getNode()).get(),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS),
+            new IndexCreationFactory()
+                .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias( MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .addAlias( MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
@@ -126,13 +127,13 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
                     BATCH_SIZE,
-                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
                     MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
         storeMailboxManager = new InMemoryMailboxManager(

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index cc6b435..d83f96f 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -95,10 +95,11 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
-            IndexCreationFactory.createIndexAndAlias(
-                new TestingClientProvider(embeddedElasticSearch.getNode()).get(),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS),
+            new IndexCreationFactory()
+                .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
@@ -109,12 +110,12 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
             factory,
             new ElasticSearchIndexer(client,
-                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client,
                 new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES));
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index 0c39e81..7d65618 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -19,13 +19,192 @@
 
 package org.apache.james.modules.mailbox;
 
+import java.util.Objects;
+import java.util.Optional;
+
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.util.Host;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+
+public class ElasticSearchConfiguration {
+    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";
+    public static final String ELASTICSEARCH_INDEX_NAME = "elasticsearch.index.name";
+    public static final String ELASTICSEARCH_NB_REPLICA = "elasticsearch.nb.replica";
+    public static final String ELASTICSEARCH_NB_SHARDS = "elasticsearch.nb.shards";
+    public static final String ELASTICSEARCH_ALIAS_READ_NAME = "elasticsearch.alias.read.name";
+    public static final String ELASTICSEARCH_ALIAS_WRITE_NAME = "elasticsearch.alias.write.name";
+    public static final String ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY = "elasticsearch.retryConnection.minDelay";
+    public static final String ELASTICSEARCH_RETRY_CONNECTION_MAX_RETRIES = "elasticsearch.retryConnection.maxRetries";
+    public static final String ELASTICSEARCH_INDEX_ATTACHMENTS = "elasticsearch.indexAttachments";
+
+    public static final int DEFAULT_CONNECTION_MAX_RETRIES = 7;
+    public static final int DEFAULT_CONNECTION_MIN_DELAY = 3000;
+    public static final boolean DEFAULT_INDEX_ATTACHMENTS = true;
+    public static final int DEFAULT_NB_SHARDS = 1;
+    public static final int DEFAULT_NB_REPLICA = 0;
+    public static final int DEFAULT_PORT = 9300;
+
+    public static ElasticSearchConfiguration fromProperties(PropertiesConfiguration configuration) throws ConfigurationException {
+        int nbShards = configuration.getInt(ELASTICSEARCH_NB_SHARDS, DEFAULT_NB_SHARDS);
+        int nbReplica = configuration.getInt(ELASTICSEARCH_NB_REPLICA, DEFAULT_NB_REPLICA);
+        int maxRetries = configuration.getInt(ELASTICSEARCH_RETRY_CONNECTION_MAX_RETRIES, DEFAULT_CONNECTION_MAX_RETRIES);
+        int minDelay = configuration.getInt(ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY, DEFAULT_CONNECTION_MIN_DELAY);
+        IndexAttachments indexAttachments = provideIndexAttachments(configuration);
+        ImmutableList<Host> hosts = getHosts(configuration);
+
+        AliasName readAlias = Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_READ_NAME))
+            .map(AliasName::new)
+            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
+        AliasName writeAlias = Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_WRITE_NAME))
+            .map(AliasName::new)
+            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
+        IndexName indexName = Optional.ofNullable(configuration.getString(ELASTICSEARCH_INDEX_NAME))
+            .map(IndexName::new)
+            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+
+        return new ElasticSearchConfiguration(
+            hosts,
+            indexName,
+            readAlias,
+            writeAlias,
+            nbShards,
+            nbReplica,
+            minDelay,
+            maxRetries,
+            indexAttachments);
+    }
+
+    private static IndexAttachments provideIndexAttachments(PropertiesConfiguration configuration) {
+        if (configuration.getBoolean(ELASTICSEARCH_INDEX_ATTACHMENTS, DEFAULT_INDEX_ATTACHMENTS)) {
+            return IndexAttachments.YES;
+        }
+        return IndexAttachments.NO;
+    }
+
+    private static ImmutableList<Host> getHosts(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 ImmutableList.of(
+                Host.from(monoHostAddress.get(),
+                monoHostPort.get()));
+        } else {
+            return Host.parseHosts(multiHosts.get(), DEFAULT_PORT);
+        }
+    }
+
+    @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 final ImmutableList<Host> hosts;
+    private final IndexName indexName;
+    private final AliasName readAliasName;
+    private final AliasName writeAliasName;
+    private final int nbShards;
+    private final int nbReplica;
+    private final int minDelay;
+    private final int maxRetries;
+    private final IndexAttachments indexAttachment;
+
+    public ElasticSearchConfiguration(ImmutableList<Host> hosts, IndexName indexName, AliasName readAliasName,
+                                      AliasName writeAliasName, int nbShards, int nbReplica, int minDelay,
+                                      int maxRetries, IndexAttachments indexAttachment) {
+        this.hosts = hosts;
+        this.indexName = indexName;
+        this.readAliasName = readAliasName;
+        this.writeAliasName = writeAliasName;
+        this.nbShards = nbShards;
+        this.nbReplica = nbReplica;
+        this.minDelay = minDelay;
+        this.maxRetries = maxRetries;
+        this.indexAttachment = indexAttachment;
+    }
+
+    public ImmutableList<Host> getHosts() {
+        return hosts;
+    }
+
+    public IndexName getIndexName() {
+        return indexName;
+    }
+
+    public AliasName getReadAliasName() {
+        return readAliasName;
+    }
+
+    public AliasName getWriteAliasName() {
+        return writeAliasName;
+    }
+
+    public int getNbShards() {
+        return nbShards;
+    }
+
+    public int getNbReplica() {
+        return nbReplica;
+    }
+
+    public int getMinDelay() {
+        return minDelay;
+    }
+
+    public int getMaxRetries() {
+        return maxRetries;
+    }
 
-import java.io.FileNotFoundException;
+    public IndexAttachments getIndexAttachment() {
+        return indexAttachment;
+    }
 
-public interface ElasticSearchConfiguration {
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof ElasticSearchConfiguration) {
+            ElasticSearchConfiguration that = (ElasticSearchConfiguration) o;
 
-    PropertiesConfiguration getConfiguration() throws FileNotFoundException, ConfigurationException;
+            return Objects.equals(this.nbShards, that.nbShards)
+                && Objects.equals(this.nbReplica, that.nbReplica)
+                && Objects.equals(this.minDelay, that.minDelay)
+                && Objects.equals(this.maxRetries, that.maxRetries)
+                && Objects.equals(this.indexAttachment, that.indexAttachment)
+                && Objects.equals(this.hosts, that.hosts)
+                && Objects.equals(this.indexName, that.indexName)
+                && Objects.equals(this.readAliasName, that.readAliasName)
+                && Objects.equals(this.writeAliasName, that.writeAliasName);
+        }
+        return false;
+    }
 
+    @Override
+    public final int hashCode() {
+        return Objects.hash(hosts, indexName, readAliasName, writeAliasName, nbShards,
+            nbReplica, minDelay, maxRetries, indexAttachment);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/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 ea59317..d9e7858 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
@@ -21,13 +21,14 @@ package org.apache.james.modules.mailbox;
 
 import java.io.FileNotFoundException;
 import java.time.LocalDateTime;
-import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 
+import javax.inject.Named;
 import javax.inject.Singleton;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.ElasticSearchConstants;
 import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.ClientProviderImpl;
 import org.apache.james.backends.es.IndexCreationFactory;
@@ -47,7 +48,6 @@ import org.elasticsearch.client.transport.NoNodeAvailableException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
@@ -57,14 +57,6 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchMailboxModule.class);
 
     public static final String ELASTICSEARCH_CONFIGURATION_NAME = "elasticsearch";
-    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;
-    private static final int DEFAULT_CONNECTION_MIN_DELAY = 3000;
-    private static final boolean DEFAULT_INDEX_ATTACHMENTS = true;
-    private static final int DEFAULT_NB_SHARDS = 1;
-    private static final int DEFAULT_NB_REPLICA = 0;
     private static final String LOCALHOST = "127.0.0.1";
 
     @Override
@@ -76,117 +68,72 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     }
 
     @Provides
-    protected IndexName provideIndexName(ElasticSearchConfiguration elasticSearchConfiguration)
-            throws ConfigurationException {
+    @Singleton
+    private ElasticSearchConfiguration getElasticSearchConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
         try {
-            return Optional.ofNullable(elasticSearchConfiguration.getConfiguration()
-                .getString("elasticsearch.index.name"))
-                .map(IndexName::new)
-                .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+            PropertiesConfiguration configuration = propertiesProvider.getConfiguration(ELASTICSEARCH_CONFIGURATION_NAME);
+            return ElasticSearchConfiguration.fromProperties(configuration);
         } catch (FileNotFoundException e) {
-            LOGGER.info("Could not find ElasticSearch configuration file. Using default index {}", MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX.getValue());
-            return MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX;
+            LOGGER.warn("Could not find " + ELASTICSEARCH_CONFIGURATION_NAME + " configuration file. Using 127.0.0.1:9300 as contact point");
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            configuration.addProperty(ElasticSearchConfiguration.ELASTICSEARCH_HOSTS, LOCALHOST);
+            return ElasticSearchConfiguration.fromProperties(configuration);
         }
     }
 
     @Provides
-    protected AliasName provideAliasName(ElasticSearchConfiguration elasticSearchConfiguration)
-            throws ConfigurationException {
-        try {
-            return Optional.ofNullable(elasticSearchConfiguration.getConfiguration()
-                .getString("elasticsearch.alias.name"))
-                .map(AliasName::new)
-                .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
-        } catch (FileNotFoundException e) {
-            LOGGER.info("Could not find ElasticSearch configuration file. Using default alias {}", MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX.getValue());
-            return MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS;
-        }
+    protected IndexName provideIndexName(ElasticSearchConfiguration configuration) {
+        return configuration.getIndexName();
     }
 
-    @Provides
-    @Singleton
-    protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration,
-                                           IndexName indexName, AliasName aliasName,
-                                           AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException {
-        PropertiesConfiguration propertiesReader = elasticSearchConfiguration.getConfiguration();
-        int maxRetries = propertiesReader.getInt("elasticsearch.retryConnection.maxRetries", DEFAULT_CONNECTION_MAX_RETRIES);
-        int minDelay = propertiesReader.getInt("elasticsearch.retryConnection.minDelay", DEFAULT_CONNECTION_MIN_DELAY);
-
-        return RetryExecutorUtil.retryOnExceptions(executor, maxRetries, minDelay, NoNodeAvailableException.class)
-            .getWithRetry(context -> connectToCluster(propertiesReader, indexName, aliasName))
-            .get();
+    @Provides @Named(ElasticSearchConstants.READ_ALIAS)
+    protected AliasName provideReadAliasName(ElasticSearchConfiguration configuration) {
+        return configuration.getReadAliasName();
     }
 
-    private Client createIndexAndMapping(Client client, IndexName indexName, AliasName aliasName, PropertiesConfiguration propertiesReader) {
-        IndexCreationFactory.createIndexAndAlias(client,
-            indexName,
-            aliasName,
-            propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.shards", DEFAULT_NB_SHARDS),
-            propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.replica", DEFAULT_NB_REPLICA));
-        NodeMappingFactory.applyMapping(client,
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-            MailboxElasticsearchConstants.MESSAGE_TYPE,
-            MailboxMappingFactory.getMappingContent());
-        return client;
+    @Provides @Named(ElasticSearchConstants.WRITE_ALIAS)
+    protected AliasName provideWriteAliasName(ElasticSearchConfiguration configuration) {
+        return configuration.getWriteAliasName();
     }
 
-    private Client connectToCluster(PropertiesConfiguration propertiesReader, IndexName indexName, AliasName aliasName)
-            throws ConfigurationException {
-        LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
-
-        return createIndexAndMapping(createClient(propertiesReader), indexName, aliasName, propertiesReader);
+    @Provides
+    @Singleton
+    protected IndexCreationFactory provideIndexCreationFactory(ElasticSearchConfiguration configuration) {
+        return new IndexCreationFactory()
+            .onIndex(configuration.getIndexName())
+            .addAlias(configuration.getReadAliasName())
+            .addAlias(configuration.getWriteAliasName())
+            .nbShards(configuration.getNbShards())
+            .nbReplica(configuration.getNbReplica());
     }
 
     @Provides
     @Singleton
-    private ElasticSearchConfiguration getElasticSearchConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
-        try {
-            PropertiesConfiguration configuration = propertiesProvider.getConfiguration(ELASTICSEARCH_CONFIGURATION_NAME);
-            return () -> configuration;
-        } catch (FileNotFoundException e) {
-            LOGGER.warn("Could not find " + ELASTICSEARCH_CONFIGURATION_NAME + " configuration file. Using 127.0.0.1:9300 as contact point");
-            PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
-            propertiesConfiguration.addProperty(ELASTICSEARCH_HOSTS, LOCALHOST);
-            return () -> propertiesConfiguration;
-        }
+    protected Client provideClientProvider(ElasticSearchConfiguration configuration,
+                                           IndexCreationFactory indexCreationFactory,
+                                           AsyncRetryExecutor executor) throws ExecutionException, InterruptedException {
+
+        return RetryExecutorUtil.retryOnExceptions(executor, configuration.getMaxRetries(), configuration.getMinDelay(), NoNodeAvailableException.class)
+            .getWithRetry(context -> connectToCluster(configuration, indexCreationFactory))
+            .get();
     }
 
-    private Client createClient(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));
+    private Client connectToCluster(ElasticSearchConfiguration configuration, IndexCreationFactory indexCreationFactory) {
+        LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
 
-        validateHostsConfigurationOptions(monoHostAddress, monoHostPort, multiHosts);
+        Client client = ClientProviderImpl.fromHosts(configuration.getHosts()).get();
 
-        if (monoHostAddress.isPresent()) {
-            return ClientProviderImpl.forHost(monoHostAddress.get(), monoHostPort.get()).get();
-        } else {
-            return ClientProviderImpl.fromHostsString(multiHosts.get()).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);
-        }
+        indexCreationFactory.createIndexAndAliases(client);
+        return NodeMappingFactory.applyMapping(client,
+            configuration.getIndexName(),
+            MailboxElasticsearchConstants.MESSAGE_TYPE,
+            MailboxMappingFactory.getMappingContent());
     }
 
     @Provides
     @Singleton
-    public IndexAttachments provideIndexAttachments(PropertiesConfiguration configuration) {
-        if (configuration.getBoolean(ELASTICSEARCH_CONFIGURATION_NAME + ".indexAttachments", DEFAULT_INDEX_ATTACHMENTS)) {
-            return IndexAttachments.YES;
-        }
-        return IndexAttachments.NO;
+    public IndexAttachments provideIndexAttachments(ElasticSearchConfiguration configuration) {
+        return configuration.getIndexAttachment();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
index 75fe4a3..85171ba 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
@@ -19,12 +19,14 @@
 
 package org.apache.james;
 
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.modules.mailbox.ElasticSearchConfiguration;
 import org.apache.james.util.streams.SwarmGenericContainer;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
+import com.google.common.base.Throwables;
 import com.google.inject.Module;
 
 
@@ -33,7 +35,7 @@ public class DockerElasticSearchRule implements GuiceModuleTestRule {
     private static final int ELASTIC_SEARCH_PORT = 9300;
     public static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
 
-    public PropertiesConfiguration getElasticSearchConfigurationForDocker() {
+    public ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
 
         configuration.addProperty("elasticsearch.masterHost", getIp());
@@ -50,7 +52,11 @@ public class DockerElasticSearchRule implements GuiceModuleTestRule {
         configuration.addProperty("elasticsearch.metrics.reports.period", 30);
         configuration.addProperty("elasticsearch.metrics.reports.index", "james-metrics");
 
-        return configuration;
+        try {
+            return ElasticSearchConfiguration.fromProperties(configuration);
+        } catch (ConfigurationException e) {
+            throw Throwables.propagate(e);
+        }
     }
 
     private SwarmGenericContainer elasticSearchContainer = new SwarmGenericContainer("elasticsearch:2.2.2")
@@ -67,7 +73,9 @@ public class DockerElasticSearchRule implements GuiceModuleTestRule {
 
     @Override
     public Module getModule() {
-        return (binder) -> binder.bind(ElasticSearchConfiguration.class).toInstance(this::getElasticSearchConfigurationForDocker);
+        return (binder) ->
+                binder.bind(ElasticSearchConfiguration.class)
+                    .toInstance(getElasticSearchConfigurationForDocker());
     }
 
     public String getIp() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 2b6b272..5e30618 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -49,9 +49,12 @@ public class TestElasticSearchModule extends AbstractModule{
     @Singleton
     protected Client provideClientProvider() {
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
-        IndexCreationFactory.createIndexAndAlias(client,
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
+
+        new IndexCreationFactory()
+            .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
+            .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+            .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+            .createIndexAndAliases(client);
         return NodeMappingFactory.applyMapping(client,
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
new file mode 100644
index 0000000..f4b7765
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
@@ -0,0 +1,347 @@
+/****************************************************************
+ * 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.modules.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Optional;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.util.Host;
+import org.junit.Test;
+
+public class ElasticSearchConfigurationTest {
+
+    @Test
+    public void getNbReplicaShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        int value = 36;
+        configuration.addProperty("elasticsearch.nb.replica", value);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getNbReplica())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getNbReplicaShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getNbReplica())
+            .isEqualTo(ElasticSearchConfiguration.DEFAULT_NB_REPLICA);
+    }
+
+    @Test
+    public void getNbShardsShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        int value = 36;
+        configuration.addProperty("elasticsearch.nb.shards", value);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getNbShards())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getNbShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getNbShards())
+            .isEqualTo(ElasticSearchConfiguration.DEFAULT_NB_SHARDS);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        int value = 36;
+        configuration.addProperty("elasticsearch.retryConnection.maxRetries", value);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getMaxRetries())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getMaxRetries())
+            .isEqualTo(ElasticSearchConfiguration.DEFAULT_CONNECTION_MAX_RETRIES);
+    }
+
+    @Test
+    public void getMinDelayShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        int value = 36;
+        configuration.addProperty("elasticsearch.retryConnection.minDelay", value);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getMinDelay())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getMinDelayShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getMinDelay())
+            .isEqualTo(ElasticSearchConfiguration.DEFAULT_CONNECTION_MIN_DELAY);
+    }
+
+    @Test
+    public void getIndexNameShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String name = "name";
+        configuration.addProperty("elasticsearch.index.name", name);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getIndexName())
+            .isEqualTo(new IndexName(name));
+    }
+
+    @Test
+    public void getIndexNameShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getIndexName())
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    }
+
+    @Test
+    public void getReadAliasNameShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String name = "name";
+        configuration.addProperty("elasticsearch.alias.read.name", name);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getReadAliasName())
+            .isEqualTo(new AliasName(name));
+    }
+
+    @Test
+    public void getReadAliasNameShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getReadAliasName())
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
+    }
+
+
+    @Test
+    public void getWriteAliasNameNameShouldReturnConfiguredValue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String name = "name";
+        configuration.addProperty("elasticsearch.alias.write.name", name);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getWriteAliasName())
+            .isEqualTo(new AliasName(name));
+    }
+
+    @Test
+    public void getWriteAliasNameShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getWriteAliasName())
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
+    }
+
+    @Test
+    public void getIndexAttachmentShouldReturnConfiguredValueWhenTrue() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.indexAttachments", true);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getIndexAttachment())
+            .isEqualTo(IndexAttachments.YES);
+    }
+
+    @Test
+    public void getIndexAttachmentShouldReturnConfiguredValueWhenFalse() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.indexAttachments", false);
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getIndexAttachment())
+            .isEqualTo(IndexAttachments.NO);
+    }
+
+    @Test
+    public void getIndexAttachmentShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("elasticsearch.hosts", "127.0.0.1");
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getIndexAttachment())
+            .isEqualTo(IndexAttachments.YES);
+    }
+
+
+    @Test
+    public void getHostsShouldReturnConfiguredHostsWhenNoPort() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String hostname = "myHost";
+        configuration.addProperty("elasticsearch.hosts", hostname);
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getHosts())
+            .containsOnly(Host.from(hostname, ElasticSearchConfiguration.DEFAULT_PORT));
+    }
+
+    @Test
+    public void getHostsShouldReturnConfiguredHosts() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String hostname = "myHost";
+        int port = 2154;
+        configuration.addProperty("elasticsearch.hosts", hostname + ":" + port);
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getHosts())
+            .containsOnly(Host.from(hostname, port));
+    }
+
+    @Test
+    public void getHostsShouldReturnConfiguredMasterHost() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String hostname = "myHost";
+        configuration.addProperty("elasticsearch.masterHost", hostname);
+        int port = 9300;
+        configuration.addProperty("elasticsearch.port", port);
+
+        ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
+
+        assertThat(elasticSearchConfiguration.getHosts())
+            .containsOnly(Host.from(hostname, port));
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenNoHostSpecify() throws Exception {
+        assertThatThrownBy(() ->
+            ElasticSearchConfiguration.validateHostsConfigurationOptions(
+                Optional.empty(),
+                Optional.empty(),
+                Optional.empty()))
+            .isInstanceOf(ConfigurationException.class)
+            .hasMessage("You should specify either (" + ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST +
+                " and " + ElasticSearchConfiguration.ELASTICSEARCH_PORT +
+                ") or " + ElasticSearchConfiguration.ELASTICSEARCH_HOSTS);
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoAndMultiHostSpecified() throws Exception {
+        assertThatThrownBy(() ->
+            ElasticSearchConfiguration.validateHostsConfigurationOptions(
+                Optional.of("localhost"),
+                Optional.of(9200),
+                Optional.of("localhost:9200")))
+            .isInstanceOf(ConfigurationException.class)
+            .hasMessage("You should choose between mono host set up and " + ElasticSearchConfiguration.ELASTICSEARCH_HOSTS);
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutPort() throws Exception {
+        assertThatThrownBy(() ->
+            ElasticSearchConfiguration.validateHostsConfigurationOptions(
+                Optional.of("localhost"),
+                Optional.empty(),
+                Optional.empty()))
+            .isInstanceOf(ConfigurationException.class)
+            .hasMessage(ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST +
+                " and " + ElasticSearchConfiguration.ELASTICSEARCH_PORT + " should be specified together");
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldThrowWhenMonoHostWithoutAddress() throws Exception {
+        assertThatThrownBy(() ->
+        ElasticSearchConfiguration.validateHostsConfigurationOptions(
+            Optional.empty(),
+            Optional.of(9200),
+            Optional.empty()))
+        .isInstanceOf(ConfigurationException.class)
+        .hasMessage(ElasticSearchConfiguration.ELASTICSEARCH_MASTER_HOST + " and " +
+            ElasticSearchConfiguration.ELASTICSEARCH_PORT + " should be specified together");
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldAcceptMonoHostConfiguration() throws Exception {
+        ElasticSearchConfiguration.validateHostsConfigurationOptions(
+            Optional.of("localhost"),
+            Optional.of(9200),
+            Optional.empty());
+    }
+
+    @Test
+    public void validateHostsConfigurationOptionsShouldAcceptMultiHostConfiguration() throws Exception {
+        ElasticSearchConfiguration.validateHostsConfigurationOptions(
+            Optional.empty(),
+            Optional.empty(),
+            Optional.of("localhost:9200"));
+    }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/server/container/guice/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
deleted file mode 100644
index 41108e7..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/****************************************************************
- * 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.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.io.FileNotFoundException;
-import java.util.Optional;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.backends.es.AliasName;
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
-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 provideIndexNameShouldRetrievedConfiguredIndexName() throws ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        String name = "name";
-        configuration.addProperty("elasticsearch.index.name", name);
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexName indexName = testee.provideIndexName(() -> configuration);
-
-        assertThat(indexName)
-            .isEqualTo(new IndexName(name));
-    }
-
-    @Test
-    public void provideIndexNameShouldReturnDefaultIndexNameWhenNone() throws ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexName indexName = testee.provideIndexName(() -> configuration);
-
-        assertThat(indexName)
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
-    }
-
-    @Test
-    public void provideIndexNameShouldReturnDefaultIndexNameWhenError() throws ConfigurationException {
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexName indexName = testee.provideIndexName(() -> {
-            throw new FileNotFoundException();
-        });
-
-        assertThat(indexName)
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
-    }
-
-    @Test
-    public void provideAliasNameShouldRetrievedConfiguredAliasName() throws ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        String name = "name";
-        configuration.addProperty("elasticsearch.alias.name", name);
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        AliasName indexName = testee.provideAliasName(() -> configuration);
-
-        assertThat(indexName)
-            .isEqualTo(new AliasName(name));
-    }
-
-    @Test
-    public void provideAliasNameShouldReturnDefaultAliasNameWhenNone() throws ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        AliasName aliasName = testee.provideAliasName(() -> configuration);
-
-        assertThat(aliasName)
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
-    }
-
-    @Test
-    public void provideAliasNameShouldReturnDefaultAliasNameWhenError() throws ConfigurationException {
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        AliasName aliasName = testee.provideAliasName(() -> {
-            throw new FileNotFoundException();
-        });
-
-        assertThat(aliasName)
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
-    }
-
-    @Test
-    public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        configuration.addProperty("elasticsearch.indexAttachments", true);
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
-
-        assertThat(indexAttachments).isEqualTo(IndexAttachments.YES);
-    }
-
-    @Test
-    public void provideIndexAttachmentsShouldReturnFalseWhenIndexAttachmentsIsFalseInConfiguration() {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        configuration.addProperty("elasticsearch.indexAttachments", false);
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
-
-        assertThat(indexAttachments).isEqualTo(IndexAttachments.NO);
-    }
-
-    @Test
-    public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsNotDefinedInConfiguration() {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-
-        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
-
-        IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
-
-        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/f3b6ac5d/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java b/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
index 3927c73..4776f06 100644
--- a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/Host.java
@@ -123,7 +123,8 @@ public class Host {
     public final boolean equals(Object object) {
         if (object instanceof Host) {
             Host that = (Host) object;
-            return Objects.equal(this.hostName, that.hostName) && Objects.equal(this.port, that.port);
+            return Objects.equal(this.hostName, that.hostName)
+                && Objects.equal(this.port, that.port);
         }
         return false;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3b6ac5d/src/site/xdoc/server/config-elasticsearch.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-elasticsearch.xml b/src/site/xdoc/server/config-elasticsearch.xml
index 2b9ad23..b5ca6c8 100644
--- a/src/site/xdoc/server/config-elasticsearch.xml
+++ b/src/site/xdoc/server/config-elasticsearch.xml
@@ -58,9 +58,12 @@
           <dd>Number of replica for index provisionned by James</dd>
           <dt><strong>elasticsearch.index.name</strong></dt>
           <dd>Name of the index backed by the alias. It will be created if missing.</dd>
-          <dt><strong>elasticsearch.alias.name</strong></dt>
-          <dd>Name of the alias to use with Apache James. It will be created if missing.
-           The target of the alias is the index name configured above.</dd>
+          <dt><strong>elasticsearch.alias.read.name</strong></dt>
+          <dd>Name of the alias to use by Apache James for reads. It will be created if missing.
+              The target of the alias is the index name configured above.</dd>
+          <dt><strong>elasticsearch.alias.write.name</strong></dt>
+          <dd>Name of the alias to use by Apache James for writes. It will be created if missing.
+              The target of the alias is the index name configured above.</dd>
           <dt><strong>elasticsearch.retryConnection.maxRetries</strong></dt>
           <dd>Number of retries when connecting the cluster</dd>
           <dt><strong>elasticsearch.retryConnection.minDelay</strong></dt>


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


[06/15] james-project git commit: JAMES-2202 Rename typo on ElasticSearch case

Posted by bt...@apache.org.
JAMES-2202 Rename typo on ElasticSearch case


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

Branch: refs/heads/master
Commit: 4f663b2dd266670f9ed3859bbd9c98cdbe3405f6
Parents: f3b6ac5
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 15:51:03 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../MailboxElasticSearchConstants.java          | 31 ++++++++++++++++++++
 .../MailboxElasticsearchConstants.java          | 31 --------------------
 .../elasticsearch/MailboxMappingFactory.java    |  2 +-
 .../ElasticSearchIntegrationTest.java           | 24 +++++++--------
 .../host/ElasticSearchHostSystem.java           | 22 +++++++-------
 .../smtp/host/CassandraJamesSmtpHostSystem.java |  4 +--
 .../mailbox/ElasticSearchConfiguration.java     |  8 ++---
 .../mailbox/ElasticSearchMailboxModule.java     |  6 ++--
 .../apache/james/EmbeddedElasticSearchRule.java |  4 +--
 .../james/JamesCapabilitiesServerTest.java      |  4 +--
 .../james/modules/TestElasticSearchModule.java  | 12 ++++----
 .../mailbox/ElasticSearchConfigurationTest.java |  8 ++---
 .../cassandra/cucumber/CassandraStepdefs.java   |  4 +--
 13 files changed, 80 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
new file mode 100644
index 0000000..80c0584
--- /dev/null
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.mailbox.elasticsearch;
+
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.TypeName;
+
+public interface MailboxElasticSearchConstants {
+    AliasName DEFAULT_MAILBOX_WRITE_ALIAS = new AliasName("mailboxWriteAlias");
+    AliasName DEFAULT_MAILBOX_READ_ALIAS = new AliasName("mailboxReadAlias");
+    IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
+    TypeName MESSAGE_TYPE = new TypeName("message");
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
deleted file mode 100644
index e1d87c2..0000000
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/****************************************************************
- * 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.mailbox.elasticsearch;
-
-import org.apache.james.backends.es.AliasName;
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.backends.es.TypeName;
-
-public interface MailboxElasticsearchConstants {
-    AliasName DEFAULT_MAILBOX_WRITE_ALIAS = new AliasName("mailboxWriteAlias");
-    AliasName DEFAULT_MAILBOX_READ_ALIAS = new AliasName("mailboxReadAlias");
-    IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
-    TypeName MESSAGE_TYPE = new TypeName("message");
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
index 142736c..25a1639 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxMappingFactory.java
@@ -80,7 +80,7 @@ public class MailboxMappingFactory {
             return jsonBuilder()
                 .startObject()
 
-                    .startObject(MailboxElasticsearchConstants.MESSAGE_TYPE.getValue())
+                    .startObject(MailboxElasticSearchConstants.MESSAGE_TYPE.getValue())
                         .startObject(PROPERTIES)
 
                             .startObject(MESSAGE_ID)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 4e18134..e380864 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -83,7 +83,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     private static final boolean IS_RECENT = true;
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
 
     @Rule
     public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
@@ -111,12 +111,12 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     protected void initializeMailboxManager() throws Exception {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
-                .addAlias( MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
-                .addAlias( MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-            MailboxElasticsearchConstants.MESSAGE_TYPE,
+            MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
+            MailboxElasticSearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
 
         MailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
@@ -127,14 +127,14 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
                     BATCH_SIZE,
-                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
-                    MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
-                MailboxElasticsearchConstants.MESSAGE_TYPE),
+                    MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
+                    MailboxElasticSearchConstants.MESSAGE_TYPE),
+                MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
+                MailboxElasticSearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
-                MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
+                MailboxElasticSearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
         storeMailboxManager = new InMemoryMailboxManager(
             mapperFactory,

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index d83f96f..0817c25 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -42,7 +42,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
 import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
 import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
@@ -82,7 +82,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
     public void beforeTest() throws Exception {
         super.beforeTest();
         this.tempDirectory = Files.createTempDirectory("elasticsearch");
-        this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+        this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
         embeddedElasticSearch.before();
         initFields();
     }
@@ -96,12 +96,12 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
-                .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
-                .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-            MailboxElasticsearchConstants.MESSAGE_TYPE,
+            MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
+            MailboxElasticSearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
 
         InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
@@ -110,12 +110,12 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
             factory,
             new ElasticSearchIndexer(client,
-                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
-                MailboxElasticsearchConstants.MESSAGE_TYPE),
+                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE),
+                MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
+                MailboxElasticSearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client,
                 new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES));
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
index 7b958f2..a7a3fbf 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
@@ -26,7 +26,7 @@ import org.apache.james.GuiceJamesServer;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.modules.CassandraJmapServerModule;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.mpt.monitor.SystemLoggingMonitor;
@@ -83,7 +83,7 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory impleme
         inMemoryDNSService = new InMemoryDNSService();
         folder = new TemporaryFolder();
         folder.create();
-        embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+        embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
         embeddedElasticSearch.before();
         jamesServer = createJamesServer();
         jamesServer.start();

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index 7d65618..8d95228 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -27,7 +27,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.IndexName;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.util.Host;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -63,13 +63,13 @@ public class ElasticSearchConfiguration {
 
         AliasName readAlias = Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_READ_NAME))
             .map(AliasName::new)
-            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
+            .orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
         AliasName writeAlias = Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_WRITE_NAME))
             .map(AliasName::new)
-            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
+            .orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
         IndexName indexName = Optional.ofNullable(configuration.getString(ELASTICSEARCH_INDEX_NAME))
             .map(IndexName::new)
-            .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+            .orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
 
         return new ElasticSearchConfiguration(
             hosts,

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/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 d9e7858..1939523 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
@@ -36,7 +36,7 @@ import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.NodeMappingFactory;
 import org.apache.james.backends.es.TypeName;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
 import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
@@ -61,7 +61,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        bind(TypeName.class).toInstance(MailboxElasticsearchConstants.MESSAGE_TYPE);
+        bind(TypeName.class).toInstance(MailboxElasticSearchConstants.MESSAGE_TYPE);
         bind(ElasticSearchListeningMessageSearchIndex.class).in(Scopes.SINGLETON);
         bind(MessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class);
         bind(ListeningMessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class);
@@ -126,7 +126,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
         indexCreationFactory.createIndexAndAliases(client);
         return NodeMappingFactory.applyMapping(client,
             configuration.getIndexName(),
-            MailboxElasticsearchConstants.MESSAGE_TYPE,
+            MailboxElasticSearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
index 5bef22e..028dc42 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
@@ -20,7 +20,7 @@
 package org.apache.james;
 
 import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.elasticsearch.node.Node;
 import org.junit.rules.RuleChain;
@@ -34,7 +34,7 @@ import com.google.inject.Module;
 public class EmbeddedElasticSearchRule implements GuiceModuleTestRule {
 
     private final TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
 
     private final RuleChain chain = RuleChain
         .outerRule(temporaryFolder)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 383d781..5f561b5 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -29,7 +29,7 @@ import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.jmap.methods.GetMessageListMethod;
 import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestFilesystemModule;
 import org.apache.james.modules.TestJMAPServerModule;
@@ -45,7 +45,7 @@ public class JamesCapabilitiesServerTest {
 
     private GuiceJamesServer server;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
     private DockerCassandraRule cassandraServer = new DockerCassandraRule();
     
     @Rule

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 5e30618..8cd728c 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -25,7 +25,7 @@ import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.IndexCreationFactory;
 import org.apache.james.backends.es.NodeMappingFactory;
 import org.apache.james.backends.es.utils.TestingClientProvider;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
 import org.elasticsearch.client.Client;
 
@@ -51,13 +51,13 @@ public class TestElasticSearchModule extends AbstractModule{
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
 
         new IndexCreationFactory()
-            .onIndex(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX)
-            .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
-            .addAlias(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+            .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+            .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+            .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
             .createIndexAndAliases(client);
         return NodeMappingFactory.applyMapping(client,
-            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
-            MailboxElasticsearchConstants.MESSAGE_TYPE,
+            MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
+            MailboxElasticSearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
index f4b7765..514f967 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchConfigurationTest.java
@@ -29,7 +29,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.IndexName;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.util.Host;
 import org.junit.Test;
 
@@ -152,7 +152,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
 
         assertThat(elasticSearchConfiguration.getIndexName())
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+            .isEqualTo(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
     }
 
     @Test
@@ -176,7 +176,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
 
         assertThat(elasticSearchConfiguration.getReadAliasName())
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
+            .isEqualTo(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
     }
 
 
@@ -201,7 +201,7 @@ public class ElasticSearchConfigurationTest {
         ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);
 
         assertThat(elasticSearchConfiguration.getWriteAliasName())
-            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
+            .isEqualTo(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f663b2d/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index 684bf3b..22f60ea 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -31,7 +31,7 @@ import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.jmap.methods.integration.cucumber.MainStepdefs;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
+import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
 import org.apache.james.modules.CassandraJmapServerModule;
 import org.junit.rules.TemporaryFolder;
 
@@ -46,7 +46,7 @@ public class CassandraStepdefs {
 
     private final MainStepdefs mainStepdefs;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
     private DockerCassandraRule cassandraServer = CucumberCassandraSingleton.cassandraServer;
 
     @Inject


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


[12/15] james-project git commit: JAMES-2205 Create webadmin main module

Posted by bt...@apache.org.
JAMES-2205 Create webadmin main module


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

Branch: refs/heads/master
Commit: fa0bcd5925df5e15b28c9cde61154402c93c6525
Parents: a312fde
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Oct 27 15:51:18 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:56:33 2017 +0700

----------------------------------------------------------------------
 pom.xml                           |  5 ++++
 server/pom.xml                    |  6 +----
 server/protocols/webadmin/pom.xml | 43 ++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fa0bcd59/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4cb8e63..d1cdfb1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1338,6 +1338,11 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-webadmin</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-webadmin-cassandra</artifactId>
                 <version>${project.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/fa0bcd59/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 33bccdf..65d4e80 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -91,11 +91,7 @@
         <module>protocols/protocols-pop3</module>
         <module>protocols/protocols-smtp</module>
         <module>protocols/webadmin-integration-test</module>
-        <module>protocols/webadmin/webadmin-cassandra</module>
-        <module>protocols/webadmin/webadmin-core</module>
-        <module>protocols/webadmin/webadmin-data</module>
-        <module>protocols/webadmin/webadmin-mailbox</module>
-        <module>protocols/webadmin/webadmin-swagger</module>
+        <module>protocols/webadmin</module>
         <module>queue/queue-activemq</module>
 
         <module>queue/queue-api</module>

http://git-wip-us.apache.org/repos/asf/james-project/blob/fa0bcd59/server/protocols/webadmin/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/pom.xml b/server/protocols/webadmin/pom.xml
new file mode 100644
index 0000000..7af36c5
--- /dev/null
+++ b/server/protocols/webadmin/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>james-project</artifactId>
+        <version>3.1.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>james-server-webadmin</artifactId>
+    <packaging>pom</packaging>
+
+    <name>Apache James :: Server :: Web Admin</name>
+
+    <modules>
+        <module>webadmin-cassandra</module>
+        <module>webadmin-core</module>
+        <module>webadmin-data</module>
+        <module>webadmin-mailbox</module>
+        <module>webadmin-swagger</module>
+    </modules>
+
+</project>


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


[05/15] james-project git commit: JAMES-2202 Add an Alias in ElasticSearch

Posted by bt...@apache.org.
JAMES-2202 Add an Alias in ElasticSearch


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

Branch: refs/heads/master
Commit: deb93a722db3f35a0acb4423fbede5e12959ed98
Parents: aebca5f
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 10:53:22 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/backends/es/AliasName.java | 49 +++++++++++++
 .../james/backends/es/IndexCreationFactory.java | 42 ++++++++---
 .../backends/es/IndexCreationFactoryTest.java   | 51 +++++++++++++
 .../backends/es/NodeMappingFactoryTest.java     | 76 ++++++++++++++++++++
 .../backends/es/search/ScrollIterableTest.java  |  4 +-
 .../MailboxElasticsearchConstants.java          |  2 +
 .../ElasticSearchIntegrationTest.java           |  5 +-
 .../host/ElasticSearchHostSystem.java           |  5 +-
 .../mailbox/ElasticSearchMailboxModule.java     | 32 +++++++--
 .../james/modules/TestElasticSearchModule.java  |  4 +-
 .../mailbox/ElasticSearchMailboxModuleTest.java | 39 ++++++++++
 src/site/xdoc/server/config-elasticsearch.xml   |  5 +-
 12 files changed, 293 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/AliasName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/AliasName.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/AliasName.java
new file mode 100644
index 0000000..80e934a
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/AliasName.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.Objects;
+
+public class AliasName {
+    private final String value;
+
+    public AliasName(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof AliasName) {
+            AliasName aliasName = (AliasName) o;
+
+            return Objects.equals(this.value, aliasName.value);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index 9797ba2..2eb9e1b 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -23,6 +23,8 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 
 import java.io.IOException;
 
+import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
+import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
@@ -36,31 +38,55 @@ public class IndexCreationFactory {
     private static final int DEFAULT_NB_REPLICA = 0;
     public static final String CASE_INSENSITIVE = "case_insensitive";
 
-    public static Client createIndex(Client client, IndexName name, int nbShards, int nbReplica) {
+    public static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName, int nbShards, int nbReplica) {
         try {
-            return createIndex(client, name, generateSetting(nbShards, nbReplica));
+            return createIndexAndAlias(client, indexName, aliasName, generateSetting(nbShards, nbReplica));
         } catch (IOException e) {
             LOGGER.error("Error while creating index : ", e);
             return client;
         }
     }
 
-    public static Client createIndex(Client client, IndexName name) {
-        return createIndex(client, name, DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA);
+    public static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName) {
+        return createIndexAndAlias(client, indexName, aliasName, DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA);
     }
 
-    private static Client createIndex(Client client, IndexName name, XContentBuilder settings) {
+    private static Client createIndexAndAlias(Client client, IndexName indexName, AliasName aliasName, XContentBuilder settings) {
+        createIndexIfNeeded(client, indexName, settings);
+        createAliasIfNeeded(client, indexName, aliasName);
+        return client;
+    }
+
+    private static void createAliasIfNeeded(Client client, IndexName indexName, AliasName aliasName) {
+        if (!aliasExist(client, aliasName)) {
+            client.admin()
+                .indices()
+                .aliases( new IndicesAliasesRequest()
+                    .addAlias(aliasName.getValue(), indexName.getValue()))
+                .actionGet();
+        }
+    }
+
+    private static boolean aliasExist(Client client, AliasName aliasName) {
+        return client.admin()
+            .indices()
+            .aliasesExist(new GetAliasesRequest()
+                .aliases(aliasName.getValue()))
+            .actionGet()
+            .exists();
+    }
+
+    private static void createIndexIfNeeded(Client client, IndexName indexName, XContentBuilder settings) {
         try {
             client.admin()
                 .indices()
-                .prepareCreate(name.getValue())
+                .prepareCreate(indexName.getValue())
                 .setSettings(settings)
                 .execute()
                 .actionGet();
         } catch (IndexAlreadyExistsException exception) {
-            LOGGER.info("Index [" + name + "] already exist");
+            LOGGER.info("Index [" + indexName + "] already exist");
         }
-        return client;
     }
 
     private static XContentBuilder generateSetting(int nbShards, int nbReplica) throws IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
new file mode 100644
index 0000000..dee1142
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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 org.apache.james.backends.es.utils.TestingClientProvider;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
+
+public class IndexCreationFactoryTest {
+    public static final IndexName INDEX_NAME = new IndexName("index");
+    public static final AliasName ALIAS_NAME = new AliasName("alias");
+
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, INDEX_NAME);
+
+    @Rule
+    public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
+
+    private ClientProvider clientProvider;
+
+    @Before
+    public void setUp() {
+        clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+    }
+
+    @Test
+    public void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
new file mode 100644
index 0000000..6aca8d7
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
+
+import org.apache.james.backends.es.utils.TestingClientProvider;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
+
+public class NodeMappingFactoryTest {
+    public static final String MESSAGE = "message";
+    public static final IndexName INDEX_NAME = new IndexName("index");
+    public static final AliasName ALIAS_NAME = new AliasName("alias");
+    public static final TypeName TYPE_NAME = new TypeName("type");
+
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, INDEX_NAME);
+
+    @Rule
+    public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
+
+    private ClientProvider clientProvider;
+
+    @Before
+    public void setUp() throws Exception {
+        clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
+        NodeMappingFactory.applyMapping(clientProvider.get(),
+            INDEX_NAME,
+            TYPE_NAME,
+            getMappingsSources());
+    }
+
+    @Test
+    public void applyMappingShouldNotThrowWhenCalledSeveralTime() throws Exception {
+        NodeMappingFactory.applyMapping(clientProvider.get(),
+            INDEX_NAME,
+            TYPE_NAME,
+            getMappingsSources());
+    }
+
+    private XContentBuilder getMappingsSources() throws Exception {
+        return jsonBuilder()
+            .startObject()
+                .startObject(TYPE_NAME.getValue())
+                    .startObject(NodeMappingFactory.PROPERTIES)
+                        .startObject(MESSAGE)
+                            .field(NodeMappingFactory.TYPE, NodeMappingFactory.STRING)
+                        .endObject()
+                    .endObject()
+                .endObject()
+            .endObject();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
index 121b8b7..4515f96 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
@@ -28,6 +28,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.ClientProvider;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.IndexCreationFactory;
@@ -52,6 +53,7 @@ public class ScrollIterableTest {
     public static final int SIZE = 2;
     public static final String MESSAGE = "message";
     public static final IndexName INDEX_NAME = new IndexName("index");
+    public static final AliasName ALIAS_NAME = new AliasName("alias");
     public static final TypeName TYPE_NAME = new TypeName("messages");
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -65,7 +67,7 @@ public class ScrollIterableTest {
     @Before
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
-        IndexCreationFactory.createIndex(clientProvider.get(), INDEX_NAME);
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(), INDEX_NAME, ALIAS_NAME);
         embeddedElasticSearch.awaitForElasticSearch();
         NodeMappingFactory.applyMapping(clientProvider.get(), INDEX_NAME, TYPE_NAME, getMappingsSources());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
index 9539e53..fb89b8e 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java
@@ -19,10 +19,12 @@
 
 package org.apache.james.mailbox.elasticsearch;
 
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.TypeName;
 
 public interface MailboxElasticsearchConstants {
+    AliasName DEFAULT_MAILBOX_ALIAS = new AliasName("mailboxAlias");
     IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
     TypeName MESSAGE_TYPE = new TypeName("message");
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index eaf7764..cab06e5 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -110,9 +110,10 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     @Override
     protected void initializeMailboxManager() throws Exception {
         Client client = NodeMappingFactory.applyMapping(
-            IndexCreationFactory.createIndex(
+            IndexCreationFactory.createIndexAndAlias(
                 new TestingClientProvider(embeddedElasticSearch.getNode()).get(),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS),
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 948acd8..2a90a99 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -95,7 +95,10 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
-            IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode()).get(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX),
+            IndexCreationFactory.createIndexAndAlias(
+                new TestingClientProvider(embeddedElasticSearch.getNode()).get(),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS),
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
             MailboxMappingFactory.getMappingContent());

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/server/container/guice/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 dee84b5..ea59317 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
@@ -28,6 +28,7 @@ import javax.inject.Singleton;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.ClientProviderImpl;
 import org.apache.james.backends.es.IndexCreationFactory;
 import org.apache.james.backends.es.IndexName;
@@ -75,7 +76,8 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     }
 
     @Provides
-    protected IndexName provideIndexName(ElasticSearchConfiguration elasticSearchConfiguration) throws ConfigurationException {
+    protected IndexName provideIndexName(ElasticSearchConfiguration elasticSearchConfiguration)
+            throws ConfigurationException {
         try {
             return Optional.ofNullable(elasticSearchConfiguration.getConfiguration()
                 .getString("elasticsearch.index.name"))
@@ -88,22 +90,37 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     }
 
     @Provides
+    protected AliasName provideAliasName(ElasticSearchConfiguration elasticSearchConfiguration)
+            throws ConfigurationException {
+        try {
+            return Optional.ofNullable(elasticSearchConfiguration.getConfiguration()
+                .getString("elasticsearch.alias.name"))
+                .map(AliasName::new)
+                .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
+        } catch (FileNotFoundException e) {
+            LOGGER.info("Could not find ElasticSearch configuration file. Using default alias {}", MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX.getValue());
+            return MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS;
+        }
+    }
+
+    @Provides
     @Singleton
     protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration,
-                                           IndexName indexName,
+                                           IndexName indexName, AliasName aliasName,
                                            AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException {
         PropertiesConfiguration propertiesReader = elasticSearchConfiguration.getConfiguration();
         int maxRetries = propertiesReader.getInt("elasticsearch.retryConnection.maxRetries", DEFAULT_CONNECTION_MAX_RETRIES);
         int minDelay = propertiesReader.getInt("elasticsearch.retryConnection.minDelay", DEFAULT_CONNECTION_MIN_DELAY);
 
         return RetryExecutorUtil.retryOnExceptions(executor, maxRetries, minDelay, NoNodeAvailableException.class)
-            .getWithRetry(context -> connectToCluster(propertiesReader, indexName))
+            .getWithRetry(context -> connectToCluster(propertiesReader, indexName, aliasName))
             .get();
     }
 
-    private Client createIndexAndMapping(Client client, IndexName indexName, PropertiesConfiguration propertiesReader) {
-        IndexCreationFactory.createIndex(client,
+    private Client createIndexAndMapping(Client client, IndexName indexName, AliasName aliasName, PropertiesConfiguration propertiesReader) {
+        IndexCreationFactory.createIndexAndAlias(client,
             indexName,
+            aliasName,
             propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.shards", DEFAULT_NB_SHARDS),
             propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.replica", DEFAULT_NB_REPLICA));
         NodeMappingFactory.applyMapping(client,
@@ -113,10 +130,11 @@ public class ElasticSearchMailboxModule extends AbstractModule {
         return client;
     }
 
-    private Client connectToCluster(PropertiesConfiguration propertiesReader, IndexName indexName) throws ConfigurationException {
+    private Client connectToCluster(PropertiesConfiguration propertiesReader, IndexName indexName, AliasName aliasName)
+            throws ConfigurationException {
         LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
 
-        return createIndexAndMapping(createClient(propertiesReader), indexName, propertiesReader);
+        return createIndexAndMapping(createClient(propertiesReader), indexName, aliasName, propertiesReader);
     }
 
     @Provides

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 7a984ec..2b6b272 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -49,7 +49,9 @@ public class TestElasticSearchModule extends AbstractModule{
     @Singleton
     protected Client provideClientProvider() {
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
-        IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX);
+        IndexCreationFactory.createIndexAndAlias(client,
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+            MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
         return NodeMappingFactory.applyMapping(client,
             MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/server/container/guice/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 dc590a9..41108e7 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
@@ -29,6 +29,7 @@ import java.util.Optional;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.IndexName;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
 import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants;
@@ -80,6 +81,44 @@ public class ElasticSearchMailboxModuleTest {
     }
 
     @Test
+    public void provideAliasNameShouldRetrievedConfiguredAliasName() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String name = "name";
+        configuration.addProperty("elasticsearch.alias.name", name);
+
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        AliasName indexName = testee.provideAliasName(() -> configuration);
+
+        assertThat(indexName)
+            .isEqualTo(new AliasName(name));
+    }
+
+    @Test
+    public void provideAliasNameShouldReturnDefaultAliasNameWhenNone() throws ConfigurationException {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        AliasName aliasName = testee.provideAliasName(() -> configuration);
+
+        assertThat(aliasName)
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
+    }
+
+    @Test
+    public void provideAliasNameShouldReturnDefaultAliasNameWhenError() throws ConfigurationException {
+        ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+        AliasName aliasName = testee.provideAliasName(() -> {
+            throw new FileNotFoundException();
+        });
+
+        assertThat(aliasName)
+            .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS);
+    }
+
+    @Test
     public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
         configuration.addProperty("elasticsearch.indexAttachments", true);

http://git-wip-us.apache.org/repos/asf/james-project/blob/deb93a72/src/site/xdoc/server/config-elasticsearch.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-elasticsearch.xml b/src/site/xdoc/server/config-elasticsearch.xml
index 94420c2..2b9ad23 100644
--- a/src/site/xdoc/server/config-elasticsearch.xml
+++ b/src/site/xdoc/server/config-elasticsearch.xml
@@ -57,7 +57,10 @@
           <dt><strong>elasticsearch.nb.replica</strong></dt>
           <dd>Number of replica for index provisionned by James</dd>
           <dt><strong>elasticsearch.index.name</strong></dt>
-          <dd>Name of the index to use with Apache James. It will be created if missing.</dd>
+          <dd>Name of the index backed by the alias. It will be created if missing.</dd>
+          <dt><strong>elasticsearch.alias.name</strong></dt>
+          <dd>Name of the alias to use with Apache James. It will be created if missing.
+           The target of the alias is the index name configured above.</dd>
           <dt><strong>elasticsearch.retryConnection.maxRetries</strong></dt>
           <dd>Number of retries when connecting the cluster</dd>
           <dt><strong>elasticsearch.retryConnection.minDelay</strong></dt>


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


[02/15] james-project git commit: JAMES-2202 Re-indent createIndex

Posted by bt...@apache.org.
JAMES-2202 Re-indent createIndex


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

Branch: refs/heads/master
Commit: 73deadf74ea5909d7d91917b9a3c34638c6809ca
Parents: 7c490ed
Author: benwa <bt...@linagora.com>
Authored: Wed Oct 25 08:59:25 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:53:02 2017 +0700

----------------------------------------------------------------------
 .../apache/james/backends/es/IndexCreationFactory.java  | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/73deadf7/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index eb6771a..9797ba2 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -51,12 +51,12 @@ public class IndexCreationFactory {
 
     private static Client createIndex(Client client, IndexName name, XContentBuilder settings) {
         try {
-                client.admin()
-                    .indices()
-                    .prepareCreate(name.getValue())
-                    .setSettings(settings)
-                    .execute()
-                    .actionGet();
+            client.admin()
+                .indices()
+                .prepareCreate(name.getValue())
+                .setSettings(settings)
+                .execute()
+                .actionGet();
         } catch (IndexAlreadyExistsException exception) {
             LOGGER.info("Index [" + name + "] already exist");
         }


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


[15/15] james-project git commit: MAILBOX-315 Increase MPT Cassandra testing speed by running James in a class rule

Posted by bt...@apache.org.
MAILBOX-315 Increase MPT Cassandra testing speed by running James in a class rule


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

Branch: refs/heads/master
Commit: b1f1077e8cafc462de55d1327af0da410db2bc1a
Parents: b4aa905
Author: benwa <bt...@linagora.com>
Authored: Mon Oct 30 15:19:39 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:57:22 2017 +0700

----------------------------------------------------------------------
 .../GenericSimpleScriptedTestProtocol.java      | 12 +++-
 .../cassandra/CassandraAuthenticatePlain.java   | 27 +++-----
 .../cassandra/CassandraAuthenticatedState.java  | 27 +++-----
 .../cassandra/CassandraConcurrentSessions.java  | 27 +++-----
 .../cassandra/CassandraCondstore.java           | 33 ++++------
 .../imapmailbox/cassandra/CassandraCopy.java    | 31 +++------
 .../imapmailbox/cassandra/CassandraEvents.java  | 31 +++------
 .../imapmailbox/cassandra/CassandraExpunge.java | 31 +++------
 .../imapmailbox/cassandra/CassandraFetch.java   | 31 +++------
 .../cassandra/CassandraFetchBodySection.java    | 33 +++-------
 .../cassandra/CassandraFetchBodyStructure.java  | 33 +++-------
 .../cassandra/CassandraFetchHeaders.java        | 31 +++------
 .../imapmailbox/cassandra/CassandraListing.java | 31 +++------
 .../CassandraListingWithSharingTest.java        | 28 ++------
 .../cassandra/CassandraMailboxAnnotation.java   | 27 +++-----
 .../cassandra/CassandraMailboxTestModule.java   | 52 ---------------
 .../CassandraMailboxWithLongNameError.java      | 31 +++------
 .../imapmailbox/cassandra/CassandraMove.java    | 31 +++------
 .../CassandraNonAuthenticatedState.java         | 31 +++------
 .../cassandra/CassandraPartialFetch.java        | 31 +++------
 .../cassandra/CassandraQuotaTest.java           | 27 +++-----
 .../imapmailbox/cassandra/CassandraRename.java  | 27 +++-----
 .../imapmailbox/cassandra/CassandraSearch.java  | 31 +++------
 .../cassandra/CassandraSecurity.java            | 31 +++------
 .../imapmailbox/cassandra/CassandraSelect.java  | 31 +++------
 .../cassandra/CassandraSelectedInbox.java       | 31 +++------
 .../cassandra/CassandraSelectedState.java       | 27 +++-----
 .../cassandra/CassandraUidSearch.java           | 31 +++------
 .../cassandra/CassandraUidSearchOnIndex.java    | 31 +++------
 .../cassandra/CassandraUserFlagsSupport.java    | 31 +++------
 .../cassandra/host/CassandraHostSystem.java     |  2 +-
 .../cassandra/host/CassandraHostSystemRule.java | 69 ++++++++++++++++++++
 .../mpt/imapmailbox/suite/UidSearchOnIndex.java |  2 +
 33 files changed, 320 insertions(+), 660 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/core/src/main/java/org/apache/james/mpt/script/GenericSimpleScriptedTestProtocol.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/script/GenericSimpleScriptedTestProtocol.java b/mpt/core/src/main/java/org/apache/james/mpt/script/GenericSimpleScriptedTestProtocol.java
index 64a562f..ed6bd5f 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/script/GenericSimpleScriptedTestProtocol.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/script/GenericSimpleScriptedTestProtocol.java
@@ -30,9 +30,13 @@ import org.apache.james.mpt.api.HostSystem;
 import org.apache.james.mpt.api.Session;
 import org.apache.james.mpt.protocol.FileProtocolSessionBuilder;
 import org.apache.james.mpt.protocol.ProtocolSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class GenericSimpleScriptedTestProtocol<T extends HostSystem, SELF extends GenericSimpleScriptedTestProtocol<?, ?>> {
-    
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(GenericSimpleScriptedTestProtocol.class);
+
     public interface PrepareCommand<T extends HostSystem> {
         void prepare(T system) throws Exception;
     }
@@ -48,7 +52,11 @@ public class GenericSimpleScriptedTestProtocol<T extends HostSystem, SELF extend
         }
         
         public void prepare(HostSystem system) throws Exception {
-            system.addUser(user, password);
+            try {
+                system.addUser(user, password);
+            } catch (Exception e) {
+                LOGGER.info("User {} already exists");
+            }
         }
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatePlain.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatePlain.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatePlain.java
index a8e83d9..091074a 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatePlain.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatePlain.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.AuthenticatePlain;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraAuthenticatePlain extends AuthenticatePlain {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatedState.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatedState.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatedState.java
index be1d1d8..fd55329 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatedState.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraAuthenticatedState.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.AuthenticatedState;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraAuthenticatedState extends AuthenticatedState {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraConcurrentSessions.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraConcurrentSessions.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraConcurrentSessions.java
index f235e5c..0b04ebc 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraConcurrentSessions.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraConcurrentSessions.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.ConcurrentSessions;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraConcurrentSessions extends ConcurrentSessions {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCondstore.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCondstore.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCondstore.java
index c5648d5..ba5f947 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCondstore.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCondstore.java
@@ -21,36 +21,31 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.host.JamesImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Condstore;
 import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.Rule;
+import org.junit.rules.RuleChain;
 
 public class CassandraCondstore extends Condstore {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    /**
+     * The underlying tests are playing with capabilities, which are configured when starting James.
+     * Hence, we can't use the RuleChain as a @ClassRule in this implementation.
+     */
+    @Rule
+    public RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private JamesImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(JamesImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected JamesImapHostSystem createJamesImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCopy.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCopy.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCopy.java
index 45aa8f9..4677a2e 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCopy.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraCopy.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Copy;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraCopy extends Copy {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraEvents.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraEvents.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraEvents.java
index 28007e6..05fafb8 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraEvents.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraEvents.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Events;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraEvents extends Events {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraExpunge.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraExpunge.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraExpunge.java
index a7ae30e..df9eb51 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraExpunge.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraExpunge.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Expunge;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraExpunge extends Expunge {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetch.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetch.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetch.java
index d5f6ddb..8a18b97 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetch.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetch.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Fetch;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraFetch extends Fetch {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodySection.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodySection.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodySection.java
index 47fcb3f..24381b5 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodySection.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodySection.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.FetchBodySection;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraFetchBodySection extends FetchBodySection {
-    
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
+
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodyStructure.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodyStructure.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodyStructure.java
index c0b2a31..0489151 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodyStructure.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchBodyStructure.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.FetchBodyStructure;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraFetchBodyStructure extends FetchBodyStructure {
-    
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
+
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchHeaders.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchHeaders.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchHeaders.java
index bd3be46..976cb7d 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchHeaders.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraFetchHeaders.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.FetchHeaders;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraFetchHeaders extends FetchHeaders {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListing.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListing.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListing.java
index c29de81..4776f25 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListing.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListing.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Listing;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraListing extends Listing {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
index 6d7fb6d..2aa398b 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraListingWithSharingTest.java
@@ -21,35 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.ListingWithSharingTest;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraListingWithSharingTest extends ListingWithSharingTest {
-    @ClassRule
-    public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
 
-    private ImapHostSystem system;
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
 
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxAnnotation.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxAnnotation.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxAnnotation.java
index 0bec8c3..1d4fdbe 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxAnnotation.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxAnnotation.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.MailboxAnnotation;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraMailboxAnnotation extends MailboxAnnotation {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTestModule.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTestModule.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTestModule.java
deleted file mode 100644
index d22246b..0000000
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxTestModule.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************
- * 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.mpt.imapmailbox.cassandra;
-
-import org.apache.james.mpt.api.HostSystem;
-import org.apache.james.mpt.api.ImapHostSystem;
-import org.apache.james.mpt.host.JamesImapHostSystem;
-import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystem;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
-
-public class CassandraMailboxTestModule extends AbstractModule {
-
-    private final String cassandraHost;
-    private final int cassandraPort;
-
-    public CassandraMailboxTestModule(String cassandraHost, int cassandraPort) {
-        this.cassandraHost = cassandraHost;
-        this.cassandraPort = cassandraPort;
-    }
-    
-    @Override
-    protected void configure() {
-        bind(HostSystem.class).to(JamesImapHostSystem.class);
-        bind(ImapHostSystem.class).to(JamesImapHostSystem.class);
-    }
-
-    @Provides
-    @Singleton
-    public JamesImapHostSystem provideHostSystem() throws Exception {
-        return new CassandraHostSystem(cassandraHost, cassandraPort);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxWithLongNameError.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxWithLongNameError.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxWithLongNameError.java
index 189118b..a8a9edb 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxWithLongNameError.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMailboxWithLongNameError.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.MailboxWithLongNameError;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraMailboxWithLongNameError extends MailboxWithLongNameError {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMove.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMove.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMove.java
index c2691f5..3de3b62 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMove.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraMove.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Move;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraMove extends Move {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraNonAuthenticatedState.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraNonAuthenticatedState.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraNonAuthenticatedState.java
index 3338b00..6851f2f 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraNonAuthenticatedState.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraNonAuthenticatedState.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.NonAuthenticatedState;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraNonAuthenticatedState extends NonAuthenticatedState {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraPartialFetch.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraPartialFetch.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraPartialFetch.java
index ef45eff..d767297 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraPartialFetch.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraPartialFetch.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.PartialFetch;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraPartialFetch extends PartialFetch {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraQuotaTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraQuotaTest.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraQuotaTest.java
index 759a484..00ba775 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraQuotaTest.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraQuotaTest.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.QuotaTest;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraQuotaTest extends QuotaTest {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraRename.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraRename.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraRename.java
index b7b5746..7e9c43f 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraRename.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraRename.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Rename;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraRename extends Rename {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSearch.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSearch.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSearch.java
index e40b985..aa85a52 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSearch.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSearch.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Search;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraSearch extends Search {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSecurity.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSecurity.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSecurity.java
index ea10c9a..49874ae 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSecurity.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSecurity.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Security;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraSecurity extends Security {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelect.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelect.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelect.java
index 2e6e95e..cd42204 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelect.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelect.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.Select;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraSelect extends Select {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedInbox.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedInbox.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedInbox.java
index 97b251b..dc71a87 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedInbox.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedInbox.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.SelectedInbox;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraSelectedInbox extends SelectedInbox {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedState.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedState.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedState.java
index 7b30c55..7c1e4ac 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedState.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraSelectedState.java
@@ -21,36 +21,27 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.SelectedState;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraSelectedState extends SelectedState {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
+        return cassandraHostSystemRule.getImapHostSystem();
     }
 
     @After
     public void tearDown() throws Exception {
-        system.afterTest();
+        cassandraHostSystemRule.clean();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearch.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearch.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearch.java
index f97610c..92069eb 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearch.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearch.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.UidSearch;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraUidSearch extends UidSearch {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearchOnIndex.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearchOnIndex.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearchOnIndex.java
index 92afdbe..5fda286 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearchOnIndex.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUidSearchOnIndex.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.UidSearchOnIndex;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraUidSearchOnIndex extends UidSearchOnIndex {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUserFlagsSupport.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUserFlagsSupport.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUserFlagsSupport.java
index c55ceb9..4bdb14f 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUserFlagsSupport.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/CassandraUserFlagsSupport.java
@@ -21,36 +21,21 @@ package org.apache.james.mpt.imapmailbox.cassandra;
 
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.mpt.api.ImapHostSystem;
+import org.apache.james.mpt.imapmailbox.cassandra.host.CassandraHostSystemRule;
 import org.apache.james.mpt.imapmailbox.suite.UserFlagsSupport;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import org.junit.rules.RuleChain;
 
 public class CassandraUserFlagsSupport extends UserFlagsSupport {
 
-    @ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+    private static CassandraHostSystemRule cassandraHostSystemRule = new CassandraHostSystemRule(cassandraServer);
+
+    @ClassRule
+    public static RuleChain ruleChaine = RuleChain.outerRule(cassandraServer).around(cassandraHostSystemRule);
 
-    private ImapHostSystem system;
-    
-    @Before
-    public void setUp() throws Exception {
-        Injector injector = Guice.createInjector(new CassandraMailboxTestModule(cassandraServer.getIp(), cassandraServer.getBindingPort()));
-        system = injector.getInstance(ImapHostSystem.class);
-        system.beforeTest();
-        super.setUp();
-    }
-    
     @Override
     protected ImapHostSystem createImapHostSystem() {
-        return system;
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.afterTest();
+        return cassandraHostSystemRule.getImapHostSystem();
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index 465a2f2..ca39444 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -154,7 +154,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
     }
 
     @Override
-    protected MailboxManager getMailboxManager() {
+    public MailboxManager getMailboxManager() {
         return mailboxManager;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystemRule.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystemRule.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystemRule.java
new file mode 100644
index 0000000..4dd951f
--- /dev/null
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystemRule.java
@@ -0,0 +1,69 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.cassandra.host;
+
+import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mpt.host.JamesImapHostSystem;
+import org.junit.rules.ExternalResource;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Throwables;
+
+public class CassandraHostSystemRule extends ExternalResource {
+
+    private static final String USERNAME = "mpt";
+
+    private final DockerCassandraRule cassandraServer;
+    private CassandraHostSystem system;
+
+    public CassandraHostSystemRule(DockerCassandraRule cassandraServer) {
+        this.cassandraServer = cassandraServer;
+    }
+
+    @Override
+    protected void before() throws Throwable {
+        system = new CassandraHostSystem(cassandraServer.getIp(), cassandraServer.getBindingPort());
+        system.beforeTest();
+    }
+
+    @Override
+    protected void after() {
+        try {
+            clean();
+        } catch (Exception e) {
+            Throwables.propagate(e);
+        }
+    }
+
+    public void clean() throws Exception {
+        MailboxManager mailboxManager = system.getMailboxManager();
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        mailboxManager.list(systemSession)
+            .forEach(Throwing.consumer(
+                mailboxPath -> mailboxManager.deleteMailbox(
+                        mailboxPath, 
+                        mailboxManager.createSystemSession(mailboxPath.getUser()))));
+    }
+
+    public JamesImapHostSystem getImapHostSystem() {
+        return system;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1f1077e/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/UidSearchOnIndex.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/UidSearchOnIndex.java b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/UidSearchOnIndex.java
index 3f19ad0..231768d 100644
--- a/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/UidSearchOnIndex.java
+++ b/mpt/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/UidSearchOnIndex.java
@@ -25,6 +25,7 @@ import org.apache.james.mpt.api.ImapHostSystem;
 import org.apache.james.mpt.imapmailbox.ImapTestConstants;
 import org.apache.james.mpt.imapmailbox.suite.base.BasicImapCommands;
 import org.apache.james.mpt.script.SimpleScriptedTestProtocol;
+import org.junit.Before;
 import org.junit.Test;
 
 public abstract class UidSearchOnIndex implements ImapTestConstants {
@@ -34,6 +35,7 @@ public abstract class UidSearchOnIndex implements ImapTestConstants {
     private ImapHostSystem system;
     private SimpleScriptedTestProtocol simpleScriptedTestProtocol;
 
+    @Before
     public void setUp() throws Exception {
         system = createImapHostSystem();
         simpleScriptedTestProtocol = new SimpleScriptedTestProtocol("/org/apache/james/imap/scripts/", system)


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


[09/15] james-project git commit: JAMES-2202 Adding a version to default INDEX

Posted by bt...@apache.org.
JAMES-2202 Adding a version to default INDEX


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

Branch: refs/heads/master
Commit: 0480d7cdb3fa57a9c6cb5b28a349ed4e3453849a
Parents: 27fe978
Author: benwa <bt...@linagora.com>
Authored: Thu Oct 26 09:06:12 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:55:12 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/elasticsearch/MailboxElasticSearchConstants.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0480d7cd/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
index 80c0584..1017933 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
@@ -26,6 +26,6 @@ import org.apache.james.backends.es.TypeName;
 public interface MailboxElasticSearchConstants {
     AliasName DEFAULT_MAILBOX_WRITE_ALIAS = new AliasName("mailboxWriteAlias");
     AliasName DEFAULT_MAILBOX_READ_ALIAS = new AliasName("mailboxReadAlias");
-    IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox");
+    IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox_v1");
     TypeName MESSAGE_TYPE = new TypeName("message");
 }


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


[11/15] james-project git commit: JAMES-2202 Create a default ElasticSearch configuration

Posted by bt...@apache.org.
JAMES-2202 Create a default ElasticSearch configuration


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

Branch: refs/heads/master
Commit: a312fde2ebbb0e12c2cb781467c27463816902fd
Parents: 76699b3
Author: benwa <bt...@linagora.com>
Authored: Fri Oct 27 08:50:22 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:55:12 2017 +0700

----------------------------------------------------------------------
 .../modules/mailbox/ElasticSearchConfiguration.java     | 12 ++++++++++++
 .../modules/mailbox/ElasticSearchMailboxModule.java     |  7 ++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a312fde2/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index e73ecc7..2fc32e9 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -55,8 +55,20 @@ public class ElasticSearchConfiguration {
     public static final int DEFAULT_NB_SHARDS = 1;
     public static final int DEFAULT_NB_REPLICA = 0;
     public static final int DEFAULT_PORT = 9300;
+    private static final String LOCALHOST = "127.0.0.1";
     public static final Optional<Integer> DEFAULT_PORT_AS_OPTIONAL = Optional.of(DEFAULT_PORT);
 
+    public static final ElasticSearchConfiguration DEFAULT_CONFIGURATION = new ElasticSearchConfiguration(
+        ImmutableList.of(Host.from(LOCALHOST, DEFAULT_PORT)),
+        MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
+        MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
+        MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
+        DEFAULT_NB_SHARDS,
+        DEFAULT_NB_REPLICA,
+        DEFAULT_CONNECTION_MIN_DELAY,
+        DEFAULT_CONNECTION_MAX_RETRIES,
+        IndexAttachments.YES);
+
     public static ElasticSearchConfiguration fromProperties(PropertiesConfiguration configuration) throws ConfigurationException {
         int nbShards = configuration.getInt(ELASTICSEARCH_NB_SHARDS, DEFAULT_NB_SHARDS);
         int nbReplica = configuration.getInt(ELASTICSEARCH_NB_REPLICA, DEFAULT_NB_REPLICA);

http://git-wip-us.apache.org/repos/asf/james-project/blob/a312fde2/server/container/guice/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 82f27a4..5286def 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
@@ -28,9 +28,9 @@ import javax.inject.Singleton;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.backends.es.ElasticSearchConstants;
 import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.ClientProviderImpl;
+import org.apache.james.backends.es.ElasticSearchConstants;
 import org.apache.james.backends.es.IndexCreationFactory;
 import org.apache.james.backends.es.IndexName;
 import org.apache.james.backends.es.NodeMappingFactory;
@@ -57,7 +57,6 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchMailboxModule.class);
 
     public static final String ELASTICSEARCH_CONFIGURATION_NAME = "elasticsearch";
-    private static final String LOCALHOST = "127.0.0.1";
 
     @Override
     protected void configure() {
@@ -75,9 +74,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
             return ElasticSearchConfiguration.fromProperties(configuration);
         } catch (FileNotFoundException e) {
             LOGGER.warn("Could not find " + ELASTICSEARCH_CONFIGURATION_NAME + " configuration file. Using 127.0.0.1:9300 as contact point");
-            PropertiesConfiguration configuration = new PropertiesConfiguration();
-            configuration.addProperty(ElasticSearchConfiguration.ELASTICSEARCH_HOSTS, LOCALHOST);
-            return ElasticSearchConfiguration.fromProperties(configuration);
+            return ElasticSearchConfiguration.DEFAULT_CONFIGURATION;
         }
     }
 


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


[14/15] james-project git commit: JAMES-2205 Generate swagger documentation when building

Posted by bt...@apache.org.
JAMES-2205 Generate swagger documentation when building


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

Branch: refs/heads/master
Commit: b4aa905b6504a8848ca263f33821173a424ed5f1
Parents: 466d91a
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Oct 27 15:49:01 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:56:47 2017 +0700

----------------------------------------------------------------------
 README.adoc                               |  1 +
 dockerfiles/compilation/java-8/compile.sh | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b4aa905b/README.adoc
----------------------------------------------------------------------
diff --git a/README.adoc b/README.adoc
index 0a372a1..3768040 100644
--- a/README.adoc
+++ b/README.adoc
@@ -107,6 +107,7 @@ To retrieve compiled artifacts, one might mount these volumes:
 - --volume $PWD/dockerfiles/run/spring/destination:/spring/destination : is the volume used to get the compiled elements for Spring packaging.
 - --volume $PWD/dockerfiles/run/guice/cassandra/destination:/cassandra/destination : is the volume used to get the compiled elements for Guice Cassandra packaging and Cassandra-LDAP packaging.
 - --volume $PWD/dockerfiles/run/guice/cassandra/destination:/jpa/destination : is the volume used to get the compiled elements for Guice JPA packaging.
+- --volume $PWD/swagger:/swagger : is the volume used to get the swagger json files for webadmin documentation.
 
 Some tests needs a DOCKER_HOST environment variable in order to be played, they will be ignored if you don't provide this variable.
 If you wish to play them, you may use a command like the following (depending on your docker configuration):

http://git-wip-us.apache.org/repos/asf/james-project/blob/b4aa905b/dockerfiles/compilation/java-8/compile.sh
----------------------------------------------------------------------
diff --git a/dockerfiles/compilation/java-8/compile.sh b/dockerfiles/compilation/java-8/compile.sh
index afc499c..9b4d298 100755
--- a/dockerfiles/compilation/java-8/compile.sh
+++ b/dockerfiles/compilation/java-8/compile.sh
@@ -13,6 +13,7 @@ ORIGIN=/origin
 CASSANDRA_DESTINATION=/cassandra/destination
 JPA_DESTINATION=/jpa/destination
 SPRING_DESTINATION=/spring/destination
+SWAGGER_DESTINATION=/swagger
 
 for arg in "$@"
 do
@@ -46,9 +47,9 @@ git checkout $SHA1
 # Compilation
 
 if [ "$SKIPTESTS" = "skipTests" ]; then
-   mvn package -DskipTests -Pcassandra,inmemory,jpa,elasticsearch,lucene,with-assembly,with-jetm
+   mvn package -DskipTests -Pcassandra,inmemory,jpa,elasticsearch,lucene,with-assembly,with-jetm,swagger-json
 else
-   mvn package -Pcassandra,inmemory,jpa,elasticsearch,lucene,with-assembly,with-jetm
+   mvn package -Pcassandra,inmemory,jpa,elasticsearch,lucene,with-assembly,with-jetm,swagger-json
 fi
 
 # Retrieve result
@@ -77,4 +78,10 @@ if [ $? -eq 0 ]; then
       echo "Copying SPRING jars"
       cp server/app/target/james-server-app-*-app.zip $SPRING_DESTINATION
    fi
+
+   if [ -d "$SWAGGER_DESTINATION" ]; then
+      cp server/protocols/webadmin/webadmin-data/target/webadmin-data.json $SWAGGER_DESTINATION || true
+      cp server/protocols/webadmin/webadmin-mailbox/target/webadmin-mailbox.json $SWAGGER_DESTINATION || true
+      cp server/protocols/webadmin/webadmin-swagger/target/webadmin-swagger.json $SWAGGER_DESTINATION || true
+   fi
 fi


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


[13/15] james-project git commit: JAMES-2205 Add a profile for generating swagger json files

Posted by bt...@apache.org.
JAMES-2205 Add a profile for generating swagger json files


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

Branch: refs/heads/master
Commit: 466d91a4fbbd09d7a0c63fd5e00f08d4218f1221
Parents: fa0bcd5
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Oct 27 15:51:33 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:56:43 2017 +0700

----------------------------------------------------------------------
 pom.xml                                         |  5 +++
 server/protocols/webadmin/webadmin-data/pom.xml | 33 ++++++++++++++++++++
 .../protocols/webadmin/webadmin-mailbox/pom.xml | 33 ++++++++++++++++++++
 .../protocols/webadmin/webadmin-swagger/pom.xml | 33 ++++++++++++++++++++
 4 files changed, 104 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/466d91a4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d1cdfb1..5e8f82f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1434,6 +1434,11 @@
                 <version>0.5.0</version>
             </dependency>
             <dependency>
+                <groupId>com.github.kongchen</groupId>
+                <artifactId>swagger-maven-plugin</artifactId>
+                <version>3.1.5</version>
+            </dependency>
+            <dependency>
                 <groupId>com.github.steveash.guavate</groupId>
                 <artifactId>guavate</artifactId>
                 <version>${guavate.version}</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/466d91a4/server/protocols/webadmin/webadmin-data/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/pom.xml b/server/protocols/webadmin/webadmin-data/pom.xml
index 8fbe4f9..e40e6ae 100644
--- a/server/protocols/webadmin/webadmin-data/pom.xml
+++ b/server/protocols/webadmin/webadmin-data/pom.xml
@@ -136,5 +136,38 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>swagger-json</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.github.kongchen</groupId>
+                        <artifactId>swagger-maven-plugin</artifactId>
+                        <configuration>
+                            <apiSources>
+                                <apiSource>
+                                    <springmvc>false</springmvc>
+                                    <locations>org.apache.james.webadmin</locations>
+                                    <info>
+                                        <title>Swagger Maven Plugin</title>
+                                        <version>v1</version>
+                                    </info>
+                                    <swaggerDirectory>${project.build.directory}</swaggerDirectory>
+                                    <swaggerFileName>webadmin-data</swaggerFileName>
+                                </apiSource>
+                            </apiSources>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>generate</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/466d91a4/server/protocols/webadmin/webadmin-mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/pom.xml b/server/protocols/webadmin/webadmin-mailbox/pom.xml
index 6c543f8..fd9e501 100644
--- a/server/protocols/webadmin/webadmin-mailbox/pom.xml
+++ b/server/protocols/webadmin/webadmin-mailbox/pom.xml
@@ -156,5 +156,38 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>swagger-json</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.github.kongchen</groupId>
+                        <artifactId>swagger-maven-plugin</artifactId>
+                        <configuration>
+                            <apiSources>
+                                <apiSource>
+                                    <springmvc>false</springmvc>
+                                    <locations>org.apache.james.webadmin</locations>
+                                    <info>
+                                        <title>Swagger Maven Plugin</title>
+                                        <version>v1</version>
+                                    </info>
+                                    <swaggerDirectory>${project.build.directory}</swaggerDirectory>
+                                    <swaggerFileName>webadmin-mailbox</swaggerFileName>
+                                </apiSource>
+                            </apiSources>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>generate</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/466d91a4/server/protocols/webadmin/webadmin-swagger/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-swagger/pom.xml b/server/protocols/webadmin/webadmin-swagger/pom.xml
index 9d5d97b..739289d 100644
--- a/server/protocols/webadmin/webadmin-swagger/pom.xml
+++ b/server/protocols/webadmin/webadmin-swagger/pom.xml
@@ -59,5 +59,38 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>swagger-json</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.github.kongchen</groupId>
+                        <artifactId>swagger-maven-plugin</artifactId>
+                        <configuration>
+                            <apiSources>
+                                <apiSource>
+                                    <springmvc>false</springmvc>
+                                    <locations>org.apache.james.webadmin</locations>
+                                    <info>
+                                        <title>Swagger Maven Plugin</title>
+                                        <version>v1</version>
+                                    </info>
+                                    <swaggerDirectory>${project.build.directory}</swaggerDirectory>
+                                    <swaggerFileName>webadmin-swagger</swaggerFileName>
+                                </apiSource>
+                            </apiSources>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>generate</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
 </project>


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


[08/15] james-project git commit: JAMES-2202 Handle a read and a write alias

Posted by bt...@apache.org.
JAMES-2202 Handle a read and a write alias


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

Branch: refs/heads/master
Commit: 27fe978053a1e0a829c34f49f6767a4839861041
Parents: fc927f0
Author: benwa <bt...@linagora.com>
Authored: Thu Oct 26 09:02:26 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 1 17:55:04 2017 +0700

----------------------------------------------------------------------
 .../james/backends/es/IndexCreationFactory.java | 13 +++---
 .../backends/es/ElasticSearchIndexerTest.java   |  2 +-
 .../backends/es/IndexCreationFactoryTest.java   | 46 +++++++++++++++++++-
 .../backends/es/NodeMappingFactoryTest.java     |  2 +-
 .../backends/es/search/ScrollIterableTest.java  |  2 +-
 .../ElasticSearchIntegrationTest.java           |  6 +--
 .../host/ElasticSearchHostSystem.java           |  2 +-
 .../mailbox/ElasticSearchConfiguration.java     | 22 +++++-----
 .../mailbox/ElasticSearchMailboxModule.java     |  2 +-
 .../james/modules/TestElasticSearchModule.java  |  2 +-
 10 files changed, 71 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index a4bcc84..3fedaea 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -22,6 +22,7 @@ package org.apache.james.backends.es;
 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Optional;
 
 import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
@@ -33,7 +34,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
 
 public class IndexCreationFactory {
 
@@ -43,18 +43,18 @@ public class IndexCreationFactory {
     public static final String CASE_INSENSITIVE = "case_insensitive";
 
     private IndexName indexName;
-    private ImmutableList.Builder<AliasName> aliases;
+    private ArrayList<AliasName> aliases;
     private Optional<Integer> nbShards;
     private Optional<Integer> nbReplica;
 
     public IndexCreationFactory() {
         indexName = null;
-        aliases = ImmutableList.builder();
+        aliases = new ArrayList<>();
         nbShards = Optional.empty();
         nbReplica = Optional.empty();
     }
 
-    public IndexCreationFactory onIndex(IndexName indexName) {
+    public IndexCreationFactory useIndex(IndexName indexName) {
         Preconditions.checkNotNull(indexName);
         this.indexName = indexName;
         return this;
@@ -67,11 +67,13 @@ public class IndexCreationFactory {
     }
 
     public IndexCreationFactory nbShards(int nbShards) {
+        Preconditions.checkArgument(nbShards > 0, "You need the number of shards to be strictly positive");
         this.nbShards = Optional.of(nbShards);
         return this;
     }
 
     public IndexCreationFactory nbReplica(int nbReplica) {
+        Preconditions.checkArgument(nbReplica >= 0, "You need the number of replica to be positive");
         this.nbReplica = Optional.of(nbReplica);
         return this;
     }
@@ -82,8 +84,7 @@ public class IndexCreationFactory {
             createIndexIfNeeded(client, indexName, generateSetting(
                 nbShards.orElse(DEFAULT_NB_SHARDS),
                 nbReplica.orElse(DEFAULT_NB_REPLICA)));
-            aliases.build()
-                .forEach(alias -> createAliasIfNeeded(client, indexName, alias));
+            aliases.forEach(alias -> createAliasIfNeeded(client, indexName, alias));
         } catch (IOException e) {
             LOGGER.error("Error while creating index : ", e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index a3a6d9c..1b7a3e3 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -59,7 +59,7 @@ public class ElasticSearchIndexerTest {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider.get(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
index 7735eb9..f02048d 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.backends.es;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.junit.Before;
 import org.junit.Rule;
@@ -42,7 +44,7 @@ public class IndexCreationFactoryTest {
     public void setUp() {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
     }
@@ -50,8 +52,48 @@ public class IndexCreationFactoryTest {
     @Test
     public void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
     }
+
+    @Test
+    public void useIndexShouldThrowWhenNull() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .useIndex(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void addAliasShouldThrowWhenNull() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .addAlias(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void nbReplicaShouldThrowWhenNegative() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbReplica(-1))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    public void nbShardsShouldThrowWhenNegative() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbShards(-1))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    public void nbShardsShouldThrowWhenZero() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbShards(0))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
index 1e0eb79..42a403f 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
@@ -47,7 +47,7 @@ public class NodeMappingFactoryTest {
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         NodeMappingFactory.applyMapping(clientProvider.get(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
index b296b8e..dbba300 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
@@ -68,7 +68,7 @@ public class ScrollIterableTest {
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         embeddedElasticSearch.awaitForElasticSearch();

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index e380864..cf3a9cc 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -111,9 +111,9 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     protected void initializeMailboxManager() throws Exception {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
-                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
-                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
             MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticSearchConstants.MESSAGE_TYPE,

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 0817c25..4d6d184 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -96,7 +96,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
                 .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
                 .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index 8d95228..3fc502f 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -91,35 +91,35 @@ public class ElasticSearchConfiguration {
     }
 
     private static ImmutableList<Host> getHosts(PropertiesConfiguration propertiesReader) throws ConfigurationException {
-        Optional<String> monoHostAddress = Optional.ofNullable(
+        Optional<String> masterHost = Optional.ofNullable(
             propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null));
-        Optional<Integer> monoHostPort = Optional.ofNullable(
+        Optional<Integer> masterPort = Optional.ofNullable(
             propertiesReader.getInteger(ELASTICSEARCH_PORT, null));
         Optional<String> multiHosts = Optional.ofNullable(
             propertiesReader.getString(ELASTICSEARCH_HOSTS, null));
 
-        validateHostsConfigurationOptions(monoHostAddress, monoHostPort, multiHosts);
+        validateHostsConfigurationOptions(masterHost, masterPort, multiHosts);
 
-        if (monoHostAddress.isPresent()) {
+        if (masterHost.isPresent()) {
             return ImmutableList.of(
-                Host.from(monoHostAddress.get(),
-                monoHostPort.get()));
+                Host.from(masterHost.get(),
+                masterPort.get()));
         } else {
             return Host.parseHosts(multiHosts.get(), DEFAULT_PORT);
         }
     }
 
     @VisibleForTesting
-    static void validateHostsConfigurationOptions(Optional<String> monoHostAddress,
-                                                  Optional<Integer> monoHostPort,
+    static void validateHostsConfigurationOptions(Optional<String> masterHost,
+                                                  Optional<Integer> masterPort,
                                                   Optional<String> multiHosts) throws ConfigurationException {
-        if (monoHostAddress.isPresent() != monoHostPort.isPresent()) {
+        if (masterHost.isPresent() != masterPort.isPresent()) {
             throw new ConfigurationException(ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + " should be specified together");
         }
-        if (multiHosts.isPresent() && monoHostAddress.isPresent()) {
+        if (multiHosts.isPresent() && masterHost.isPresent()) {
             throw new ConfigurationException("You should choose between mono host set up and " + ELASTICSEARCH_HOSTS);
         }
-        if (!multiHosts.isPresent() && !monoHostAddress.isPresent()) {
+        if (!multiHosts.isPresent() && !masterHost.isPresent()) {
             throw new ConfigurationException("You should specify either (" + ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + ") or " + ELASTICSEARCH_HOSTS);
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/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 bab0ae3..82f27a4 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
@@ -100,7 +100,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     @Singleton
     protected IndexCreationFactory provideIndexCreationFactory(ElasticSearchConfiguration configuration) {
         return new IndexCreationFactory()
-            .onIndex(configuration.getIndexName())
+            .useIndex(configuration.getIndexName())
             .addAlias(configuration.getReadAliasName())
             .addAlias(configuration.getWriteAliasName())
             .nbShards(configuration.getNbShards())

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 8cd728c..428f160 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -51,7 +51,7 @@ public class TestElasticSearchModule extends AbstractModule{
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
 
         new IndexCreationFactory()
-            .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+            .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
             .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
             .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
             .createIndexAndAliases(client);


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