You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/01/06 03:02:50 UTC

[james-project] 11/12: JAMES-3771 Fix thread leak issue within DeleteAllIndexDocumentsCleanupStrategy

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 250a79dcf0aef85badda0dfb5f9bc76f2c07a516
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Jan 3 17:33:15 2023 +0700

    JAMES-3771 Fix thread leak issue within DeleteAllIndexDocumentsCleanupStrategy
---
 .../opensearch/DockerOpenSearchExtension.java         | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/backends-common/opensearch/src/test/java/org/apache/james/backends/opensearch/DockerOpenSearchExtension.java b/backends-common/opensearch/src/test/java/org/apache/james/backends/opensearch/DockerOpenSearchExtension.java
index aee8790003..0f27bdd978 100644
--- a/backends-common/opensearch/src/test/java/org/apache/james/backends/opensearch/DockerOpenSearchExtension.java
+++ b/backends-common/opensearch/src/test/java/org/apache/james/backends/opensearch/DockerOpenSearchExtension.java
@@ -47,6 +47,7 @@ public class DockerOpenSearchExtension implements AfterEachCallback, BeforeEachC
 
     public static class DeleteAllIndexDocumentsCleanupStrategy implements CleanupStrategy {
         private final WriteAliasName aliasName;
+        private ReactorOpenSearchClient client;
 
         public DeleteAllIndexDocumentsCleanupStrategy(WriteAliasName aliasName) {
             this.aliasName = aliasName;
@@ -58,7 +59,7 @@ public class DockerOpenSearchExtension implements AfterEachCallback, BeforeEachC
                 .ignoreExceptions()
                 .until(() -> {
                     openSearch.flushIndices();
-                    ReactorOpenSearchClient client = openSearch.clientProvider().get();
+                    ReactorOpenSearchClient client = client(openSearch);
                     new DeleteByQueryPerformer(client, aliasName)
                         .perform(new MatchAllQuery.Builder().build()._toQuery())
                         .block();
@@ -66,18 +67,18 @@ public class DockerOpenSearchExtension implements AfterEachCallback, BeforeEachC
                         .query(new MatchAllQuery.Builder().build()._toQuery())
                         .build();
                     openSearch.flushIndices();
-                    boolean result = client.search(searchRequest)
+                    return client.search(searchRequest)
                         .map(searchResponse -> searchResponse.hits().hits().size())
                         .block() == 0;
-
-                    try {
-                        client.close();
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
-                    }
-                    return result;
                 });
         }
+
+        private ReactorOpenSearchClient client(DockerOpenSearch openSearch) {
+            if (client == null) {
+                client = openSearch.clientProvider().get();
+            }
+            return client;
+        }
     }
 
     private final DockerOpenSearch openSearch = DockerOpenSearchSingleton.INSTANCE;


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