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.10 by jsr166, Tue Dec 1 09:48:12 2009 UTC vs.
Revision 1.14 by jsr166, Sat Oct 9 19:30:35 2010 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);
# Line 78 | Line 78 | public class ScheduledExecutorSubclassTe
78       * execute successfully executes a runnable
79       */
80      public void testExecute() throws InterruptedException {
81 <        TrackedShortRunnable runnable =new TrackedShortRunnable();
81 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
82          CustomExecutor p1 = new CustomExecutor(1);
83          p1.execute(runnable);
84          assertFalse(runnable.done);
# Line 107 | Line 107 | public class ScheduledExecutorSubclassTe
107      }
108  
109      /**
110 <     *  delayed schedule of runnable successfully executes after delay
110 >     * delayed schedule of runnable successfully executes after delay
111       */
112      public void testSchedule3() throws InterruptedException {
113          TrackedShortRunnable runnable = new TrackedShortRunnable();
# Line 190 | Line 190 | public class ScheduledExecutorSubclassTe
190  
191  
192      /**
193 <     *  execute (null) throws NPE
193 >     * execute(null) throws NPE
194       */
195      public void testExecuteNull() throws InterruptedException {
196          CustomExecutor se = new CustomExecutor(1);
# Line 202 | Line 202 | public class ScheduledExecutorSubclassTe
202      }
203  
204      /**
205 <     * schedule (null) throws NPE
205 >     * schedule(null) throws NPE
206       */
207      public void testScheduleNull() throws InterruptedException {
208          CustomExecutor se = new CustomExecutor(1);
# Line 264 | Line 264 | public class ScheduledExecutorSubclassTe
264      }
265  
266      /**
267 <     *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
267 >     * scheduleAtFixedRate throws RejectedExecutionException if shutdown
268       */
269      public void testScheduleAtFixedRate1_RejectedExecutionException() {
270          CustomExecutor se = new CustomExecutor(1);
# Line 296 | Line 296 | public class ScheduledExecutorSubclassTe
296      }
297  
298      /**
299 <     *  getActiveCount increases but doesn't overestimate, when a
300 <     *  thread becomes active
299 >     * getActiveCount increases but doesn't overestimate, when a
300 >     * thread becomes active
301       */
302      public void testGetActiveCount() throws InterruptedException {
303          CustomExecutor p2 = new CustomExecutor(2);
# Line 309 | Line 309 | public class ScheduledExecutorSubclassTe
309      }
310  
311      /**
312 <     *    getCompletedTaskCount increases, but doesn't overestimate,
313 <     *   when tasks complete
312 >     * getCompletedTaskCount increases, but doesn't overestimate,
313 >     * when tasks complete
314       */
315      public void testGetCompletedTaskCount() throws InterruptedException {
316          CustomExecutor p2 = new CustomExecutor(2);
# Line 322 | Line 322 | public class ScheduledExecutorSubclassTe
322      }
323  
324      /**
325 <     *  getCorePoolSize returns size given in constructor if not otherwise set
325 >     * getCorePoolSize returns size given in constructor if not otherwise set
326       */
327      public void testGetCorePoolSize() {
328          CustomExecutor p1 = new CustomExecutor(1);
# Line 331 | Line 331 | public class ScheduledExecutorSubclassTe
331      }
332  
333      /**
334 <     *    getLargestPoolSize increases, but doesn't overestimate, when
335 <     *   multiple threads active
334 >     * getLargestPoolSize increases, but doesn't overestimate, when
335 >     * multiple threads active
336       */
337      public void testGetLargestPoolSize() throws InterruptedException {
338          CustomExecutor p2 = new CustomExecutor(2);
# Line 345 | Line 345 | public class ScheduledExecutorSubclassTe
345      }
346  
347      /**
348 <     *   getPoolSize increases, but doesn't overestimate, when threads
349 <     *   become active
348 >     * getPoolSize increases, but doesn't overestimate, when threads
349 >     * become active
350       */
351      public void testGetPoolSize() {
352          CustomExecutor p1 = new CustomExecutor(1);
# Line 357 | Line 357 | public class ScheduledExecutorSubclassTe
357      }
358  
359      /**
360 <     *    getTaskCount increases, but doesn't overestimate, when tasks
361 <     *    submitted
360 >     * getTaskCount increases, but doesn't overestimate, when tasks
361 >     * submitted
362       */
363      public void testGetTaskCount() throws InterruptedException {
364          CustomExecutor p1 = new CustomExecutor(1);
# Line 406 | Line 406 | public class ScheduledExecutorSubclassTe
406      }
407  
408      /**
409 <     *   is isShutDown is false before shutdown, true after
409 >     * isShutDown is false before shutdown, true after
410       */
411      public void testIsShutdown() {
412          CustomExecutor p1 = new CustomExecutor(1);
# Line 421 | Line 421 | public class ScheduledExecutorSubclassTe
421  
422  
423      /**
424 <     *  isTerminated is false before termination, true after
424 >     * isTerminated is false before termination, true after
425       */
426      public void testIsTerminated() throws InterruptedException {
427          CustomExecutor p1 = new CustomExecutor(1);
# Line 435 | Line 435 | public class ScheduledExecutorSubclassTe
435      }
436  
437      /**
438 <     *  isTerminating is not true when running or when terminated
438 >     * isTerminating is not true when running or when terminated
439       */
440      public void testIsTerminating() throws InterruptedException {
441          CustomExecutor p1 = new CustomExecutor(1);
# Line 497 | Line 497 | public class ScheduledExecutorSubclassTe
497      }
498  
499      /**
500 <     *  purge removes cancelled tasks from the queue
500 >     * purge removes cancelled tasks from the queue
501       */
502      public void testPurge() throws InterruptedException {
503          CustomExecutor p1 = new CustomExecutor(1);
# Line 526 | Line 526 | public class ScheduledExecutorSubclassTe
526      }
527  
528      /**
529 <     *  shutDownNow returns a list containing tasks that were not run
529 >     * shutDownNow returns a list containing tasks that were not run
530       */
531      public void testShutDownNow() {
532          CustomExecutor p1 = new CustomExecutor(1);
# Line 707 | 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 {
713            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
714            l.add(new Callable<String>() {
715                      public String call() {
716                          try {
717                              latch.await();
718                          } catch (InterruptedException quittingTime) {}
719                          return TEST_STRING;
720                      }});
721            l.add(null);
716              e.invokeAny(l);
717              shouldThrow();
718          } catch (NullPointerException success) {
# Line 733 | 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 {
737            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
738            l.add(new NPETask());
733              e.invokeAny(l);
734              shouldThrow();
735          } catch (ExecutionException success) {
# Line 751 | 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 793 | 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 {
797            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
798            l.add(new StringTask());
799            l.add(null);
794              e.invokeAll(l);
795              shouldThrow();
796          } catch (NullPointerException success) {
# Line 810 | 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>>();
815 <            l.add(new NPETask());
816 <            List<Future<String>> result = e.invokeAll(l);
817 <            assertEquals(1, result.size());
818 <            for (Future<String> future : result)
819 <                future.get();
812 >            futures.get(0).get();
813              shouldThrow();
814          } catch (ExecutionException success) {
815              assertTrue(success.getCause() instanceof NullPointerException);
# Line 831 | 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 862 | 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 {
866            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
867            l.add(new StringTask());
861              e.invokeAny(l, MEDIUM_DELAY_MS, null);
862              shouldThrow();
863          } catch (NullPointerException success) {
# Line 891 | 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 {
897            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
898            l.add(new Callable<String>() {
899                      public String call() {
900                          try {
901                              latch.await();
902                          } catch (InterruptedException quittingTime) {}
903                          return TEST_STRING;
904                      }});
905            l.add(null);
893              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
894              shouldThrow();
895          } catch (NullPointerException success) {
# Line 917 | 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 {
921            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
922            l.add(new NPETask());
910              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
911              shouldThrow();
912          } catch (ExecutionException success) {
# Line 935 | 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 964 | 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 {
968            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
969            l.add(new StringTask());
957              e.invokeAll(l, MEDIUM_DELAY_MS, null);
958              shouldThrow();
959          } catch (NullPointerException success) {
# Line 993 | 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 {
997            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
998            l.add(new StringTask());
999            l.add(null);
987              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
988              shouldThrow();
989          } catch (NullPointerException success) {
# Line 1010 | 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>>();
1015 <            l.add(new NPETask());
1016 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1017 <            assertEquals(1, result.size());
1018 <            for (Future<String> future : result)
1019 <                future.get();
1006 >            futures.get(0).get();
1007              shouldThrow();
1008          } catch (ExecutionException success) {
1009              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1031 | 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 1049 | 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