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.25 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.28 by jsr166, Wed Nov 18 16:13:11 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 37 | Line 38 | public class ThreadPoolExecutorTest exte
38          }
39      }
40  
41 <    static class FailingThreadFactory implements ThreadFactory{
41 >    static class FailingThreadFactory implements ThreadFactory {
42          int calls = 0;
43 <        public Thread newThread(Runnable r){
43 >        public Thread newThread(Runnable r) {
44              if (++calls > 1) return null;
45              return new Thread(r);
46          }
# 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++){
311 >        for (int i = 0; i < 5; i++) {
312              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
313              p1.execute(tasks[i]);
314          }
# 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++){
336 >        for (int i = 0; i < 5; i++) {
337              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
338              p1.execute(tasks[i]);
339          }
# 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++){
362 >        for (int i = 0; i < 5; i++) {
363              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
364              p1.execute(tasks[i]);
365          }
# 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 <        }
441 <        catch (IllegalArgumentException success){}
404 >        } catch (IllegalArgumentException success) {}
405      }
406  
407      /**
# Line 446 | Line 409 | public class ThreadPoolExecutorTest exte
409       */
410      public void testConstructor2() {
411          try {
412 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
412 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
413              shouldThrow();
414 <        }
452 <        catch (IllegalArgumentException success){}
414 >        } catch (IllegalArgumentException success) {}
415      }
416  
417      /**
# Line 457 | Line 419 | public class ThreadPoolExecutorTest exte
419       */
420      public void testConstructor3() {
421          try {
422 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
422 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
423              shouldThrow();
424 <        }
463 <        catch (IllegalArgumentException success){}
424 >        } catch (IllegalArgumentException success) {}
425      }
426  
427      /**
# Line 468 | Line 429 | public class ThreadPoolExecutorTest exte
429       */
430      public void testConstructor4() {
431          try {
432 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
432 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
433              shouldThrow();
434 <        }
474 <        catch (IllegalArgumentException success){}
434 >        } catch (IllegalArgumentException success) {}
435      }
436  
437      /**
# Line 479 | Line 439 | public class ThreadPoolExecutorTest exte
439       */
440      public void testConstructor5() {
441          try {
442 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
442 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
443              shouldThrow();
444 <        }
485 <        catch (IllegalArgumentException success){}
444 >        } catch (IllegalArgumentException success) {}
445      }
446  
447      /**
# Line 490 | Line 449 | public class ThreadPoolExecutorTest exte
449       */
450      public void testConstructorNullPointerException() {
451          try {
452 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
452 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null);
453              shouldThrow();
454 <        }
496 <        catch (NullPointerException success){}
454 >        } catch (NullPointerException success) {}
455      }
456  
457  
# Line 503 | Line 461 | public class ThreadPoolExecutorTest exte
461       */
462      public void testConstructor6() {
463          try {
464 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
464 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
465              shouldThrow();
466 <        } catch (IllegalArgumentException success){}
466 >        } catch (IllegalArgumentException success) {}
467      }
468  
469      /**
# Line 513 | Line 471 | public class ThreadPoolExecutorTest exte
471       */
472      public void testConstructor7() {
473          try {
474 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
474 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
475              shouldThrow();
476 <        }
519 <        catch (IllegalArgumentException success){}
476 >        } catch (IllegalArgumentException success) {}
477      }
478  
479      /**
# Line 524 | Line 481 | public class ThreadPoolExecutorTest exte
481       */
482      public void testConstructor8() {
483          try {
484 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
484 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
485              shouldThrow();
486 <        }
530 <        catch (IllegalArgumentException success){}
486 >        } catch (IllegalArgumentException success) {}
487      }
488  
489      /**
# Line 535 | Line 491 | public class ThreadPoolExecutorTest exte
491       */
492      public void testConstructor9() {
493          try {
494 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
494 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
495              shouldThrow();
496 <        }
541 <        catch (IllegalArgumentException success){}
496 >        } catch (IllegalArgumentException success) {}
497      }
498  
499      /**
# Line 546 | Line 501 | public class ThreadPoolExecutorTest exte
501       */
502      public void testConstructor10() {
503          try {
504 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
504 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
505              shouldThrow();
506 <        }
552 <        catch (IllegalArgumentException success){}
506 >        } catch (IllegalArgumentException success) {}
507      }
508  
509      /**
# Line 557 | Line 511 | public class ThreadPoolExecutorTest exte
511       */
512      public void testConstructorNullPointerException2() {
513          try {
514 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
514 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
515              shouldThrow();
516 <        }
563 <        catch (NullPointerException success){}
516 >        } catch (NullPointerException success) {}
517      }
518  
519      /**
# Line 569 | Line 522 | public class ThreadPoolExecutorTest exte
522      public void testConstructorNullPointerException3() {
523          try {
524              ThreadFactory f = null;
525 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
525 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
526              shouldThrow();
527 <        }
575 <        catch (NullPointerException success){}
527 >        } catch (NullPointerException success) {}
528      }
529  
530  
# Line 581 | Line 533 | public class ThreadPoolExecutorTest exte
533       */
534      public void testConstructor11() {
535          try {
536 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
536 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
537              shouldThrow();
538 <        }
587 <        catch (IllegalArgumentException success){}
538 >        } catch (IllegalArgumentException success) {}
539      }
540  
541      /**
# Line 592 | Line 543 | public class ThreadPoolExecutorTest exte
543       */
544      public void testConstructor12() {
545          try {
546 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
546 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
547              shouldThrow();
548 <        }
598 <        catch (IllegalArgumentException success){}
548 >        } catch (IllegalArgumentException success) {}
549      }
550  
551      /**
# Line 603 | Line 553 | public class ThreadPoolExecutorTest exte
553       */
554      public void testConstructor13() {
555          try {
556 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
556 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
557              shouldThrow();
558 <        }
609 <        catch (IllegalArgumentException success){}
558 >        } catch (IllegalArgumentException success) {}
559      }
560  
561      /**
# Line 614 | Line 563 | public class ThreadPoolExecutorTest exte
563       */
564      public void testConstructor14() {
565          try {
566 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
566 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
567              shouldThrow();
568 <        }
620 <        catch (IllegalArgumentException success){}
568 >        } catch (IllegalArgumentException success) {}
569      }
570  
571      /**
# Line 625 | Line 573 | public class ThreadPoolExecutorTest exte
573       */
574      public void testConstructor15() {
575          try {
576 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
576 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
577              shouldThrow();
578 <        }
631 <        catch (IllegalArgumentException success){}
578 >        } catch (IllegalArgumentException success) {}
579      }
580  
581      /**
# Line 636 | Line 583 | public class ThreadPoolExecutorTest exte
583       */
584      public void testConstructorNullPointerException4() {
585          try {
586 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
586 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
587              shouldThrow();
588 <        }
642 <        catch (NullPointerException success){}
588 >        } catch (NullPointerException success) {}
589      }
590  
591      /**
# Line 648 | Line 594 | public class ThreadPoolExecutorTest exte
594      public void testConstructorNullPointerException5() {
595          try {
596              RejectedExecutionHandler r = null;
597 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
597 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
598              shouldThrow();
599 <        }
654 <        catch (NullPointerException success){}
599 >        } catch (NullPointerException success) {}
600      }
601  
602  
# Line 660 | Line 605 | public class ThreadPoolExecutorTest exte
605       */
606      public void testConstructor16() {
607          try {
608 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
608 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
609              shouldThrow();
610 <        }
666 <        catch (IllegalArgumentException success){}
610 >        } catch (IllegalArgumentException success) {}
611      }
612  
613      /**
# Line 671 | Line 615 | public class ThreadPoolExecutorTest exte
615       */
616      public void testConstructor17() {
617          try {
618 <            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
618 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
619              shouldThrow();
620 <        }
677 <        catch (IllegalArgumentException success){}
620 >        } catch (IllegalArgumentException success) {}
621      }
622  
623      /**
# Line 682 | Line 625 | public class ThreadPoolExecutorTest exte
625       */
626      public void testConstructor18() {
627          try {
628 <            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
628 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
629              shouldThrow();
630 <        }
688 <        catch (IllegalArgumentException success){}
630 >        } catch (IllegalArgumentException success) {}
631      }
632  
633      /**
# Line 693 | Line 635 | public class ThreadPoolExecutorTest exte
635       */
636      public void testConstructor19() {
637          try {
638 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
638 >            new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
639              shouldThrow();
640 <        }
699 <        catch (IllegalArgumentException success){}
640 >        } catch (IllegalArgumentException success) {}
641      }
642  
643      /**
# Line 704 | Line 645 | public class ThreadPoolExecutorTest exte
645       */
646      public void testConstructor20() {
647          try {
648 <            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
648 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
649              shouldThrow();
650 <        }
710 <        catch (IllegalArgumentException success){}
650 >        } catch (IllegalArgumentException success) {}
651      }
652  
653      /**
# Line 715 | Line 655 | public class ThreadPoolExecutorTest exte
655       */
656      public void testConstructorNullPointerException6() {
657          try {
658 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
658 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
659              shouldThrow();
660 <        }
721 <        catch (NullPointerException success){}
660 >        } catch (NullPointerException success) {}
661      }
662  
663      /**
# Line 727 | Line 666 | public class ThreadPoolExecutorTest exte
666      public void testConstructorNullPointerException7() {
667          try {
668              RejectedExecutionHandler r = null;
669 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
669 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
670              shouldThrow();
671 <        }
733 <        catch (NullPointerException success){}
671 >        } catch (NullPointerException success) {}
672      }
673  
674      /**
# Line 739 | Line 677 | public class ThreadPoolExecutorTest exte
677      public void testConstructorNullPointerException8() {
678          try {
679              ThreadFactory f = null;
680 <            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
680 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
681              shouldThrow();
682 <        }
745 <        catch (NullPointerException successdn8){}
682 >        } catch (NullPointerException success) {}
683      }
684  
685  
# Line 751 | Line 688 | public class ThreadPoolExecutorTest exte
688       *  if saturated.
689       */
690      public void testSaturatedExecute() {
691 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
691 >        ThreadPoolExecutor p =
692 >            new ThreadPoolExecutor(1, 1,
693 >                                   LONG_DELAY_MS, MILLISECONDS,
694 >                                   new ArrayBlockingQueue<Runnable>(1));
695          try {
696 <
757 <            for (int i = 0; i < 5; ++i){
696 >            for (int i = 0; i < 2; ++i)
697                  p.execute(new MediumRunnable());
698 +            for (int i = 0; i < 2; ++i) {
699 +                try {
700 +                    p.execute(new MediumRunnable());
701 +                    shouldThrow();
702 +                } catch (RejectedExecutionException success) {}
703              }
704 <            shouldThrow();
705 <        } catch (RejectedExecutionException success){}
706 <        joinPool(p);
704 >        } finally {
705 >            joinPool(p);
706 >        }
707      }
708  
709      /**
# Line 767 | Line 711 | public class ThreadPoolExecutorTest exte
711       */
712      public void testSaturatedExecute2() {
713          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
714 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
714 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
715          try {
716  
717              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
718 <            for (int i = 0; i < 5; ++i){
718 >            for (int i = 0; i < 5; ++i) {
719                  tasks[i] = new TrackedNoOpRunnable();
720              }
721              TrackedLongRunnable mr = new TrackedLongRunnable();
722              p.execute(mr);
723 <            for (int i = 0; i < 5; ++i){
723 >            for (int i = 0; i < 5; ++i) {
724                  p.execute(tasks[i]);
725              }
726              for (int i = 1; i < 5; ++i) {
727                  assertTrue(tasks[i].done);
728              }
729              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
786        } catch (RejectedExecutionException ex){
787            unexpectedException();
730          } finally {
731              joinPool(p);
732          }
# Line 795 | Line 737 | public class ThreadPoolExecutorTest exte
737       */
738      public void testSaturatedExecute3() {
739          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
740 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
740 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
741          try {
742  
743              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
744 <            for (int i = 0; i < 5; ++i){
744 >            for (int i = 0; i < 5; ++i) {
745                  tasks[i] = new TrackedNoOpRunnable();
746              }
747              p.execute(new TrackedLongRunnable());
748 <            for (int i = 0; i < 5; ++i){
748 >            for (int i = 0; i < 5; ++i) {
749                  p.execute(tasks[i]);
750              }
751 <            for (int i = 0; i < 5; ++i){
751 >            for (int i = 0; i < 5; ++i) {
752                  assertFalse(tasks[i].done);
753              }
754              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
813        } catch (RejectedExecutionException ex){
814            unexpectedException();
755          } finally {
756              joinPool(p);
757          }
# Line 822 | Line 762 | public class ThreadPoolExecutorTest exte
762       */
763      public void testSaturatedExecute4() {
764          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
765 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
765 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
766          try {
767              p.execute(new TrackedLongRunnable());
768              TrackedLongRunnable r2 = new TrackedLongRunnable();
# Line 833 | Line 773 | public class ThreadPoolExecutorTest exte
773              assertFalse(p.getQueue().contains(r2));
774              assertTrue(p.getQueue().contains(r3));
775              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
836        } catch (RejectedExecutionException ex){
837            unexpectedException();
776          } finally {
777              joinPool(p);
778          }
# Line 845 | Line 783 | public class ThreadPoolExecutorTest exte
783       */
784      public void testRejectedExecutionExceptionOnShutdown() {
785          ThreadPoolExecutor tpe =
786 <            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
786 >            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
787          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
788          try {
789              tpe.execute(new NoOpRunnable());
790              shouldThrow();
791 <        } catch (RejectedExecutionException success){}
791 >        } catch (RejectedExecutionException success) {}
792  
793          joinPool(tpe);
794      }
# Line 860 | Line 798 | public class ThreadPoolExecutorTest exte
798       */
799      public void testCallerRunsOnShutdown() {
800          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
801 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
801 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
802  
803          try { p.shutdown(); } catch (SecurityException ok) { return; }
804          try {
805              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
806              p.execute(r);
807              assertFalse(r.done);
870        } catch (RejectedExecutionException success){
871            unexpectedException();
808          } finally {
809              joinPool(p);
810          }
# Line 879 | Line 815 | public class ThreadPoolExecutorTest exte
815       */
816      public void testDiscardOnShutdown() {
817          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
818 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
818 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
819  
820          try { p.shutdown(); } catch (SecurityException ok) { return; }
821          try {
822              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
823              p.execute(r);
824              assertFalse(r.done);
889        } catch (RejectedExecutionException success){
890            unexpectedException();
825          } finally {
826              joinPool(p);
827          }
# Line 899 | Line 833 | public class ThreadPoolExecutorTest exte
833       */
834      public void testDiscardOldestOnShutdown() {
835          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
836 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
836 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
837  
838          try { p.shutdown(); } catch (SecurityException ok) { return; }
839          try {
840              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
841              p.execute(r);
842              assertFalse(r.done);
909        } catch (RejectedExecutionException success){
910            unexpectedException();
843          } finally {
844              joinPool(p);
845          }
# Line 918 | Line 850 | public class ThreadPoolExecutorTest exte
850       *  execute (null) throws NPE
851       */
852      public void testExecuteNull() {
853 <        ThreadPoolExecutor tpe = null;
853 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
854          try {
923            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
855              tpe.execute(null);
856              shouldThrow();
857 <        } catch (NullPointerException success){}
857 >        } catch (NullPointerException success) {}
858  
859          joinPool(tpe);
860      }
# Line 932 | Line 863 | public class ThreadPoolExecutorTest exte
863       *  setCorePoolSize of negative value throws IllegalArgumentException
864       */
865      public void testCorePoolSizeIllegalArgumentException() {
866 <        ThreadPoolExecutor tpe = null;
867 <        try {
868 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
869 <        } catch (Exception e){}
866 >        ThreadPoolExecutor tpe =
867 >            new ThreadPoolExecutor(1, 2,
868 >                                   LONG_DELAY_MS, MILLISECONDS,
869 >                                   new ArrayBlockingQueue<Runnable>(10));
870          try {
871              tpe.setCorePoolSize(-1);
872              shouldThrow();
873 <        } catch (IllegalArgumentException success){
873 >        } catch (IllegalArgumentException success) {
874          } finally {
875              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
876          }
# Line 951 | Line 882 | public class ThreadPoolExecutorTest exte
882       *  given a value less the core pool size
883       */
884      public void testMaximumPoolSizeIllegalArgumentException() {
885 <        ThreadPoolExecutor tpe = null;
886 <        try {
887 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
888 <        } catch (Exception e){}
885 >        ThreadPoolExecutor tpe =
886 >            new ThreadPoolExecutor(2, 3,
887 >                                   LONG_DELAY_MS, MILLISECONDS,
888 >                                   new ArrayBlockingQueue<Runnable>(10));
889          try {
890              tpe.setMaximumPoolSize(1);
891              shouldThrow();
892 <        } catch (IllegalArgumentException success){
892 >        } catch (IllegalArgumentException success) {
893          } finally {
894              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
895          }
# Line 970 | Line 901 | public class ThreadPoolExecutorTest exte
901       *  if given a negative value
902       */
903      public void testMaximumPoolSizeIllegalArgumentException2() {
904 <        ThreadPoolExecutor tpe = null;
905 <        try {
906 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
907 <        } catch (Exception e){}
904 >        ThreadPoolExecutor tpe =
905 >            new ThreadPoolExecutor(2, 3,
906 >                                   LONG_DELAY_MS, MILLISECONDS,
907 >                                   new ArrayBlockingQueue<Runnable>(10));
908          try {
909              tpe.setMaximumPoolSize(-1);
910              shouldThrow();
911 <        } catch (IllegalArgumentException success){
911 >        } catch (IllegalArgumentException success) {
912          } finally {
913              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
914          }
# Line 990 | Line 921 | public class ThreadPoolExecutorTest exte
921       *  when given a negative value
922       */
923      public void testKeepAliveTimeIllegalArgumentException() {
924 <        ThreadPoolExecutor tpe = null;
925 <        try {
926 <            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
927 <        } catch (Exception e){}
997 <
924 >        ThreadPoolExecutor tpe =
925 >            new ThreadPoolExecutor(2, 3,
926 >                                   LONG_DELAY_MS, MILLISECONDS,
927 >                                   new ArrayBlockingQueue<Runnable>(10));
928          try {
929 <            tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
929 >            tpe.setKeepAliveTime(-1,MILLISECONDS);
930              shouldThrow();
931 <        } catch (IllegalArgumentException success){
931 >        } catch (IllegalArgumentException success) {
932          } finally {
933              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
934          }
# Line 1018 | Line 948 | public class ThreadPoolExecutorTest exte
948      /**
949       * beforeExecute and afterExecute are called when executing task
950       */
951 <    public void testBeforeAfter() {
951 >    public void testBeforeAfter() throws InterruptedException {
952          ExtendedTPE tpe = new ExtendedTPE();
953          try {
954              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1028 | Line 958 | public class ThreadPoolExecutorTest exte
958              assertTrue(tpe.beforeCalled);
959              assertTrue(tpe.afterCalled);
960              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1031        }
1032        catch (Exception ex) {
1033            unexpectedException();
961          } finally {
962              joinPool(tpe);
963          }
# Line 1039 | Line 966 | public class ThreadPoolExecutorTest exte
966      /**
967       * completed submit of callable returns result
968       */
969 <    public void testSubmitCallable() {
970 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
969 >    public void testSubmitCallable() throws Exception {
970 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
971          try {
972              Future<String> future = e.submit(new StringTask());
973              String result = future.get();
974              assertSame(TEST_STRING, result);
1048        }
1049        catch (ExecutionException ex) {
1050            unexpectedException();
1051        }
1052        catch (InterruptedException ex) {
1053            unexpectedException();
975          } finally {
976              joinPool(e);
977          }
# Line 1059 | Line 980 | public class ThreadPoolExecutorTest exte
980      /**
981       * completed submit of runnable returns successfully
982       */
983 <    public void testSubmitRunnable() {
984 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
983 >    public void testSubmitRunnable() throws Exception {
984 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
985          try {
986              Future<?> future = e.submit(new NoOpRunnable());
987              future.get();
988              assertTrue(future.isDone());
1068        }
1069        catch (ExecutionException ex) {
1070            unexpectedException();
1071        }
1072        catch (InterruptedException ex) {
1073            unexpectedException();
989          } finally {
990              joinPool(e);
991          }
# Line 1079 | Line 994 | public class ThreadPoolExecutorTest exte
994      /**
995       * completed submit of (runnable, result) returns result
996       */
997 <    public void testSubmitRunnable2() {
998 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
997 >    public void testSubmitRunnable2() throws Exception {
998 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
999          try {
1000              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1001              String result = future.get();
1002              assertSame(TEST_STRING, result);
1088        }
1089        catch (ExecutionException ex) {
1090            unexpectedException();
1091        }
1092        catch (InterruptedException ex) {
1093            unexpectedException();
1003          } finally {
1004              joinPool(e);
1005          }
1006      }
1007  
1008  
1100
1101
1102
1009      /**
1010       * invokeAny(null) throws NPE
1011       */
1012 <    public void testInvokeAny1() {
1013 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1012 >    public void testInvokeAny1() throws Exception {
1013 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1014          try {
1015              e.invokeAny(null);
1016 +            shouldThrow();
1017          } catch (NullPointerException success) {
1111        } catch (Exception ex) {
1112            unexpectedException();
1018          } finally {
1019              joinPool(e);
1020          }
# Line 1118 | Line 1023 | public class ThreadPoolExecutorTest exte
1023      /**
1024       * invokeAny(empty collection) throws IAE
1025       */
1026 <    public void testInvokeAny2() {
1027 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1026 >    public void testInvokeAny2() throws Exception {
1027 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1028          try {
1029              e.invokeAny(new ArrayList<Callable<String>>());
1030 +            shouldThrow();
1031          } catch (IllegalArgumentException success) {
1126        } catch (Exception ex) {
1127            unexpectedException();
1032          } finally {
1033              joinPool(e);
1034          }
# Line 1133 | Line 1037 | public class ThreadPoolExecutorTest exte
1037      /**
1038       * invokeAny(c) throws NPE if c has null elements
1039       */
1040 <    public void testInvokeAny3() {
1041 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1040 >    public void testInvokeAny3() throws Exception {
1041 >        final CountDownLatch latch = new CountDownLatch(1);
1042 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1043          try {
1044              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1045 <            l.add(new StringTask());
1045 >            l.add(new CheckedCallable<String>() {
1046 >                      public String realCall() throws InterruptedException {
1047 >                          latch.await();
1048 >                          return TEST_STRING;
1049 >                      }});
1050              l.add(null);
1051              e.invokeAny(l);
1052 +            shouldThrow();
1053          } catch (NullPointerException success) {
1144        } catch (Exception ex) {
1145            unexpectedException();
1054          } finally {
1055 +            latch.countDown();
1056              joinPool(e);
1057          }
1058      }
# Line 1151 | Line 1060 | public class ThreadPoolExecutorTest exte
1060      /**
1061       * invokeAny(c) throws ExecutionException if no task completes
1062       */
1063 <    public void testInvokeAny4() {
1064 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1063 >    public void testInvokeAny4() throws Exception {
1064 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1065          try {
1066              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1067              l.add(new NPETask());
1068              e.invokeAny(l);
1069 +            shouldThrow();
1070          } catch (ExecutionException success) {
1071 <        } catch (Exception ex) {
1162 <            unexpectedException();
1071 >            assertTrue(success.getCause() instanceof NullPointerException);
1072          } finally {
1073              joinPool(e);
1074          }
# Line 1168 | Line 1077 | public class ThreadPoolExecutorTest exte
1077      /**
1078       * invokeAny(c) returns result of some task
1079       */
1080 <    public void testInvokeAny5() {
1081 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1080 >    public void testInvokeAny5() throws Exception {
1081 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1082          try {
1083              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1084              l.add(new StringTask());
1085              l.add(new StringTask());
1086              String result = e.invokeAny(l);
1087              assertSame(TEST_STRING, result);
1179        } catch (ExecutionException success) {
1180        } catch (Exception ex) {
1181            unexpectedException();
1088          } finally {
1089              joinPool(e);
1090          }
# Line 1187 | Line 1093 | public class ThreadPoolExecutorTest exte
1093      /**
1094       * invokeAll(null) throws NPE
1095       */
1096 <    public void testInvokeAll1() {
1097 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1096 >    public void testInvokeAll1() throws Exception {
1097 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1098          try {
1099              e.invokeAll(null);
1100 +            shouldThrow();
1101          } catch (NullPointerException success) {
1195        } catch (Exception ex) {
1196            unexpectedException();
1102          } finally {
1103              joinPool(e);
1104          }
# Line 1202 | Line 1107 | public class ThreadPoolExecutorTest exte
1107      /**
1108       * invokeAll(empty collection) returns empty collection
1109       */
1110 <    public void testInvokeAll2() {
1111 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1110 >    public void testInvokeAll2() throws InterruptedException {
1111 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1112          try {
1113              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1114              assertTrue(r.isEmpty());
1210        } catch (Exception ex) {
1211            unexpectedException();
1115          } finally {
1116              joinPool(e);
1117          }
# Line 1217 | Line 1120 | public class ThreadPoolExecutorTest exte
1120      /**
1121       * invokeAll(c) throws NPE if c has null elements
1122       */
1123 <    public void testInvokeAll3() {
1124 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1123 >    public void testInvokeAll3() throws Exception {
1124 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1125          try {
1126              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1127              l.add(new StringTask());
1128              l.add(null);
1129              e.invokeAll(l);
1130 +            shouldThrow();
1131          } catch (NullPointerException success) {
1228        } catch (Exception ex) {
1229            unexpectedException();
1132          } finally {
1133              joinPool(e);
1134          }
# Line 1235 | Line 1137 | public class ThreadPoolExecutorTest exte
1137      /**
1138       * get of element of invokeAll(c) throws exception on failed task
1139       */
1140 <    public void testInvokeAll4() {
1141 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1140 >    public void testInvokeAll4() throws Exception {
1141 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1142          try {
1143              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1144              l.add(new NPETask());
1145              List<Future<String>> result = e.invokeAll(l);
1146              assertEquals(1, result.size());
1147 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1148 <                it.next().get();
1149 <        } catch (ExecutionException success) {
1150 <        } catch (Exception ex) {
1151 <            unexpectedException();
1147 >            for (Future<String> future : result) {
1148 >                try {
1149 >                    future.get();
1150 >                    shouldThrow();
1151 >                } catch (ExecutionException success) {
1152 >                    Throwable cause = success.getCause();
1153 >                    assertTrue(cause instanceof NullPointerException);
1154 >                }
1155 >            }
1156          } finally {
1157              joinPool(e);
1158          }
# Line 1255 | Line 1161 | public class ThreadPoolExecutorTest exte
1161      /**
1162       * invokeAll(c) returns results of all completed tasks
1163       */
1164 <    public void testInvokeAll5() {
1165 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1164 >    public void testInvokeAll5() throws Exception {
1165 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1166          try {
1167              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1168              l.add(new StringTask());
1169              l.add(new StringTask());
1170              List<Future<String>> result = e.invokeAll(l);
1171              assertEquals(2, result.size());
1172 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1173 <                assertSame(TEST_STRING, it.next().get());
1268 <        } catch (ExecutionException success) {
1269 <        } catch (Exception ex) {
1270 <            unexpectedException();
1172 >            for (Future<String> future : result)
1173 >                assertSame(TEST_STRING, future.get());
1174          } finally {
1175              joinPool(e);
1176          }
# Line 1278 | Line 1181 | public class ThreadPoolExecutorTest exte
1181      /**
1182       * timed invokeAny(null) throws NPE
1183       */
1184 <    public void testTimedInvokeAny1() {
1185 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1184 >    public void testTimedInvokeAny1() throws Exception {
1185 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1186          try {
1187 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1187 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1188 >            shouldThrow();
1189          } catch (NullPointerException success) {
1286        } catch (Exception ex) {
1287            unexpectedException();
1190          } finally {
1191              joinPool(e);
1192          }
# Line 1293 | Line 1195 | public class ThreadPoolExecutorTest exte
1195      /**
1196       * timed invokeAny(,,null) throws NPE
1197       */
1198 <    public void testTimedInvokeAnyNullTimeUnit() {
1199 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1198 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1199 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1200          try {
1201              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1202              l.add(new StringTask());
1203              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1204 +            shouldThrow();
1205          } catch (NullPointerException success) {
1303        } catch (Exception ex) {
1304            unexpectedException();
1206          } finally {
1207              joinPool(e);
1208          }
# Line 1310 | Line 1211 | public class ThreadPoolExecutorTest exte
1211      /**
1212       * timed invokeAny(empty collection) throws IAE
1213       */
1214 <    public void testTimedInvokeAny2() {
1215 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1214 >    public void testTimedInvokeAny2() throws Exception {
1215 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1216          try {
1217 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1217 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1218 >            shouldThrow();
1219          } catch (IllegalArgumentException success) {
1318        } catch (Exception ex) {
1319            unexpectedException();
1220          } finally {
1221              joinPool(e);
1222          }
# Line 1325 | Line 1225 | public class ThreadPoolExecutorTest exte
1225      /**
1226       * timed invokeAny(c) throws NPE if c has null elements
1227       */
1228 <    public void testTimedInvokeAny3() {
1229 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1228 >    public void testTimedInvokeAny3() throws Exception {
1229 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1230          try {
1231              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1232              l.add(new StringTask());
1233              l.add(null);
1234 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1234 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1235 >            shouldThrow();
1236          } catch (NullPointerException success) {
1336        } catch (Exception ex) {
1337            ex.printStackTrace();
1338            unexpectedException();
1237          } finally {
1238              joinPool(e);
1239          }
# Line 1344 | Line 1242 | public class ThreadPoolExecutorTest exte
1242      /**
1243       * timed invokeAny(c) throws ExecutionException if no task completes
1244       */
1245 <    public void testTimedInvokeAny4() {
1246 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1245 >    public void testTimedInvokeAny4() throws Exception {
1246 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1247          try {
1248              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1249              l.add(new NPETask());
1250 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1250 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1251 >            shouldThrow();
1252          } catch (ExecutionException success) {
1253 <        } catch (Exception ex) {
1355 <            unexpectedException();
1253 >            assertTrue(success.getCause() instanceof NullPointerException);
1254          } finally {
1255              joinPool(e);
1256          }
# Line 1361 | Line 1259 | public class ThreadPoolExecutorTest exte
1259      /**
1260       * timed invokeAny(c) returns result of some task
1261       */
1262 <    public void testTimedInvokeAny5() {
1263 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1262 >    public void testTimedInvokeAny5() throws Exception {
1263 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1264          try {
1265              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1266              l.add(new StringTask());
1267              l.add(new StringTask());
1268 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1268 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1269              assertSame(TEST_STRING, result);
1372        } catch (ExecutionException success) {
1373        } catch (Exception ex) {
1374            unexpectedException();
1270          } finally {
1271              joinPool(e);
1272          }
# Line 1380 | Line 1275 | public class ThreadPoolExecutorTest exte
1275      /**
1276       * timed invokeAll(null) throws NPE
1277       */
1278 <    public void testTimedInvokeAll1() {
1279 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1278 >    public void testTimedInvokeAll1() throws Exception {
1279 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1280          try {
1281 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1281 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1282 >            shouldThrow();
1283          } catch (NullPointerException success) {
1388        } catch (Exception ex) {
1389            unexpectedException();
1284          } finally {
1285              joinPool(e);
1286          }
# Line 1395 | Line 1289 | public class ThreadPoolExecutorTest exte
1289      /**
1290       * timed invokeAll(,,null) throws NPE
1291       */
1292 <    public void testTimedInvokeAllNullTimeUnit() {
1293 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1292 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1293 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1294          try {
1295              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1296              l.add(new StringTask());
1297              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1298 +            shouldThrow();
1299          } catch (NullPointerException success) {
1405        } catch (Exception ex) {
1406            unexpectedException();
1300          } finally {
1301              joinPool(e);
1302          }
# Line 1412 | Line 1305 | public class ThreadPoolExecutorTest exte
1305      /**
1306       * timed invokeAll(empty collection) returns empty collection
1307       */
1308 <    public void testTimedInvokeAll2() {
1309 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1308 >    public void testTimedInvokeAll2() throws InterruptedException {
1309 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1310          try {
1311 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1311 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1312              assertTrue(r.isEmpty());
1420        } catch (Exception ex) {
1421            unexpectedException();
1313          } finally {
1314              joinPool(e);
1315          }
# Line 1427 | Line 1318 | public class ThreadPoolExecutorTest exte
1318      /**
1319       * timed invokeAll(c) throws NPE if c has null elements
1320       */
1321 <    public void testTimedInvokeAll3() {
1322 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1321 >    public void testTimedInvokeAll3() 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              l.add(null);
1327 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1327 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1328 >            shouldThrow();
1329          } catch (NullPointerException success) {
1438        } catch (Exception ex) {
1439            unexpectedException();
1330          } finally {
1331              joinPool(e);
1332          }
# Line 1445 | Line 1335 | public class ThreadPoolExecutorTest exte
1335      /**
1336       * get of element of invokeAll(c) throws exception on failed task
1337       */
1338 <    public void testTimedInvokeAll4() {
1339 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1338 >    public void testTimedInvokeAll4() throws Exception {
1339 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1340          try {
1341              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1342              l.add(new NPETask());
1343 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1343 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1344              assertEquals(1, result.size());
1345 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1346 <                it.next().get();
1345 >            for (Future<String> future : result)
1346 >                future.get();
1347 >            shouldThrow();
1348          } catch (ExecutionException success) {
1349 <        } catch (Exception ex) {
1459 <            unexpectedException();
1349 >            assertTrue(success.getCause() instanceof NullPointerException);
1350          } finally {
1351              joinPool(e);
1352          }
# Line 1465 | Line 1355 | public class ThreadPoolExecutorTest exte
1355      /**
1356       * timed invokeAll(c) returns results of all completed tasks
1357       */
1358 <    public void testTimedInvokeAll5() {
1359 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1358 >    public void testTimedInvokeAll5() throws Exception {
1359 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1360          try {
1361              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1362              l.add(new StringTask());
1363              l.add(new StringTask());
1364 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1364 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1365              assertEquals(2, result.size());
1366              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1367                  assertSame(TEST_STRING, it.next().get());
1478        } catch (ExecutionException success) {
1479        } catch (Exception ex) {
1480            unexpectedException();
1368          } finally {
1369              joinPool(e);
1370          }
# Line 1486 | Line 1373 | public class ThreadPoolExecutorTest exte
1373      /**
1374       * timed invokeAll(c) cancels tasks not completed by timeout
1375       */
1376 <    public void testTimedInvokeAll6() {
1377 <        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1376 >    public void testTimedInvokeAll6() throws Exception {
1377 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1378          try {
1379              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1380              l.add(new StringTask());
1381              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1382              l.add(new StringTask());
1383 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1383 >            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1384              assertEquals(3, result.size());
1385              Iterator<Future<String>> it = result.iterator();
1386              Future<String> f1 = it.next();
# Line 1504 | Line 1391 | public class ThreadPoolExecutorTest exte
1391              assertTrue(f3.isDone());
1392              assertFalse(f1.isCancelled());
1393              assertTrue(f2.isCancelled());
1507        } catch (Exception ex) {
1508            unexpectedException();
1394          } finally {
1395              joinPool(e);
1396          }
# Line 1515 | Line 1400 | public class ThreadPoolExecutorTest exte
1400       * Execution continues if there is at least one thread even if
1401       * thread factory fails to create more
1402       */
1403 <    public void testFailingThreadFactory() {
1404 <        ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1403 >    public void testFailingThreadFactory() throws InterruptedException {
1404 >        ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1405          try {
1406              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1407              for (int k = 0; k < 100; ++k) {
1408                  e.execute(new NoOpRunnable());
1409              }
1410              Thread.sleep(LONG_DELAY_MS);
1526        } catch (Exception ex) {
1527            unexpectedException();
1411          } finally {
1412              joinPool(e);
1413          }
# Line 1534 | Line 1417 | public class ThreadPoolExecutorTest exte
1417       * allowsCoreThreadTimeOut is by default false.
1418       */
1419      public void testAllowsCoreThreadTimeOut() {
1420 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1420 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1421          assertFalse(tpe.allowsCoreThreadTimeOut());
1422          joinPool(tpe);
1423      }
# Line 1542 | Line 1425 | public class ThreadPoolExecutorTest exte
1425      /**
1426       * allowCoreThreadTimeOut(true) causes idle threads to time out
1427       */
1428 <    public void testAllowCoreThreadTimeOut_true() {
1429 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1428 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1429 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1430          tpe.allowCoreThreadTimeOut(true);
1431          tpe.execute(new NoOpRunnable());
1432          try {
1433              Thread.sleep(MEDIUM_DELAY_MS);
1434              assertEquals(0, tpe.getPoolSize());
1552        } catch (InterruptedException e){
1553            unexpectedException();
1435          } finally {
1436              joinPool(tpe);
1437          }
# Line 1559 | Line 1440 | public class ThreadPoolExecutorTest exte
1440      /**
1441       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1442       */
1443 <    public void testAllowCoreThreadTimeOut_false() {
1444 <        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1443 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1444 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1445          tpe.allowCoreThreadTimeOut(false);
1446          tpe.execute(new NoOpRunnable());
1447          try {
1448              Thread.sleep(MEDIUM_DELAY_MS);
1449              assertTrue(tpe.getPoolSize() >= 1);
1569        } catch (InterruptedException e){
1570            unexpectedException();
1450          } finally {
1451              joinPool(tpe);
1452          }
# Line 1577 | Line 1456 | public class ThreadPoolExecutorTest exte
1456       * execute allows the same task to be submitted multiple times, even
1457       * if rejected
1458       */
1459 <    public void testRejectedRecycledTask() {
1459 >    public void testRejectedRecycledTask() throws InterruptedException {
1460          final int nTasks = 1000;
1461          final AtomicInteger nRun = new AtomicInteger(0);
1462          final Runnable recycledTask = new Runnable() {
# Line 1600 | Line 1479 | public class ThreadPoolExecutorTest exte
1479              }
1480              Thread.sleep(5000); // enough time to run all tasks
1481              assertEquals(nRun.get(), nTasks);
1603        } catch (Exception ex) {
1604            ex.printStackTrace();
1605            unexpectedException();
1482          } finally {
1483              p.shutdown();
1484          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines