You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/05/20 09:40:02 UTC

[james-project] 05/09: JAMES-2765 Migrate quota-search-elasticsearch to ES 6 REST client

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 230b51979ce4d2221fec86c9794e8d51ab96e3be
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu May 16 17:43:34 2019 +0700

    JAMES-2765 Migrate quota-search-elasticsearch to ES 6 REST client
---
 .../plugin/quota-search-elasticsearch-v6/pom.xml   |  4 +-
 .../ElasticSearchQuotaConfiguration.java           |  6 +--
 .../elasticsearch/ElasticSearchQuotaSearcher.java  | 43 +++++++++----------
 .../search/elasticsearch/QuotaQueryConverter.java  |  6 +--
 .../QuotaRatioElasticSearchConstants.java          |  8 ++--
 .../elasticsearch/QuotaRatioMappingFactory.java    | 37 +++++++---------
 .../QuotaSearchIndexCreationUtil.java              | 21 ++++-----
 .../events/ElasticSearchQuotaMailboxListener.java  | 10 ++---
 .../ElasticSearchQuotaConfigurationTest.java       |  6 +--
 ...lasticSearchQuotaSearchTestSystemExtension.java | 26 +++++------
 .../ElasticSearchQuotaSearcherTest.java            |  2 +-
 .../ElasticSearchQuotaMailboxListenerTest.java     | 50 +++++++++++-----------
 pom.xml                                            | 11 +++++
 13 files changed, 112 insertions(+), 118 deletions(-)

diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/pom.xml b/mailbox/plugin/quota-search-elasticsearch-v6/pom.xml
index c1eeca6..7135337 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/pom.xml
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/pom.xml
@@ -34,11 +34,11 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>apache-james-backends-es</artifactId>
+            <artifactId>apache-james-backends-es-v6</artifactId>
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>apache-james-backends-es</artifactId>
+            <artifactId>apache-james-backends-es-v6</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfiguration.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfiguration.java
index c14f339..53e6d9b 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfiguration.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfiguration.java
@@ -24,9 +24,9 @@ import java.util.Optional;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.backends.es.ReadAliasName;
-import org.apache.james.backends.es.WriteAliasName;
+import org.apache.james.backends.es.v6.IndexName;
+import org.apache.james.backends.es.v6.ReadAliasName;
+import org.apache.james.backends.es.v6.WriteAliasName;
 
 public class ElasticSearchQuotaConfiguration {
 
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
index 21d55a8..55ce6c9 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
@@ -19,22 +19,24 @@
 
 package org.apache.james.quota.search.elasticsearch;
 
-import static org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE;
 import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.USER;
 
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Stream;
 
-import org.apache.james.backends.es.AliasName;
-import org.apache.james.backends.es.ReadAliasName;
-import org.apache.james.backends.es.search.ScrollIterable;
+import org.apache.james.backends.es.v6.AliasName;
+import org.apache.james.backends.es.v6.NodeMappingFactory;
+import org.apache.james.backends.es.v6.ReadAliasName;
+import org.apache.james.backends.es.v6.search.ScrollIterable;
 import org.apache.james.core.User;
 import org.apache.james.quota.search.QuotaQuery;
 import org.apache.james.quota.search.QuotaSearcher;
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.client.Client;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.client.RestHighLevelClient;
 import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.elasticsearch.search.sort.SortBuilders;
 import org.elasticsearch.search.sort.SortOrder;
 
@@ -43,11 +45,11 @@ import com.github.steveash.guavate.Guavate;
 public class ElasticSearchQuotaSearcher implements QuotaSearcher {
     private static final TimeValue TIMEOUT = new TimeValue(60000);
 
-    private final Client client;
+    private final RestHighLevelClient client;
     private final AliasName readAlias;
     private final QuotaQueryConverter quotaQueryConverter;
 
-    public ElasticSearchQuotaSearcher(Client client, ReadAliasName readAlias) {
+    public ElasticSearchQuotaSearcher(RestHighLevelClient client, ReadAliasName readAlias) {
         this.client = client;
         this.readAlias = readAlias;
         this.quotaQueryConverter = new QuotaQueryConverter();
@@ -59,8 +61,7 @@ public class ElasticSearchQuotaSearcher implements QuotaSearcher {
             .stream()
             .flatMap(searchResponse -> Arrays.stream(searchResponse.getHits()
                 .getHits()))
-            .map(hit -> hit.field(USER))
-            .map(field -> (String) field.getValue())
+            .map(SearchHit::getId)
             .map(User::fromUsername)
             .skip(query.getOffset().getValue());
 
@@ -70,22 +71,20 @@ public class ElasticSearchQuotaSearcher implements QuotaSearcher {
             .collect(Guavate.toImmutableList());
     }
 
-    public SearchRequestBuilder prepareSearch(QuotaQuery query) {
-        SearchRequestBuilder searchRequestBuilder = client.prepareSearch(readAlias.getValue())
-            .setTypes(QUOTA_RATIO_TYPE.getValue())
-            .setScroll(TIMEOUT)
-            .addFields(USER)
-            .setQuery(quotaQueryConverter.from(query));
+    public SearchRequest prepareSearch(QuotaQuery query) {
+        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
+            .query(quotaQueryConverter.from(query))
+            .sort(SortBuilders.fieldSort(USER)
+                .order(SortOrder.ASC));
 
         query.getLimit()
             .getValue()
-            .ifPresent(searchRequestBuilder::setSize);
-
-        searchRequestBuilder.addSort(
-            SortBuilders.fieldSort(USER)
-                .order(SortOrder.ASC));
+            .ifPresent(sourceBuilder::size);
 
-        return searchRequestBuilder;
+        return new SearchRequest(readAlias.getValue())
+            .types(NodeMappingFactory.DEFAULT_MAPPING_NAME)
+            .scroll(TIMEOUT)
+            .source(sourceBuilder);
     }
 
 }
\ No newline at end of file
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
index b02d8ac..a67d063 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
@@ -43,10 +43,10 @@ import org.elasticsearch.index.query.TermQueryBuilder;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 
-public class QuotaQueryConverter {
+class QuotaQueryConverter {
     private final Map<Class<? extends QuotaClause>, Function<QuotaClause, QueryBuilder>> clauseConverter;
 
-    public QuotaQueryConverter() {
+    QuotaQueryConverter() {
         Builder<Class<? extends QuotaClause>, Function<QuotaClause, QueryBuilder>> builder = ImmutableMap.builder();
         
         builder.put(HasDomain.class, this::convertHasDomain);
@@ -57,7 +57,7 @@ public class QuotaQueryConverter {
         clauseConverter = builder.build();
     }
 
-    public QueryBuilder from(QuotaQuery query) {
+    QueryBuilder from(QuotaQuery query) {
         List<QuotaClause> clauses = query.getClause().getClauses();
         if (clauses.isEmpty()) {
             return matchAllQuery();
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
index e3ceadd..43cb89e 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
@@ -19,10 +19,9 @@
 
 package org.apache.james.quota.search.elasticsearch;
 
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.backends.es.ReadAliasName;
-import org.apache.james.backends.es.TypeName;
-import org.apache.james.backends.es.WriteAliasName;
+import org.apache.james.backends.es.v6.IndexName;
+import org.apache.james.backends.es.v6.ReadAliasName;
+import org.apache.james.backends.es.v6.WriteAliasName;
 
 public interface QuotaRatioElasticSearchConstants {
 
@@ -33,5 +32,4 @@ public interface QuotaRatioElasticSearchConstants {
     WriteAliasName DEFAULT_QUOTA_RATIO_WRITE_ALIAS = new WriteAliasName("quota_ratio_write_alias");
     ReadAliasName DEFAULT_QUOTA_RATIO_READ_ALIAS = new ReadAliasName("quota_ratio_read_alias");
     IndexName DEFAULT_QUOTA_RATIO_INDEX = new IndexName("quota_ratio_v1");
-    TypeName QUOTA_RATIO_TYPE = new TypeName("quota_ratio");
 }
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
index 128f1d1..78d7aa3 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
@@ -19,12 +19,10 @@
 
 package org.apache.james.quota.search.elasticsearch;
 
-import static org.apache.james.backends.es.NodeMappingFactory.DOUBLE;
-import static org.apache.james.backends.es.NodeMappingFactory.INDEX;
-import static org.apache.james.backends.es.NodeMappingFactory.NOT_ANALYZED;
-import static org.apache.james.backends.es.NodeMappingFactory.PROPERTIES;
-import static org.apache.james.backends.es.NodeMappingFactory.STRING;
-import static org.apache.james.backends.es.NodeMappingFactory.TYPE;
+import static org.apache.james.backends.es.v6.NodeMappingFactory.DOUBLE;
+import static org.apache.james.backends.es.v6.NodeMappingFactory.KEYWORD;
+import static org.apache.james.backends.es.v6.NodeMappingFactory.PROPERTIES;
+import static org.apache.james.backends.es.v6.NodeMappingFactory.TYPE;
 import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.DOMAIN;
 import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.QUOTA_RATIO;
 import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.USER;
@@ -34,29 +32,24 @@ import java.io.IOException;
 
 import org.elasticsearch.common.xcontent.XContentBuilder;
 
-public class QuotaRatioMappingFactory {
+class QuotaRatioMappingFactory {
 
     public static XContentBuilder getMappingContent() {
         try {
             return jsonBuilder()
                 .startObject()
+                    .startObject(PROPERTIES)
 
-                    .startObject(QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE.getValue())
-                        .startObject(PROPERTIES)
-
-                            .startObject(USER)
-                                .field(TYPE, STRING)
-                                .field(INDEX, NOT_ANALYZED)
-                            .endObject()
+                        .startObject(USER)
+                            .field(TYPE, KEYWORD)
+                        .endObject()
 
-                            .startObject(DOMAIN)
-                                .field(TYPE, STRING)
-                                .field(INDEX, NOT_ANALYZED)
-                            .endObject()
+                        .startObject(DOMAIN)
+                            .field(TYPE, KEYWORD)
+                        .endObject()
 
-                            .startObject(QUOTA_RATIO)
-                                .field(TYPE, DOUBLE)
-                            .endObject()
+                        .startObject(QUOTA_RATIO)
+                            .field(TYPE, DOUBLE)
                         .endObject()
                     .endObject()
                 .endObject();
@@ -64,4 +57,4 @@ public class QuotaRatioMappingFactory {
             throw new RuntimeException(e);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
index f546230..3555b28 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
@@ -19,20 +19,22 @@
 
 package org.apache.james.quota.search.elasticsearch;
 
-import org.apache.james.backends.es.AliasName;
-import org.apache.james.backends.es.ElasticSearchConfiguration;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.backends.es.NodeMappingFactory;
-import org.elasticsearch.client.Client;
+import java.io.IOException;
+
+import org.apache.james.backends.es.v6.AliasName;
+import org.apache.james.backends.es.v6.ElasticSearchConfiguration;
+import org.apache.james.backends.es.v6.IndexCreationFactory;
+import org.apache.james.backends.es.v6.IndexName;
+import org.apache.james.backends.es.v6.NodeMappingFactory;
+import org.elasticsearch.client.RestHighLevelClient;
 
 public class QuotaSearchIndexCreationUtil {
 
-    public static Client prepareClient(Client client,
+    public static RestHighLevelClient prepareClient(RestHighLevelClient client,
                                        AliasName readAlias,
                                        AliasName writeAlias,
                                        IndexName indexName,
-                                       ElasticSearchConfiguration configuration) {
+                                       ElasticSearchConfiguration configuration) throws IOException {
 
         return NodeMappingFactory.applyMapping(
             new IndexCreationFactory(configuration)
@@ -41,11 +43,10 @@ public class QuotaSearchIndexCreationUtil {
                 .addAlias(writeAlias)
                 .createIndexAndAliases(client),
             indexName,
-            QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
             QuotaRatioMappingFactory.getMappingContent());
     }
 
-    public static Client prepareDefaultClient(Client client, ElasticSearchConfiguration configuration) {
+    public static RestHighLevelClient prepareDefaultClient(RestHighLevelClient client, ElasticSearchConfiguration configuration) throws IOException {
         return prepareClient(client,
             QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS,
             QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
index 2b828f2..1a14c0c 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
@@ -18,10 +18,12 @@
  ****************************************************************/
 package org.apache.james.quota.search.elasticsearch.events;
 
+import java.io.IOException;
+
 import javax.inject.Inject;
 import javax.inject.Named;
 
-import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.backends.es.v6.ElasticSearchIndexer;
 import org.apache.james.core.User;
 import org.apache.james.mailbox.events.Event;
 import org.apache.james.mailbox.events.Group;
@@ -29,8 +31,6 @@ import org.apache.james.mailbox.events.MailboxListener;
 import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
 import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-
 public class ElasticSearchQuotaMailboxListener implements MailboxListener.GroupMailboxListener {
     public static class ElasticSearchQuotaMailboxListenerGroup extends Group {
     }
@@ -59,11 +59,11 @@ public class ElasticSearchQuotaMailboxListener implements MailboxListener.GroupM
     }
 
     @Override
-    public void event(Event event) throws JsonProcessingException {
+    public void event(Event event) throws IOException {
         handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
     }
 
-    private void handleEvent(User user, QuotaUsageUpdatedEvent event) throws JsonProcessingException {
+    private void handleEvent(User user, QuotaUsageUpdatedEvent event) throws IOException {
         indexer.index(user.asString(),
             quotaRatioToElasticSearchJson.convertToJson(user.asString(), event));
     }
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfigurationTest.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfigurationTest.java
index a57a10e..2027436 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfigurationTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaConfigurationTest.java
@@ -23,9 +23,9 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.backends.es.IndexName;
-import org.apache.james.backends.es.ReadAliasName;
-import org.apache.james.backends.es.WriteAliasName;
+import org.apache.james.backends.es.v6.IndexName;
+import org.apache.james.backends.es.v6.ReadAliasName;
+import org.apache.james.backends.es.v6.WriteAliasName;
 import org.junit.Test;
 
 public class ElasticSearchQuotaConfigurationTest {
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
index 5e63c46..a4194ca 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
@@ -21,13 +21,10 @@ package org.apache.james.quota.search.elasticsearch;
 
 import static org.mockito.Mockito.mock;
 
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-import org.apache.james.backends.es.DockerElasticSearch;
-import org.apache.james.backends.es.DockerElasticSearchSingleton;
-import org.apache.james.backends.es.ElasticSearchConfiguration;
-import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.backends.es.v6.DockerElasticSearch;
+import org.apache.james.backends.es.v6.DockerElasticSearchSingleton;
+import org.apache.james.backends.es.v6.ElasticSearchConfiguration;
+import org.apache.james.backends.es.v6.ElasticSearchIndexer;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.domainlist.memory.MemoryDomainList;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
@@ -36,8 +33,7 @@ import org.apache.james.quota.search.QuotaSearchTestSystem;
 import org.apache.james.quota.search.elasticsearch.events.ElasticSearchQuotaMailboxListener;
 import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
 import org.apache.james.user.memory.MemoryUsersRepository;
-import org.apache.james.util.concurrent.NamedThreadFactory;
-import org.elasticsearch.client.Client;
+import org.elasticsearch.client.RestHighLevelClient;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
@@ -57,10 +53,10 @@ public class ElasticSearchQuotaSearchTestSystemExtension implements ParameterRes
     @Override
     public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
         try {
-            Client client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
+            RestHighLevelClient client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
                 elasticSearch.clientProvider().get(),
                 ElasticSearchConfiguration.builder()
-                    .addHost(elasticSearch.getTcpHost())
+                    .addHost(elasticSearch.getHttpHost())
                     .build());
 
             InMemoryIntegrationResources resources = InMemoryIntegrationResources.defaultResources();
@@ -71,11 +67,9 @@ public class ElasticSearchQuotaSearchTestSystemExtension implements ParameterRes
             MemoryDomainList domainList = new MemoryDomainList(dnsService);
             usersRepository.setDomainList(domainList);
 
-            ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
             ElasticSearchQuotaMailboxListener listener = new ElasticSearchQuotaMailboxListener(
-                new ElasticSearchIndexer(client, Executors.newSingleThreadExecutor(threadFactory),
-                    QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
-                    QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE),
+                new ElasticSearchIndexer(client,
+                    QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS),
                 new QuotaRatioToElasticSearchJson());
 
             resources.getMailboxManager().getEventBus().register(listener);
@@ -92,7 +86,7 @@ public class ElasticSearchQuotaSearchTestSystemExtension implements ParameterRes
                 usersRepository,
                 domainList,
                 resources.getCurrentQuotaManager(),
-                () -> elasticSearch.awaitForElasticSearch());
+                elasticSearch::awaitForElasticSearch);
         } catch (Exception e) {
             throw new ParameterResolutionException("Error while resolving parameter", e);
         }
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
index ad26532..2d4b79e 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
@@ -23,6 +23,6 @@ import org.apache.james.quota.search.QuotaSearcherContract;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(ElasticSearchQuotaSearchTestSystemExtension.class)
-public class ElasticSearchQuotaSearcherTest implements QuotaSearcherContract {
+class ElasticSearchQuotaSearcherTest implements QuotaSearcherContract {
 
 }
diff --git a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
index d3f7811..bfead33 100644
--- a/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch-v6/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -23,15 +23,13 @@ import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.BOB
 import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.NOW;
 import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.QUOTAROOT;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
-import static org.mockito.Mockito.mock;
 
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
+import java.io.IOException;
 
-import org.apache.james.backends.es.DockerElasticSearchRule;
-import org.apache.james.backends.es.ElasticSearchConfiguration;
-import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.backends.es.v6.DockerElasticSearchRule;
+import org.apache.james.backends.es.v6.ElasticSearchConfiguration;
+import org.apache.james.backends.es.v6.ElasticSearchIndexer;
+import org.apache.james.backends.es.v6.NodeMappingFactory;
 import org.apache.james.mailbox.events.Event;
 import org.apache.james.mailbox.events.Group;
 import org.apache.james.mailbox.quota.QuotaFixture.Counts;
@@ -40,9 +38,12 @@ import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
 import org.apache.james.quota.search.elasticsearch.QuotaSearchIndexCreationUtil;
 import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
-import org.apache.james.util.concurrent.NamedThreadFactory;
+import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.client.Client;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -51,27 +52,23 @@ public class ElasticSearchQuotaMailboxListenerTest {
     private static Event.EventId EVENT_ID = Event.EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4");
 
     private static final int BATCH_SIZE = 1;
-    private static final Event DUMB_EVENT = mock(Event.class);
 
     @Rule
     public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
     private ElasticSearchQuotaMailboxListener quotaMailboxListener;
-    private Client client;
+    private RestHighLevelClient client;
 
     @Before
-    public void setUp() {
-        client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
-            elasticSearch.clientProvider().get(),
-            ElasticSearchConfiguration.builder()
-                .addHost(elasticSearch.getTcpHost())
-                .build());
+    public void setUp() throws IOException {
+        client = elasticSearch.clientProvider().get();
+
+        QuotaSearchIndexCreationUtil.prepareDefaultClient(client, ElasticSearchConfiguration.builder()
+            .addHost(elasticSearch.getDockerElasticSearch().getHttpHost())
+            .build());
 
-        ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
         quotaMailboxListener = new ElasticSearchQuotaMailboxListener(
             new ElasticSearchIndexer(client,
-                Executors.newSingleThreadExecutor(threadFactory),
                 QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
-                QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
                 BATCH_SIZE),
             new QuotaRatioToElasticSearchJson());
     }
@@ -95,11 +92,12 @@ public class ElasticSearchQuotaMailboxListenerTest {
 
         elasticSearch.awaitForElasticSearch();
 
-        SearchResponse searchResponse = client.prepareSearch(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS.getValue())
-            .setTypes(QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE.getValue())
-            .setQuery(matchAllQuery())
-            .execute()
-            .get();
-        assertThat(searchResponse.getHits().totalHits()).isEqualTo(1);
+        SearchResponse searchResponse = client.search(new SearchRequest(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS.getValue())
+                .types(NodeMappingFactory.DEFAULT_MAPPING_NAME)
+                .source(new SearchSourceBuilder()
+                    .query(QueryBuilders.matchAllQuery())),
+            RequestOptions.DEFAULT);
+
+        assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
     }
 }
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7100134..933c8f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -698,6 +698,17 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-backends-es-v6</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-backends-es-v6</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
                 <artifactId>apache-james-backends-jpa</artifactId>
                 <version>${project.version}</version>
             </dependency>


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