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

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.6 by jsr166, Fri Nov 20 22:58:48 2009 UTC vs.
Revision 1.11 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 12 | Line 12 | import java.util.concurrent.atomic.*;
12  
13   public class ScheduledExecutorSubclassTest extends JSR166TestCase {
14      public static void main(String[] args) {
15 <        junit.textui.TestRunner.run (suite());
15 >        junit.textui.TestRunner.run (suite());
16      }
17      public static Test suite() {
18 <        return new TestSuite(ScheduledExecutorSubclassTest.class);
18 >        return new TestSuite(ScheduledExecutorSubclassTest.class);
19      }
20  
21      static class CustomTask<V> implements RunnableScheduledFuture<V> {
# Line 74 | Line 74 | public class ScheduledExecutorSubclassTe
74      }
75  
76  
77
77      /**
78       * execute successfully executes a runnable
79       */
# Line 196 | Line 195 | public class ScheduledExecutorSubclassTe
195      public void testExecuteNull() throws InterruptedException {
196          CustomExecutor se = new CustomExecutor(1);
197          try {
198 <            se.execute(null);
198 >            se.execute(null);
199              shouldThrow();
200 <        } catch (NullPointerException success) {}
201 <        joinPool(se);
200 >        } catch (NullPointerException success) {}
201 >        joinPool(se);
202      }
203  
204      /**
# Line 207 | Line 206 | public class ScheduledExecutorSubclassTe
206       */
207      public void testScheduleNull() throws InterruptedException {
208          CustomExecutor se = new CustomExecutor(1);
209 <        try {
209 >        try {
210              TrackedCallable callable = null;
211 <            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
211 >            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
212              shouldThrow();
213 <        } catch (NullPointerException success) {}
214 <        joinPool(se);
213 >        } catch (NullPointerException success) {}
214 >        joinPool(se);
215      }
216  
217      /**
# Line 313 | Line 312 | public class ScheduledExecutorSubclassTe
312       *    getCompletedTaskCount increases, but doesn't overestimate,
313       *   when tasks complete
314       */
315 <    public void testGetCompletedTaskCount()throws InterruptedException  {
315 >    public void testGetCompletedTaskCount() throws InterruptedException {
316          CustomExecutor p2 = new CustomExecutor(2);
317          assertEquals(0, p2.getCompletedTaskCount());
318          p2.execute(new SmallRunnable());
# Line 376 | Line 375 | public class ScheduledExecutorSubclassTe
375       */
376      public void testGetThreadFactory() {
377          ThreadFactory tf = new SimpleThreadFactory();
378 <        CustomExecutor p = new CustomExecutor(1, tf);
378 >        CustomExecutor p = new CustomExecutor(1, tf);
379          assertSame(tf, p.getThreadFactory());
380          joinPool(p);
381      }
# Line 386 | Line 385 | public class ScheduledExecutorSubclassTe
385       */
386      public void testSetThreadFactory() {
387          ThreadFactory tf = new SimpleThreadFactory();
388 <        CustomExecutor p = new CustomExecutor(1);
388 >        CustomExecutor p = new CustomExecutor(1);
389          p.setThreadFactory(tf);
390          assertSame(tf, p.getThreadFactory());
391          joinPool(p);
# Line 396 | Line 395 | public class ScheduledExecutorSubclassTe
395       * setThreadFactory(null) throws NPE
396       */
397      public void testSetThreadFactoryNull() {
398 <        CustomExecutor p = new CustomExecutor(1);
398 >        CustomExecutor p = new CustomExecutor(1);
399          try {
400              p.setThreadFactory(null);
401              shouldThrow();
# Line 410 | Line 409 | public class ScheduledExecutorSubclassTe
409       *   is isShutDown is false before shutdown, true after
410       */
411      public void testIsShutdown() {
412 <        CustomExecutor p1 = new CustomExecutor(1);
412 >        CustomExecutor p1 = new CustomExecutor(1);
413          try {
414              assertFalse(p1.isShutdown());
415          }
416          finally {
417              try { p1.shutdown(); } catch (SecurityException ok) { return; }
418          }
419 <        assertTrue(p1.isShutdown());
419 >        assertTrue(p1.isShutdown());
420      }
421  
422  
# Line 425 | Line 424 | public class ScheduledExecutorSubclassTe
424       *  isTerminated is false before termination, true after
425       */
426      public void testIsTerminated() throws InterruptedException {
427 <        CustomExecutor p1 = new CustomExecutor(1);
427 >        CustomExecutor p1 = new CustomExecutor(1);
428          try {
429              p1.execute(new SmallRunnable());
430          } finally {
# Line 439 | Line 438 | public class ScheduledExecutorSubclassTe
438       *  isTerminating is not true when running or when terminated
439       */
440      public void testIsTerminating() throws InterruptedException {
441 <        CustomExecutor p1 = new CustomExecutor(1);
441 >        CustomExecutor p1 = new CustomExecutor(1);
442          assertFalse(p1.isTerminating());
443          try {
444              p1.execute(new SmallRunnable());
# Line 530 | Line 529 | public class ScheduledExecutorSubclassTe
529       *  shutDownNow returns a list containing tasks that were not run
530       */
531      public void testShutDownNow() {
532 <        CustomExecutor p1 = new CustomExecutor(1);
532 >        CustomExecutor p1 = new CustomExecutor(1);
533          for (int i = 0; i < 5; i++)
534              p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
535          List l;
# Line 539 | Line 538 | public class ScheduledExecutorSubclassTe
538          } catch (SecurityException ok) {
539              return;
540          }
541 <        assertTrue(p1.isShutdown());
542 <        assertTrue(l.size() > 0 && l.size() <= 5);
541 >        assertTrue(p1.isShutdown());
542 >        assertTrue(l.size() > 0 && l.size() <= 5);
543          joinPool(p1);
544      }
545  
# Line 708 | Line 707 | public class ScheduledExecutorSubclassTe
707       * invokeAny(c) throws NPE if c has null elements
708       */
709      public void testInvokeAny3() throws Exception {
710 <        final CountDownLatch latch = new CountDownLatch(1);
710 >        CountDownLatch latch = new CountDownLatch(1);
711          ExecutorService e = new CustomExecutor(2);
712 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
713 +        l.add(latchAwaitingStringTask(latch));
714 +        l.add(null);
715          try {
714            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
715            l.add(new Callable<String>() {
716                      public String call() {
717                          try {
718                              latch.await();
719                          } catch (InterruptedException ok) {}
720                          return TEST_STRING;
721                      }});
722            l.add(null);
716              e.invokeAny(l);
717              shouldThrow();
718          } catch (NullPointerException success) {
# Line 734 | Line 727 | public class ScheduledExecutorSubclassTe
727       */
728      public void testInvokeAny4() throws Exception {
729          ExecutorService e = new CustomExecutor(2);
730 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
731 +        l.add(new NPETask());
732          try {
738            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
739            l.add(new NPETask());
733              e.invokeAny(l);
734              shouldThrow();
735          } catch (ExecutionException success) {
# Line 752 | Line 745 | public class ScheduledExecutorSubclassTe
745      public void testInvokeAny5() throws Exception {
746          ExecutorService e = new CustomExecutor(2);
747          try {
748 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
748 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
749              l.add(new StringTask());
750              l.add(new StringTask());
751              String result = e.invokeAny(l);
# Line 794 | Line 787 | public class ScheduledExecutorSubclassTe
787       */
788      public void testInvokeAll3() throws Exception {
789          ExecutorService e = new CustomExecutor(2);
790 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
791 +        l.add(new StringTask());
792 +        l.add(null);
793          try {
798            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
799            l.add(new StringTask());
800            l.add(null);
794              e.invokeAll(l);
795              shouldThrow();
796          } catch (NullPointerException success) {
# Line 811 | Line 804 | public class ScheduledExecutorSubclassTe
804       */
805      public void testInvokeAll4() throws Exception {
806          ExecutorService e = new CustomExecutor(2);
807 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
808 +        l.add(new NPETask());
809 +        List<Future<String>> futures = e.invokeAll(l);
810 +        assertEquals(1, futures.size());
811          try {
812 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
816 <            l.add(new NPETask());
817 <            List<Future<String>> result = e.invokeAll(l);
818 <            assertEquals(1, result.size());
819 <            for (Future<String> future : result)
820 <                future.get();
812 >            futures.get(0).get();
813              shouldThrow();
814          } catch (ExecutionException success) {
815              assertTrue(success.getCause() instanceof NullPointerException);
# Line 832 | Line 824 | public class ScheduledExecutorSubclassTe
824      public void testInvokeAll5() throws Exception {
825          ExecutorService e = new CustomExecutor(2);
826          try {
827 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
827 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
828              l.add(new StringTask());
829              l.add(new StringTask());
830 <            List<Future<String>> result = e.invokeAll(l);
831 <            assertEquals(2, result.size());
832 <            for (Future<String> future : result)
830 >            List<Future<String>> futures = e.invokeAll(l);
831 >            assertEquals(2, futures.size());
832 >            for (Future<String> future : futures)
833                  assertSame(TEST_STRING, future.get());
834          } finally {
835              joinPool(e);
# Line 863 | Line 855 | public class ScheduledExecutorSubclassTe
855       */
856      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
857          ExecutorService e = new CustomExecutor(2);
858 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
859 +        l.add(new StringTask());
860          try {
867            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
868            l.add(new StringTask());
861              e.invokeAny(l, MEDIUM_DELAY_MS, null);
862              shouldThrow();
863          } catch (NullPointerException success) {
# Line 892 | Line 884 | public class ScheduledExecutorSubclassTe
884       * timed invokeAny(c) throws NPE if c has null elements
885       */
886      public void testTimedInvokeAny3() throws Exception {
887 <        final CountDownLatch latch = new CountDownLatch(1);
887 >        CountDownLatch latch = new CountDownLatch(1);
888          ExecutorService e = new CustomExecutor(2);
889 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
890 +        l.add(latchAwaitingStringTask(latch));
891 +        l.add(null);
892          try {
898            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
899            l.add(new Callable<String>() {
900                      public String call() {
901                          try {
902                              latch.await();
903                          } catch (InterruptedException ok) {}
904                          return TEST_STRING;
905                      }});
906            l.add(null);
893              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
894              shouldThrow();
895          } catch (NullPointerException success) {
# Line 918 | Line 904 | public class ScheduledExecutorSubclassTe
904       */
905      public void testTimedInvokeAny4() throws Exception {
906          ExecutorService e = new CustomExecutor(2);
907 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
908 +        l.add(new NPETask());
909          try {
922            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
923            l.add(new NPETask());
910              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
911              shouldThrow();
912          } catch (ExecutionException success) {
# Line 936 | Line 922 | public class ScheduledExecutorSubclassTe
922      public void testTimedInvokeAny5() throws Exception {
923          ExecutorService e = new CustomExecutor(2);
924          try {
925 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
925 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
926              l.add(new StringTask());
927              l.add(new StringTask());
928              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 965 | Line 951 | public class ScheduledExecutorSubclassTe
951       */
952      public void testTimedInvokeAllNullTimeUnit() throws Exception {
953          ExecutorService e = new CustomExecutor(2);
954 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
955 +        l.add(new StringTask());
956          try {
969            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
970            l.add(new StringTask());
957              e.invokeAll(l, MEDIUM_DELAY_MS, null);
958              shouldThrow();
959          } catch (NullPointerException success) {
# Line 994 | Line 980 | public class ScheduledExecutorSubclassTe
980       */
981      public void testTimedInvokeAll3() throws Exception {
982          ExecutorService e = new CustomExecutor(2);
983 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
984 +        l.add(new StringTask());
985 +        l.add(null);
986          try {
998            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
999            l.add(new StringTask());
1000            l.add(null);
987              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
988              shouldThrow();
989          } catch (NullPointerException success) {
# Line 1011 | Line 997 | public class ScheduledExecutorSubclassTe
997       */
998      public void testTimedInvokeAll4() throws Exception {
999          ExecutorService e = new CustomExecutor(2);
1000 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1001 +        l.add(new NPETask());
1002 +        List<Future<String>> futures =
1003 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1004 +        assertEquals(1, futures.size());
1005          try {
1006 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1016 <            l.add(new NPETask());
1017 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1018 <            assertEquals(1, result.size());
1019 <            for (Future<String> future : result)
1020 <                future.get();
1006 >            futures.get(0).get();
1007              shouldThrow();
1008          } catch (ExecutionException success) {
1009              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1032 | Line 1018 | public class ScheduledExecutorSubclassTe
1018      public void testTimedInvokeAll5() throws Exception {
1019          ExecutorService e = new CustomExecutor(2);
1020          try {
1021 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1021 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1022              l.add(new StringTask());
1023              l.add(new StringTask());
1024 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1025 <            assertEquals(2, result.size());
1026 <            for (Future<String> future : result)
1024 >            List<Future<String>> futures =
1025 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1026 >            assertEquals(2, futures.size());
1027 >            for (Future<String> future : futures)
1028                  assertSame(TEST_STRING, future.get());
1029          } finally {
1030              joinPool(e);
# Line 1050 | Line 1037 | public class ScheduledExecutorSubclassTe
1037      public void testTimedInvokeAll6() throws Exception {
1038          ExecutorService e = new CustomExecutor(2);
1039          try {
1040 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1040 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1041              l.add(new StringTask());
1042              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1043              l.add(new StringTask());
1044 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1045 <            assertEquals(3, result.size());
1046 <            Iterator<Future<String>> it = result.iterator();
1044 >            List<Future<String>> futures =
1045 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1046 >            assertEquals(3, futures.size());
1047 >            Iterator<Future<String>> it = futures.iterator();
1048              Future<String> f1 = it.next();
1049              Future<String> f2 = it.next();
1050              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines