< prev index next >

test/jdk/java/util/concurrent/tck/ExecutorCompletionServiceTest.java

Print this page
8192944: Miscellaneous changes imported from jsr166 CVS 2017-12-08
Reviewed-by: martin, psandoz, chegar

*** 103,114 **** } /** * A taken submitted task is completed */ ! public void testTake() ! throws InterruptedException, ExecutionException { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); cs.submit(new StringTask()); Future f = cs.take(); assertTrue(f.isDone()); assertSame(TEST_STRING, f.get()); --- 103,113 ---- } /** * A taken submitted task is completed */ ! public void testTake() throws Exception { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); cs.submit(new StringTask()); Future f = cs.take(); assertTrue(f.isDone()); assertSame(TEST_STRING, f.get());
*** 125,136 **** } /** * poll returns non-null when the returned task is completed */ ! public void testPoll1() ! throws InterruptedException, ExecutionException { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); assertNull(cs.poll()); cs.submit(new StringTask()); long startTime = System.nanoTime(); --- 124,134 ---- } /** * poll returns non-null when the returned task is completed */ ! public void testPoll1() throws Exception { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); assertNull(cs.poll()); cs.submit(new StringTask()); long startTime = System.nanoTime();
*** 145,163 **** } /** * timed poll returns non-null when the returned task is completed */ ! public void testPoll2() ! throws InterruptedException, ExecutionException { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); assertNull(cs.poll()); cs.submit(new StringTask()); long startTime = System.nanoTime(); Future f; ! while ((f = cs.poll(SHORT_DELAY_MS, MILLISECONDS)) == null) { if (millisElapsedSince(startTime) > LONG_DELAY_MS) fail("timed out"); Thread.yield(); } assertTrue(f.isDone()); --- 143,161 ---- } /** * timed poll returns non-null when the returned task is completed */ ! public void testPoll2() throws Exception { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); assertNull(cs.poll()); cs.submit(new StringTask()); long startTime = System.nanoTime(); Future f; ! while ((f = cs.poll(timeoutMillis(), MILLISECONDS)) == null) { ! assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); if (millisElapsedSince(startTime) > LONG_DELAY_MS) fail("timed out"); Thread.yield(); } assertTrue(f.isDone());
*** 165,176 **** } /** * poll returns null before the returned task is completed */ ! public void testPollReturnsNull() ! throws InterruptedException, ExecutionException { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); final CountDownLatch proceed = new CountDownLatch(1); cs.submit(new Callable() { public String call() throws Exception { await(proceed); return TEST_STRING; --- 163,173 ---- } /** * poll returns null before the returned task is completed */ ! public void testPollReturnsNullBeforeCompletion() throws Exception { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); final CountDownLatch proceed = new CountDownLatch(1); cs.submit(new Callable() { public String call() throws Exception { await(proceed); return TEST_STRING;
*** 186,218 **** } /** * successful and failed tasks are both returned */ ! public void testTaskAssortment() ! throws InterruptedException, ExecutionException { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); ArithmeticException ex = new ArithmeticException(); ! for (int i = 0; i < 2; i++) { cs.submit(new StringTask()); cs.submit(callableThrowing(ex)); cs.submit(runnableThrowing(ex), null); } int normalCompletions = 0; int exceptionalCompletions = 0; ! for (int i = 0; i < 3 * 2; i++) { try { ! if (cs.take().get() == TEST_STRING) normalCompletions++; ! } ! catch (ExecutionException expected) { ! assertTrue(expected.getCause() instanceof ArithmeticException); exceptionalCompletions++; } } ! assertEquals(2 * 1, normalCompletions); ! assertEquals(2 * 2, exceptionalCompletions); assertNull(cs.poll()); } /** * Submitting to underlying AES that overrides newTaskFor(Callable) --- 183,214 ---- } /** * successful and failed tasks are both returned */ ! public void testTaskAssortment() throws Exception { CompletionService cs = new ExecutorCompletionService(cachedThreadPool); ArithmeticException ex = new ArithmeticException(); ! final int rounds = 2; ! for (int i = rounds; i--> 0; ) { cs.submit(new StringTask()); cs.submit(callableThrowing(ex)); cs.submit(runnableThrowing(ex), null); } int normalCompletions = 0; int exceptionalCompletions = 0; ! for (int i = 3 * rounds; i--> 0; ) { try { ! assertSame(TEST_STRING, cs.take().get()); normalCompletions++; ! } catch (ExecutionException expected) { ! assertSame(ex, expected.getCause()); exceptionalCompletions++; } } ! assertEquals(1 * rounds, normalCompletions); ! assertEquals(2 * rounds, exceptionalCompletions); assertNull(cs.poll()); } /** * Submitting to underlying AES that overrides newTaskFor(Callable)
< prev index next >