From b03d217acf5d15b98d98ef244fe9d44dba8ee8d9 Mon Sep 17 00:00:00 2001 From: Jens Wilke Date: Fri, 10 Jun 2016 11:53:33 +0200 Subject: [PATCH] CompletionListenerFuture enhanced tests, coordinate with thread start to trigger problems more reliable, tracked by https://github.com/jsr107/jsr107spec/issues/320 --- .../integration/CompletionListenerFutureTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cache-tests/src/test/java/javax/cache/integration/CompletionListenerFutureTest.java b/cache-tests/src/test/java/javax/cache/integration/CompletionListenerFutureTest.java index e59a86f..b88ebbf 100644 --- a/cache-tests/src/test/java/javax/cache/integration/CompletionListenerFutureTest.java +++ b/cache-tests/src/test/java/javax/cache/integration/CompletionListenerFutureTest.java @@ -11,6 +11,7 @@ import org.junit.Test; import java.lang.UnsupportedOperationException; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -118,15 +119,19 @@ public void testIsDone() { @Test public void testWakeup() throws InterruptedException { /* Currently test only with 1 thread to be compatible with 1.0. Can be incremented later. */ - final int THREAD_COUNT = 1; + final int THREAD_COUNT = 2; final long TIMEOUT_MILLIS = 1 * 60 * 1000; final CompletionListenerFuture future = new CompletionListenerFuture(); + /* Waits until threads are running. */ + final CountDownLatch countDown = new CountDownLatch(THREAD_COUNT + 1); Thread[] threads = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { Thread t = threads[i] = new Thread() { @Override public void run() { try { + countDown.countDown(); + countDown.await(); future.get(); } catch (Exception e) { e.printStackTrace(); @@ -135,6 +140,9 @@ public void run() { }; t.start(); } + countDown.countDown(); + countDown.await(); + Thread.sleep(42); future.onCompletion(); for (int i = 0; i < THREAD_COUNT; i++) { Thread t = threads[i];