You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2018/12/26 14:02:34 UTC
[10/13] tomee git commit: use countdownlatch
use countdownlatch
Signed-off-by: brunobat <br...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/1d99d91b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/1d99d91b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/1d99d91b
Branch: refs/heads/master
Commit: 1d99d91bf9711396cca3c80c01331a2296c53683
Parents: cc2cd4c
Author: brunobat <br...@gmail.com>
Authored: Mon Dec 24 16:09:04 2018 +0000
Committer: brunobat <br...@gmail.com>
Committed: Mon Dec 24 16:09:04 2018 +0000
----------------------------------------------------------------------
.../executor/ThreadFactoryServiceTest.java | 32 +++++++++++++++++---
1 file changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/1d99d91b/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java
----------------------------------------------------------------------
diff --git a/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java b/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java
index 7ab2d15..efe2771 100644
--- a/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java
+++ b/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java
@@ -7,11 +7,15 @@ import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.superbiz.executor.ThreadFactoryService.LongTask;
import javax.inject.Inject;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
@@ -33,6 +37,8 @@ import static org.junit.Assert.assertEquals;
@RunWith(Arquillian.class)
public class ThreadFactoryServiceTest {
+ private static final Logger LOGGER = Logger.getLogger(ThreadFactoryServiceTest.class.getSimpleName());
+
@Inject
private ThreadFactoryService factoryService;
@@ -43,16 +49,32 @@ public class ThreadFactoryServiceTest {
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
- //TODO failing to load due to missing DeployerBusinessRemote
@Test
public void asyncTask() throws InterruptedException {
- //task was completed
- assertEquals(2, factoryService.asyncTask(1));
+ final CountDownLatch countDownLatch = new CountDownLatch(1);
+ final LongTask longTask = new LongTask(1, 50, countDownLatch);
+ factoryService.asyncTask(longTask);
+
+ countDownLatch.await(200, TimeUnit.MILLISECONDS); // With the countdown latch we don't block unnecessarily.
+ LOGGER.info("task was completed");
+
+ assertEquals(2, longTask.getResult());
}
@Test
public void asyncHangingTask() throws InterruptedException {
- // task was interrupted and operation was not completed.
- assertEquals(1, factoryService.asyncHangingTask(1));
+ final CountDownLatch countDownLatch = new CountDownLatch(1);
+ final LongTask longTask = new LongTask(1, 1000000, countDownLatch);
+
+ try {
+ factoryService.asyncHangingTask(longTask);
+ } catch (RuntimeException e) {
+ //
+ }
+ countDownLatch.await(200, TimeUnit.MILLISECONDS);
+ LOGGER.info("task was interrupted and operation was not completed.");
+
+// assertTrue(longTask.getIsTerminated());
+ assertEquals(1, longTask.getResult());
}
}
\ No newline at end of file