1168 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1169 |
|
*/ |
1170 |
|
public void testTimedInvokeAll6() throws Exception { |
1171 |
< |
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1172 |
< |
try (PoolCleaner cleaner = cleaner(e)) { |
1173 |
< |
for (long timeout = timeoutMillis();;) { |
1171 |
> |
for (long timeout = timeoutMillis();;) { |
1172 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1173 |
> |
final Callable<String> waiter = new CheckedCallable<String>() { |
1174 |
> |
public String realCall() { |
1175 |
> |
try { done.await(LONG_DELAY_MS, MILLISECONDS); } |
1176 |
> |
catch (InterruptedException ok) {} |
1177 |
> |
return "1"; }}; |
1178 |
> |
final ExecutorService p = new ScheduledThreadPoolExecutor(2); |
1179 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1180 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
1181 |
|
tasks.add(new StringTask("0")); |
1182 |
< |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1182 |
> |
tasks.add(waiter); |
1183 |
|
tasks.add(new StringTask("2")); |
1184 |
|
long startTime = System.nanoTime(); |
1185 |
|
List<Future<String>> futures = |
1186 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1186 |
> |
p.invokeAll(tasks, timeout, MILLISECONDS); |
1187 |
|
assertEquals(tasks.size(), futures.size()); |
1188 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1189 |
|
for (Future future : futures) |