345 |
|
* invokeAny(c) throws NPE if c has null elements |
346 |
|
*/ |
347 |
|
public void testInvokeAny3() throws Exception { |
348 |
– |
final CountDownLatch latch = new CountDownLatch(1); |
348 |
|
ExecutorService e = new DirectExecutorService(); |
349 |
+ |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
350 |
+ |
l.add(new Callable<Integer>() { |
351 |
+ |
public Integer call() { return 5/0; }}); |
352 |
+ |
l.add(null); |
353 |
|
try { |
351 |
– |
ArrayList<Callable<Integer>> l |
352 |
– |
= new ArrayList<Callable<Integer>>(); |
353 |
– |
l.add(new Callable<Integer>() { |
354 |
– |
public Integer call() { return 5/0; }}); |
355 |
– |
l.add(null); |
354 |
|
e.invokeAny(l); |
355 |
|
shouldThrow(); |
356 |
|
} catch (NullPointerException success) { |
357 |
|
} finally { |
360 |
– |
latch.countDown(); |
358 |
|
joinPool(e); |
359 |
|
} |
360 |
|
} |
364 |
|
*/ |
365 |
|
public void testInvokeAny4() throws InterruptedException { |
366 |
|
ExecutorService e = new DirectExecutorService(); |
367 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
368 |
+ |
l.add(new NPETask()); |
369 |
|
try { |
371 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
372 |
– |
l.add(new NPETask()); |
370 |
|
e.invokeAny(l); |
371 |
|
shouldThrow(); |
372 |
|
} catch (ExecutionException success) { |
382 |
|
public void testInvokeAny5() throws Exception { |
383 |
|
ExecutorService e = new DirectExecutorService(); |
384 |
|
try { |
385 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
385 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
386 |
|
l.add(new StringTask()); |
387 |
|
l.add(new StringTask()); |
388 |
|
String result = e.invokeAny(l); |
424 |
|
*/ |
425 |
|
public void testInvokeAll3() throws InterruptedException { |
426 |
|
ExecutorService e = new DirectExecutorService(); |
427 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
428 |
+ |
l.add(new StringTask()); |
429 |
+ |
l.add(null); |
430 |
|
try { |
431 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
432 |
– |
l.add(new StringTask()); |
433 |
– |
l.add(null); |
431 |
|
e.invokeAll(l); |
432 |
|
shouldThrow(); |
433 |
|
} catch (NullPointerException success) { |
442 |
|
public void testInvokeAll4() throws Exception { |
443 |
|
ExecutorService e = new DirectExecutorService(); |
444 |
|
try { |
445 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
445 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
446 |
|
l.add(new NPETask()); |
447 |
< |
List<Future<String>> result = e.invokeAll(l); |
448 |
< |
assertEquals(1, result.size()); |
449 |
< |
for (Future<String> future : result) { |
450 |
< |
try { |
451 |
< |
future.get(); |
452 |
< |
shouldThrow(); |
453 |
< |
} catch (ExecutionException success) { |
457 |
< |
Throwable cause = success.getCause(); |
458 |
< |
assertTrue(cause instanceof NullPointerException); |
459 |
< |
} |
447 |
> |
List<Future<String>> futures = e.invokeAll(l); |
448 |
> |
assertEquals(1, futures.size()); |
449 |
> |
try { |
450 |
> |
futures.get(0).get(); |
451 |
> |
shouldThrow(); |
452 |
> |
} catch (ExecutionException success) { |
453 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
454 |
|
} |
455 |
|
} finally { |
456 |
|
joinPool(e); |
463 |
|
public void testInvokeAll5() throws Exception { |
464 |
|
ExecutorService e = new DirectExecutorService(); |
465 |
|
try { |
466 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
466 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
467 |
|
l.add(new StringTask()); |
468 |
|
l.add(new StringTask()); |
469 |
< |
List<Future<String>> result = e.invokeAll(l); |
470 |
< |
assertEquals(2, result.size()); |
471 |
< |
for (Future<String> future : result) |
469 |
> |
List<Future<String>> futures = e.invokeAll(l); |
470 |
> |
assertEquals(2, futures.size()); |
471 |
> |
for (Future<String> future : futures) |
472 |
|
assertSame(TEST_STRING, future.get()); |
473 |
|
} finally { |
474 |
|
joinPool(e); |
495 |
|
*/ |
496 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
497 |
|
ExecutorService e = new DirectExecutorService(); |
498 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
499 |
+ |
l.add(new StringTask()); |
500 |
|
try { |
505 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
506 |
– |
l.add(new StringTask()); |
501 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
502 |
|
shouldThrow(); |
503 |
|
} catch (NullPointerException success) { |
524 |
|
* timed invokeAny(c) throws NPE if c has null elements |
525 |
|
*/ |
526 |
|
public void testTimedInvokeAny3() throws Exception { |
533 |
– |
final CountDownLatch latch = new CountDownLatch(1); |
527 |
|
ExecutorService e = new DirectExecutorService(); |
528 |
+ |
List<Callable<Integer>> l = new ArrayList<Callable<Integer>>(); |
529 |
+ |
l.add(new Callable<Integer>() { |
530 |
+ |
public Integer call() { return 5/0; }}); |
531 |
+ |
l.add(null); |
532 |
|
try { |
536 |
– |
ArrayList<Callable<Integer>> l |
537 |
– |
= new ArrayList<Callable<Integer>>(); |
538 |
– |
l.add(new Callable<Integer>() { |
539 |
– |
public Integer call() { return 5/0; }}); |
540 |
– |
l.add(null); |
533 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
534 |
|
shouldThrow(); |
535 |
|
} catch (NullPointerException success) { |
536 |
|
} finally { |
545 |
– |
latch.countDown(); |
537 |
|
joinPool(e); |
538 |
|
} |
539 |
|
} |
543 |
|
*/ |
544 |
|
public void testTimedInvokeAny4() throws Exception { |
545 |
|
ExecutorService e = new DirectExecutorService(); |
546 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
547 |
+ |
l.add(new NPETask()); |
548 |
|
try { |
556 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
557 |
– |
l.add(new NPETask()); |
549 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
550 |
|
shouldThrow(); |
551 |
|
} catch (ExecutionException success) { |
561 |
|
public void testTimedInvokeAny5() throws Exception { |
562 |
|
ExecutorService e = new DirectExecutorService(); |
563 |
|
try { |
564 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
564 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
565 |
|
l.add(new StringTask()); |
566 |
|
l.add(new StringTask()); |
567 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
590 |
|
*/ |
591 |
|
public void testTimedInvokeAllNullTimeUnit() throws InterruptedException { |
592 |
|
ExecutorService e = new DirectExecutorService(); |
593 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
594 |
+ |
l.add(new StringTask()); |
595 |
|
try { |
603 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
604 |
– |
l.add(new StringTask()); |
596 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
597 |
|
shouldThrow(); |
598 |
|
} catch (NullPointerException success) { |
619 |
|
*/ |
620 |
|
public void testTimedInvokeAll3() throws InterruptedException { |
621 |
|
ExecutorService e = new DirectExecutorService(); |
622 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
623 |
+ |
l.add(new StringTask()); |
624 |
+ |
l.add(null); |
625 |
|
try { |
632 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
633 |
– |
l.add(new StringTask()); |
634 |
– |
l.add(null); |
626 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
627 |
|
shouldThrow(); |
628 |
|
} catch (NullPointerException success) { |
637 |
|
public void testTimedInvokeAll4() throws Exception { |
638 |
|
ExecutorService e = new DirectExecutorService(); |
639 |
|
try { |
640 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
640 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
641 |
|
l.add(new NPETask()); |
642 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
643 |
< |
assertEquals(1, result.size()); |
644 |
< |
for (Future<String> future : result) { |
645 |
< |
try { |
646 |
< |
future.get(); |
647 |
< |
shouldThrow(); |
648 |
< |
} catch (ExecutionException success) { |
649 |
< |
assertTrue(success.getCause() instanceof NullPointerException); |
659 |
< |
} |
642 |
> |
List<Future<String>> futures = |
643 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
644 |
> |
assertEquals(1, futures.size()); |
645 |
> |
try { |
646 |
> |
futures.get(0).get(); |
647 |
> |
shouldThrow(); |
648 |
> |
} catch (ExecutionException success) { |
649 |
> |
assertTrue(success.getCause() instanceof NullPointerException); |
650 |
|
} |
651 |
|
} finally { |
652 |
|
joinPool(e); |
659 |
|
public void testTimedInvokeAll5() throws Exception { |
660 |
|
ExecutorService e = new DirectExecutorService(); |
661 |
|
try { |
662 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
662 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
663 |
|
l.add(new StringTask()); |
664 |
|
l.add(new StringTask()); |
665 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
666 |
< |
assertEquals(2, result.size()); |
667 |
< |
for (Future<String> future : result) |
665 |
> |
List<Future<String>> futures = |
666 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
667 |
> |
assertEquals(2, futures.size()); |
668 |
> |
for (Future<String> future : futures) |
669 |
|
assertSame(TEST_STRING, future.get()); |
670 |
|
} finally { |
671 |
|
joinPool(e); |
678 |
|
public void testTimedInvokeAll6() throws InterruptedException { |
679 |
|
ExecutorService e = new DirectExecutorService(); |
680 |
|
try { |
681 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
681 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
682 |
|
l.add(new StringTask()); |
683 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
684 |
|
l.add(new StringTask()); |
685 |
< |
List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS); |
686 |
< |
assertEquals(3, result.size()); |
687 |
< |
Iterator<Future<String>> it = result.iterator(); |
685 |
> |
List<Future<String>> futures = |
686 |
> |
e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS); |
687 |
> |
assertEquals(3, futures.size()); |
688 |
> |
Iterator<Future<String>> it = futures.iterator(); |
689 |
|
Future<String> f1 = it.next(); |
690 |
|
Future<String> f2 = it.next(); |
691 |
|
Future<String> f3 = it.next(); |