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.26 by jsr166, Mon Nov 16 05:30:08 2009 UTC vs.
Revision 1.27 by jsr166, Wed Nov 18 05:39:51 2009 UTC

# Line 7 | Line 7
7   */
8  
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   import java.util.concurrent.atomic.*;
12   import junit.framework.*;
13   import java.util.*;
# Line 24 | Line 25 | public class ThreadPoolExecutorTest exte
25          volatile boolean afterCalled = false;
26          volatile boolean terminatedCalled = false;
27          public ExtendedTPE() {
28 <            super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
28 >            super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue<Runnable>());
29          }
30          protected void beforeExecute(Thread t, Runnable r) {
31              beforeCalled = true;
# Line 49 | Line 50 | public class ThreadPoolExecutorTest exte
50      /**
51       *  execute successfully executes a runnable
52       */
53 <    public void testExecute() {
54 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
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 Runnable() {
56 <                    public void run() {
57 <                        try {
58 <                            Thread.sleep(SHORT_DELAY_MS);
59 <                        } catch (InterruptedException e) {
60 <                            threadUnexpectedException();
61 <                        }
62 <                    }
63 <                });
56 >            p1.execute(new ShortRunnable());
57              Thread.sleep(SMALL_DELAY_MS);
58 <        } catch (InterruptedException e) {
59 <            unexpectedException();
58 >        } finally {
59 >            joinPool(p1);
60          }
68        joinPool(p1);
61      }
62  
63      /**
64       *  getActiveCount increases but doesn't overestimate, when a
65       *  thread becomes active
66       */
67 <    public void testGetActiveCount() {
68 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
67 >    public void testGetActiveCount() throws InterruptedException {
68 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
69          assertEquals(0, p2.getActiveCount());
70          p2.execute(new MediumRunnable());
71 <        try {
80 <            Thread.sleep(SHORT_DELAY_MS);
81 <        } catch (Exception e) {
82 <            unexpectedException();
83 <        }
71 >        Thread.sleep(SHORT_DELAY_MS);
72          assertEquals(1, p2.getActiveCount());
73          joinPool(p2);
74      }
# Line 89 | Line 77 | public class ThreadPoolExecutorTest exte
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, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
80 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
81          assertEquals(0, p2.getPoolSize());
82          assertTrue(p2.prestartCoreThread());
83          assertEquals(1, p2.getPoolSize());
# Line 104 | Line 92 | public class ThreadPoolExecutorTest exte
92       *  prestartAllCoreThreads starts all corePoolSize threads
93       */
94      public void testPrestartAllCoreThreads() {
95 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
95 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
96          assertEquals(0, p2.getPoolSize());
97          p2.prestartAllCoreThreads();
98          assertEquals(2, p2.getPoolSize());
# Line 117 | Line 105 | public class ThreadPoolExecutorTest exte
105       *   getCompletedTaskCount increases, but doesn't overestimate,
106       *   when tasks complete
107       */
108 <    public void testGetCompletedTaskCount() {
109 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
108 >    public void testGetCompletedTaskCount() throws InterruptedException {
109 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
110          assertEquals(0, p2.getCompletedTaskCount());
111          p2.execute(new ShortRunnable());
112 <        try {
125 <            Thread.sleep(SMALL_DELAY_MS);
126 <        } catch (Exception e) {
127 <            unexpectedException();
128 <        }
112 >        Thread.sleep(SMALL_DELAY_MS);
113          assertEquals(1, p2.getCompletedTaskCount());
114          try { p2.shutdown(); } catch (SecurityException ok) { return; }
115          joinPool(p2);
# Line 135 | Line 119 | public class ThreadPoolExecutorTest exte
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, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
122 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
123          assertEquals(1, p1.getCorePoolSize());
124          joinPool(p1);
125      }
# Line 144 | Line 128 | public class ThreadPoolExecutorTest exte
128       *   getKeepAliveTime returns value given in constructor if not otherwise set
129       */
130      public void testGetKeepAliveTime() {
131 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
131 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
132          assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS));
133          joinPool(p2);
134      }
# Line 155 | Line 139 | public class ThreadPoolExecutorTest exte
139       */
140      public void testGetThreadFactory() {
141          ThreadFactory tf = new SimpleThreadFactory();
142 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
142 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
143          assertSame(tf, p.getThreadFactory());
144          joinPool(p);
145      }
# Line 164 | Line 148 | public class ThreadPoolExecutorTest exte
148       * setThreadFactory sets the thread factory returned by getThreadFactory
149       */
150      public void testSetThreadFactory() {
151 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
151 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
152          ThreadFactory tf = new SimpleThreadFactory();
153          p.setThreadFactory(tf);
154          assertSame(tf, p.getThreadFactory());
# Line 176 | Line 160 | public class ThreadPoolExecutorTest exte
160       * setThreadFactory(null) throws NPE
161       */
162      public void testSetThreadFactoryNull() {
163 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
163 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
164          try {
165              p.setThreadFactory(null);
166              shouldThrow();
# Line 191 | Line 175 | public class ThreadPoolExecutorTest exte
175       */
176      public void testGetRejectedExecutionHandler() {
177          RejectedExecutionHandler h = new NoOpREHandler();
178 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
178 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
179          assertSame(h, p.getRejectedExecutionHandler());
180          joinPool(p);
181      }
# Line 201 | Line 185 | public class ThreadPoolExecutorTest exte
185       * getRejectedExecutionHandler
186       */
187      public void testSetRejectedExecutionHandler() {
188 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
188 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
189          RejectedExecutionHandler h = new NoOpREHandler();
190          p.setRejectedExecutionHandler(h);
191          assertSame(h, p.getRejectedExecutionHandler());
# Line 213 | Line 197 | public class ThreadPoolExecutorTest exte
197       * setRejectedExecutionHandler(null) throws NPE
198       */
199      public void testSetRejectedExecutionHandlerNull() {
200 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
200 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
201          try {
202              p.setRejectedExecutionHandler(null);
203              shouldThrow();
# Line 228 | Line 212 | public class ThreadPoolExecutorTest exte
212       *   getLargestPoolSize increases, but doesn't overestimate, when
213       *   multiple threads active
214       */
215 <    public void testGetLargestPoolSize() {
216 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
217 <        try {
218 <            assertEquals(0, p2.getLargestPoolSize());
219 <            p2.execute(new MediumRunnable());
220 <            p2.execute(new MediumRunnable());
221 <            Thread.sleep(SHORT_DELAY_MS);
238 <            assertEquals(2, p2.getLargestPoolSize());
239 <        } catch (Exception e) {
240 <            unexpectedException();
241 <        }
215 >    public void testGetLargestPoolSize() throws InterruptedException {
216 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
217 >        assertEquals(0, p2.getLargestPoolSize());
218 >        p2.execute(new MediumRunnable());
219 >        p2.execute(new MediumRunnable());
220 >        Thread.sleep(SHORT_DELAY_MS);
221 >        assertEquals(2, p2.getLargestPoolSize());
222          joinPool(p2);
223      }
224  
# Line 247 | Line 227 | public class ThreadPoolExecutorTest exte
227       *   otherwise set
228       */
229      public void testGetMaximumPoolSize() {
230 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
230 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
231          assertEquals(2, p2.getMaximumPoolSize());
232          joinPool(p2);
233      }
# Line 257 | Line 237 | public class ThreadPoolExecutorTest exte
237       *   become active
238       */
239      public void testGetPoolSize() {
240 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
240 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
241          assertEquals(0, p1.getPoolSize());
242          p1.execute(new MediumRunnable());
243          assertEquals(1, p1.getPoolSize());
# Line 267 | Line 247 | public class ThreadPoolExecutorTest exte
247      /**
248       *  getTaskCount increases, but doesn't overestimate, when tasks submitted
249       */
250 <    public void testGetTaskCount() {
251 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
252 <        try {
253 <            assertEquals(0, p1.getTaskCount());
254 <            p1.execute(new MediumRunnable());
255 <            Thread.sleep(SHORT_DELAY_MS);
276 <            assertEquals(1, p1.getTaskCount());
277 <        } catch (Exception e) {
278 <            unexpectedException();
279 <        }
250 >    public void testGetTaskCount() throws InterruptedException {
251 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
252 >        assertEquals(0, p1.getTaskCount());
253 >        p1.execute(new MediumRunnable());
254 >        Thread.sleep(SHORT_DELAY_MS);
255 >        assertEquals(1, p1.getTaskCount());
256          joinPool(p1);
257      }
258  
# Line 285 | Line 261 | public class ThreadPoolExecutorTest exte
261       */
262      public void testIsShutdown() {
263  
264 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.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());
# Line 296 | Line 272 | public class ThreadPoolExecutorTest exte
272      /**
273       *  isTerminated is false before termination, true after
274       */
275 <    public void testIsTerminated() {
276 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
275 >    public void testIsTerminated() throws InterruptedException {
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());
280          } finally {
281              try { p1.shutdown(); } catch (SecurityException ok) { return; }
282          }
283 <        try {
284 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
309 <            assertTrue(p1.isTerminated());
310 <        } catch (Exception e) {
311 <            unexpectedException();
312 <        }
283 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
284 >        assertTrue(p1.isTerminated());
285      }
286  
287      /**
288       *  isTerminating is not true when running or when terminated
289       */
290 <    public void testIsTerminating() {
291 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
290 >    public void testIsTerminating() throws InterruptedException {
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 324 | Line 296 | public class ThreadPoolExecutorTest exte
296          } finally {
297              try { p1.shutdown(); } catch (SecurityException ok) { return; }
298          }
299 <        try {
300 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
301 <            assertTrue(p1.isTerminated());
330 <            assertFalse(p1.isTerminating());
331 <        } catch (Exception e) {
332 <            unexpectedException();
333 <        }
299 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
300 >        assertTrue(p1.isTerminated());
301 >        assertFalse(p1.isTerminating());
302      }
303  
304      /**
305       * getQueue returns the work queue, which contains queued tasks
306       */
307 <    public void testGetQueue() {
307 >    public void testGetQueue() throws InterruptedException {
308          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
309 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
309 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q);
310          FutureTask[] tasks = new FutureTask[5];
311          for (int i = 0; i < 5; i++) {
312              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
# Line 353 | Line 321 | public class ThreadPoolExecutorTest exte
321              for (int i = 1; i < 5; ++i)
322                  tasks[i].cancel(true);
323              p1.shutdownNow();
356        } catch (Exception e) {
357            unexpectedException();
324          } finally {
325              joinPool(p1);
326          }
# Line 363 | Line 329 | public class ThreadPoolExecutorTest exte
329      /**
330       * remove(task) removes queued task, and fails to remove active task
331       */
332 <    public void testRemove() {
332 >    public void testRemove() throws InterruptedException {
333          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
334 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
334 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q);
335          FutureTask[] tasks = new FutureTask[5];
336          for (int i = 0; i < 5; i++) {
337              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
# Line 382 | Line 348 | public class ThreadPoolExecutorTest exte
348              assertTrue(q.contains(tasks[3]));
349              assertTrue(p1.remove(tasks[3]));
350              assertFalse(q.contains(tasks[3]));
385        } catch (Exception e) {
386            unexpectedException();
351          } finally {
352              joinPool(p1);
353          }
# Line 393 | Line 357 | public class ThreadPoolExecutorTest exte
357       *   purge removes cancelled tasks from the queue
358       */
359      public void testPurge() {
360 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
360 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
361          FutureTask[] tasks = new FutureTask[5];
362          for (int i = 0; i < 5; i++) {
363              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
# Line 411 | 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, TimeUnit.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 435 | Line 399 | public class ThreadPoolExecutorTest exte
399       */
400      public void testConstructor1() {
401          try {
402 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
402 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
403              shouldThrow();
404          }
405          catch (IllegalArgumentException success) {}
# Line 446 | Line 410 | public class ThreadPoolExecutorTest exte
410       */
411      public void testConstructor2() {
412          try {
413 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
413 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
414              shouldThrow();
415          }
416          catch (IllegalArgumentException success) {}
# Line 457 | Line 421 | public class ThreadPoolExecutorTest exte
421       */
422      public void testConstructor3() {
423          try {
424 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
424 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
425              shouldThrow();
426          }
427          catch (IllegalArgumentException success) {}
# Line 468 | Line 432 | public class ThreadPoolExecutorTest exte
432       */
433      public void testConstructor4() {
434          try {
435 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
435 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
436              shouldThrow();
437          }
438          catch (IllegalArgumentException success) {}
# Line 479 | Line 443 | public class ThreadPoolExecutorTest exte
443       */
444      public void testConstructor5() {
445          try {
446 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
446 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
447              shouldThrow();
448          }
449          catch (IllegalArgumentException success) {}
# Line 490 | Line 454 | public class ThreadPoolExecutorTest exte
454       */
455      public void testConstructorNullPointerException() {
456          try {
457 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
457 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null);
458              shouldThrow();
459          }
460          catch (NullPointerException success) {}
# Line 503 | Line 467 | public class ThreadPoolExecutorTest exte
467       */
468      public void testConstructor6() {
469          try {
470 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
470 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
471              shouldThrow();
472 <        } catch (IllegalArgumentException success) {}
472 >        }
473 >        catch (IllegalArgumentException success) {}
474      }
475  
476      /**
# Line 513 | Line 478 | public class ThreadPoolExecutorTest exte
478       */
479      public void testConstructor7() {
480          try {
481 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
481 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
482              shouldThrow();
483          }
484          catch (IllegalArgumentException success) {}
# Line 524 | Line 489 | public class ThreadPoolExecutorTest exte
489       */
490      public void testConstructor8() {
491          try {
492 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
492 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
493              shouldThrow();
494          }
495          catch (IllegalArgumentException success) {}
# Line 535 | Line 500 | public class ThreadPoolExecutorTest exte
500       */
501      public void testConstructor9() {
502          try {
503 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
503 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
504              shouldThrow();
505          }
506          catch (IllegalArgumentException success) {}
# Line 546 | Line 511 | public class ThreadPoolExecutorTest exte
511       */
512      public void testConstructor10() {
513          try {
514 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
514 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
515              shouldThrow();
516          }
517          catch (IllegalArgumentException success) {}
# Line 557 | Line 522 | public class ThreadPoolExecutorTest exte
522       */
523      public void testConstructorNullPointerException2() {
524          try {
525 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
525 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
526              shouldThrow();
527          }
528          catch (NullPointerException success) {}
# Line 569 | Line 534 | public class ThreadPoolExecutorTest exte
534      public void testConstructorNullPointerException3() {
535          try {
536              ThreadFactory f = null;
537 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
537 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
538              shouldThrow();
539          }
540          catch (NullPointerException success) {}
# Line 581 | Line 546 | public class ThreadPoolExecutorTest exte
546       */
547      public void testConstructor11() {
548          try {
549 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
549 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
550              shouldThrow();
551          }
552          catch (IllegalArgumentException success) {}
# Line 592 | Line 557 | public class ThreadPoolExecutorTest exte
557       */
558      public void testConstructor12() {
559          try {
560 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
560 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
561              shouldThrow();
562          }
563          catch (IllegalArgumentException success) {}
# Line 603 | Line 568 | public class ThreadPoolExecutorTest exte
568       */
569      public void testConstructor13() {
570          try {
571 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
571 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
572              shouldThrow();
573          }
574          catch (IllegalArgumentException success) {}
# Line 614 | Line 579 | public class ThreadPoolExecutorTest exte
579       */
580      public void testConstructor14() {
581          try {
582 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
582 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
583              shouldThrow();
584          }
585          catch (IllegalArgumentException success) {}
# Line 625 | Line 590 | public class ThreadPoolExecutorTest exte
590       */
591      public void testConstructor15() {
592          try {
593 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
593 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
594              shouldThrow();
595          }
596          catch (IllegalArgumentException success) {}
# Line 636 | Line 601 | public class ThreadPoolExecutorTest exte
601       */
602      public void testConstructorNullPointerException4() {
603          try {
604 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
604 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
605              shouldThrow();
606          }
607          catch (NullPointerException success) {}
# Line 648 | Line 613 | public class ThreadPoolExecutorTest exte
613      public void testConstructorNullPointerException5() {
614          try {
615              RejectedExecutionHandler r = null;
616 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
616 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
617              shouldThrow();
618          }
619          catch (NullPointerException success) {}
# Line 660 | Line 625 | public class ThreadPoolExecutorTest exte
625       */
626      public void testConstructor16() {
627          try {
628 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
628 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
629              shouldThrow();
630          }
631          catch (IllegalArgumentException success) {}
# Line 671 | Line 636 | public class ThreadPoolExecutorTest exte
636       */
637      public void testConstructor17() {
638          try {
639 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
639 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
640              shouldThrow();
641          }
642          catch (IllegalArgumentException success) {}
# Line 682 | Line 647 | public class ThreadPoolExecutorTest exte
647       */
648      public void testConstructor18() {
649          try {
650 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
650 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
651              shouldThrow();
652          }
653          catch (IllegalArgumentException success) {}
# Line 693 | Line 658 | public class ThreadPoolExecutorTest exte
658       */
659      public void testConstructor19() {
660          try {
661 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
661 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
662              shouldThrow();
663          }
664          catch (IllegalArgumentException success) {}
# Line 704 | Line 669 | public class ThreadPoolExecutorTest exte
669       */
670      public void testConstructor20() {
671          try {
672 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
672 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
673              shouldThrow();
674          }
675          catch (IllegalArgumentException success) {}
# Line 715 | Line 680 | public class ThreadPoolExecutorTest exte
680       */
681      public void testConstructorNullPointerException6() {
682          try {
683 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
683 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
684              shouldThrow();
685          }
686          catch (NullPointerException success) {}
# Line 727 | Line 692 | public class ThreadPoolExecutorTest exte
692      public void testConstructorNullPointerException7() {
693          try {
694              RejectedExecutionHandler r = null;
695 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
695 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
696              shouldThrow();
697          }
698          catch (NullPointerException success) {}
# Line 739 | Line 704 | public class ThreadPoolExecutorTest exte
704      public void testConstructorNullPointerException8() {
705          try {
706              ThreadFactory f = null;
707 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
707 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
708              shouldThrow();
709          }
710 <        catch (NullPointerException successdn8) {}
710 >        catch (NullPointerException success) {}
711      }
712  
713  
# Line 751 | Line 716 | public class ThreadPoolExecutorTest exte
716       *  if saturated.
717       */
718      public void testSaturatedExecute() {
719 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
719 >        ThreadPoolExecutor p =
720 >            new ThreadPoolExecutor(1, 1,
721 >                                   LONG_DELAY_MS, MILLISECONDS,
722 >                                   new ArrayBlockingQueue<Runnable>(1));
723          try {
724 <
757 <            for (int i = 0; i < 5; ++i) {
724 >            for (int i = 0; i < 2; ++i)
725                  p.execute(new MediumRunnable());
726 +            for (int i = 0; i < 2; ++i) {
727 +                try {
728 +                    p.execute(new MediumRunnable());
729 +                    shouldThrow();
730 +                } catch (RejectedExecutionException success) {}
731              }
732 <            shouldThrow();
733 <        } catch (RejectedExecutionException success) {}
734 <        joinPool(p);
732 >        } finally {
733 >            joinPool(p);
734 >        }
735      }
736  
737      /**
# Line 767 | Line 739 | public class ThreadPoolExecutorTest exte
739       */
740      public void testSaturatedExecute2() {
741          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
742 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
742 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
743          try {
744  
745              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
# Line 783 | Line 755 | public class ThreadPoolExecutorTest exte
755                  assertTrue(tasks[i].done);
756              }
757              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
786        } catch (RejectedExecutionException ex) {
787            unexpectedException();
758          } finally {
759              joinPool(p);
760          }
# Line 795 | Line 765 | public class ThreadPoolExecutorTest exte
765       */
766      public void testSaturatedExecute3() {
767          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
768 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
768 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
769          try {
770  
771              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
# Line 810 | Line 780 | public class ThreadPoolExecutorTest exte
780                  assertFalse(tasks[i].done);
781              }
782              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
813        } catch (RejectedExecutionException ex) {
814            unexpectedException();
783          } finally {
784              joinPool(p);
785          }
# Line 822 | Line 790 | public class ThreadPoolExecutorTest exte
790       */
791      public void testSaturatedExecute4() {
792          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
793 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
793 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
794          try {
795              p.execute(new TrackedLongRunnable());
796              TrackedLongRunnable r2 = new TrackedLongRunnable();
# Line 833 | Line 801 | public class ThreadPoolExecutorTest exte
801              assertFalse(p.getQueue().contains(r2));
802              assertTrue(p.getQueue().contains(r3));
803              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
836        } catch (RejectedExecutionException ex) {
837            unexpectedException();
804          } finally {
805              joinPool(p);
806          }
# Line 845 | Line 811 | public class ThreadPoolExecutorTest exte
811       */
812      public void testRejectedExecutionExceptionOnShutdown() {
813          ThreadPoolExecutor tpe =
814 <            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
814 >            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
815          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
816          try {
817              tpe.execute(new NoOpRunnable());
# Line 860 | Line 826 | public class ThreadPoolExecutorTest exte
826       */
827      public void testCallerRunsOnShutdown() {
828          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
829 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
829 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
830  
831          try { p.shutdown(); } catch (SecurityException ok) { return; }
832          try {
833              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
834              p.execute(r);
835              assertFalse(r.done);
870        } catch (RejectedExecutionException success) {
871            unexpectedException();
836          } finally {
837              joinPool(p);
838          }
# Line 879 | Line 843 | public class ThreadPoolExecutorTest exte
843       */
844      public void testDiscardOnShutdown() {
845          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
846 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
846 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
847  
848          try { p.shutdown(); } catch (SecurityException ok) { return; }
849          try {
850              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
851              p.execute(r);
852              assertFalse(r.done);
889        } catch (RejectedExecutionException success) {
890            unexpectedException();
853          } finally {
854              joinPool(p);
855          }
# Line 899 | Line 861 | public class ThreadPoolExecutorTest exte
861       */
862      public void testDiscardOldestOnShutdown() {
863          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
864 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
864 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
865  
866          try { p.shutdown(); } catch (SecurityException ok) { return; }
867          try {
868              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
869              p.execute(r);
870              assertFalse(r.done);
909        } catch (RejectedExecutionException success) {
910            unexpectedException();
871          } finally {
872              joinPool(p);
873          }
# Line 920 | Line 880 | public class ThreadPoolExecutorTest exte
880      public void testExecuteNull() {
881          ThreadPoolExecutor tpe = null;
882          try {
883 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
883 >            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
884              tpe.execute(null);
885              shouldThrow();
886          } catch (NullPointerException success) {}
# Line 932 | Line 892 | public class ThreadPoolExecutorTest exte
892       *  setCorePoolSize of negative value throws IllegalArgumentException
893       */
894      public void testCorePoolSizeIllegalArgumentException() {
895 <        ThreadPoolExecutor tpe = null;
896 <        try {
897 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
898 <        } catch (Exception e) {}
895 >        ThreadPoolExecutor tpe =
896 >            new ThreadPoolExecutor(1, 2,
897 >                                   LONG_DELAY_MS, MILLISECONDS,
898 >                                   new ArrayBlockingQueue<Runnable>(10));
899          try {
900              tpe.setCorePoolSize(-1);
901              shouldThrow();
# Line 951 | Line 911 | public class ThreadPoolExecutorTest exte
911       *  given a value less the core pool size
912       */
913      public void testMaximumPoolSizeIllegalArgumentException() {
914 <        ThreadPoolExecutor tpe = null;
915 <        try {
916 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
917 <        } catch (Exception e) {}
914 >        ThreadPoolExecutor tpe =
915 >            new ThreadPoolExecutor(2, 3,
916 >                                   LONG_DELAY_MS, MILLISECONDS,
917 >                                   new ArrayBlockingQueue<Runnable>(10));
918          try {
919              tpe.setMaximumPoolSize(1);
920              shouldThrow();
# Line 970 | Line 930 | public class ThreadPoolExecutorTest exte
930       *  if given a negative value
931       */
932      public void testMaximumPoolSizeIllegalArgumentException2() {
933 <        ThreadPoolExecutor tpe = null;
934 <        try {
935 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
936 <        } catch (Exception e) {}
933 >        ThreadPoolExecutor tpe =
934 >            new ThreadPoolExecutor(2, 3,
935 >                                   LONG_DELAY_MS, MILLISECONDS,
936 >                                   new ArrayBlockingQueue<Runnable>(10));
937          try {
938              tpe.setMaximumPoolSize(-1);
939              shouldThrow();
# Line 990 | Line 950 | public class ThreadPoolExecutorTest exte
950       *  when given a negative value
951       */
952      public void testKeepAliveTimeIllegalArgumentException() {
953 <        ThreadPoolExecutor tpe = null;
954 <        try {
955 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
956 <        } catch (Exception e) {}
997 <
953 >        ThreadPoolExecutor tpe =
954 >            new ThreadPoolExecutor(2, 3,
955 >                                   LONG_DELAY_MS, MILLISECONDS,
956 >                                   new ArrayBlockingQueue<Runnable>(10));
957          try {
958 <            tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
958 >            tpe.setKeepAliveTime(-1,MILLISECONDS);
959              shouldThrow();
960          } catch (IllegalArgumentException success) {
961          } finally {
# Line 1018 | Line 977 | public class ThreadPoolExecutorTest exte
977      /**
978       * beforeExecute and afterExecute are called when executing task
979       */
980 <    public void testBeforeAfter() {
980 >    public void testBeforeAfter() throws InterruptedException {
981          ExtendedTPE tpe = new ExtendedTPE();
982          try {
983              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1028 | Line 987 | public class ThreadPoolExecutorTest exte
987              assertTrue(tpe.beforeCalled);
988              assertTrue(tpe.afterCalled);
989              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1031        }
1032        catch (Exception ex) {
1033            unexpectedException();
990          } finally {
991              joinPool(tpe);
992          }
# Line 1039 | Line 995 | public class ThreadPoolExecutorTest exte
995      /**
996       * completed submit of callable returns result
997       */
998 <    public void testSubmitCallable() {
999 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
998 >    public void testSubmitCallable() throws Exception {
999 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1000          try {
1001              Future<String> future = e.submit(new StringTask());
1002              String result = future.get();
1003              assertSame(TEST_STRING, result);
1048        }
1049        catch (ExecutionException ex) {
1050            unexpectedException();
1051        }
1052        catch (InterruptedException ex) {
1053            unexpectedException();
1004          } finally {
1005              joinPool(e);
1006          }
# Line 1059 | Line 1009 | public class ThreadPoolExecutorTest exte
1009      /**
1010       * completed submit of runnable returns successfully
1011       */
1012 <    public void testSubmitRunnable() {
1013 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1012 >    public void testSubmitRunnable() throws Exception {
1013 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1014          try {
1015              Future<?> future = e.submit(new NoOpRunnable());
1016              future.get();
1017              assertTrue(future.isDone());
1068        }
1069        catch (ExecutionException ex) {
1070            unexpectedException();
1071        }
1072        catch (InterruptedException ex) {
1073            unexpectedException();
1018          } finally {
1019              joinPool(e);
1020          }
# Line 1079 | Line 1023 | public class ThreadPoolExecutorTest exte
1023      /**
1024       * completed submit of (runnable, result) returns result
1025       */
1026 <    public void testSubmitRunnable2() {
1027 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1026 >    public void testSubmitRunnable2() throws Exception {
1027 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1028          try {
1029              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1030              String result = future.get();
1031              assertSame(TEST_STRING, result);
1088        }
1089        catch (ExecutionException ex) {
1090            unexpectedException();
1091        }
1092        catch (InterruptedException ex) {
1093            unexpectedException();
1032          } finally {
1033              joinPool(e);
1034          }
1035      }
1036  
1037  
1100
1101
1102
1038      /**
1039       * invokeAny(null) throws NPE
1040       */
1041 <    public void testInvokeAny1() {
1042 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1041 >    public void testInvokeAny1() throws Exception {
1042 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1043          try {
1044              e.invokeAny(null);
1045 +            shouldThrow();
1046          } catch (NullPointerException success) {
1111        } catch (Exception ex) {
1112            unexpectedException();
1047          } finally {
1048              joinPool(e);
1049          }
# Line 1118 | Line 1052 | public class ThreadPoolExecutorTest exte
1052      /**
1053       * invokeAny(empty collection) throws IAE
1054       */
1055 <    public void testInvokeAny2() {
1056 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1055 >    public void testInvokeAny2() throws Exception {
1056 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1057          try {
1058              e.invokeAny(new ArrayList<Callable<String>>());
1059 +            shouldThrow();
1060          } catch (IllegalArgumentException success) {
1126        } catch (Exception ex) {
1127            unexpectedException();
1061          } finally {
1062              joinPool(e);
1063          }
# Line 1133 | Line 1066 | public class ThreadPoolExecutorTest exte
1066      /**
1067       * invokeAny(c) throws NPE if c has null elements
1068       */
1069 <    public void testInvokeAny3() {
1070 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1069 >    public void testInvokeAny3() throws Exception {
1070 >        final CountDownLatch latch = new CountDownLatch(1);
1071 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1072          try {
1073              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1074 <            l.add(new StringTask());
1074 >            l.add(new CheckedCallable<String>() {
1075 >                      public String realCall() throws InterruptedException {
1076 >                          latch.await();
1077 >                          return TEST_STRING;
1078 >                      }});
1079              l.add(null);
1080              e.invokeAny(l);
1081 +            shouldThrow();
1082          } catch (NullPointerException success) {
1144        } catch (Exception ex) {
1145            unexpectedException();
1083          } finally {
1084 +            latch.countDown();
1085              joinPool(e);
1086          }
1087      }
# Line 1151 | Line 1089 | public class ThreadPoolExecutorTest exte
1089      /**
1090       * invokeAny(c) throws ExecutionException if no task completes
1091       */
1092 <    public void testInvokeAny4() {
1093 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1092 >    public void testInvokeAny4() throws Exception {
1093 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1094          try {
1095              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1096              l.add(new NPETask());
1097              e.invokeAny(l);
1098 +            shouldThrow();
1099          } catch (ExecutionException success) {
1100 <        } catch (Exception ex) {
1162 <            unexpectedException();
1100 >            assertTrue(success.getCause() instanceof NullPointerException);
1101          } finally {
1102              joinPool(e);
1103          }
# Line 1168 | Line 1106 | public class ThreadPoolExecutorTest exte
1106      /**
1107       * invokeAny(c) returns result of some task
1108       */
1109 <    public void testInvokeAny5() {
1110 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1109 >    public void testInvokeAny5() throws Exception {
1110 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1111          try {
1112              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1113              l.add(new StringTask());
1114              l.add(new StringTask());
1115              String result = e.invokeAny(l);
1116              assertSame(TEST_STRING, result);
1179        } catch (ExecutionException success) {
1180        } catch (Exception ex) {
1181            unexpectedException();
1117          } finally {
1118              joinPool(e);
1119          }
# Line 1187 | Line 1122 | public class ThreadPoolExecutorTest exte
1122      /**
1123       * invokeAll(null) throws NPE
1124       */
1125 <    public void testInvokeAll1() {
1126 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1125 >    public void testInvokeAll1() throws Exception {
1126 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1127          try {
1128              e.invokeAll(null);
1129 +            shouldThrow();
1130          } catch (NullPointerException success) {
1195        } catch (Exception ex) {
1196            unexpectedException();
1131          } finally {
1132              joinPool(e);
1133          }
# Line 1202 | Line 1136 | public class ThreadPoolExecutorTest exte
1136      /**
1137       * invokeAll(empty collection) returns empty collection
1138       */
1139 <    public void testInvokeAll2() {
1140 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1139 >    public void testInvokeAll2() throws InterruptedException {
1140 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1141          try {
1142              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1143              assertTrue(r.isEmpty());
1210        } catch (Exception ex) {
1211            unexpectedException();
1144          } finally {
1145              joinPool(e);
1146          }
# Line 1217 | Line 1149 | public class ThreadPoolExecutorTest exte
1149      /**
1150       * invokeAll(c) throws NPE if c has null elements
1151       */
1152 <    public void testInvokeAll3() {
1153 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1152 >    public void testInvokeAll3() throws Exception {
1153 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1154          try {
1155              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1156              l.add(new StringTask());
1157              l.add(null);
1158              e.invokeAll(l);
1159 +            shouldThrow();
1160          } catch (NullPointerException success) {
1228        } catch (Exception ex) {
1229            unexpectedException();
1161          } finally {
1162              joinPool(e);
1163          }
# Line 1235 | Line 1166 | public class ThreadPoolExecutorTest exte
1166      /**
1167       * get of element of invokeAll(c) throws exception on failed task
1168       */
1169 <    public void testInvokeAll4() {
1170 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1169 >    public void testInvokeAll4() throws Exception {
1170 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1171          try {
1172              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1173              l.add(new NPETask());
1174              List<Future<String>> result = e.invokeAll(l);
1175              assertEquals(1, result.size());
1176 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1177 <                it.next().get();
1178 <        } catch (ExecutionException success) {
1179 <        } catch (Exception ex) {
1180 <            unexpectedException();
1176 >            for (Future<String> future : result) {
1177 >                try {
1178 >                    future.get();
1179 >                    shouldThrow();
1180 >                } catch (ExecutionException success) {
1181 >                    Throwable cause = success.getCause();
1182 >                    assertTrue(cause instanceof NullPointerException);
1183 >                }
1184 >            }
1185          } finally {
1186              joinPool(e);
1187          }
# Line 1255 | Line 1190 | public class ThreadPoolExecutorTest exte
1190      /**
1191       * invokeAll(c) returns results of all completed tasks
1192       */
1193 <    public void testInvokeAll5() {
1194 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1193 >    public void testInvokeAll5() throws Exception {
1194 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1195          try {
1196              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1197              l.add(new StringTask());
1198              l.add(new StringTask());
1199              List<Future<String>> result = e.invokeAll(l);
1200              assertEquals(2, result.size());
1201 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1202 <                assertSame(TEST_STRING, it.next().get());
1268 <        } catch (ExecutionException success) {
1269 <        } catch (Exception ex) {
1270 <            unexpectedException();
1201 >            for (Future<String> future : result)
1202 >                assertSame(TEST_STRING, future.get());
1203          } finally {
1204              joinPool(e);
1205          }
# Line 1278 | Line 1210 | public class ThreadPoolExecutorTest exte
1210      /**
1211       * timed invokeAny(null) throws NPE
1212       */
1213 <    public void testTimedInvokeAny1() {
1214 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1213 >    public void testTimedInvokeAny1() throws Exception {
1214 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1215          try {
1216 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1216 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1217 >            shouldThrow();
1218          } catch (NullPointerException success) {
1286        } catch (Exception ex) {
1287            unexpectedException();
1219          } finally {
1220              joinPool(e);
1221          }
# Line 1293 | Line 1224 | public class ThreadPoolExecutorTest exte
1224      /**
1225       * timed invokeAny(,,null) throws NPE
1226       */
1227 <    public void testTimedInvokeAnyNullTimeUnit() {
1228 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1227 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1228 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1229          try {
1230              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1231              l.add(new StringTask());
1232              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1233 +            shouldThrow();
1234          } catch (NullPointerException success) {
1303        } catch (Exception ex) {
1304            unexpectedException();
1235          } finally {
1236              joinPool(e);
1237          }
# Line 1310 | Line 1240 | public class ThreadPoolExecutorTest exte
1240      /**
1241       * timed invokeAny(empty collection) throws IAE
1242       */
1243 <    public void testTimedInvokeAny2() {
1244 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1243 >    public void testTimedInvokeAny2() throws Exception {
1244 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1245          try {
1246 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1246 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1247 >            shouldThrow();
1248          } catch (IllegalArgumentException success) {
1318        } catch (Exception ex) {
1319            unexpectedException();
1249          } finally {
1250              joinPool(e);
1251          }
# Line 1325 | Line 1254 | public class ThreadPoolExecutorTest exte
1254      /**
1255       * timed invokeAny(c) throws NPE if c has null elements
1256       */
1257 <    public void testTimedInvokeAny3() {
1258 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257 >    public void testTimedInvokeAny3() throws Exception {
1258 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1259          try {
1260              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1261              l.add(new StringTask());
1262              l.add(null);
1263 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1263 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1264 >            shouldThrow();
1265          } catch (NullPointerException success) {
1336        } catch (Exception ex) {
1337            ex.printStackTrace();
1338            unexpectedException();
1266          } finally {
1267              joinPool(e);
1268          }
# Line 1344 | Line 1271 | public class ThreadPoolExecutorTest exte
1271      /**
1272       * timed invokeAny(c) throws ExecutionException if no task completes
1273       */
1274 <    public void testTimedInvokeAny4() {
1275 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1274 >    public void testTimedInvokeAny4() throws Exception {
1275 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1276          try {
1277              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1278              l.add(new NPETask());
1279 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1279 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1280 >            shouldThrow();
1281          } catch (ExecutionException success) {
1282 <        } catch (Exception ex) {
1355 <            unexpectedException();
1282 >            assertTrue(success.getCause() instanceof NullPointerException);
1283          } finally {
1284              joinPool(e);
1285          }
# Line 1361 | Line 1288 | public class ThreadPoolExecutorTest exte
1288      /**
1289       * timed invokeAny(c) returns result of some task
1290       */
1291 <    public void testTimedInvokeAny5() {
1292 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1291 >    public void testTimedInvokeAny5() throws Exception {
1292 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1293          try {
1294              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1295              l.add(new StringTask());
1296              l.add(new StringTask());
1297 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1297 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1298              assertSame(TEST_STRING, result);
1372        } catch (ExecutionException success) {
1373        } catch (Exception ex) {
1374            unexpectedException();
1299          } finally {
1300              joinPool(e);
1301          }
# Line 1380 | Line 1304 | public class ThreadPoolExecutorTest exte
1304      /**
1305       * timed invokeAll(null) throws NPE
1306       */
1307 <    public void testTimedInvokeAll1() {
1308 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1307 >    public void testTimedInvokeAll1() throws Exception {
1308 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1309          try {
1310 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1310 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1311 >            shouldThrow();
1312          } catch (NullPointerException success) {
1388        } catch (Exception ex) {
1389            unexpectedException();
1313          } finally {
1314              joinPool(e);
1315          }
# Line 1395 | Line 1318 | public class ThreadPoolExecutorTest exte
1318      /**
1319       * timed invokeAll(,,null) throws NPE
1320       */
1321 <    public void testTimedInvokeAllNullTimeUnit() {
1322 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1321 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1322 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1323          try {
1324              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1325              l.add(new StringTask());
1326              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1327 +            shouldThrow();
1328          } catch (NullPointerException success) {
1405        } catch (Exception ex) {
1406            unexpectedException();
1329          } finally {
1330              joinPool(e);
1331          }
# Line 1412 | Line 1334 | public class ThreadPoolExecutorTest exte
1334      /**
1335       * timed invokeAll(empty collection) returns empty collection
1336       */
1337 <    public void testTimedInvokeAll2() {
1338 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1337 >    public void testTimedInvokeAll2() throws InterruptedException {
1338 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1339          try {
1340 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1340 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1341              assertTrue(r.isEmpty());
1420        } catch (Exception ex) {
1421            unexpectedException();
1342          } finally {
1343              joinPool(e);
1344          }
# Line 1427 | Line 1347 | public class ThreadPoolExecutorTest exte
1347      /**
1348       * timed invokeAll(c) throws NPE if c has null elements
1349       */
1350 <    public void testTimedInvokeAll3() {
1351 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1350 >    public void testTimedInvokeAll3() throws Exception {
1351 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1352          try {
1353              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1354              l.add(new StringTask());
1355              l.add(null);
1356 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1356 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1357 >            shouldThrow();
1358          } catch (NullPointerException success) {
1438        } catch (Exception ex) {
1439            unexpectedException();
1359          } finally {
1360              joinPool(e);
1361          }
# Line 1445 | Line 1364 | public class ThreadPoolExecutorTest exte
1364      /**
1365       * get of element of invokeAll(c) throws exception on failed task
1366       */
1367 <    public void testTimedInvokeAll4() {
1368 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1367 >    public void testTimedInvokeAll4() throws Exception {
1368 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1369          try {
1370              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1371              l.add(new NPETask());
1372 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1372 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1373              assertEquals(1, result.size());
1374 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1375 <                it.next().get();
1374 >            for (Future<String> future : result)
1375 >                future.get();
1376 >            shouldThrow();
1377          } catch (ExecutionException success) {
1378 <        } catch (Exception ex) {
1459 <            unexpectedException();
1378 >            assertTrue(success.getCause() instanceof NullPointerException);
1379          } finally {
1380              joinPool(e);
1381          }
# Line 1465 | Line 1384 | public class ThreadPoolExecutorTest exte
1384      /**
1385       * timed invokeAll(c) returns results of all completed tasks
1386       */
1387 <    public void testTimedInvokeAll5() {
1388 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1387 >    public void testTimedInvokeAll5() throws Exception {
1388 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1389          try {
1390              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1391              l.add(new StringTask());
1392              l.add(new StringTask());
1393 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1393 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1394              assertEquals(2, result.size());
1395              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1396                  assertSame(TEST_STRING, it.next().get());
1478        } catch (ExecutionException success) {
1479        } catch (Exception ex) {
1480            unexpectedException();
1397          } finally {
1398              joinPool(e);
1399          }
# Line 1486 | Line 1402 | public class ThreadPoolExecutorTest exte
1402      /**
1403       * timed invokeAll(c) cancels tasks not completed by timeout
1404       */
1405 <    public void testTimedInvokeAll6() {
1406 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1405 >    public void testTimedInvokeAll6() throws Exception {
1406 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1407          try {
1408              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1409              l.add(new StringTask());
1410              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1411              l.add(new StringTask());
1412 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1412 >            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1413              assertEquals(3, result.size());
1414              Iterator<Future<String>> it = result.iterator();
1415              Future<String> f1 = it.next();
# Line 1504 | Line 1420 | public class ThreadPoolExecutorTest exte
1420              assertTrue(f3.isDone());
1421              assertFalse(f1.isCancelled());
1422              assertTrue(f2.isCancelled());
1507        } catch (Exception ex) {
1508            unexpectedException();
1423          } finally {
1424              joinPool(e);
1425          }
# Line 1515 | Line 1429 | public class ThreadPoolExecutorTest exte
1429       * Execution continues if there is at least one thread even if
1430       * thread factory fails to create more
1431       */
1432 <    public void testFailingThreadFactory() {
1433 <        ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1432 >    public void testFailingThreadFactory() throws InterruptedException {
1433 >        ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1434          try {
1435              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1436              for (int k = 0; k < 100; ++k) {
1437                  e.execute(new NoOpRunnable());
1438              }
1439              Thread.sleep(LONG_DELAY_MS);
1526        } catch (Exception ex) {
1527            unexpectedException();
1440          } finally {
1441              joinPool(e);
1442          }
# Line 1534 | Line 1446 | public class ThreadPoolExecutorTest exte
1446       * allowsCoreThreadTimeOut is by default false.
1447       */
1448      public void testAllowsCoreThreadTimeOut() {
1449 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1449 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1450          assertFalse(tpe.allowsCoreThreadTimeOut());
1451          joinPool(tpe);
1452      }
# Line 1542 | Line 1454 | public class ThreadPoolExecutorTest exte
1454      /**
1455       * allowCoreThreadTimeOut(true) causes idle threads to time out
1456       */
1457 <    public void testAllowCoreThreadTimeOut_true() {
1458 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1457 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1458 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1459          tpe.allowCoreThreadTimeOut(true);
1460          tpe.execute(new NoOpRunnable());
1461          try {
1462              Thread.sleep(MEDIUM_DELAY_MS);
1463              assertEquals(0, tpe.getPoolSize());
1552        } catch (InterruptedException e) {
1553            unexpectedException();
1464          } finally {
1465              joinPool(tpe);
1466          }
# Line 1559 | Line 1469 | public class ThreadPoolExecutorTest exte
1469      /**
1470       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1471       */
1472 <    public void testAllowCoreThreadTimeOut_false() {
1473 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1472 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1473 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1474          tpe.allowCoreThreadTimeOut(false);
1475          tpe.execute(new NoOpRunnable());
1476          try {
1477              Thread.sleep(MEDIUM_DELAY_MS);
1478              assertTrue(tpe.getPoolSize() >= 1);
1569        } catch (InterruptedException e) {
1570            unexpectedException();
1479          } finally {
1480              joinPool(tpe);
1481          }
# Line 1577 | Line 1485 | public class ThreadPoolExecutorTest exte
1485       * execute allows the same task to be submitted multiple times, even
1486       * if rejected
1487       */
1488 <    public void testRejectedRecycledTask() {
1488 >    public void testRejectedRecycledTask() throws InterruptedException {
1489          final int nTasks = 1000;
1490          final AtomicInteger nRun = new AtomicInteger(0);
1491          final Runnable recycledTask = new Runnable() {
# Line 1600 | Line 1508 | public class ThreadPoolExecutorTest exte
1508              }
1509              Thread.sleep(5000); // enough time to run all tasks
1510              assertEquals(nRun.get(), nTasks);
1603        } catch (Exception ex) {
1604            ex.printStackTrace();
1605            unexpectedException();
1511          } finally {
1512              p.shutdown();
1513          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines