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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines