ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AbstractExecutorServiceTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.19 by jsr166, Fri Nov 20 05:25:10 2009 UTC vs.
Revision 1.22 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 10 | Line 10
10   import junit.framework.*;
11   import java.util.*;
12   import java.util.concurrent.*;
13 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
14   import java.math.BigInteger;
15   import java.security.*;
16  
# Line 344 | Line 345 | public class AbstractExecutorServiceTest
345       * invokeAny(c) throws NPE if c has null elements
346       */
347      public void testInvokeAny3() throws Exception {
347        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 {
350            ArrayList<Callable<Integer>> l
351                = new ArrayList<Callable<Integer>>();
352            l.add(new Callable<Integer>() {
353                      public Integer call() { return 5/0; }});
354            l.add(null);
354              e.invokeAny(l);
355              shouldThrow();
356          } catch (NullPointerException success) {
357          } finally {
359            latch.countDown();
358              joinPool(e);
359          }
360      }
# Line 366 | Line 364 | public class AbstractExecutorServiceTest
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 {
370            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
371            l.add(new NPETask());
370              e.invokeAny(l);
371              shouldThrow();
372          } catch (ExecutionException success) {
# Line 384 | Line 382 | public class AbstractExecutorServiceTest
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);
# Line 426 | Line 424 | public class AbstractExecutorServiceTest
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 {
430            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
431            l.add(new StringTask());
432            l.add(null);
431              e.invokeAll(l);
432              shouldThrow();
433          } catch (NullPointerException success) {
# Line 444 | Line 442 | public class AbstractExecutorServiceTest
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) {
456 <                    Throwable cause = success.getCause();
457 <                    assertTrue(cause instanceof NullPointerException);
458 <                }
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);
# Line 468 | Line 463 | public class AbstractExecutorServiceTest
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);
# Line 487 | Line 482 | public class AbstractExecutorServiceTest
482      public void testTimedInvokeAny1() throws Exception {
483          ExecutorService e = new DirectExecutorService();
484          try {
485 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
485 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
486              shouldThrow();
487          } catch (NullPointerException success) {
488          } finally {
# Line 500 | Line 495 | public class AbstractExecutorServiceTest
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 {
504            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
505            l.add(new StringTask());
501              e.invokeAny(l, MEDIUM_DELAY_MS, null);
502              shouldThrow();
503          } catch (NullPointerException success) {
# Line 517 | Line 512 | public class AbstractExecutorServiceTest
512      public void testTimedInvokeAny2() throws Exception {
513          ExecutorService e = new DirectExecutorService();
514          try {
515 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
515 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
516              shouldThrow();
517          } catch (IllegalArgumentException success) {
518          } finally {
# Line 529 | Line 524 | public class AbstractExecutorServiceTest
524       * timed invokeAny(c) throws NPE if c has null elements
525       */
526      public void testTimedInvokeAny3() throws Exception {
532        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 {
533 <            ArrayList<Callable<Integer>> l
536 <                = new ArrayList<Callable<Integer>>();
537 <            l.add(new Callable<Integer>() {
538 <                      public Integer call() { return 5/0; }});
539 <            l.add(null);
540 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
533 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
534              shouldThrow();
535          } catch (NullPointerException success) {
536          } finally {
544            latch.countDown();
537              joinPool(e);
538          }
539      }
# Line 551 | Line 543 | public class AbstractExecutorServiceTest
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 {
549 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
556 <            l.add(new NPETask());
557 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
549 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
550              shouldThrow();
551          } catch (ExecutionException success) {
552              assertTrue(success.getCause() instanceof NullPointerException);
# Line 569 | Line 561 | public class AbstractExecutorServiceTest
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, TimeUnit.MILLISECONDS);
567 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
568              assertSame(TEST_STRING, result);
569          } finally {
570              joinPool(e);
# Line 585 | Line 577 | public class AbstractExecutorServiceTest
577      public void testTimedInvokeAll1() throws InterruptedException {
578          ExecutorService e = new DirectExecutorService();
579          try {
580 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
580 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
581              shouldThrow();
582          } catch (NullPointerException success) {
583          } finally {
# Line 598 | Line 590 | public class AbstractExecutorServiceTest
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 {
602            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
603            l.add(new StringTask());
596              e.invokeAll(l, MEDIUM_DELAY_MS, null);
597              shouldThrow();
598          } catch (NullPointerException success) {
# Line 615 | Line 607 | public class AbstractExecutorServiceTest
607      public void testTimedInvokeAll2() throws InterruptedException {
608          ExecutorService e = new DirectExecutorService();
609          try {
610 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
610 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
611              assertTrue(r.isEmpty());
612          } finally {
613              joinPool(e);
# Line 627 | Line 619 | public class AbstractExecutorServiceTest
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 {
626 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
632 <            l.add(new StringTask());
633 <            l.add(null);
634 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
626 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
627              shouldThrow();
628          } catch (NullPointerException success) {
629          } finally {
# Line 645 | Line 637 | public class AbstractExecutorServiceTest
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, TimeUnit.MILLISECONDS);
643 <            assertEquals(1, result.size());
644 <            for (Future<String> future : result) {
645 <                try {
646 <                    future.get();
647 <                } catch (ExecutionException success) {
648 <                    assertTrue(success.getCause() instanceof NullPointerException);
649 <                }
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);
# Line 667 | Line 659 | public class AbstractExecutorServiceTest
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, TimeUnit.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);
# Line 685 | Line 678 | public class AbstractExecutorServiceTest
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, TimeUnit.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();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines