603 |
|
public void testTimedInvokeAll6() throws Exception { |
604 |
|
ExecutorService e = new DirectExecutorService(); |
605 |
|
try { |
606 |
< |
long timeout = timeoutMillis(); |
607 |
< |
List<Callable<String>> tasks = new ArrayList<>(); |
608 |
< |
tasks.add(new StringTask("0")); |
609 |
< |
tasks.add(Executors.callable(possiblyInterruptedRunnable(timeout), |
610 |
< |
TEST_STRING)); |
611 |
< |
tasks.add(new StringTask("2")); |
612 |
< |
long startTime = System.nanoTime(); |
613 |
< |
List<Future<String>> futures = |
614 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
615 |
< |
assertEquals(tasks.size(), futures.size()); |
616 |
< |
assertTrue(millisElapsedSince(startTime) >= timeout); |
617 |
< |
for (Future future : futures) |
618 |
< |
assertTrue(future.isDone()); |
619 |
< |
assertEquals("0", futures.get(0).get()); |
620 |
< |
assertEquals(TEST_STRING, futures.get(1).get()); |
621 |
< |
assertTrue(futures.get(2).isCancelled()); |
606 |
> |
for (long timeout = timeoutMillis();;) { |
607 |
> |
List<Callable<String>> tasks = new ArrayList<>(); |
608 |
> |
tasks.add(new StringTask("0")); |
609 |
> |
tasks.add(Executors.callable(possiblyInterruptedRunnable(timeout), |
610 |
> |
TEST_STRING)); |
611 |
> |
tasks.add(new StringTask("2")); |
612 |
> |
long startTime = System.nanoTime(); |
613 |
> |
List<Future<String>> futures = |
614 |
> |
e.invokeAll(tasks, timeout, MILLISECONDS); |
615 |
> |
assertEquals(tasks.size(), futures.size()); |
616 |
> |
assertTrue(millisElapsedSince(startTime) >= timeout); |
617 |
> |
for (Future future : futures) |
618 |
> |
assertTrue(future.isDone()); |
619 |
> |
try { |
620 |
> |
assertEquals("0", futures.get(0).get()); |
621 |
> |
assertEquals(TEST_STRING, futures.get(1).get()); |
622 |
> |
} catch (CancellationException retryWithLongerTimeout) { |
623 |
> |
// unusual delay before starting second task |
624 |
> |
timeout *= 2; |
625 |
> |
if (timeout >= LONG_DELAY_MS / 2) |
626 |
> |
fail("expected exactly one task to be cancelled"); |
627 |
> |
continue; |
628 |
> |
} |
629 |
> |
assertTrue(futures.get(2).isCancelled()); |
630 |
> |
break; |
631 |
> |
} |
632 |
|
} finally { |
633 |
|
joinPool(e); |
634 |
|
} |