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 ro...@apache.org on 2019/06/17 13:02:27 UTC

[james-project] 03/05: JAMES-2788 release threads in TaskRoutesTest

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

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

commit 44557665bc3d754bb5b805557e4774cb9575c44f
Author: RĂ©mi Kowalski <rk...@linagora.com>
AuthorDate: Tue Jun 11 15:53:38 2019 +0200

    JAMES-2788 release threads in TaskRoutesTest
---
 .../james/webadmin/routes/TasksRoutesTest.java     | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
index 1a693dc..cb1becf 100644
--- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java
@@ -49,6 +49,7 @@ class TasksRoutesTest {
 
     private MemoryTaskManager taskManager;
     private WebAdminServer webAdminServer;
+    private CountDownLatch waitingForResultLatch;
 
     @BeforeEach
     void setUp() {
@@ -60,10 +61,13 @@ class TasksRoutesTest {
         RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer)
             .setBasePath(TasksRoutes.BASE)
             .build();
+
+        waitingForResultLatch = new CountDownLatch(1);
     }
 
     @AfterEach
     void tearDown() {
+        waitingForResultLatch.countDown();
         taskManager.stop();
         webAdminServer.destroy();
     }
@@ -81,7 +85,7 @@ class TasksRoutesTest {
         CountDownLatch taskInProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             taskInProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -97,20 +101,24 @@ class TasksRoutesTest {
             .body("[0].class", is(not(empty())));
     }
 
-    private void await() {
+    private void await(CountDownLatch latch) {
         try {
-            new CountDownLatch(1).await();
+            latch.await();
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
     }
 
+    private void waitForResult() {
+        await(waitingForResultLatch);
+    }
+
     @Test
     void listShouldListTaskWhenStatusFilter() throws Exception {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -133,7 +141,7 @@ class TasksRoutesTest {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -153,7 +161,7 @@ class TasksRoutesTest {
         CountDownLatch inProgressLatch = new CountDownLatch(1);
         TaskId taskId = taskManager.submit(() -> {
             inProgressLatch.countDown();
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 
@@ -218,7 +226,7 @@ class TasksRoutesTest {
     @Test
     void deleteShouldReturnOk() {
         TaskId taskId = taskManager.submit(() -> {
-            await();
+            waitForResult();
             return Task.Result.COMPLETED;
         });
 


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