james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/18] james-project git commit: MAILBOX-266 DeleteByQueryPerformer should be tested synchronously in tests
Date Wed, 06 Apr 2016 09:21:59 GMT
MAILBOX-266 DeleteByQueryPerformer should be tested synchronously in tests

Otherwise, await() can be called before the BulkRequest being sent. In this case, await succeeds,
and further conditions fails, as the state has not been modified as required.


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

Branch: refs/heads/master
Commit: f43a4e32fba8dd021729d8fc4dd987b7006e07c8
Parents: b99d0c7
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Mar 28 10:32:08 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Apr 6 16:18:45 2016 +0700

----------------------------------------------------------------------
 .../elasticsearch/DeleteByQueryPerformer.java        | 15 +++++++--------
 .../elasticsearch/ElasticSearchIndexerTest.java      | 12 +++++++++---
 2 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f43a4e32/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/DeleteByQueryPerformer.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/DeleteByQueryPerformer.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/DeleteByQueryPerformer.java
index 895f016..f2a54fa 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/DeleteByQueryPerformer.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/DeleteByQueryPerformer.java
@@ -56,23 +56,22 @@ public class DeleteByQueryPerformer {
         this.batchSize = batchSize;
     }
 
-    public void perform(QueryBuilder queryBuilder) {
+    public Void perform(QueryBuilder queryBuilder) {
         executor.execute(() -> doDeleteByQuery(queryBuilder));
+        return null;
     }
 
-    private Void doDeleteByQuery(QueryBuilder queryBuilder) {
+    protected void doDeleteByQuery(QueryBuilder queryBuilder) {
         try (Client client = clientProvider.get()) {
-            ScrollIterable scrollIterable = new ScrollIterable(client,
+            new ScrollIterable(client,
                 client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
                     .setTypes(ElasticSearchIndexer.MESSAGE_TYPE)
                     .setScroll(TIMEOUT)
                     .setNoFields()
                     .setQuery(queryBuilder)
-                    .setSize(batchSize));
-            for (SearchResponse searchResponse : scrollIterable) {
-                deleteRetrievedIds(client, searchResponse);
-            }
-            return null;
+                    .setSize(batchSize))
+                .stream()
+                .forEach(searchResponse -> deleteRetrievedIds(client, searchResponse));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f43a4e32/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
index 7501c57..e05eced 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants;
 import org.apache.james.mailbox.elasticsearch.utils.TestingClientProvider;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.client.Client;
+import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.node.Node;
 import org.junit.Before;
@@ -41,7 +42,7 @@ import com.google.common.collect.Lists;
 
 public class ElasticSearchIndexerTest {
 
-    public static final int MINIMUM_BATCH_SIZE = 1;
+    private static final int MINIMUM_BATCH_SIZE = 1;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder);
 
@@ -50,13 +51,18 @@ public class ElasticSearchIndexerTest {
 
     private Node node;
     private ElasticSearchIndexer testee;
-    private DeleteByQueryPerformer deleteByQueryPerformer;
 
     @Before
     public void setup() throws IOException {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
-        deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider, Executors.newSingleThreadExecutor(),
MINIMUM_BATCH_SIZE);
+        DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider,
Executors.newSingleThreadExecutor(), MINIMUM_BATCH_SIZE) {
+            @Override
+            public Void perform(QueryBuilder queryBuilder) {
+                doDeleteByQuery(queryBuilder);
+                return null;
+            }
+        };
         testee = new ElasticSearchIndexer(clientProvider, deleteByQueryPerformer);
     }
     


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