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.30 by jsr166, Fri Nov 20 22:58:48 2009 UTC vs.
Revision 1.35 by jsr166, Sat Oct 9 19:30:35 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 48 | Line 48 | public class ThreadPoolExecutorTest exte
48  
49  
50      /**
51 <     *  execute successfully executes a runnable
51 >     * execute successfully executes a runnable
52       */
53      public void testExecute() throws InterruptedException {
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          }
61      }
62  
63      /**
64 <     *  getActiveCount increases but doesn't overestimate, when a
65 <     *  thread becomes active
64 >     * getActiveCount increases but doesn't overestimate, when a
65 >     * thread becomes active
66       */
67      public void testGetActiveCount() throws InterruptedException {
68          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 74 | Line 74 | public class ThreadPoolExecutorTest exte
74      }
75  
76      /**
77 <     *  prestartCoreThread starts a thread if under corePoolSize, else doesn't
77 >     * prestartCoreThread starts a thread if under corePoolSize, else doesn't
78       */
79      public void testPrestartCoreThread() {
80          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 89 | Line 89 | public class ThreadPoolExecutorTest exte
89      }
90  
91      /**
92 <     *  prestartAllCoreThreads starts all corePoolSize threads
92 >     * prestartAllCoreThreads starts all corePoolSize threads
93       */
94      public void testPrestartAllCoreThreads() {
95          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 102 | Line 102 | public class ThreadPoolExecutorTest exte
102      }
103  
104      /**
105 <     *   getCompletedTaskCount increases, but doesn't overestimate,
106 <     *   when tasks complete
105 >     * getCompletedTaskCount increases, but doesn't overestimate,
106 >     * when tasks complete
107       */
108      public void testGetCompletedTaskCount() throws InterruptedException {
109          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 116 | Line 116 | public class ThreadPoolExecutorTest exte
116      }
117  
118      /**
119 <     *   getCorePoolSize returns size given in constructor if not otherwise set
119 >     * getCorePoolSize returns size given in constructor if not otherwise set
120       */
121      public void testGetCorePoolSize() {
122          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 125 | Line 125 | public class ThreadPoolExecutorTest exte
125      }
126  
127      /**
128 <     *   getKeepAliveTime returns value given in constructor if not otherwise set
128 >     * getKeepAliveTime returns value given in constructor if not otherwise set
129       */
130      public void testGetKeepAliveTime() {
131          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 209 | Line 209 | public class ThreadPoolExecutorTest exte
209  
210  
211      /**
212 <     *   getLargestPoolSize increases, but doesn't overestimate, when
213 <     *   multiple threads active
212 >     * getLargestPoolSize increases, but doesn't overestimate, when
213 >     * multiple threads active
214       */
215      public void testGetLargestPoolSize() throws InterruptedException {
216          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 223 | Line 223 | public class ThreadPoolExecutorTest exte
223      }
224  
225      /**
226 <     *   getMaximumPoolSize returns value given in constructor if not
227 <     *   otherwise set
226 >     * getMaximumPoolSize returns value given in constructor if not
227 >     * otherwise set
228       */
229      public void testGetMaximumPoolSize() {
230          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 233 | Line 233 | public class ThreadPoolExecutorTest exte
233      }
234  
235      /**
236 <     *   getPoolSize increases, but doesn't overestimate, when threads
237 <     *   become active
236 >     * getPoolSize increases, but doesn't overestimate, when threads
237 >     * become active
238       */
239      public void testGetPoolSize() {
240          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 245 | Line 245 | public class ThreadPoolExecutorTest exte
245      }
246  
247      /**
248 <     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
248 >     * getTaskCount increases, but doesn't overestimate, when tasks submitted
249       */
250      public void testGetTaskCount() throws InterruptedException {
251          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 257 | Line 257 | public class ThreadPoolExecutorTest exte
257      }
258  
259      /**
260 <     *   isShutDown is false before shutdown, true after
260 >     * isShutDown is false before shutdown, true after
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  
271  
272      /**
273 <     *  isTerminated is false before termination, true after
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 285 | Line 285 | public class ThreadPoolExecutorTest exte
285      }
286  
287      /**
288 <     *  isTerminating is not true when running or when terminated
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 354 | Line 354 | public class ThreadPoolExecutorTest exte
354      }
355  
356      /**
357 <     *   purge removes cancelled tasks from the queue
357 >     * purge removes cancelled tasks from the queue
358       */
359      public void testPurge() {
360          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 372 | Line 372 | public class ThreadPoolExecutorTest exte
372      }
373  
374      /**
375 <     *  shutDownNow returns a list containing tasks that were not run
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 684 | Line 683 | public class ThreadPoolExecutorTest exte
683  
684  
685      /**
686 <     *  execute throws RejectedExecutionException
688 <     *  if saturated.
686 >     * execute throws RejectedExecutionException if saturated.
687       */
688      public void testSaturatedExecute() {
689          ThreadPoolExecutor p =
# Line 707 | Line 705 | public class ThreadPoolExecutorTest exte
705      }
706  
707      /**
708 <     *  executor using CallerRunsPolicy runs task if saturated.
708 >     * executor using CallerRunsPolicy runs task if saturated.
709       */
710      public void testSaturatedExecute2() {
711          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
# Line 733 | Line 731 | public class ThreadPoolExecutorTest exte
731      }
732  
733      /**
734 <     *  executor using DiscardPolicy drops task if saturated.
734 >     * executor using DiscardPolicy drops task if saturated.
735       */
736      public void testSaturatedExecute3() {
737          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
# Line 758 | Line 756 | public class ThreadPoolExecutorTest exte
756      }
757  
758      /**
759 <     *  executor using DiscardOldestPolicy drops oldest task if saturated.
759 >     * executor using DiscardOldestPolicy drops oldest task if saturated.
760       */
761      public void testSaturatedExecute4() {
762          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
# Line 779 | Line 777 | public class ThreadPoolExecutorTest exte
777      }
778  
779      /**
780 <     *  execute throws RejectedExecutionException if shutdown
780 >     * execute throws RejectedExecutionException if shutdown
781       */
782      public void testRejectedExecutionExceptionOnShutdown() {
783          ThreadPoolExecutor tpe =
784              new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
785          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
786 <        try {
787 <            tpe.execute(new NoOpRunnable());
788 <            shouldThrow();
789 <        } catch (RejectedExecutionException success) {}
786 >        try {
787 >            tpe.execute(new NoOpRunnable());
788 >            shouldThrow();
789 >        } catch (RejectedExecutionException success) {}
790  
791 <        joinPool(tpe);
791 >        joinPool(tpe);
792      }
793  
794      /**
795 <     *  execute using CallerRunsPolicy drops task on shutdown
795 >     * execute using CallerRunsPolicy drops task on shutdown
796       */
797      public void testCallerRunsOnShutdown() {
798          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
799          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
800  
801          try { p.shutdown(); } catch (SecurityException ok) { return; }
802 <        try {
802 >        try {
803              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
804 <            p.execute(r);
804 >            p.execute(r);
805              assertFalse(r.done);
806          } finally {
807              joinPool(p);
# Line 811 | Line 809 | public class ThreadPoolExecutorTest exte
809      }
810  
811      /**
812 <     *  execute using DiscardPolicy drops task on shutdown
812 >     * execute using DiscardPolicy drops task on shutdown
813       */
814      public void testDiscardOnShutdown() {
815          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
816          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
817  
818          try { p.shutdown(); } catch (SecurityException ok) { return; }
819 <        try {
819 >        try {
820              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
821 <            p.execute(r);
821 >            p.execute(r);
822              assertFalse(r.done);
823          } finally {
824              joinPool(p);
# Line 829 | Line 827 | public class ThreadPoolExecutorTest exte
827  
828  
829      /**
830 <     *  execute using DiscardOldestPolicy drops task on shutdown
830 >     * execute using DiscardOldestPolicy drops task on shutdown
831       */
832      public void testDiscardOldestOnShutdown() {
833          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
834          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
835  
836          try { p.shutdown(); } catch (SecurityException ok) { return; }
837 <        try {
837 >        try {
838              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
839 <            p.execute(r);
839 >            p.execute(r);
840              assertFalse(r.done);
841          } finally {
842              joinPool(p);
# Line 847 | Line 845 | public class ThreadPoolExecutorTest exte
845  
846  
847      /**
848 <     *  execute (null) throws NPE
848 >     * execute(null) throws NPE
849       */
850      public void testExecuteNull() {
851          ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
852          try {
853 <            tpe.execute(null);
853 >            tpe.execute(null);
854              shouldThrow();
855 <        } catch (NullPointerException success) {}
855 >        } catch (NullPointerException success) {}
856  
857 <        joinPool(tpe);
857 >        joinPool(tpe);
858      }
859  
860      /**
861 <     *  setCorePoolSize of negative value throws IllegalArgumentException
861 >     * setCorePoolSize of negative value throws IllegalArgumentException
862       */
863      public void testCorePoolSizeIllegalArgumentException() {
864 <        ThreadPoolExecutor tpe =
864 >        ThreadPoolExecutor tpe =
865              new ThreadPoolExecutor(1, 2,
866                                     LONG_DELAY_MS, MILLISECONDS,
867                                     new ArrayBlockingQueue<Runnable>(10));
868 <        try {
869 <            tpe.setCorePoolSize(-1);
870 <            shouldThrow();
871 <        } catch (IllegalArgumentException success) {
868 >        try {
869 >            tpe.setCorePoolSize(-1);
870 >            shouldThrow();
871 >        } catch (IllegalArgumentException success) {
872          } finally {
873              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
874          }
# Line 878 | Line 876 | public class ThreadPoolExecutorTest exte
876      }
877  
878      /**
879 <     *  setMaximumPoolSize(int) throws IllegalArgumentException if
880 <     *  given a value less the core pool size
879 >     * setMaximumPoolSize(int) throws IllegalArgumentException if
880 >     * given a value less the core pool size
881       */
882      public void testMaximumPoolSizeIllegalArgumentException() {
883          ThreadPoolExecutor tpe =
# Line 897 | Line 895 | public class ThreadPoolExecutorTest exte
895      }
896  
897      /**
898 <     *  setMaximumPoolSize throws IllegalArgumentException
899 <     *  if given a negative value
898 >     * setMaximumPoolSize throws IllegalArgumentException
899 >     * if given a negative value
900       */
901      public void testMaximumPoolSizeIllegalArgumentException2() {
902          ThreadPoolExecutor tpe =
# Line 917 | Line 915 | public class ThreadPoolExecutorTest exte
915  
916  
917      /**
918 <     *  setKeepAliveTime  throws IllegalArgumentException
919 <     *  when given a negative value
918 >     * setKeepAliveTime throws IllegalArgumentException
919 >     * when given a negative value
920       */
921      public void testKeepAliveTimeIllegalArgumentException() {
922 <        ThreadPoolExecutor tpe =
922 >        ThreadPoolExecutor tpe =
923              new ThreadPoolExecutor(2, 3,
924                                     LONG_DELAY_MS, MILLISECONDS,
925                                     new ArrayBlockingQueue<Runnable>(10));
926 <        try {
926 >        try {
927              tpe.setKeepAliveTime(-1,MILLISECONDS);
928              shouldThrow();
929          } catch (IllegalArgumentException success) {
# Line 1038 | Line 1036 | public class ThreadPoolExecutorTest exte
1036       * invokeAny(c) throws NPE if c has null elements
1037       */
1038      public void testInvokeAny3() throws Exception {
1039 <        final CountDownLatch latch = new CountDownLatch(1);
1039 >        CountDownLatch latch = new CountDownLatch(1);
1040          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1041 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1042 +        l.add(latchAwaitingStringTask(latch));
1043 +        l.add(null);
1044          try {
1044            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1045            l.add(new Callable<String>() {
1046                      public String call() {
1047                          try {
1048                              latch.await();
1049                          } catch (InterruptedException ok) {}
1050                          return TEST_STRING;
1051                      }});
1052            l.add(null);
1045              e.invokeAny(l);
1046              shouldThrow();
1047          } catch (NullPointerException success) {
# Line 1064 | Line 1056 | public class ThreadPoolExecutorTest exte
1056       */
1057      public void testInvokeAny4() throws Exception {
1058          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1059 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1060 +        l.add(new NPETask());
1061          try {
1068            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1069            l.add(new NPETask());
1062              e.invokeAny(l);
1063              shouldThrow();
1064          } catch (ExecutionException success) {
# Line 1082 | Line 1074 | public class ThreadPoolExecutorTest exte
1074      public void testInvokeAny5() throws Exception {
1075          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1076          try {
1077 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1077 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1078              l.add(new StringTask());
1079              l.add(new StringTask());
1080              String result = e.invokeAny(l);
# Line 1124 | Line 1116 | public class ThreadPoolExecutorTest exte
1116       */
1117      public void testInvokeAll3() throws Exception {
1118          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1119 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1120 +        l.add(new StringTask());
1121 +        l.add(null);
1122          try {
1128            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1129            l.add(new StringTask());
1130            l.add(null);
1123              e.invokeAll(l);
1124              shouldThrow();
1125          } catch (NullPointerException success) {
# Line 1142 | Line 1134 | public class ThreadPoolExecutorTest exte
1134      public void testInvokeAll4() throws Exception {
1135          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1136          try {
1137 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1137 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1138              l.add(new NPETask());
1139 <            List<Future<String>> result = e.invokeAll(l);
1140 <            assertEquals(1, result.size());
1141 <            for (Future<String> future : result) {
1142 <                try {
1143 <                    future.get();
1144 <                    shouldThrow();
1145 <                } catch (ExecutionException success) {
1154 <                    Throwable cause = success.getCause();
1155 <                    assertTrue(cause instanceof NullPointerException);
1156 <                }
1139 >            List<Future<String>> futures = e.invokeAll(l);
1140 >            assertEquals(1, futures.size());
1141 >            try {
1142 >                futures.get(0).get();
1143 >                shouldThrow();
1144 >            } catch (ExecutionException success) {
1145 >                assertTrue(success.getCause() instanceof NullPointerException);
1146              }
1147          } finally {
1148              joinPool(e);
# Line 1166 | Line 1155 | public class ThreadPoolExecutorTest exte
1155      public void testInvokeAll5() throws Exception {
1156          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1157          try {
1158 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1158 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1159              l.add(new StringTask());
1160              l.add(new StringTask());
1161 <            List<Future<String>> result = e.invokeAll(l);
1162 <            assertEquals(2, result.size());
1163 <            for (Future<String> future : result)
1161 >            List<Future<String>> futures = e.invokeAll(l);
1162 >            assertEquals(2, futures.size());
1163 >            for (Future<String> future : futures)
1164                  assertSame(TEST_STRING, future.get());
1165          } finally {
1166              joinPool(e);
# Line 1199 | Line 1188 | public class ThreadPoolExecutorTest exte
1188       */
1189      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1190          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1191 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1192 +        l.add(new StringTask());
1193          try {
1203            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1204            l.add(new StringTask());
1194              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1195              shouldThrow();
1196          } catch (NullPointerException success) {
# Line 1228 | Line 1217 | public class ThreadPoolExecutorTest exte
1217       * timed invokeAny(c) throws NPE if c has null elements
1218       */
1219      public void testTimedInvokeAny3() throws Exception {
1220 <        final CountDownLatch latch = new CountDownLatch(1);
1220 >        CountDownLatch latch = new CountDownLatch(1);
1221          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1222 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1223 +        l.add(latchAwaitingStringTask(latch));
1224 +        l.add(null);
1225          try {
1234            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1235            l.add(new Callable<String>() {
1236                      public String call() {
1237                          try {
1238                              latch.await();
1239                          } catch (InterruptedException ok) {}
1240                          return TEST_STRING;
1241                      }});
1242            l.add(null);
1226              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1227              shouldThrow();
1228          } catch (NullPointerException success) {
# Line 1254 | Line 1237 | public class ThreadPoolExecutorTest exte
1237       */
1238      public void testTimedInvokeAny4() throws Exception {
1239          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1240 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1241 +        l.add(new NPETask());
1242          try {
1258            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259            l.add(new NPETask());
1243              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1244              shouldThrow();
1245          } catch (ExecutionException success) {
# Line 1272 | Line 1255 | public class ThreadPoolExecutorTest exte
1255      public void testTimedInvokeAny5() throws Exception {
1256          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257          try {
1258 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1258 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1259              l.add(new StringTask());
1260              l.add(new StringTask());
1261              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 1301 | Line 1284 | public class ThreadPoolExecutorTest exte
1284       */
1285      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1286          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1287 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1288 +        l.add(new StringTask());
1289          try {
1305            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1306            l.add(new StringTask());
1290              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1291              shouldThrow();
1292          } catch (NullPointerException success) {
# Line 1330 | Line 1313 | public class ThreadPoolExecutorTest exte
1313       */
1314      public void testTimedInvokeAll3() throws Exception {
1315          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1316 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1317 +        l.add(new StringTask());
1318 +        l.add(null);
1319          try {
1334            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1335            l.add(new StringTask());
1336            l.add(null);
1320              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1321              shouldThrow();
1322          } catch (NullPointerException success) {
# Line 1347 | Line 1330 | public class ThreadPoolExecutorTest exte
1330       */
1331      public void testTimedInvokeAll4() throws Exception {
1332          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1333 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1334 +        l.add(new NPETask());
1335 +        List<Future<String>> futures =
1336 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1337 +        assertEquals(1, futures.size());
1338          try {
1339 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1352 <            l.add(new NPETask());
1353 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1354 <            assertEquals(1, result.size());
1355 <            for (Future<String> future : result)
1356 <                future.get();
1339 >            futures.get(0).get();
1340              shouldThrow();
1341          } catch (ExecutionException success) {
1342              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1368 | Line 1351 | public class ThreadPoolExecutorTest exte
1351      public void testTimedInvokeAll5() throws Exception {
1352          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1353          try {
1354 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1354 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1355              l.add(new StringTask());
1356              l.add(new StringTask());
1357 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1358 <            assertEquals(2, result.size());
1359 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1360 <                assertSame(TEST_STRING, it.next().get());
1357 >            List<Future<String>> futures =
1358 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1359 >            assertEquals(2, futures.size());
1360 >            for (Future<String> future : futures)
1361 >                assertSame(TEST_STRING, future.get());
1362          } finally {
1363              joinPool(e);
1364          }
# Line 1386 | Line 1370 | public class ThreadPoolExecutorTest exte
1370      public void testTimedInvokeAll6() throws Exception {
1371          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1372          try {
1373 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1373 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1374              l.add(new StringTask());
1375              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1376              l.add(new StringTask());
1377 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1378 <            assertEquals(3, result.size());
1379 <            Iterator<Future<String>> it = result.iterator();
1377 >            List<Future<String>> futures =
1378 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1379 >            assertEquals(3, futures.size());
1380 >            Iterator<Future<String>> it = futures.iterator();
1381              Future<String> f1 = it.next();
1382              Future<String> f2 = it.next();
1383              Future<String> f3 = it.next();
# Line 1413 | Line 1398 | public class ThreadPoolExecutorTest exte
1398      public void testFailingThreadFactory() throws InterruptedException {
1399          ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1400          try {
1401 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1401 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1402              for (int k = 0; k < 100; ++k) {
1403                  e.execute(new NoOpRunnable());
1404              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines