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

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.28 by jsr166, Tue Dec 1 09:48:12 2009 UTC vs.
Revision 1.29 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 658 | Line 658 | public class ScheduledExecutorTest exten
658       * invokeAny(c) throws NPE if c has null elements
659       */
660      public void testInvokeAny3() throws Exception {
661 <        final CountDownLatch latch = new CountDownLatch(1);
661 >        CountDownLatch latch = new CountDownLatch(1);
662          ExecutorService e = new ScheduledThreadPoolExecutor(2);
663 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
664 +        l.add(latchAwaitingStringTask(latch));
665 +        l.add(null);
666          try {
664            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
665            l.add(new Callable<String>() {
666                      public String call() {
667                          try {
668                              latch.await();
669                          } catch (InterruptedException quittingTime) {}
670                          return TEST_STRING;
671                      }});
672            l.add(null);
667              e.invokeAny(l);
668              shouldThrow();
669          } catch (NullPointerException success) {
# Line 684 | Line 678 | public class ScheduledExecutorTest exten
678       */
679      public void testInvokeAny4() throws Exception {
680          ExecutorService e = new ScheduledThreadPoolExecutor(2);
681 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
682 +        l.add(new NPETask());
683          try {
688            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
689            l.add(new NPETask());
684              e.invokeAny(l);
685              shouldThrow();
686          } catch (ExecutionException success) {
# Line 702 | Line 696 | public class ScheduledExecutorTest exten
696      public void testInvokeAny5() throws Exception {
697          ExecutorService e = new ScheduledThreadPoolExecutor(2);
698          try {
699 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
699 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
700              l.add(new StringTask());
701              l.add(new StringTask());
702              String result = e.invokeAny(l);
# Line 744 | Line 738 | public class ScheduledExecutorTest exten
738       */
739      public void testInvokeAll3() throws Exception {
740          ExecutorService e = new ScheduledThreadPoolExecutor(2);
741 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
742 +        l.add(new StringTask());
743 +        l.add(null);
744          try {
748            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
749            l.add(new StringTask());
750            l.add(null);
745              e.invokeAll(l);
746              shouldThrow();
747          } catch (NullPointerException success) {
# Line 761 | Line 755 | public class ScheduledExecutorTest exten
755       */
756      public void testInvokeAll4() throws Exception {
757          ExecutorService e = new ScheduledThreadPoolExecutor(2);
758 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
759 +        l.add(new NPETask());
760 +        List<Future<String>> futures = e.invokeAll(l);
761 +        assertEquals(1, futures.size());
762          try {
763 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
766 <            l.add(new NPETask());
767 <            List<Future<String>> result = e.invokeAll(l);
768 <            assertEquals(1, result.size());
769 <            for (Future<String> future : result)
770 <                future.get();
763 >            futures.get(0).get();
764              shouldThrow();
765          } catch (ExecutionException success) {
766              assertTrue(success.getCause() instanceof NullPointerException);
# Line 782 | Line 775 | public class ScheduledExecutorTest exten
775      public void testInvokeAll5() throws Exception {
776          ExecutorService e = new ScheduledThreadPoolExecutor(2);
777          try {
778 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
778 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
779              l.add(new StringTask());
780              l.add(new StringTask());
781 <            List<Future<String>> result = e.invokeAll(l);
782 <            assertEquals(2, result.size());
783 <            for (Future<String> future : result)
781 >            List<Future<String>> futures = e.invokeAll(l);
782 >            assertEquals(2, futures.size());
783 >            for (Future<String> future : futures)
784                  assertSame(TEST_STRING, future.get());
785          } finally {
786              joinPool(e);
# Line 813 | Line 806 | public class ScheduledExecutorTest exten
806       */
807      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
808          ExecutorService e = new ScheduledThreadPoolExecutor(2);
809 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
810 +        l.add(new StringTask());
811          try {
817            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
818            l.add(new StringTask());
812              e.invokeAny(l, MEDIUM_DELAY_MS, null);
813              shouldThrow();
814          } catch (NullPointerException success) {
# Line 842 | Line 835 | public class ScheduledExecutorTest exten
835       * timed invokeAny(c) throws NPE if c has null elements
836       */
837      public void testTimedInvokeAny3() throws Exception {
838 <        final CountDownLatch latch = new CountDownLatch(1);
838 >        CountDownLatch latch = new CountDownLatch(1);
839          ExecutorService e = new ScheduledThreadPoolExecutor(2);
840 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
841 +        l.add(latchAwaitingStringTask(latch));
842 +        l.add(null);
843          try {
848            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
849            l.add(new Callable<String>() {
850                      public String call() {
851                          try {
852                              latch.await();
853                          } catch (InterruptedException quittingTime) {}
854                          return TEST_STRING;
855                      }});
856            l.add(null);
844              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
845              shouldThrow();
846          } catch (NullPointerException success) {
# Line 868 | Line 855 | public class ScheduledExecutorTest exten
855       */
856      public void testTimedInvokeAny4() throws Exception {
857          ExecutorService e = new ScheduledThreadPoolExecutor(2);
858 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
859 +        l.add(new NPETask());
860          try {
872            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
873            l.add(new NPETask());
861              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
862              shouldThrow();
863          } catch (ExecutionException success) {
# Line 886 | Line 873 | public class ScheduledExecutorTest exten
873      public void testTimedInvokeAny5() throws Exception {
874          ExecutorService e = new ScheduledThreadPoolExecutor(2);
875          try {
876 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
876 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
877              l.add(new StringTask());
878              l.add(new StringTask());
879              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 915 | Line 902 | public class ScheduledExecutorTest exten
902       */
903      public void testTimedInvokeAllNullTimeUnit() throws Exception {
904          ExecutorService e = new ScheduledThreadPoolExecutor(2);
905 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
906 +        l.add(new StringTask());
907          try {
919            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
920            l.add(new StringTask());
908              e.invokeAll(l, MEDIUM_DELAY_MS, null);
909              shouldThrow();
910          } catch (NullPointerException success) {
# Line 944 | Line 931 | public class ScheduledExecutorTest exten
931       */
932      public void testTimedInvokeAll3() throws Exception {
933          ExecutorService e = new ScheduledThreadPoolExecutor(2);
934 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
935 +        l.add(new StringTask());
936 +        l.add(null);
937          try {
948            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
949            l.add(new StringTask());
950            l.add(null);
938              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
939              shouldThrow();
940          } catch (NullPointerException success) {
# Line 961 | Line 948 | public class ScheduledExecutorTest exten
948       */
949      public void testTimedInvokeAll4() throws Exception {
950          ExecutorService e = new ScheduledThreadPoolExecutor(2);
951 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
952 +        l.add(new NPETask());
953 +        List<Future<String>> futures =
954 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
955 +        assertEquals(1, futures.size());
956          try {
957 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
966 <            l.add(new NPETask());
967 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
968 <            assertEquals(1, result.size());
969 <            for (Future<String> future : result)
970 <                future.get();
957 >            futures.get(0).get();
958              shouldThrow();
959          } catch (ExecutionException success) {
960              assertTrue(success.getCause() instanceof NullPointerException);
# Line 982 | Line 969 | public class ScheduledExecutorTest exten
969      public void testTimedInvokeAll5() throws Exception {
970          ExecutorService e = new ScheduledThreadPoolExecutor(2);
971          try {
972 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
972 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
973              l.add(new StringTask());
974              l.add(new StringTask());
975 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
976 <            assertEquals(2, result.size());
977 <            for (Future<String> future : result)
975 >            List<Future<String>> futures =
976 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
977 >            assertEquals(2, futures.size());
978 >            for (Future<String> future : futures)
979                  assertSame(TEST_STRING, future.get());
980          } finally {
981              joinPool(e);
# Line 1000 | Line 988 | public class ScheduledExecutorTest exten
988      public void testTimedInvokeAll6() throws Exception {
989          ExecutorService e = new ScheduledThreadPoolExecutor(2);
990          try {
991 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
991 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
992              l.add(new StringTask());
993              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
994              l.add(new StringTask());
995 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
996 <            assertEquals(3, result.size());
997 <            Iterator<Future<String>> it = result.iterator();
995 >            List<Future<String>> futures =
996 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
997 >            assertEquals(3, futures.size());
998 >            Iterator<Future<String>> it = futures.iterator();
999              Future<String> f1 = it.next();
1000              Future<String> f2 = it.next();
1001              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines