james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [07/15] james-project git commit: JAMES-2408 Allow one to await the execution of ElasticSearchIndexer::deleteAll
Date Wed, 06 Jun 2018 07:01:01 GMT
JAMES-2408 Allow one to await the execution of ElasticSearchIndexer::deleteAll

Note that this is used in case of mailbox deletions to delete messages that are anyway not
accessible anymore, as a background task.

However, we might have an embedded ElasticSearch not being active while the deleteByQuery
is not finished yet, leading to test failures. Awaiting the task solves this issue.


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

Branch: refs/heads/master
Commit: 92829a20cac4c7133da48ed8d6d98e8c1cb48a70
Parents: b902c20
Author: benwa <btellier@linagora.com>
Authored: Tue Jun 5 11:09:13 2018 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Wed Jun 6 08:58:57 2018 +0200

----------------------------------------------------------------------
 .../org/apache/james/backends/es/DeleteByQueryPerformer.java | 5 +++--
 .../org/apache/james/backends/es/ElasticSearchIndexer.java   | 5 +++--
 .../apache/james/backends/es/ElasticSearchIndexerTest.java   | 8 ++++----
 3 files changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/92829a20/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 024511b..f78d80f 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
@@ -20,6 +20,7 @@
 package org.apache.james.backends.es;
 
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 
 import org.apache.james.backends.es.search.ScrollIterable;
 import org.elasticsearch.action.ListenableActionFuture;
@@ -57,8 +58,8 @@ public class DeleteByQueryPerformer {
         this.typeName = typeName;
     }
 
-    public void perform(QueryBuilder queryBuilder) {
-        executor.execute(() -> doDeleteByQuery(queryBuilder));
+    public Future<?> perform(QueryBuilder queryBuilder) {
+        return executor.submit(() -> doDeleteByQuery(queryBuilder));
     }
 
     protected void doDeleteByQuery(QueryBuilder queryBuilder) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/92829a20/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 009e331..ae61a9f 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
@@ -21,6 +21,7 @@ package org.apache.james.backends.es;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 
 import org.apache.commons.lang3.StringUtils;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
@@ -105,8 +106,8 @@ public class ElasticSearchIndexer {
         }
     }
 
-    public void deleteAllMatchingQuery(QueryBuilder queryBuilder) {
-        deleteByQueryPerformer.perform(queryBuilder);
+    public Future<?> deleteAllMatchingQuery(QueryBuilder queryBuilder) {
+        return deleteByQueryPerformer.perform(queryBuilder);
     }
 
     private void checkArgument(String content) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/92829a20/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 d5121e0..544389d 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
@@ -140,14 +140,14 @@ public class ElasticSearchIndexerTest {
     }
 
     @Test
-    public void deleteByQueryShouldWorkOnSingleMessage() {
+    public void deleteByQueryShouldWorkOnSingleMessage() throws Exception {
         String messageId = "1:2";
         String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
 
         testee.index(messageId, content);
         embeddedElasticSearch.awaitForElasticSearch();
         
-        testee.deleteAllMatchingQuery(termQuery("property", "1"));
+        testee.deleteAllMatchingQuery(termQuery("property", "1")).get();
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
@@ -160,7 +160,7 @@ public class ElasticSearchIndexerTest {
     }
 
     @Test
-    public void deleteByQueryShouldWorkWhenMultipleMessages() {
+    public void deleteByQueryShouldWorkWhenMultipleMessages() throws Exception {
         String messageId = "1:1";
         String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
         
@@ -177,7 +177,7 @@ public class ElasticSearchIndexerTest {
         testee.index(messageId3, content3);
         embeddedElasticSearch.awaitForElasticSearch();
 
-        testee.deleteAllMatchingQuery(termQuery("property", "1"));
+        testee.deleteAllMatchingQuery(termQuery("property", "1")).get();
         embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {


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


Mime
View raw message