192 |
|
public void testInterruptedSubmit() throws InterruptedException { |
193 |
|
final CountDownLatch submitted = new CountDownLatch(1); |
194 |
|
final CountDownLatch quittingTime = new CountDownLatch(1); |
195 |
– |
final ExecutorService p |
196 |
– |
= new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, |
197 |
– |
new ArrayBlockingQueue<Runnable>(10)); |
195 |
|
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
196 |
|
public Void realCall() throws InterruptedException { |
197 |
|
quittingTime.await(); |
198 |
|
return null; |
199 |
|
}}; |
200 |
< |
try { |
200 |
> |
final ExecutorService p |
201 |
> |
= new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, |
202 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
203 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
204 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
205 |
|
public void realRun() throws Exception { |
206 |
|
Future<Void> future = p.submit(awaiter); |
211 |
|
submitted.await(); |
212 |
|
t.interrupt(); |
213 |
|
t.join(); |
214 |
– |
} finally { |
214 |
|
quittingTime.countDown(); |
216 |
– |
joinPool(p); |
215 |
|
} |
216 |
|
} |
217 |
|
|
220 |
|
* throws exception |
221 |
|
*/ |
222 |
|
public void testSubmitEE() throws InterruptedException { |
223 |
< |
ThreadPoolExecutor p = |
223 |
> |
final ThreadPoolExecutor p = |
224 |
|
new ThreadPoolExecutor(1, 1, |
225 |
|
60, TimeUnit.SECONDS, |
226 |
|
new ArrayBlockingQueue<Runnable>(10)); |
227 |
< |
|
228 |
< |
Callable c = new Callable() { |
229 |
< |
public Object call() { throw new ArithmeticException(); }}; |
230 |
< |
|
231 |
< |
try { |
232 |
< |
p.submit(c).get(); |
233 |
< |
shouldThrow(); |
234 |
< |
} catch (ExecutionException success) { |
235 |
< |
assertTrue(success.getCause() instanceof ArithmeticException); |
227 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
228 |
> |
Callable c = new Callable() { |
229 |
> |
public Object call() { throw new ArithmeticException(); }}; |
230 |
> |
try { |
231 |
> |
p.submit(c).get(); |
232 |
> |
shouldThrow(); |
233 |
> |
} catch (ExecutionException success) { |
234 |
> |
assertTrue(success.getCause() instanceof ArithmeticException); |
235 |
> |
} |
236 |
|
} |
239 |
– |
joinPool(p); |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
|
* invokeAny(null) throws NPE |
241 |
|
*/ |
242 |
|
public void testInvokeAny1() throws Exception { |
243 |
< |
ExecutorService e = new DirectExecutorService(); |
244 |
< |
try { |
245 |
< |
e.invokeAny(null); |
246 |
< |
shouldThrow(); |
247 |
< |
} catch (NullPointerException success) { |
248 |
< |
} finally { |
252 |
< |
joinPool(e); |
243 |
> |
final ExecutorService e = new DirectExecutorService(); |
244 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
245 |
> |
try { |
246 |
> |
e.invokeAny(null); |
247 |
> |
shouldThrow(); |
248 |
> |
} catch (NullPointerException success) {} |
249 |
|
} |
250 |
|
} |
251 |
|
|
253 |
|
* invokeAny(empty collection) throws IAE |
254 |
|
*/ |
255 |
|
public void testInvokeAny2() throws Exception { |
256 |
< |
ExecutorService e = new DirectExecutorService(); |
257 |
< |
try { |
258 |
< |
e.invokeAny(new ArrayList<Callable<String>>()); |
259 |
< |
shouldThrow(); |
260 |
< |
} catch (IllegalArgumentException success) { |
261 |
< |
} finally { |
266 |
< |
joinPool(e); |
256 |
> |
final ExecutorService e = new DirectExecutorService(); |
257 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
258 |
> |
try { |
259 |
> |
e.invokeAny(new ArrayList<Callable<String>>()); |
260 |
> |
shouldThrow(); |
261 |
> |
} catch (IllegalArgumentException success) {} |
262 |
|
} |
263 |
|
} |
264 |
|
|
266 |
|
* invokeAny(c) throws NPE if c has null elements |
267 |
|
*/ |
268 |
|
public void testInvokeAny3() throws Exception { |
269 |
< |
ExecutorService e = new DirectExecutorService(); |
270 |
< |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
271 |
< |
l.add(new Callable<Long>() { |
272 |
< |
public Long call() { throw new ArithmeticException(); }}); |
273 |
< |
l.add(null); |
274 |
< |
try { |
275 |
< |
e.invokeAny(l); |
276 |
< |
shouldThrow(); |
277 |
< |
} catch (NullPointerException success) { |
278 |
< |
} finally { |
284 |
< |
joinPool(e); |
269 |
> |
final ExecutorService e = new DirectExecutorService(); |
270 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
271 |
> |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
272 |
> |
l.add(new Callable<Long>() { |
273 |
> |
public Long call() { throw new ArithmeticException(); }}); |
274 |
> |
l.add(null); |
275 |
> |
try { |
276 |
> |
e.invokeAny(l); |
277 |
> |
shouldThrow(); |
278 |
> |
} catch (NullPointerException success) {} |
279 |
|
} |
280 |
|
} |
281 |
|
|
283 |
|
* invokeAny(c) throws ExecutionException if no task in c completes |
284 |
|
*/ |
285 |
|
public void testInvokeAny4() throws InterruptedException { |
286 |
< |
ExecutorService e = new DirectExecutorService(); |
287 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
288 |
< |
l.add(new NPETask()); |
289 |
< |
try { |
290 |
< |
e.invokeAny(l); |
291 |
< |
shouldThrow(); |
292 |
< |
} catch (ExecutionException success) { |
293 |
< |
assertTrue(success.getCause() instanceof NullPointerException); |
294 |
< |
} finally { |
295 |
< |
joinPool(e); |
286 |
> |
final ExecutorService e = new DirectExecutorService(); |
287 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
288 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
289 |
> |
l.add(new NPETask()); |
290 |
> |
try { |
291 |
> |
e.invokeAny(l); |
292 |
> |
shouldThrow(); |
293 |
> |
} catch (ExecutionException success) { |
294 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
295 |
> |
} |
296 |
|
} |
297 |
|
} |
298 |
|
|
300 |
|
* invokeAny(c) returns result of some task in c if at least one completes |
301 |
|
*/ |
302 |
|
public void testInvokeAny5() throws Exception { |
303 |
< |
ExecutorService e = new DirectExecutorService(); |
304 |
< |
try { |
303 |
> |
final ExecutorService e = new DirectExecutorService(); |
304 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
305 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
306 |
|
l.add(new StringTask()); |
307 |
|
l.add(new StringTask()); |
308 |
|
String result = e.invokeAny(l); |
309 |
|
assertSame(TEST_STRING, result); |
316 |
– |
} finally { |
317 |
– |
joinPool(e); |
310 |
|
} |
311 |
|
} |
312 |
|
|
314 |
|
* invokeAll(null) throws NPE |
315 |
|
*/ |
316 |
|
public void testInvokeAll1() throws InterruptedException { |
317 |
< |
ExecutorService e = new DirectExecutorService(); |
318 |
< |
try { |
319 |
< |
e.invokeAll(null); |
320 |
< |
shouldThrow(); |
321 |
< |
} catch (NullPointerException success) { |
322 |
< |
} finally { |
331 |
< |
joinPool(e); |
317 |
> |
final ExecutorService e = new DirectExecutorService(); |
318 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
319 |
> |
try { |
320 |
> |
e.invokeAll(null); |
321 |
> |
shouldThrow(); |
322 |
> |
} catch (NullPointerException success) {} |
323 |
|
} |
324 |
|
} |
325 |
|
|
327 |
|
* invokeAll(empty collection) returns empty collection |
328 |
|
*/ |
329 |
|
public void testInvokeAll2() throws InterruptedException { |
330 |
< |
ExecutorService e = new DirectExecutorService(); |
331 |
< |
try { |
330 |
> |
final ExecutorService e = new DirectExecutorService(); |
331 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
332 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
333 |
|
assertTrue(r.isEmpty()); |
343 |
– |
} finally { |
344 |
– |
joinPool(e); |
334 |
|
} |
335 |
|
} |
336 |
|
|
338 |
|
* invokeAll(c) throws NPE if c has null elements |
339 |
|
*/ |
340 |
|
public void testInvokeAll3() throws InterruptedException { |
341 |
< |
ExecutorService e = new DirectExecutorService(); |
342 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
343 |
< |
l.add(new StringTask()); |
344 |
< |
l.add(null); |
345 |
< |
try { |
346 |
< |
e.invokeAll(l); |
347 |
< |
shouldThrow(); |
348 |
< |
} catch (NullPointerException success) { |
349 |
< |
} finally { |
361 |
< |
joinPool(e); |
341 |
> |
final ExecutorService e = new DirectExecutorService(); |
342 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
343 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
344 |
> |
l.add(new StringTask()); |
345 |
> |
l.add(null); |
346 |
> |
try { |
347 |
> |
e.invokeAll(l); |
348 |
> |
shouldThrow(); |
349 |
> |
} catch (NullPointerException success) {} |
350 |
|
} |
351 |
|
} |
352 |
|
|
354 |
|
* get of returned element of invokeAll(c) throws exception on failed task |
355 |
|
*/ |
356 |
|
public void testInvokeAll4() throws Exception { |
357 |
< |
ExecutorService e = new DirectExecutorService(); |
358 |
< |
try { |
357 |
> |
final ExecutorService e = new DirectExecutorService(); |
358 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
359 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
360 |
|
l.add(new NPETask()); |
361 |
|
List<Future<String>> futures = e.invokeAll(l); |
366 |
|
} catch (ExecutionException success) { |
367 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
368 |
|
} |
381 |
– |
} finally { |
382 |
– |
joinPool(e); |
369 |
|
} |
370 |
|
} |
371 |
|
|
373 |
|
* invokeAll(c) returns results of all completed tasks in c |
374 |
|
*/ |
375 |
|
public void testInvokeAll5() throws Exception { |
376 |
< |
ExecutorService e = new DirectExecutorService(); |
377 |
< |
try { |
376 |
> |
final ExecutorService e = new DirectExecutorService(); |
377 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
378 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
379 |
|
l.add(new StringTask()); |
380 |
|
l.add(new StringTask()); |
382 |
|
assertEquals(2, futures.size()); |
383 |
|
for (Future<String> future : futures) |
384 |
|
assertSame(TEST_STRING, future.get()); |
399 |
– |
} finally { |
400 |
– |
joinPool(e); |
385 |
|
} |
386 |
|
} |
387 |
|
|
389 |
|
* timed invokeAny(null) throws NPE |
390 |
|
*/ |
391 |
|
public void testTimedInvokeAny1() throws Exception { |
392 |
< |
ExecutorService e = new DirectExecutorService(); |
393 |
< |
try { |
394 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
395 |
< |
shouldThrow(); |
396 |
< |
} catch (NullPointerException success) { |
397 |
< |
} finally { |
414 |
< |
joinPool(e); |
392 |
> |
final ExecutorService e = new DirectExecutorService(); |
393 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
394 |
> |
try { |
395 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
396 |
> |
shouldThrow(); |
397 |
> |
} catch (NullPointerException success) {} |
398 |
|
} |
399 |
|
} |
400 |
|
|
402 |
|
* timed invokeAny(null time unit) throws NPE |
403 |
|
*/ |
404 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
405 |
< |
ExecutorService e = new DirectExecutorService(); |
406 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
407 |
< |
l.add(new StringTask()); |
408 |
< |
try { |
409 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
410 |
< |
shouldThrow(); |
411 |
< |
} catch (NullPointerException success) { |
412 |
< |
} finally { |
430 |
< |
joinPool(e); |
405 |
> |
final ExecutorService e = new DirectExecutorService(); |
406 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
407 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
408 |
> |
l.add(new StringTask()); |
409 |
> |
try { |
410 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
411 |
> |
shouldThrow(); |
412 |
> |
} catch (NullPointerException success) {} |
413 |
|
} |
414 |
|
} |
415 |
|
|
417 |
|
* timed invokeAny(empty collection) throws IAE |
418 |
|
*/ |
419 |
|
public void testTimedInvokeAny2() throws Exception { |
420 |
< |
ExecutorService e = new DirectExecutorService(); |
421 |
< |
try { |
422 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
423 |
< |
shouldThrow(); |
424 |
< |
} catch (IllegalArgumentException success) { |
425 |
< |
} finally { |
426 |
< |
joinPool(e); |
420 |
> |
final ExecutorService e = new DirectExecutorService(); |
421 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
422 |
> |
try { |
423 |
> |
e.invokeAny(new ArrayList<Callable<String>>(), |
424 |
> |
MEDIUM_DELAY_MS, MILLISECONDS); |
425 |
> |
shouldThrow(); |
426 |
> |
} catch (IllegalArgumentException success) {} |
427 |
|
} |
428 |
|
} |
429 |
|
|
431 |
|
* timed invokeAny(c) throws NPE if c has null elements |
432 |
|
*/ |
433 |
|
public void testTimedInvokeAny3() throws Exception { |
434 |
< |
ExecutorService e = new DirectExecutorService(); |
435 |
< |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
436 |
< |
l.add(new Callable<Long>() { |
437 |
< |
public Long call() { throw new ArithmeticException(); }}); |
438 |
< |
l.add(null); |
439 |
< |
try { |
440 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
441 |
< |
shouldThrow(); |
442 |
< |
} catch (NullPointerException success) { |
443 |
< |
} finally { |
462 |
< |
joinPool(e); |
434 |
> |
final ExecutorService e = new DirectExecutorService(); |
435 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
436 |
> |
List<Callable<Long>> l = new ArrayList<Callable<Long>>(); |
437 |
> |
l.add(new Callable<Long>() { |
438 |
> |
public Long call() { throw new ArithmeticException(); }}); |
439 |
> |
l.add(null); |
440 |
> |
try { |
441 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
442 |
> |
shouldThrow(); |
443 |
> |
} catch (NullPointerException success) {} |
444 |
|
} |
445 |
|
} |
446 |
|
|
448 |
|
* timed invokeAny(c) throws ExecutionException if no task completes |
449 |
|
*/ |
450 |
|
public void testTimedInvokeAny4() throws Exception { |
451 |
< |
ExecutorService e = new DirectExecutorService(); |
452 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
453 |
< |
l.add(new NPETask()); |
454 |
< |
try { |
455 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
456 |
< |
shouldThrow(); |
457 |
< |
} catch (ExecutionException success) { |
458 |
< |
assertTrue(success.getCause() instanceof NullPointerException); |
459 |
< |
} finally { |
460 |
< |
joinPool(e); |
451 |
> |
final ExecutorService e = new DirectExecutorService(); |
452 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
453 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
454 |
> |
l.add(new NPETask()); |
455 |
> |
try { |
456 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
457 |
> |
shouldThrow(); |
458 |
> |
} catch (ExecutionException success) { |
459 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
460 |
> |
} |
461 |
|
} |
462 |
|
} |
463 |
|
|
465 |
|
* timed invokeAny(c) returns result of some task in c |
466 |
|
*/ |
467 |
|
public void testTimedInvokeAny5() throws Exception { |
468 |
< |
ExecutorService e = new DirectExecutorService(); |
469 |
< |
try { |
468 |
> |
final ExecutorService e = new DirectExecutorService(); |
469 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
470 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
471 |
|
l.add(new StringTask()); |
472 |
|
l.add(new StringTask()); |
473 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
474 |
|
assertSame(TEST_STRING, result); |
494 |
– |
} finally { |
495 |
– |
joinPool(e); |
475 |
|
} |
476 |
|
} |
477 |
|
|
479 |
|
* timed invokeAll(null) throws NPE |
480 |
|
*/ |
481 |
|
public void testTimedInvokeAll1() throws InterruptedException { |
482 |
< |
ExecutorService e = new DirectExecutorService(); |
483 |
< |
try { |
484 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
485 |
< |
shouldThrow(); |
486 |
< |
} catch (NullPointerException success) { |
487 |
< |
} finally { |
509 |
< |
joinPool(e); |
482 |
> |
final ExecutorService e = new DirectExecutorService(); |
483 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
484 |
> |
try { |
485 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
486 |
> |
shouldThrow(); |
487 |
> |
} catch (NullPointerException success) {} |
488 |
|
} |
489 |
|
} |
490 |
|
|
492 |
|
* timed invokeAll(null time unit) throws NPE |
493 |
|
*/ |
494 |
|
public void testTimedInvokeAllNullTimeUnit() throws InterruptedException { |
495 |
< |
ExecutorService e = new DirectExecutorService(); |
496 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
497 |
< |
l.add(new StringTask()); |
498 |
< |
try { |
499 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
500 |
< |
shouldThrow(); |
501 |
< |
} catch (NullPointerException success) { |
502 |
< |
} finally { |
525 |
< |
joinPool(e); |
495 |
> |
final ExecutorService e = new DirectExecutorService(); |
496 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
497 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
498 |
> |
l.add(new StringTask()); |
499 |
> |
try { |
500 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
501 |
> |
shouldThrow(); |
502 |
> |
} catch (NullPointerException success) {} |
503 |
|
} |
504 |
|
} |
505 |
|
|
507 |
|
* timed invokeAll(empty collection) returns empty collection |
508 |
|
*/ |
509 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
510 |
< |
ExecutorService e = new DirectExecutorService(); |
511 |
< |
try { |
510 |
> |
final ExecutorService e = new DirectExecutorService(); |
511 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
512 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
513 |
|
assertTrue(r.isEmpty()); |
537 |
– |
} finally { |
538 |
– |
joinPool(e); |
514 |
|
} |
515 |
|
} |
516 |
|
|
518 |
|
* timed invokeAll(c) throws NPE if c has null elements |
519 |
|
*/ |
520 |
|
public void testTimedInvokeAll3() throws InterruptedException { |
521 |
< |
ExecutorService e = new DirectExecutorService(); |
522 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
523 |
< |
l.add(new StringTask()); |
524 |
< |
l.add(null); |
525 |
< |
try { |
526 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
527 |
< |
shouldThrow(); |
528 |
< |
} catch (NullPointerException success) { |
529 |
< |
} finally { |
555 |
< |
joinPool(e); |
521 |
> |
final ExecutorService e = new DirectExecutorService(); |
522 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
523 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
524 |
> |
l.add(new StringTask()); |
525 |
> |
l.add(null); |
526 |
> |
try { |
527 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
528 |
> |
shouldThrow(); |
529 |
> |
} catch (NullPointerException success) {} |
530 |
|
} |
531 |
|
} |
532 |
|
|
534 |
|
* get of returned element of invokeAll(c) throws exception on failed task |
535 |
|
*/ |
536 |
|
public void testTimedInvokeAll4() throws Exception { |
537 |
< |
ExecutorService e = new DirectExecutorService(); |
538 |
< |
try { |
537 |
> |
final ExecutorService e = new DirectExecutorService(); |
538 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
539 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
540 |
|
l.add(new NPETask()); |
541 |
|
List<Future<String>> futures = |
547 |
|
} catch (ExecutionException success) { |
548 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
549 |
|
} |
576 |
– |
} finally { |
577 |
– |
joinPool(e); |
550 |
|
} |
551 |
|
} |
552 |
|
|
554 |
|
* timed invokeAll(c) returns results of all completed tasks in c |
555 |
|
*/ |
556 |
|
public void testTimedInvokeAll5() throws Exception { |
557 |
< |
ExecutorService e = new DirectExecutorService(); |
558 |
< |
try { |
557 |
> |
final ExecutorService e = new DirectExecutorService(); |
558 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
559 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
560 |
|
l.add(new StringTask()); |
561 |
|
l.add(new StringTask()); |
564 |
|
assertEquals(2, futures.size()); |
565 |
|
for (Future<String> future : futures) |
566 |
|
assertSame(TEST_STRING, future.get()); |
595 |
– |
} finally { |
596 |
– |
joinPool(e); |
567 |
|
} |
568 |
|
} |
569 |
|
|
571 |
|
* timed invokeAll cancels tasks not completed by timeout |
572 |
|
*/ |
573 |
|
public void testTimedInvokeAll6() throws Exception { |
574 |
< |
ExecutorService e = new DirectExecutorService(); |
575 |
< |
try { |
574 |
> |
final ExecutorService e = new DirectExecutorService(); |
575 |
> |
try (PoolCleaner cleaner = cleaner(e)) { |
576 |
|
for (long timeout = timeoutMillis();;) { |
577 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
578 |
|
tasks.add(new StringTask("0")); |
599 |
|
assertTrue(futures.get(2).isCancelled()); |
600 |
|
break; |
601 |
|
} |
632 |
– |
} finally { |
633 |
– |
joinPool(e); |
602 |
|
} |
603 |
|
} |
604 |
|
|