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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.27 by jsr166, Wed Nov 18 05:39:51 2009 UTC vs.
Revision 1.34 by jsr166, Wed Aug 25 00:07:03 2010 UTC

# Line 14 | Line 14 | import java.util.*;
14  
15   public class ThreadPoolExecutorTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20          return new TestSuite(ThreadPoolExecutorTest.class);
# Line 54 | Line 54 | public class ThreadPoolExecutorTest exte
54          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
55          try {
56              p1.execute(new ShortRunnable());
57 <            Thread.sleep(SMALL_DELAY_MS);
57 >            Thread.sleep(SMALL_DELAY_MS);
58          } finally {
59              joinPool(p1);
60          }
# Line 261 | Line 261 | public class ThreadPoolExecutorTest exte
261       */
262      public void testIsShutdown() {
263  
264 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
264 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
265          assertFalse(p1.isShutdown());
266          try { p1.shutdown(); } catch (SecurityException ok) { return; }
267 <        assertTrue(p1.isShutdown());
267 >        assertTrue(p1.isShutdown());
268          joinPool(p1);
269      }
270  
# Line 273 | Line 273 | public class ThreadPoolExecutorTest exte
273       *  isTerminated is false before termination, true after
274       */
275      public void testIsTerminated() throws InterruptedException {
276 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
276 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
277          assertFalse(p1.isTerminated());
278          try {
279              p1.execute(new MediumRunnable());
# Line 288 | Line 288 | public class ThreadPoolExecutorTest exte
288       *  isTerminating is not true when running or when terminated
289       */
290      public void testIsTerminating() throws InterruptedException {
291 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
291 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
292          assertFalse(p1.isTerminating());
293          try {
294              p1.execute(new SmallRunnable());
# Line 375 | Line 375 | public class ThreadPoolExecutorTest exte
375       *  shutDownNow returns a list containing tasks that were not run
376       */
377      public void testShutDownNow() {
378 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
378 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
379          List l;
380          try {
381              for (int i = 0; i < 5; i++)
# Line 385 | Line 385 | public class ThreadPoolExecutorTest exte
385              try {
386                  l = p1.shutdownNow();
387              } catch (SecurityException ok) { return; }
388
388          }
389 <        assertTrue(p1.isShutdown());
390 <        assertTrue(l.size() <= 4);
389 >        assertTrue(p1.isShutdown());
390 >        assertTrue(l.size() <= 4);
391      }
392  
393      // Exception Tests
# Line 401 | Line 400 | public class ThreadPoolExecutorTest exte
400          try {
401              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
402              shouldThrow();
403 <        }
405 <        catch (IllegalArgumentException success) {}
403 >        } catch (IllegalArgumentException success) {}
404      }
405  
406      /**
# Line 412 | Line 410 | public class ThreadPoolExecutorTest exte
410          try {
411              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
412              shouldThrow();
413 <        }
416 <        catch (IllegalArgumentException success) {}
413 >        } catch (IllegalArgumentException success) {}
414      }
415  
416      /**
# Line 423 | Line 420 | public class ThreadPoolExecutorTest exte
420          try {
421              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
422              shouldThrow();
423 <        }
427 <        catch (IllegalArgumentException success) {}
423 >        } catch (IllegalArgumentException success) {}
424      }
425  
426      /**
# Line 434 | Line 430 | public class ThreadPoolExecutorTest exte
430          try {
431              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
432              shouldThrow();
433 <        }
438 <        catch (IllegalArgumentException success) {}
433 >        } catch (IllegalArgumentException success) {}
434      }
435  
436      /**
# Line 445 | Line 440 | public class ThreadPoolExecutorTest exte
440          try {
441              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
442              shouldThrow();
443 <        }
449 <        catch (IllegalArgumentException success) {}
443 >        } catch (IllegalArgumentException success) {}
444      }
445  
446      /**
# Line 456 | Line 450 | public class ThreadPoolExecutorTest exte
450          try {
451              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null);
452              shouldThrow();
453 <        }
460 <        catch (NullPointerException success) {}
453 >        } catch (NullPointerException success) {}
454      }
455  
456  
# Line 469 | Line 462 | public class ThreadPoolExecutorTest exte
462          try {
463              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
464              shouldThrow();
465 <        }
473 <        catch (IllegalArgumentException success) {}
465 >        } catch (IllegalArgumentException success) {}
466      }
467  
468      /**
# Line 480 | Line 472 | public class ThreadPoolExecutorTest exte
472          try {
473              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
474              shouldThrow();
475 <        }
484 <        catch (IllegalArgumentException success) {}
475 >        } catch (IllegalArgumentException success) {}
476      }
477  
478      /**
# Line 491 | Line 482 | public class ThreadPoolExecutorTest exte
482          try {
483              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
484              shouldThrow();
485 <        }
495 <        catch (IllegalArgumentException success) {}
485 >        } catch (IllegalArgumentException success) {}
486      }
487  
488      /**
# Line 502 | Line 492 | public class ThreadPoolExecutorTest exte
492          try {
493              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
494              shouldThrow();
495 <        }
506 <        catch (IllegalArgumentException success) {}
495 >        } catch (IllegalArgumentException success) {}
496      }
497  
498      /**
# Line 513 | Line 502 | public class ThreadPoolExecutorTest exte
502          try {
503              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
504              shouldThrow();
505 <        }
517 <        catch (IllegalArgumentException success) {}
505 >        } catch (IllegalArgumentException success) {}
506      }
507  
508      /**
# Line 524 | Line 512 | public class ThreadPoolExecutorTest exte
512          try {
513              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
514              shouldThrow();
515 <        }
528 <        catch (NullPointerException success) {}
515 >        } catch (NullPointerException success) {}
516      }
517  
518      /**
# Line 536 | Line 523 | public class ThreadPoolExecutorTest exte
523              ThreadFactory f = null;
524              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
525              shouldThrow();
526 <        }
540 <        catch (NullPointerException success) {}
526 >        } catch (NullPointerException success) {}
527      }
528  
529  
# Line 548 | Line 534 | public class ThreadPoolExecutorTest exte
534          try {
535              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
536              shouldThrow();
537 <        }
552 <        catch (IllegalArgumentException success) {}
537 >        } catch (IllegalArgumentException success) {}
538      }
539  
540      /**
# Line 559 | Line 544 | public class ThreadPoolExecutorTest exte
544          try {
545              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
546              shouldThrow();
547 <        }
563 <        catch (IllegalArgumentException success) {}
547 >        } catch (IllegalArgumentException success) {}
548      }
549  
550      /**
# Line 570 | Line 554 | public class ThreadPoolExecutorTest exte
554          try {
555              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
556              shouldThrow();
557 <        }
574 <        catch (IllegalArgumentException success) {}
557 >        } catch (IllegalArgumentException success) {}
558      }
559  
560      /**
# Line 581 | Line 564 | public class ThreadPoolExecutorTest exte
564          try {
565              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
566              shouldThrow();
567 <        }
585 <        catch (IllegalArgumentException success) {}
567 >        } catch (IllegalArgumentException success) {}
568      }
569  
570      /**
# Line 592 | Line 574 | public class ThreadPoolExecutorTest exte
574          try {
575              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
576              shouldThrow();
577 <        }
596 <        catch (IllegalArgumentException success) {}
577 >        } catch (IllegalArgumentException success) {}
578      }
579  
580      /**
# Line 603 | Line 584 | public class ThreadPoolExecutorTest exte
584          try {
585              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
586              shouldThrow();
587 <        }
607 <        catch (NullPointerException success) {}
587 >        } catch (NullPointerException success) {}
588      }
589  
590      /**
# Line 615 | Line 595 | public class ThreadPoolExecutorTest exte
595              RejectedExecutionHandler r = null;
596              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
597              shouldThrow();
598 <        }
619 <        catch (NullPointerException success) {}
598 >        } catch (NullPointerException success) {}
599      }
600  
601  
# Line 627 | Line 606 | public class ThreadPoolExecutorTest exte
606          try {
607              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
608              shouldThrow();
609 <        }
631 <        catch (IllegalArgumentException success) {}
609 >        } catch (IllegalArgumentException success) {}
610      }
611  
612      /**
# Line 638 | Line 616 | public class ThreadPoolExecutorTest exte
616          try {
617              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
618              shouldThrow();
619 <        }
642 <        catch (IllegalArgumentException success) {}
619 >        } catch (IllegalArgumentException success) {}
620      }
621  
622      /**
# Line 649 | Line 626 | public class ThreadPoolExecutorTest exte
626          try {
627              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
628              shouldThrow();
629 <        }
653 <        catch (IllegalArgumentException success) {}
629 >        } catch (IllegalArgumentException success) {}
630      }
631  
632      /**
# Line 660 | Line 636 | public class ThreadPoolExecutorTest exte
636          try {
637              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
638              shouldThrow();
639 <        }
664 <        catch (IllegalArgumentException success) {}
639 >        } catch (IllegalArgumentException success) {}
640      }
641  
642      /**
# Line 671 | Line 646 | public class ThreadPoolExecutorTest exte
646          try {
647              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
648              shouldThrow();
649 <        }
675 <        catch (IllegalArgumentException success) {}
649 >        } catch (IllegalArgumentException success) {}
650      }
651  
652      /**
# Line 682 | Line 656 | public class ThreadPoolExecutorTest exte
656          try {
657              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
658              shouldThrow();
659 <        }
686 <        catch (NullPointerException success) {}
659 >        } catch (NullPointerException success) {}
660      }
661  
662      /**
# Line 694 | Line 667 | public class ThreadPoolExecutorTest exte
667              RejectedExecutionHandler r = null;
668              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
669              shouldThrow();
670 <        }
698 <        catch (NullPointerException success) {}
670 >        } catch (NullPointerException success) {}
671      }
672  
673      /**
# Line 706 | Line 678 | public class ThreadPoolExecutorTest exte
678              ThreadFactory f = null;
679              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
680              shouldThrow();
681 <        }
710 <        catch (NullPointerException success) {}
681 >        } catch (NullPointerException success) {}
682      }
683  
684  
# Line 813 | Line 784 | public class ThreadPoolExecutorTest exte
784          ThreadPoolExecutor tpe =
785              new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
786          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
787 <        try {
788 <            tpe.execute(new NoOpRunnable());
789 <            shouldThrow();
790 <        } catch (RejectedExecutionException success) {}
787 >        try {
788 >            tpe.execute(new NoOpRunnable());
789 >            shouldThrow();
790 >        } catch (RejectedExecutionException success) {}
791  
792 <        joinPool(tpe);
792 >        joinPool(tpe);
793      }
794  
795      /**
# Line 829 | Line 800 | public class ThreadPoolExecutorTest exte
800          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
801  
802          try { p.shutdown(); } catch (SecurityException ok) { return; }
803 <        try {
803 >        try {
804              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
805 <            p.execute(r);
805 >            p.execute(r);
806              assertFalse(r.done);
807          } finally {
808              joinPool(p);
# Line 846 | Line 817 | public class ThreadPoolExecutorTest exte
817          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
818  
819          try { p.shutdown(); } catch (SecurityException ok) { return; }
820 <        try {
820 >        try {
821              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
822 <            p.execute(r);
822 >            p.execute(r);
823              assertFalse(r.done);
824          } finally {
825              joinPool(p);
# Line 864 | Line 835 | public class ThreadPoolExecutorTest exte
835          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
836  
837          try { p.shutdown(); } catch (SecurityException ok) { return; }
838 <        try {
838 >        try {
839              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
840 <            p.execute(r);
840 >            p.execute(r);
841              assertFalse(r.done);
842          } finally {
843              joinPool(p);
# Line 875 | Line 846 | public class ThreadPoolExecutorTest exte
846  
847  
848      /**
849 <     *  execute (null) throws NPE
849 >     * execute(null) throws NPE
850       */
851      public void testExecuteNull() {
852 <        ThreadPoolExecutor tpe = null;
852 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
853          try {
854 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
884 <            tpe.execute(null);
854 >            tpe.execute(null);
855              shouldThrow();
856 <        } catch (NullPointerException success) {}
856 >        } catch (NullPointerException success) {}
857  
858 <        joinPool(tpe);
858 >        joinPool(tpe);
859      }
860  
861      /**
862 <     *  setCorePoolSize of negative value throws IllegalArgumentException
862 >     * setCorePoolSize of negative value throws IllegalArgumentException
863       */
864      public void testCorePoolSizeIllegalArgumentException() {
865 <        ThreadPoolExecutor tpe =
865 >        ThreadPoolExecutor tpe =
866              new ThreadPoolExecutor(1, 2,
867                                     LONG_DELAY_MS, MILLISECONDS,
868                                     new ArrayBlockingQueue<Runnable>(10));
869 <        try {
870 <            tpe.setCorePoolSize(-1);
871 <            shouldThrow();
872 <        } catch (IllegalArgumentException success) {
869 >        try {
870 >            tpe.setCorePoolSize(-1);
871 >            shouldThrow();
872 >        } catch (IllegalArgumentException success) {
873          } finally {
874              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
875          }
# Line 950 | Line 920 | public class ThreadPoolExecutorTest exte
920       *  when given a negative value
921       */
922      public void testKeepAliveTimeIllegalArgumentException() {
923 <        ThreadPoolExecutor tpe =
923 >        ThreadPoolExecutor tpe =
924              new ThreadPoolExecutor(2, 3,
925                                     LONG_DELAY_MS, MILLISECONDS,
926                                     new ArrayBlockingQueue<Runnable>(10));
927 <        try {
927 >        try {
928              tpe.setKeepAliveTime(-1,MILLISECONDS);
929              shouldThrow();
930          } catch (IllegalArgumentException success) {
# Line 1067 | Line 1037 | public class ThreadPoolExecutorTest exte
1037       * invokeAny(c) throws NPE if c has null elements
1038       */
1039      public void testInvokeAny3() throws Exception {
1040 <        final CountDownLatch latch = new CountDownLatch(1);
1040 >        CountDownLatch latch = new CountDownLatch(1);
1041          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1042 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1043 +        l.add(latchAwaitingStringTask(latch));
1044 +        l.add(null);
1045          try {
1073            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1074            l.add(new CheckedCallable<String>() {
1075                      public String realCall() throws InterruptedException {
1076                          latch.await();
1077                          return TEST_STRING;
1078                      }});
1079            l.add(null);
1046              e.invokeAny(l);
1047              shouldThrow();
1048          } catch (NullPointerException success) {
# Line 1091 | Line 1057 | public class ThreadPoolExecutorTest exte
1057       */
1058      public void testInvokeAny4() throws Exception {
1059          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1060 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1061 +        l.add(new NPETask());
1062          try {
1095            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1096            l.add(new NPETask());
1063              e.invokeAny(l);
1064              shouldThrow();
1065          } catch (ExecutionException success) {
# Line 1109 | Line 1075 | public class ThreadPoolExecutorTest exte
1075      public void testInvokeAny5() throws Exception {
1076          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1077          try {
1078 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1078 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1079              l.add(new StringTask());
1080              l.add(new StringTask());
1081              String result = e.invokeAny(l);
# Line 1151 | Line 1117 | public class ThreadPoolExecutorTest exte
1117       */
1118      public void testInvokeAll3() throws Exception {
1119          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1120 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1121 +        l.add(new StringTask());
1122 +        l.add(null);
1123          try {
1155            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1156            l.add(new StringTask());
1157            l.add(null);
1124              e.invokeAll(l);
1125              shouldThrow();
1126          } catch (NullPointerException success) {
# Line 1169 | Line 1135 | public class ThreadPoolExecutorTest exte
1135      public void testInvokeAll4() throws Exception {
1136          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1137          try {
1138 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1138 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1139              l.add(new NPETask());
1140 <            List<Future<String>> result = e.invokeAll(l);
1141 <            assertEquals(1, result.size());
1142 <            for (Future<String> future : result) {
1143 <                try {
1144 <                    future.get();
1145 <                    shouldThrow();
1146 <                } catch (ExecutionException success) {
1181 <                    Throwable cause = success.getCause();
1182 <                    assertTrue(cause instanceof NullPointerException);
1183 <                }
1140 >            List<Future<String>> futures = e.invokeAll(l);
1141 >            assertEquals(1, futures.size());
1142 >            try {
1143 >                futures.get(0).get();
1144 >                shouldThrow();
1145 >            } catch (ExecutionException success) {
1146 >                assertTrue(success.getCause() instanceof NullPointerException);
1147              }
1148          } finally {
1149              joinPool(e);
# Line 1193 | Line 1156 | public class ThreadPoolExecutorTest exte
1156      public void testInvokeAll5() throws Exception {
1157          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1158          try {
1159 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1159 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1160              l.add(new StringTask());
1161              l.add(new StringTask());
1162 <            List<Future<String>> result = e.invokeAll(l);
1163 <            assertEquals(2, result.size());
1164 <            for (Future<String> future : result)
1162 >            List<Future<String>> futures = e.invokeAll(l);
1163 >            assertEquals(2, futures.size());
1164 >            for (Future<String> future : futures)
1165                  assertSame(TEST_STRING, future.get());
1166          } finally {
1167              joinPool(e);
# Line 1226 | Line 1189 | public class ThreadPoolExecutorTest exte
1189       */
1190      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1191          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1192 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1193 +        l.add(new StringTask());
1194          try {
1230            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1231            l.add(new StringTask());
1195              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1196              shouldThrow();
1197          } catch (NullPointerException success) {
# Line 1255 | Line 1218 | public class ThreadPoolExecutorTest exte
1218       * timed invokeAny(c) throws NPE if c has null elements
1219       */
1220      public void testTimedInvokeAny3() throws Exception {
1221 +        CountDownLatch latch = new CountDownLatch(1);
1222          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1223 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1224 +        l.add(latchAwaitingStringTask(latch));
1225 +        l.add(null);
1226          try {
1260            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1261            l.add(new StringTask());
1262            l.add(null);
1227              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1228              shouldThrow();
1229          } catch (NullPointerException success) {
1230          } finally {
1231 +            latch.countDown();
1232              joinPool(e);
1233          }
1234      }
# Line 1273 | Line 1238 | public class ThreadPoolExecutorTest exte
1238       */
1239      public void testTimedInvokeAny4() throws Exception {
1240          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1241 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1242 +        l.add(new NPETask());
1243          try {
1277            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1278            l.add(new NPETask());
1244              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1245              shouldThrow();
1246          } catch (ExecutionException success) {
# Line 1291 | Line 1256 | public class ThreadPoolExecutorTest exte
1256      public void testTimedInvokeAny5() throws Exception {
1257          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1258          try {
1259 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1260              l.add(new StringTask());
1261              l.add(new StringTask());
1262              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 1320 | Line 1285 | public class ThreadPoolExecutorTest exte
1285       */
1286      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1287          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1288 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1289 +        l.add(new StringTask());
1290          try {
1324            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1325            l.add(new StringTask());
1291              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1292              shouldThrow();
1293          } catch (NullPointerException success) {
# Line 1349 | Line 1314 | public class ThreadPoolExecutorTest exte
1314       */
1315      public void testTimedInvokeAll3() throws Exception {
1316          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1317 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1318 +        l.add(new StringTask());
1319 +        l.add(null);
1320          try {
1353            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1354            l.add(new StringTask());
1355            l.add(null);
1321              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1322              shouldThrow();
1323          } catch (NullPointerException success) {
# Line 1366 | Line 1331 | public class ThreadPoolExecutorTest exte
1331       */
1332      public void testTimedInvokeAll4() throws Exception {
1333          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1334 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1335 +        l.add(new NPETask());
1336 +        List<Future<String>> futures =
1337 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1338 +        assertEquals(1, futures.size());
1339          try {
1340 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1371 <            l.add(new NPETask());
1372 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1373 <            assertEquals(1, result.size());
1374 <            for (Future<String> future : result)
1375 <                future.get();
1340 >            futures.get(0).get();
1341              shouldThrow();
1342          } catch (ExecutionException success) {
1343              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1387 | Line 1352 | public class ThreadPoolExecutorTest exte
1352      public void testTimedInvokeAll5() throws Exception {
1353          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1354          try {
1355 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1355 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1356              l.add(new StringTask());
1357              l.add(new StringTask());
1358 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1359 <            assertEquals(2, result.size());
1360 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1361 <                assertSame(TEST_STRING, it.next().get());
1358 >            List<Future<String>> futures =
1359 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1360 >            assertEquals(2, futures.size());
1361 >            for (Future<String> future : futures)
1362 >                assertSame(TEST_STRING, future.get());
1363          } finally {
1364              joinPool(e);
1365          }
# Line 1405 | Line 1371 | public class ThreadPoolExecutorTest exte
1371      public void testTimedInvokeAll6() throws Exception {
1372          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1373          try {
1374 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1374 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1375              l.add(new StringTask());
1376              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1377              l.add(new StringTask());
1378 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1379 <            assertEquals(3, result.size());
1380 <            Iterator<Future<String>> it = result.iterator();
1378 >            List<Future<String>> futures =
1379 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1380 >            assertEquals(3, futures.size());
1381 >            Iterator<Future<String>> it = futures.iterator();
1382              Future<String> f1 = it.next();
1383              Future<String> f2 = it.next();
1384              Future<String> f3 = it.next();
# Line 1432 | Line 1399 | public class ThreadPoolExecutorTest exte
1399      public void testFailingThreadFactory() throws InterruptedException {
1400          ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1401          try {
1402 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1402 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1403              for (int k = 0; k < 100; ++k) {
1404                  e.execute(new NoOpRunnable());
1405              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines