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

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.15 by jsr166, Tue Dec 1 09:54:17 2009 UTC vs.
Revision 1.16 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 702 | Line 702 | public class ForkJoinPoolTest extends JS
702       */
703      public void testInvokeAny3() throws Throwable {
704          ExecutorService e = new ForkJoinPool(1);
705 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
706 +        l.add(null);
707          try {
706            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
707            l.add(null);
708              e.invokeAny(l);
709              shouldThrow();
710          } catch (NullPointerException success) {
# Line 717 | Line 717 | public class ForkJoinPoolTest extends JS
717       * invokeAny(c) throws NullPointerException if c has null elements
718       */
719      public void testInvokeAny4() throws Throwable {
720 +        CountDownLatch latch = new CountDownLatch(1);
721          ExecutorService e = new ForkJoinPool(1);
722 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
723 +        l.add(latchAwaitingStringTask(latch));
724 +        l.add(null);
725          try {
722            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
723            l.add(new Callable<String>() {
724                public String call() {
725                    // The delay gives the pool a chance to notice
726                    // the null element.
727                    sleepTillInterrupted(SMALL_DELAY_MS);
728                    return "foo";
729                }});
730            l.add(null);
726              e.invokeAny(l);
727              shouldThrow();
728          } catch (NullPointerException success) {
729          } finally {
730 +            latch.countDown();
731              joinPool(e);
732          }
733      }
# Line 741 | Line 737 | public class ForkJoinPoolTest extends JS
737       */
738      public void testInvokeAny5() throws Throwable {
739          ExecutorService e = new ForkJoinPool(1);
740 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
741 +        l.add(new NPETask());
742          try {
745            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
746            l.add(new NPETask());
743              e.invokeAny(l);
744              shouldThrow();
745          } catch (ExecutionException success) {
# Line 759 | Line 755 | public class ForkJoinPoolTest extends JS
755      public void testInvokeAny6() throws Throwable {
756          ExecutorService e = new ForkJoinPool(1);
757          try {
758 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
758 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
759              l.add(new StringTask());
760              l.add(new StringTask());
761              String result = e.invokeAny(l);
# Line 802 | Line 798 | public class ForkJoinPoolTest extends JS
798       */
799      public void testInvokeAll3() throws InterruptedException {
800          ExecutorService e = new ForkJoinPool(1);
801 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
802 +        l.add(new StringTask());
803 +        l.add(null);
804          try {
806            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
807            l.add(new StringTask());
808            l.add(null);
805              e.invokeAll(l);
806              shouldThrow();
807          } catch (NullPointerException success) {
# Line 820 | Line 816 | public class ForkJoinPoolTest extends JS
816       */
817      public void testInvokeAll4() throws Throwable {
818          ExecutorService e = new ForkJoinPool(1);
819 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
820 +        l.add(new NPETask());
821 +        List<Future<String>> futures = e.invokeAll(l);
822 +        assertEquals(1, futures.size());
823          try {
824 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
825 <            l.add(new NPETask());
826 <            List<Future<String>> result = e.invokeAll(l);
827 <            assertEquals(1, result.size());
828 <            for (Future<String> future : result)
829 <                future.get();
824 >            futures.get(0).get();
825              shouldThrow();
826          } catch (ExecutionException success) {
827              assertTrue(success.getCause() instanceof NullPointerException);
# Line 841 | Line 836 | public class ForkJoinPoolTest extends JS
836      public void testInvokeAll5() throws Throwable {
837          ExecutorService e = new ForkJoinPool(1);
838          try {
839 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
839 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
840              l.add(new StringTask());
841              l.add(new StringTask());
842 <            List<Future<String>> result = e.invokeAll(l);
843 <            assertEquals(2, result.size());
844 <            for (Future<String> future : result)
842 >            List<Future<String>> futures = e.invokeAll(l);
843 >            assertEquals(2, futures.size());
844 >            for (Future<String> future : futures)
845                  assertSame(TEST_STRING, future.get());
846          } finally {
847              joinPool(e);
# Line 873 | Line 868 | public class ForkJoinPoolTest extends JS
868       */
869      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
870          ExecutorService e = new ForkJoinPool(1);
871 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
872 +        l.add(new StringTask());
873          try {
877            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
878            l.add(new StringTask());
874              e.invokeAny(l, MEDIUM_DELAY_MS, null);
875              shouldThrow();
876          } catch (NullPointerException success) {
# Line 903 | Line 898 | public class ForkJoinPoolTest extends JS
898       * timed invokeAny(c) throws NullPointerException if c has null elements
899       */
900      public void testTimedInvokeAny3() throws Throwable {
901 <        final CountDownLatch latch = new CountDownLatch(1);
901 >        CountDownLatch latch = new CountDownLatch(1);
902          ExecutorService e = new ForkJoinPool(1);
903 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
904 +        l.add(latchAwaitingStringTask(latch));
905 +        l.add(null);
906          try {
909            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
910            l.add(new Callable<String>() {
911                      public String call() {
912                          try {
913                              latch.await();
914                          } catch (InterruptedException ok) {}
915                          return TEST_STRING;
916                      }});
917            l.add(null);
907              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
908              shouldThrow();
909          } catch (NullPointerException success) {
# Line 929 | Line 918 | public class ForkJoinPoolTest extends JS
918       */
919      public void testTimedInvokeAny4() throws Throwable {
920          ExecutorService e = new ForkJoinPool(1);
921 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
922 +        l.add(new NPETask());
923          try {
933            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
934            l.add(new NPETask());
924              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
925              shouldThrow();
926          } catch (ExecutionException success) {
# Line 947 | Line 936 | public class ForkJoinPoolTest extends JS
936      public void testTimedInvokeAny5() throws Throwable {
937          ExecutorService e = new ForkJoinPool(1);
938          try {
939 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
939 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
940              l.add(new StringTask());
941              l.add(new StringTask());
942              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 976 | Line 965 | public class ForkJoinPoolTest extends JS
965       */
966      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
967          ExecutorService e = new ForkJoinPool(1);
968 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
969 +        l.add(new StringTask());
970          try {
980            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
981            l.add(new StringTask());
971              e.invokeAll(l, MEDIUM_DELAY_MS, null);
972              shouldThrow();
973          } catch (NullPointerException success) {
# Line 1007 | Line 996 | public class ForkJoinPoolTest extends JS
996       */
997      public void testTimedInvokeAll3() throws InterruptedException {
998          ExecutorService e = new ForkJoinPool(1);
999 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1000 +        l.add(new StringTask());
1001 +        l.add(null);
1002          try {
1011            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1012            l.add(new StringTask());
1013            l.add(null);
1003              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1004              shouldThrow();
1005          } catch (NullPointerException success) {
# Line 1024 | Line 1013 | public class ForkJoinPoolTest extends JS
1013       */
1014      public void testTimedInvokeAll4() throws Throwable {
1015          ExecutorService e = new ForkJoinPool(1);
1016 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1017 +        l.add(new NPETask());
1018 +        List<Future<String>> futures
1019 +            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1020 +        assertEquals(1, futures.size());
1021          try {
1022 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1029 <            l.add(new NPETask());
1030 <            List<Future<String>> result
1031 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1032 <            assertEquals(1, result.size());
1033 <            for (Future<String> future : result)
1034 <                future.get();
1022 >            futures.get(0).get();
1023              shouldThrow();
1024          } catch (ExecutionException success) {
1025              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1046 | Line 1034 | public class ForkJoinPoolTest extends JS
1034      public void testTimedInvokeAll5() throws Throwable {
1035          ExecutorService e = new ForkJoinPool(1);
1036          try {
1037 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1037 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1038              l.add(new StringTask());
1039              l.add(new StringTask());
1040 <            List<Future<String>> result
1040 >            List<Future<String>> futures
1041                  = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1042 <            assertEquals(2, result.size());
1043 <            for (Future<String> future : result)
1042 >            assertEquals(2, futures.size());
1043 >            for (Future<String> future : futures)
1044                  assertSame(TEST_STRING, future.get());
1045          } finally {
1046              joinPool(e);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines