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

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.2 by jsr166, Mon Nov 2 20:28:32 2009 UTC vs.
Revision 1.19 by jsr166, Sat Oct 9 19:30:35 2010 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.locks.*;
12  
13   import junit.framework.*;
# Line 14 | Line 15 | import java.util.*;
15  
16   public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20      public static Test suite() {
21 <        return new TestSuite(ThreadPoolExecutorTest.class);
21 >        return new TestSuite(ThreadPoolExecutorSubclassTest.class);
22      }
23  
24      static class CustomTask<V> implements RunnableFuture<V> {
# Line 29 | Line 30 | public class ThreadPoolExecutorSubclassT
30          V result;
31          Thread thread;
32          Exception exception;
33 <        CustomTask(Callable<V> c) { callable = c; }
34 <        CustomTask(final Runnable r, final V res) { callable = new Callable<V>() {
33 >        CustomTask(Callable<V> c) {
34 >            if (c == null) throw new NullPointerException();
35 >            callable = c;
36 >        }
37 >        CustomTask(final Runnable r, final V res) {
38 >            if (r == null) throw new NullPointerException();
39 >            callable = new Callable<V>() {
40              public V call() throws Exception { r.run(); return res; }};
41          }
42          public boolean isDone() {
# Line 68 | Line 74 | public class ThreadPoolExecutorSubclassT
74              try {
75                  v = callable.call();
76              }
77 <            catch(Exception ex) {
77 >            catch (Exception ex) {
78                  e = ex;
79              }
80              lock.lock();
# Line 93 | Line 99 | public class ThreadPoolExecutorSubclassT
99              finally { lock.unlock(); }
100          }
101          public V get(long timeout, TimeUnit unit)
102 <            throws InterruptedException, ExecutionException, TimeoutException{
102 >            throws InterruptedException, ExecutionException, TimeoutException {
103              long nanos = unit.toNanos(timeout);
104              lock.lock();
105              try {
# Line 162 | Line 168 | public class ThreadPoolExecutorSubclassT
168          volatile boolean afterCalled = false;
169          volatile boolean terminatedCalled = false;
170          public CustomTPE() {
171 <            super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
171 >            super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue<Runnable>());
172          }
173          protected void beforeExecute(Thread t, Runnable r) {
174              beforeCalled = true;
# Line 176 | Line 182 | public class ThreadPoolExecutorSubclassT
182  
183      }
184  
185 <    static class FailingThreadFactory implements ThreadFactory{
185 >    static class FailingThreadFactory implements ThreadFactory {
186          int calls = 0;
187 <        public Thread newThread(Runnable r){
187 >        public Thread newThread(Runnable r) {
188              if (++calls > 1) return null;
189              return new Thread(r);
190          }
# Line 186 | Line 192 | public class ThreadPoolExecutorSubclassT
192  
193  
194      /**
195 <     *  execute successfully executes a runnable
195 >     * execute successfully executes a runnable
196       */
197 <    public void testExecute() {
198 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
197 >    public void testExecute() throws InterruptedException {
198 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
199          try {
200 <            p1.execute(new Runnable() {
201 <                    public void run() {
202 <                        try {
203 <                            Thread.sleep(SHORT_DELAY_MS);
198 <                        } catch(InterruptedException e){
199 <                            threadUnexpectedException();
200 <                        }
201 <                    }
202 <                });
203 <            Thread.sleep(SMALL_DELAY_MS);
204 <        } catch(InterruptedException e){
205 <            unexpectedException();
200 >            p1.execute(new ShortRunnable());
201 >            Thread.sleep(SMALL_DELAY_MS);
202 >        } finally {
203 >            joinPool(p1);
204          }
207        joinPool(p1);
205      }
206  
207      /**
208 <     *  getActiveCount increases but doesn't overestimate, when a
209 <     *  thread becomes active
208 >     * getActiveCount increases but doesn't overestimate, when a
209 >     * thread becomes active
210       */
211 <    public void testGetActiveCount() {
212 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
211 >    public void testGetActiveCount() throws InterruptedException {
212 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
213          assertEquals(0, p2.getActiveCount());
214          p2.execute(new MediumRunnable());
215 <        try {
219 <            Thread.sleep(SHORT_DELAY_MS);
220 <        } catch(Exception e){
221 <            unexpectedException();
222 <        }
215 >        Thread.sleep(SHORT_DELAY_MS);
216          assertEquals(1, p2.getActiveCount());
217          joinPool(p2);
218      }
219  
220      /**
221 <     *  prestartCoreThread starts a thread if under corePoolSize, else doesn't
221 >     * prestartCoreThread starts a thread if under corePoolSize, else doesn't
222       */
223      public void testPrestartCoreThread() {
224 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
224 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
225          assertEquals(0, p2.getPoolSize());
226          assertTrue(p2.prestartCoreThread());
227          assertEquals(1, p2.getPoolSize());
# Line 240 | Line 233 | public class ThreadPoolExecutorSubclassT
233      }
234  
235      /**
236 <     *  prestartAllCoreThreads starts all corePoolSize threads
236 >     * prestartAllCoreThreads starts all corePoolSize threads
237       */
238      public void testPrestartAllCoreThreads() {
239 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
239 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
240          assertEquals(0, p2.getPoolSize());
241          p2.prestartAllCoreThreads();
242          assertEquals(2, p2.getPoolSize());
# Line 253 | Line 246 | public class ThreadPoolExecutorSubclassT
246      }
247  
248      /**
249 <     *   getCompletedTaskCount increases, but doesn't overestimate,
250 <     *   when tasks complete
249 >     * getCompletedTaskCount increases, but doesn't overestimate,
250 >     * when tasks complete
251       */
252 <    public void testGetCompletedTaskCount() {
253 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
252 >    public void testGetCompletedTaskCount() throws InterruptedException {
253 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
254          assertEquals(0, p2.getCompletedTaskCount());
255          p2.execute(new ShortRunnable());
256 <        try {
264 <            Thread.sleep(SMALL_DELAY_MS);
265 <        } catch(Exception e){
266 <            unexpectedException();
267 <        }
256 >        Thread.sleep(SMALL_DELAY_MS);
257          assertEquals(1, p2.getCompletedTaskCount());
258 <        try { p2.shutdown(); } catch(SecurityException ok) { return; }
258 >        try { p2.shutdown(); } catch (SecurityException ok) { return; }
259          joinPool(p2);
260      }
261  
262      /**
263 <     *   getCorePoolSize returns size given in constructor if not otherwise set
263 >     * getCorePoolSize returns size given in constructor if not otherwise set
264       */
265      public void testGetCorePoolSize() {
266 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
266 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
267          assertEquals(1, p1.getCorePoolSize());
268          joinPool(p1);
269      }
270  
271      /**
272 <     *   getKeepAliveTime returns value given in constructor if not otherwise set
272 >     * getKeepAliveTime returns value given in constructor if not otherwise set
273       */
274      public void testGetKeepAliveTime() {
275 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
275 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
276          assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS));
277          joinPool(p2);
278      }
# Line 294 | Line 283 | public class ThreadPoolExecutorSubclassT
283       */
284      public void testGetThreadFactory() {
285          ThreadFactory tf = new SimpleThreadFactory();
286 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
286 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
287          assertSame(tf, p.getThreadFactory());
288          joinPool(p);
289      }
# Line 303 | Line 292 | public class ThreadPoolExecutorSubclassT
292       * setThreadFactory sets the thread factory returned by getThreadFactory
293       */
294      public void testSetThreadFactory() {
295 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
295 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
296          ThreadFactory tf = new SimpleThreadFactory();
297          p.setThreadFactory(tf);
298          assertSame(tf, p.getThreadFactory());
# Line 315 | Line 304 | public class ThreadPoolExecutorSubclassT
304       * setThreadFactory(null) throws NPE
305       */
306      public void testSetThreadFactoryNull() {
307 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
307 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
308          try {
309              p.setThreadFactory(null);
310              shouldThrow();
# Line 330 | Line 319 | public class ThreadPoolExecutorSubclassT
319       */
320      public void testGetRejectedExecutionHandler() {
321          RejectedExecutionHandler h = new NoOpREHandler();
322 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
322 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
323          assertSame(h, p.getRejectedExecutionHandler());
324          joinPool(p);
325      }
# Line 340 | Line 329 | public class ThreadPoolExecutorSubclassT
329       * getRejectedExecutionHandler
330       */
331      public void testSetRejectedExecutionHandler() {
332 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
332 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
333          RejectedExecutionHandler h = new NoOpREHandler();
334          p.setRejectedExecutionHandler(h);
335          assertSame(h, p.getRejectedExecutionHandler());
# Line 352 | Line 341 | public class ThreadPoolExecutorSubclassT
341       * setRejectedExecutionHandler(null) throws NPE
342       */
343      public void testSetRejectedExecutionHandlerNull() {
344 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
344 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
345          try {
346              p.setRejectedExecutionHandler(null);
347              shouldThrow();
# Line 364 | Line 353 | public class ThreadPoolExecutorSubclassT
353  
354  
355      /**
356 <     *   getLargestPoolSize increases, but doesn't overestimate, when
357 <     *   multiple threads active
356 >     * getLargestPoolSize increases, but doesn't overestimate, when
357 >     * multiple threads active
358       */
359 <    public void testGetLargestPoolSize() {
360 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
361 <        try {
362 <            assertEquals(0, p2.getLargestPoolSize());
363 <            p2.execute(new MediumRunnable());
364 <            p2.execute(new MediumRunnable());
365 <            Thread.sleep(SHORT_DELAY_MS);
377 <            assertEquals(2, p2.getLargestPoolSize());
378 <        } catch(Exception e){
379 <            unexpectedException();
380 <        }
359 >    public void testGetLargestPoolSize() throws InterruptedException {
360 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
361 >        assertEquals(0, p2.getLargestPoolSize());
362 >        p2.execute(new MediumRunnable());
363 >        p2.execute(new MediumRunnable());
364 >        Thread.sleep(SHORT_DELAY_MS);
365 >        assertEquals(2, p2.getLargestPoolSize());
366          joinPool(p2);
367      }
368  
369      /**
370 <     *   getMaximumPoolSize returns value given in constructor if not
371 <     *   otherwise set
370 >     * getMaximumPoolSize returns value given in constructor if not
371 >     * otherwise set
372       */
373      public void testGetMaximumPoolSize() {
374 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
374 >        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
375          assertEquals(2, p2.getMaximumPoolSize());
376          joinPool(p2);
377      }
378  
379      /**
380 <     *   getPoolSize increases, but doesn't overestimate, when threads
381 <     *   become active
380 >     * getPoolSize increases, but doesn't overestimate, when threads
381 >     * become active
382       */
383      public void testGetPoolSize() {
384 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
384 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
385          assertEquals(0, p1.getPoolSize());
386          p1.execute(new MediumRunnable());
387          assertEquals(1, p1.getPoolSize());
# Line 404 | Line 389 | public class ThreadPoolExecutorSubclassT
389      }
390  
391      /**
392 <     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
392 >     * getTaskCount increases, but doesn't overestimate, when tasks submitted
393       */
394 <    public void testGetTaskCount() {
395 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
396 <        try {
397 <            assertEquals(0, p1.getTaskCount());
398 <            p1.execute(new MediumRunnable());
399 <            Thread.sleep(SHORT_DELAY_MS);
415 <            assertEquals(1, p1.getTaskCount());
416 <        } catch(Exception e){
417 <            unexpectedException();
418 <        }
394 >    public void testGetTaskCount() throws InterruptedException {
395 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
396 >        assertEquals(0, p1.getTaskCount());
397 >        p1.execute(new MediumRunnable());
398 >        Thread.sleep(SHORT_DELAY_MS);
399 >        assertEquals(1, p1.getTaskCount());
400          joinPool(p1);
401      }
402  
403      /**
404 <     *   isShutDown is false before shutdown, true after
404 >     * isShutDown is false before shutdown, true after
405       */
406      public void testIsShutdown() {
407  
408 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
408 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
409          assertFalse(p1.isShutdown());
410 <        try { p1.shutdown(); } catch(SecurityException ok) { return; }
411 <        assertTrue(p1.isShutdown());
410 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
411 >        assertTrue(p1.isShutdown());
412          joinPool(p1);
413      }
414  
415  
416      /**
417 <     *  isTerminated is false before termination, true after
417 >     * isTerminated is false before termination, true after
418       */
419 <    public void testIsTerminated() {
420 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
419 >    public void testIsTerminated() throws InterruptedException {
420 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
421          assertFalse(p1.isTerminated());
422          try {
423              p1.execute(new MediumRunnable());
424          } finally {
425 <            try { p1.shutdown(); } catch(SecurityException ok) { return; }
445 <        }
446 <        try {
447 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
448 <            assertTrue(p1.isTerminated());
449 <        } catch(Exception e){
450 <            unexpectedException();
425 >            try { p1.shutdown(); } catch (SecurityException ok) { return; }
426          }
427 +        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
428 +        assertTrue(p1.isTerminated());
429      }
430  
431      /**
432 <     *  isTerminating is not true when running or when terminated
432 >     * isTerminating is not true when running or when terminated
433       */
434 <    public void testIsTerminating() {
435 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
434 >    public void testIsTerminating() throws InterruptedException {
435 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
436          assertFalse(p1.isTerminating());
437          try {
438              p1.execute(new SmallRunnable());
439              assertFalse(p1.isTerminating());
440          } finally {
441 <            try { p1.shutdown(); } catch(SecurityException ok) { return; }
465 <        }
466 <        try {
467 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
468 <            assertTrue(p1.isTerminated());
469 <            assertFalse(p1.isTerminating());
470 <        } catch(Exception e){
471 <            unexpectedException();
441 >            try { p1.shutdown(); } catch (SecurityException ok) { return; }
442          }
443 +        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
444 +        assertTrue(p1.isTerminated());
445 +        assertFalse(p1.isTerminating());
446      }
447  
448      /**
449       * getQueue returns the work queue, which contains queued tasks
450       */
451 <    public void testGetQueue() {
451 >    public void testGetQueue() throws InterruptedException {
452          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
453 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
453 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q);
454          FutureTask[] tasks = new FutureTask[5];
455 <        for(int i = 0; i < 5; i++){
455 >        for (int i = 0; i < 5; i++) {
456              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
457              p1.execute(tasks[i]);
458          }
# Line 492 | Line 465 | public class ThreadPoolExecutorSubclassT
465              for (int i = 1; i < 5; ++i)
466                  tasks[i].cancel(true);
467              p1.shutdownNow();
495        } catch(Exception e) {
496            unexpectedException();
468          } finally {
469              joinPool(p1);
470          }
# Line 502 | Line 473 | public class ThreadPoolExecutorSubclassT
473      /**
474       * remove(task) removes queued task, and fails to remove active task
475       */
476 <    public void testRemove() {
476 >    public void testRemove() throws InterruptedException {
477          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
478 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
478 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q);
479          FutureTask[] tasks = new FutureTask[5];
480 <        for(int i = 0; i < 5; i++){
480 >        for (int i = 0; i < 5; i++) {
481              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
482              p1.execute(tasks[i]);
483          }
# Line 521 | Line 492 | public class ThreadPoolExecutorSubclassT
492              assertTrue(q.contains(tasks[3]));
493              assertTrue(p1.remove(tasks[3]));
494              assertFalse(q.contains(tasks[3]));
524        } catch(Exception e) {
525            unexpectedException();
495          } finally {
496              joinPool(p1);
497          }
498      }
499  
500      /**
501 <     *   purge removes cancelled tasks from the queue
501 >     * purge removes cancelled tasks from the queue
502       */
503      public void testPurge() {
504 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
504 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
505          FutureTask[] tasks = new FutureTask[5];
506 <        for(int i = 0; i < 5; i++){
506 >        for (int i = 0; i < 5; i++) {
507              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
508              p1.execute(tasks[i]);
509          }
# Line 547 | Line 516 | public class ThreadPoolExecutorSubclassT
516      }
517  
518      /**
519 <     *  shutDownNow returns a list containing tasks that were not run
519 >     * shutDownNow returns a list containing tasks that were not run
520       */
521      public void testShutDownNow() {
522 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
522 >        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
523          List l;
524          try {
525 <            for(int i = 0; i < 5; i++)
525 >            for (int i = 0; i < 5; i++)
526                  p1.execute(new MediumPossiblyInterruptedRunnable());
527          }
528          finally {
529              try {
530                  l = p1.shutdownNow();
531              } catch (SecurityException ok) { return; }
563
532          }
533 <        assertTrue(p1.isShutdown());
534 <        assertTrue(l.size() <= 4);
533 >        assertTrue(p1.isShutdown());
534 >        assertTrue(l.size() <= 4);
535      }
536  
537      // Exception Tests
# Line 574 | Line 542 | public class ThreadPoolExecutorSubclassT
542       */
543      public void testConstructor1() {
544          try {
545 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
545 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
546              shouldThrow();
547 <        }
580 <        catch (IllegalArgumentException success){}
547 >        } catch (IllegalArgumentException success) {}
548      }
549  
550      /**
# Line 585 | Line 552 | public class ThreadPoolExecutorSubclassT
552       */
553      public void testConstructor2() {
554          try {
555 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
555 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
556              shouldThrow();
557 <        }
591 <        catch (IllegalArgumentException success){}
557 >        } catch (IllegalArgumentException success) {}
558      }
559  
560      /**
# Line 596 | Line 562 | public class ThreadPoolExecutorSubclassT
562       */
563      public void testConstructor3() {
564          try {
565 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
565 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
566              shouldThrow();
567 <        }
602 <        catch (IllegalArgumentException success){}
567 >        } catch (IllegalArgumentException success) {}
568      }
569  
570      /**
# Line 607 | Line 572 | public class ThreadPoolExecutorSubclassT
572       */
573      public void testConstructor4() {
574          try {
575 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
575 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
576              shouldThrow();
577 <        }
613 <        catch (IllegalArgumentException success){}
577 >        } catch (IllegalArgumentException success) {}
578      }
579  
580      /**
# Line 618 | Line 582 | public class ThreadPoolExecutorSubclassT
582       */
583      public void testConstructor5() {
584          try {
585 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
585 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
586              shouldThrow();
587 <        }
624 <        catch (IllegalArgumentException success){}
587 >        } catch (IllegalArgumentException success) {}
588      }
589  
590      /**
# Line 629 | Line 592 | public class ThreadPoolExecutorSubclassT
592       */
593      public void testConstructorNullPointerException() {
594          try {
595 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
595 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null);
596              shouldThrow();
597 <        }
635 <        catch (NullPointerException success){}
597 >        } catch (NullPointerException success) {}
598      }
599  
600  
# Line 642 | Line 604 | public class ThreadPoolExecutorSubclassT
604       */
605      public void testConstructor6() {
606          try {
607 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
607 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
608              shouldThrow();
609 <        } catch (IllegalArgumentException success){}
609 >        } catch (IllegalArgumentException success) {}
610      }
611  
612      /**
# Line 652 | Line 614 | public class ThreadPoolExecutorSubclassT
614       */
615      public void testConstructor7() {
616          try {
617 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
617 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
618              shouldThrow();
619 <        }
658 <        catch (IllegalArgumentException success){}
619 >        } catch (IllegalArgumentException success) {}
620      }
621  
622      /**
# Line 663 | Line 624 | public class ThreadPoolExecutorSubclassT
624       */
625      public void testConstructor8() {
626          try {
627 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
627 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
628              shouldThrow();
629 <        }
669 <        catch (IllegalArgumentException success){}
629 >        } catch (IllegalArgumentException success) {}
630      }
631  
632      /**
# Line 674 | Line 634 | public class ThreadPoolExecutorSubclassT
634       */
635      public void testConstructor9() {
636          try {
637 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
637 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
638              shouldThrow();
639 <        }
680 <        catch (IllegalArgumentException success){}
639 >        } catch (IllegalArgumentException success) {}
640      }
641  
642      /**
# Line 685 | Line 644 | public class ThreadPoolExecutorSubclassT
644       */
645      public void testConstructor10() {
646          try {
647 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
647 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
648              shouldThrow();
649 <        }
691 <        catch (IllegalArgumentException success){}
649 >        } catch (IllegalArgumentException success) {}
650      }
651  
652      /**
# Line 696 | Line 654 | public class ThreadPoolExecutorSubclassT
654       */
655      public void testConstructorNullPointerException2() {
656          try {
657 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
657 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
658              shouldThrow();
659 <        }
702 <        catch (NullPointerException success){}
659 >        } catch (NullPointerException success) {}
660      }
661  
662      /**
# Line 708 | Line 665 | public class ThreadPoolExecutorSubclassT
665      public void testConstructorNullPointerException3() {
666          try {
667              ThreadFactory f = null;
668 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
668 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
669              shouldThrow();
670 <        }
714 <        catch (NullPointerException success){}
670 >        } catch (NullPointerException success) {}
671      }
672  
673  
# Line 720 | Line 676 | public class ThreadPoolExecutorSubclassT
676       */
677      public void testConstructor11() {
678          try {
679 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
679 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
680              shouldThrow();
681 <        }
726 <        catch (IllegalArgumentException success){}
681 >        } catch (IllegalArgumentException success) {}
682      }
683  
684      /**
# Line 731 | Line 686 | public class ThreadPoolExecutorSubclassT
686       */
687      public void testConstructor12() {
688          try {
689 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
689 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
690              shouldThrow();
691 <        }
737 <        catch (IllegalArgumentException success){}
691 >        } catch (IllegalArgumentException success) {}
692      }
693  
694      /**
# Line 742 | Line 696 | public class ThreadPoolExecutorSubclassT
696       */
697      public void testConstructor13() {
698          try {
699 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
699 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
700              shouldThrow();
701 <        }
748 <        catch (IllegalArgumentException success){}
701 >        } catch (IllegalArgumentException success) {}
702      }
703  
704      /**
# Line 753 | Line 706 | public class ThreadPoolExecutorSubclassT
706       */
707      public void testConstructor14() {
708          try {
709 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
709 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
710              shouldThrow();
711 <        }
759 <        catch (IllegalArgumentException success){}
711 >        } catch (IllegalArgumentException success) {}
712      }
713  
714      /**
# Line 764 | Line 716 | public class ThreadPoolExecutorSubclassT
716       */
717      public void testConstructor15() {
718          try {
719 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
719 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
720              shouldThrow();
721 <        }
770 <        catch (IllegalArgumentException success){}
721 >        } catch (IllegalArgumentException success) {}
722      }
723  
724      /**
# Line 775 | Line 726 | public class ThreadPoolExecutorSubclassT
726       */
727      public void testConstructorNullPointerException4() {
728          try {
729 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
729 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
730              shouldThrow();
731 <        }
781 <        catch (NullPointerException success){}
731 >        } catch (NullPointerException success) {}
732      }
733  
734      /**
# Line 787 | Line 737 | public class ThreadPoolExecutorSubclassT
737      public void testConstructorNullPointerException5() {
738          try {
739              RejectedExecutionHandler r = null;
740 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
740 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
741              shouldThrow();
742 <        }
793 <        catch (NullPointerException success){}
742 >        } catch (NullPointerException success) {}
743      }
744  
745  
# Line 799 | Line 748 | public class ThreadPoolExecutorSubclassT
748       */
749      public void testConstructor16() {
750          try {
751 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
751 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
752              shouldThrow();
753 <        }
805 <        catch (IllegalArgumentException success){}
753 >        } catch (IllegalArgumentException success) {}
754      }
755  
756      /**
# Line 810 | Line 758 | public class ThreadPoolExecutorSubclassT
758       */
759      public void testConstructor17() {
760          try {
761 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
761 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
762              shouldThrow();
763 <        }
816 <        catch (IllegalArgumentException success){}
763 >        } catch (IllegalArgumentException success) {}
764      }
765  
766      /**
# Line 821 | Line 768 | public class ThreadPoolExecutorSubclassT
768       */
769      public void testConstructor18() {
770          try {
771 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
771 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
772              shouldThrow();
773 <        }
827 <        catch (IllegalArgumentException success){}
773 >        } catch (IllegalArgumentException success) {}
774      }
775  
776      /**
# Line 832 | Line 778 | public class ThreadPoolExecutorSubclassT
778       */
779      public void testConstructor19() {
780          try {
781 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
781 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
782              shouldThrow();
783 <        }
838 <        catch (IllegalArgumentException success){}
783 >        } catch (IllegalArgumentException success) {}
784      }
785  
786      /**
# Line 843 | Line 788 | public class ThreadPoolExecutorSubclassT
788       */
789      public void testConstructor20() {
790          try {
791 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
791 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
792              shouldThrow();
793 <        }
849 <        catch (IllegalArgumentException success){}
793 >        } catch (IllegalArgumentException success) {}
794      }
795  
796      /**
# Line 854 | Line 798 | public class ThreadPoolExecutorSubclassT
798       */
799      public void testConstructorNullPointerException6() {
800          try {
801 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
801 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
802              shouldThrow();
803 <        }
860 <        catch (NullPointerException success){}
803 >        } catch (NullPointerException success) {}
804      }
805  
806      /**
# Line 866 | Line 809 | public class ThreadPoolExecutorSubclassT
809      public void testConstructorNullPointerException7() {
810          try {
811              RejectedExecutionHandler r = null;
812 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
812 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
813              shouldThrow();
814 <        }
872 <        catch (NullPointerException success){}
814 >        } catch (NullPointerException success) {}
815      }
816  
817      /**
# Line 878 | Line 820 | public class ThreadPoolExecutorSubclassT
820      public void testConstructorNullPointerException8() {
821          try {
822              ThreadFactory f = null;
823 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
823 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
824              shouldThrow();
825 <        }
884 <        catch (NullPointerException successdn8){}
825 >        } catch (NullPointerException success) {}
826      }
827  
828  
829      /**
830 <     *  execute throws RejectedExecutionException
890 <     *  if saturated.
830 >     * execute throws RejectedExecutionException if saturated.
831       */
832      public void testSaturatedExecute() {
833 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
833 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
834          try {
835  
836 <            for(int i = 0; i < 5; ++i){
836 >            for (int i = 0; i < 5; ++i) {
837                  p.execute(new MediumRunnable());
838              }
839              shouldThrow();
840 <        } catch(RejectedExecutionException success){}
840 >        } catch (RejectedExecutionException success) {}
841          joinPool(p);
842      }
843  
844      /**
845 <     *  executor using CallerRunsPolicy runs task if saturated.
845 >     * executor using CallerRunsPolicy runs task if saturated.
846       */
847      public void testSaturatedExecute2() {
848          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
849 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
849 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
850          try {
851  
852              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
853 <            for(int i = 0; i < 5; ++i){
853 >            for (int i = 0; i < 5; ++i) {
854                  tasks[i] = new TrackedNoOpRunnable();
855              }
856              TrackedLongRunnable mr = new TrackedLongRunnable();
857              p.execute(mr);
858 <            for(int i = 0; i < 5; ++i){
858 >            for (int i = 0; i < 5; ++i) {
859                  p.execute(tasks[i]);
860              }
861 <            for(int i = 1; i < 5; ++i) {
861 >            for (int i = 1; i < 5; ++i) {
862                  assertTrue(tasks[i].done);
863              }
864 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
925 <        } catch(RejectedExecutionException ex){
926 <            unexpectedException();
864 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
865          } finally {
866              joinPool(p);
867          }
868      }
869  
870      /**
871 <     *  executor using DiscardPolicy drops task if saturated.
871 >     * executor using DiscardPolicy drops task if saturated.
872       */
873      public void testSaturatedExecute3() {
874          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
875 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
875 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
876          try {
877  
878              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
879 <            for(int i = 0; i < 5; ++i){
879 >            for (int i = 0; i < 5; ++i) {
880                  tasks[i] = new TrackedNoOpRunnable();
881              }
882              p.execute(new TrackedLongRunnable());
883 <            for(int i = 0; i < 5; ++i){
883 >            for (int i = 0; i < 5; ++i) {
884                  p.execute(tasks[i]);
885              }
886 <            for(int i = 0; i < 5; ++i){
886 >            for (int i = 0; i < 5; ++i) {
887                  assertFalse(tasks[i].done);
888              }
889 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
952 <        } catch(RejectedExecutionException ex){
953 <            unexpectedException();
889 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
890          } finally {
891              joinPool(p);
892          }
893      }
894  
895      /**
896 <     *  executor using DiscardOldestPolicy drops oldest task if saturated.
896 >     * executor using DiscardOldestPolicy drops oldest task if saturated.
897       */
898      public void testSaturatedExecute4() {
899          RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy();
900 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
900 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
901          try {
902              p.execute(new TrackedLongRunnable());
903              TrackedLongRunnable r2 = new TrackedLongRunnable();
# Line 971 | Line 907 | public class ThreadPoolExecutorSubclassT
907              p.execute(r3);
908              assertFalse(p.getQueue().contains(r2));
909              assertTrue(p.getQueue().contains(r3));
910 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
975 <        } catch(RejectedExecutionException ex){
976 <            unexpectedException();
910 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
911          } finally {
912              joinPool(p);
913          }
914      }
915  
916      /**
917 <     *  execute throws RejectedExecutionException if shutdown
917 >     * execute throws RejectedExecutionException if shutdown
918       */
919      public void testRejectedExecutionExceptionOnShutdown() {
920          ThreadPoolExecutor tpe =
921 <            new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
922 <        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
923 <        try {
924 <            tpe.execute(new NoOpRunnable());
925 <            shouldThrow();
926 <        } catch(RejectedExecutionException success){}
921 >            new CustomTPE(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
922 >        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
923 >        try {
924 >            tpe.execute(new NoOpRunnable());
925 >            shouldThrow();
926 >        } catch (RejectedExecutionException success) {}
927  
928 <        joinPool(tpe);
928 >        joinPool(tpe);
929      }
930  
931      /**
932 <     *  execute using CallerRunsPolicy drops task on shutdown
932 >     * execute using CallerRunsPolicy drops task on shutdown
933       */
934      public void testCallerRunsOnShutdown() {
935          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
936 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
936 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
937  
938 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
939 <        try {
938 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
939 >        try {
940              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
941 <            p.execute(r);
941 >            p.execute(r);
942              assertFalse(r.done);
1009        } catch(RejectedExecutionException success){
1010            unexpectedException();
943          } finally {
944              joinPool(p);
945          }
946      }
947  
948      /**
949 <     *  execute using DiscardPolicy drops task on shutdown
949 >     * execute using DiscardPolicy drops task on shutdown
950       */
951      public void testDiscardOnShutdown() {
952          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
953 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
953 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
954  
955 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
956 <        try {
955 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
956 >        try {
957              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
958 <            p.execute(r);
958 >            p.execute(r);
959              assertFalse(r.done);
1028        } catch(RejectedExecutionException success){
1029            unexpectedException();
960          } finally {
961              joinPool(p);
962          }
# Line 1034 | Line 964 | public class ThreadPoolExecutorSubclassT
964  
965  
966      /**
967 <     *  execute using DiscardOldestPolicy drops task on shutdown
967 >     * execute using DiscardOldestPolicy drops task on shutdown
968       */
969      public void testDiscardOldestOnShutdown() {
970          RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy();
971 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
971 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
972  
973 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
974 <        try {
973 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
974 >        try {
975              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
976 <            p.execute(r);
976 >            p.execute(r);
977              assertFalse(r.done);
1048        } catch(RejectedExecutionException success){
1049            unexpectedException();
978          } finally {
979              joinPool(p);
980          }
# Line 1054 | Line 982 | public class ThreadPoolExecutorSubclassT
982  
983  
984      /**
985 <     *  execute (null) throws NPE
985 >     * execute(null) throws NPE
986       */
987      public void testExecuteNull() {
988          ThreadPoolExecutor tpe = null;
989          try {
990 <            tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
991 <            tpe.execute(null);
990 >            tpe = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
991 >            tpe.execute(null);
992              shouldThrow();
993 <        } catch(NullPointerException success){}
993 >        } catch (NullPointerException success) {}
994  
995 <        joinPool(tpe);
995 >        joinPool(tpe);
996      }
997  
998      /**
999 <     *  setCorePoolSize of negative value throws IllegalArgumentException
999 >     * setCorePoolSize of negative value throws IllegalArgumentException
1000       */
1001      public void testCorePoolSizeIllegalArgumentException() {
1002 <        ThreadPoolExecutor tpe = null;
1003 <        try {
1004 <            tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1005 <        } catch(Exception e){}
1006 <        try {
1007 <            tpe.setCorePoolSize(-1);
1080 <            shouldThrow();
1081 <        } catch(IllegalArgumentException success){
1002 >        ThreadPoolExecutor tpe =
1003 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1004 >        try {
1005 >            tpe.setCorePoolSize(-1);
1006 >            shouldThrow();
1007 >        } catch (IllegalArgumentException success) {
1008          } finally {
1009 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1009 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1010          }
1011          joinPool(tpe);
1012      }
1013  
1014      /**
1015 <     *  setMaximumPoolSize(int) throws IllegalArgumentException if
1016 <     *  given a value less the core pool size
1015 >     * setMaximumPoolSize(int) throws IllegalArgumentException
1016 >     * if given a value less the core pool size
1017       */
1018      public void testMaximumPoolSizeIllegalArgumentException() {
1019 <        ThreadPoolExecutor tpe = null;
1020 <        try {
1095 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1096 <        } catch(Exception e){}
1019 >        ThreadPoolExecutor tpe =
1020 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1021          try {
1022              tpe.setMaximumPoolSize(1);
1023              shouldThrow();
1024 <        } catch(IllegalArgumentException success){
1024 >        } catch (IllegalArgumentException success) {
1025          } finally {
1026 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1026 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1027          }
1028          joinPool(tpe);
1029      }
1030  
1031      /**
1032 <     *  setMaximumPoolSize throws IllegalArgumentException
1033 <     *  if given a negative value
1032 >     * setMaximumPoolSize throws IllegalArgumentException
1033 >     * if given a negative value
1034       */
1035      public void testMaximumPoolSizeIllegalArgumentException2() {
1036 <        ThreadPoolExecutor tpe = null;
1037 <        try {
1114 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1115 <        } catch(Exception e){}
1036 >        ThreadPoolExecutor tpe =
1037 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1038          try {
1039              tpe.setMaximumPoolSize(-1);
1040              shouldThrow();
1041 <        } catch(IllegalArgumentException success){
1041 >        } catch (IllegalArgumentException success) {
1042          } finally {
1043 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1043 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1044          }
1045          joinPool(tpe);
1046      }
1047  
1048  
1049      /**
1050 <     *  setKeepAliveTime  throws IllegalArgumentException
1051 <     *  when given a negative value
1050 >     * setKeepAliveTime throws IllegalArgumentException
1051 >     * when given a negative value
1052       */
1053      public void testKeepAliveTimeIllegalArgumentException() {
1054 <        ThreadPoolExecutor tpe = null;
1055 <        try {
1134 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1135 <        } catch(Exception e){}
1054 >        ThreadPoolExecutor tpe =
1055 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1056  
1057 <        try {
1058 <            tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
1057 >        try {
1058 >            tpe.setKeepAliveTime(-1,MILLISECONDS);
1059              shouldThrow();
1060 <        } catch(IllegalArgumentException success){
1060 >        } catch (IllegalArgumentException success) {
1061          } finally {
1062 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1062 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1063          }
1064          joinPool(tpe);
1065      }
# Line 1149 | Line 1069 | public class ThreadPoolExecutorSubclassT
1069       */
1070      public void testTerminated() {
1071          CustomTPE tpe = new CustomTPE();
1072 <        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1072 >        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1073          assertTrue(tpe.terminatedCalled);
1074          joinPool(tpe);
1075      }
# Line 1157 | Line 1077 | public class ThreadPoolExecutorSubclassT
1077      /**
1078       * beforeExecute and afterExecute are called when executing task
1079       */
1080 <    public void testBeforeAfter() {
1080 >    public void testBeforeAfter() throws InterruptedException {
1081          CustomTPE tpe = new CustomTPE();
1082          try {
1083              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1166 | Line 1086 | public class ThreadPoolExecutorSubclassT
1086              assertTrue(r.done);
1087              assertTrue(tpe.beforeCalled);
1088              assertTrue(tpe.afterCalled);
1089 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1170 <        }
1171 <        catch(Exception ex) {
1172 <            unexpectedException();
1089 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1090          } finally {
1091              joinPool(tpe);
1092          }
# Line 1178 | Line 1095 | public class ThreadPoolExecutorSubclassT
1095      /**
1096       * completed submit of callable returns result
1097       */
1098 <    public void testSubmitCallable() {
1099 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1098 >    public void testSubmitCallable() throws Exception {
1099 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1100          try {
1101              Future<String> future = e.submit(new StringTask());
1102              String result = future.get();
1103              assertSame(TEST_STRING, result);
1187        }
1188        catch (ExecutionException ex) {
1189            unexpectedException();
1190        }
1191        catch (InterruptedException ex) {
1192            unexpectedException();
1104          } finally {
1105              joinPool(e);
1106          }
# Line 1198 | Line 1109 | public class ThreadPoolExecutorSubclassT
1109      /**
1110       * completed submit of runnable returns successfully
1111       */
1112 <    public void testSubmitRunnable() {
1113 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1112 >    public void testSubmitRunnable() throws Exception {
1113 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1114          try {
1115              Future<?> future = e.submit(new NoOpRunnable());
1116              future.get();
1117              assertTrue(future.isDone());
1207        }
1208        catch (ExecutionException ex) {
1209            unexpectedException();
1210        }
1211        catch (InterruptedException ex) {
1212            unexpectedException();
1118          } finally {
1119              joinPool(e);
1120          }
# Line 1218 | Line 1123 | public class ThreadPoolExecutorSubclassT
1123      /**
1124       * completed submit of (runnable, result) returns result
1125       */
1126 <    public void testSubmitRunnable2() {
1127 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1126 >    public void testSubmitRunnable2() throws Exception {
1127 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1128          try {
1129              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1130              String result = future.get();
1131              assertSame(TEST_STRING, result);
1227        }
1228        catch (ExecutionException ex) {
1229            unexpectedException();
1230        }
1231        catch (InterruptedException ex) {
1232            unexpectedException();
1132          } finally {
1133              joinPool(e);
1134          }
1135      }
1136  
1137  
1239
1240
1241
1138      /**
1139       * invokeAny(null) throws NPE
1140       */
1141 <    public void testInvokeAny1() {
1142 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1141 >    public void testInvokeAny1() throws Exception {
1142 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1143          try {
1144              e.invokeAny(null);
1145 +            shouldThrow();
1146          } catch (NullPointerException success) {
1250        } catch(Exception ex) {
1251            unexpectedException();
1147          } finally {
1148              joinPool(e);
1149          }
# Line 1257 | Line 1152 | public class ThreadPoolExecutorSubclassT
1152      /**
1153       * invokeAny(empty collection) throws IAE
1154       */
1155 <    public void testInvokeAny2() {
1156 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1155 >    public void testInvokeAny2() throws Exception {
1156 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1157          try {
1158              e.invokeAny(new ArrayList<Callable<String>>());
1159 +            shouldThrow();
1160          } catch (IllegalArgumentException success) {
1265        } catch(Exception ex) {
1266            unexpectedException();
1161          } finally {
1162              joinPool(e);
1163          }
# Line 1272 | Line 1166 | public class ThreadPoolExecutorSubclassT
1166      /**
1167       * invokeAny(c) throws NPE if c has null elements
1168       */
1169 <    public void testInvokeAny3() {
1170 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1169 >    public void testInvokeAny3() throws Exception {
1170 >        CountDownLatch latch = new CountDownLatch(1);
1171 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1172 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1173 >        l.add(latchAwaitingStringTask(latch));
1174 >        l.add(null);
1175          try {
1278            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1279            l.add(new StringTask());
1280            l.add(null);
1176              e.invokeAny(l);
1177 +            shouldThrow();
1178          } catch (NullPointerException success) {
1283        } catch(Exception ex) {
1284            unexpectedException();
1179          } finally {
1180 +            latch.countDown();
1181              joinPool(e);
1182          }
1183      }
# Line 1290 | Line 1185 | public class ThreadPoolExecutorSubclassT
1185      /**
1186       * invokeAny(c) throws ExecutionException if no task completes
1187       */
1188 <    public void testInvokeAny4() {
1189 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1188 >    public void testInvokeAny4() throws Exception {
1189 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1190 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1191 >        l.add(new NPETask());
1192          try {
1296            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1297            l.add(new NPETask());
1193              e.invokeAny(l);
1194 +            shouldThrow();
1195          } catch (ExecutionException success) {
1196 <        } catch(Exception ex) {
1301 <            unexpectedException();
1196 >            assertTrue(success.getCause() instanceof NullPointerException);
1197          } finally {
1198              joinPool(e);
1199          }
# Line 1307 | Line 1202 | public class ThreadPoolExecutorSubclassT
1202      /**
1203       * invokeAny(c) returns result of some task
1204       */
1205 <    public void testInvokeAny5() {
1206 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1205 >    public void testInvokeAny5() throws Exception {
1206 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1207          try {
1208 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1208 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1209              l.add(new StringTask());
1210              l.add(new StringTask());
1211              String result = e.invokeAny(l);
1212              assertSame(TEST_STRING, result);
1318        } catch (ExecutionException success) {
1319        } catch(Exception ex) {
1320            unexpectedException();
1213          } finally {
1214              joinPool(e);
1215          }
# Line 1326 | Line 1218 | public class ThreadPoolExecutorSubclassT
1218      /**
1219       * invokeAll(null) throws NPE
1220       */
1221 <    public void testInvokeAll1() {
1222 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1221 >    public void testInvokeAll1() throws Exception {
1222 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1223          try {
1224              e.invokeAll(null);
1225 +            shouldThrow();
1226          } catch (NullPointerException success) {
1334        } catch(Exception ex) {
1335            unexpectedException();
1227          } finally {
1228              joinPool(e);
1229          }
# Line 1341 | Line 1232 | public class ThreadPoolExecutorSubclassT
1232      /**
1233       * invokeAll(empty collection) returns empty collection
1234       */
1235 <    public void testInvokeAll2() {
1236 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1235 >    public void testInvokeAll2() throws Exception {
1236 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1237          try {
1238              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1239              assertTrue(r.isEmpty());
1349        } catch(Exception ex) {
1350            unexpectedException();
1240          } finally {
1241              joinPool(e);
1242          }
# Line 1356 | Line 1245 | public class ThreadPoolExecutorSubclassT
1245      /**
1246       * invokeAll(c) throws NPE if c has null elements
1247       */
1248 <    public void testInvokeAll3() {
1249 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1248 >    public void testInvokeAll3() throws Exception {
1249 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1250 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1251 >        l.add(new StringTask());
1252 >        l.add(null);
1253          try {
1362            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1363            l.add(new StringTask());
1364            l.add(null);
1254              e.invokeAll(l);
1255 +            shouldThrow();
1256          } catch (NullPointerException success) {
1367        } catch(Exception ex) {
1368            unexpectedException();
1257          } finally {
1258              joinPool(e);
1259          }
# Line 1374 | Line 1262 | public class ThreadPoolExecutorSubclassT
1262      /**
1263       * get of element of invokeAll(c) throws exception on failed task
1264       */
1265 <    public void testInvokeAll4() {
1266 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1265 >    public void testInvokeAll4() throws Exception {
1266 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1267 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1268 >        l.add(new NPETask());
1269 >        List<Future<String>> futures = e.invokeAll(l);
1270 >        assertEquals(1, futures.size());
1271          try {
1272 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1273 <            l.add(new NPETask());
1274 <            List<Future<String>> result = e.invokeAll(l);
1275 <            assertEquals(1, result.size());
1384 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1385 <                it.next().get();
1386 <        } catch(ExecutionException success) {
1387 <        } catch(Exception ex) {
1388 <            unexpectedException();
1272 >            futures.get(0).get();
1273 >            shouldThrow();
1274 >        } catch (ExecutionException success) {
1275 >            assertTrue(success.getCause() instanceof NullPointerException);
1276          } finally {
1277              joinPool(e);
1278          }
# Line 1394 | Line 1281 | public class ThreadPoolExecutorSubclassT
1281      /**
1282       * invokeAll(c) returns results of all completed tasks
1283       */
1284 <    public void testInvokeAll5() {
1285 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1284 >    public void testInvokeAll5() throws Exception {
1285 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1286          try {
1287 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1287 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1288              l.add(new StringTask());
1289              l.add(new StringTask());
1290 <            List<Future<String>> result = e.invokeAll(l);
1291 <            assertEquals(2, result.size());
1292 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1293 <                assertSame(TEST_STRING, it.next().get());
1407 <        } catch (ExecutionException success) {
1408 <        } catch(Exception ex) {
1409 <            unexpectedException();
1290 >            List<Future<String>> futures = e.invokeAll(l);
1291 >            assertEquals(2, futures.size());
1292 >            for (Future<String> future : futures)
1293 >                assertSame(TEST_STRING, future.get());
1294          } finally {
1295              joinPool(e);
1296          }
# Line 1417 | Line 1301 | public class ThreadPoolExecutorSubclassT
1301      /**
1302       * timed invokeAny(null) throws NPE
1303       */
1304 <    public void testTimedInvokeAny1() {
1305 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1304 >    public void testTimedInvokeAny1() throws Exception {
1305 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1306          try {
1307 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1307 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1308 >            shouldThrow();
1309          } catch (NullPointerException success) {
1425        } catch(Exception ex) {
1426            unexpectedException();
1310          } finally {
1311              joinPool(e);
1312          }
# Line 1432 | Line 1315 | public class ThreadPoolExecutorSubclassT
1315      /**
1316       * timed invokeAny(,,null) throws NPE
1317       */
1318 <    public void testTimedInvokeAnyNullTimeUnit() {
1319 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1318 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1319 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1320 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1321 >        l.add(new StringTask());
1322          try {
1438            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1439            l.add(new StringTask());
1323              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1324 +            shouldThrow();
1325          } catch (NullPointerException success) {
1442        } catch(Exception ex) {
1443            unexpectedException();
1326          } finally {
1327              joinPool(e);
1328          }
# Line 1449 | Line 1331 | public class ThreadPoolExecutorSubclassT
1331      /**
1332       * timed invokeAny(empty collection) throws IAE
1333       */
1334 <    public void testTimedInvokeAny2() {
1335 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1334 >    public void testTimedInvokeAny2() throws Exception {
1335 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1336          try {
1337 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1337 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1338 >            shouldThrow();
1339          } catch (IllegalArgumentException success) {
1457        } catch(Exception ex) {
1458            unexpectedException();
1340          } finally {
1341              joinPool(e);
1342          }
# Line 1464 | Line 1345 | public class ThreadPoolExecutorSubclassT
1345      /**
1346       * timed invokeAny(c) throws NPE if c has null elements
1347       */
1348 <    public void testTimedInvokeAny3() {
1349 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1348 >    public void testTimedInvokeAny3() throws Exception {
1349 >        CountDownLatch latch = new CountDownLatch(1);
1350 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1351 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1352 >        l.add(latchAwaitingStringTask(latch));
1353 >        l.add(null);
1354          try {
1355 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1356 <            l.add(new StringTask());
1472 <            l.add(null);
1473 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1355 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1356 >            shouldThrow();
1357          } catch (NullPointerException success) {
1475        } catch(Exception ex) {
1476            ex.printStackTrace();
1477            unexpectedException();
1358          } finally {
1359 +            latch.countDown();
1360              joinPool(e);
1361          }
1362      }
# Line 1483 | Line 1364 | public class ThreadPoolExecutorSubclassT
1364      /**
1365       * timed invokeAny(c) throws ExecutionException if no task completes
1366       */
1367 <    public void testTimedInvokeAny4() {
1368 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1367 >    public void testTimedInvokeAny4() throws Exception {
1368 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1369 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1370 >        l.add(new NPETask());
1371          try {
1372 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1373 <            l.add(new NPETask());
1374 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1375 <        } catch(ExecutionException success) {
1493 <        } catch(Exception ex) {
1494 <            unexpectedException();
1372 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1373 >            shouldThrow();
1374 >        } catch (ExecutionException success) {
1375 >            assertTrue(success.getCause() instanceof NullPointerException);
1376          } finally {
1377              joinPool(e);
1378          }
# Line 1500 | Line 1381 | public class ThreadPoolExecutorSubclassT
1381      /**
1382       * timed invokeAny(c) returns result of some task
1383       */
1384 <    public void testTimedInvokeAny5() {
1385 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1384 >    public void testTimedInvokeAny5() throws Exception {
1385 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1386          try {
1387 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1387 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1388              l.add(new StringTask());
1389              l.add(new StringTask());
1390 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1390 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1391              assertSame(TEST_STRING, result);
1511        } catch (ExecutionException success) {
1512        } catch(Exception ex) {
1513            unexpectedException();
1392          } finally {
1393              joinPool(e);
1394          }
# Line 1519 | Line 1397 | public class ThreadPoolExecutorSubclassT
1397      /**
1398       * timed invokeAll(null) throws NPE
1399       */
1400 <    public void testTimedInvokeAll1() {
1401 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1400 >    public void testTimedInvokeAll1() throws Exception {
1401 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1402          try {
1403 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1403 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1404 >            shouldThrow();
1405          } catch (NullPointerException success) {
1527        } catch(Exception ex) {
1528            unexpectedException();
1406          } finally {
1407              joinPool(e);
1408          }
# Line 1534 | Line 1411 | public class ThreadPoolExecutorSubclassT
1411      /**
1412       * timed invokeAll(,,null) throws NPE
1413       */
1414 <    public void testTimedInvokeAllNullTimeUnit() {
1415 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1414 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1415 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1416 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1417 >        l.add(new StringTask());
1418          try {
1540            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1541            l.add(new StringTask());
1419              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1420 +            shouldThrow();
1421          } catch (NullPointerException success) {
1544        } catch(Exception ex) {
1545            unexpectedException();
1422          } finally {
1423              joinPool(e);
1424          }
# Line 1551 | Line 1427 | public class ThreadPoolExecutorSubclassT
1427      /**
1428       * timed invokeAll(empty collection) returns empty collection
1429       */
1430 <    public void testTimedInvokeAll2() {
1431 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1430 >    public void testTimedInvokeAll2() throws Exception {
1431 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1432          try {
1433 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1433 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1434              assertTrue(r.isEmpty());
1559        } catch(Exception ex) {
1560            unexpectedException();
1435          } finally {
1436              joinPool(e);
1437          }
# Line 1566 | Line 1440 | public class ThreadPoolExecutorSubclassT
1440      /**
1441       * timed invokeAll(c) throws NPE if c has null elements
1442       */
1443 <    public void testTimedInvokeAll3() {
1444 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1443 >    public void testTimedInvokeAll3() throws Exception {
1444 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1445 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1446 >        l.add(new StringTask());
1447 >        l.add(null);
1448          try {
1449 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1450 <            l.add(new StringTask());
1574 <            l.add(null);
1575 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1449 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1450 >            shouldThrow();
1451          } catch (NullPointerException success) {
1577        } catch(Exception ex) {
1578            unexpectedException();
1452          } finally {
1453              joinPool(e);
1454          }
# Line 1584 | Line 1457 | public class ThreadPoolExecutorSubclassT
1457      /**
1458       * get of element of invokeAll(c) throws exception on failed task
1459       */
1460 <    public void testTimedInvokeAll4() {
1461 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1460 >    public void testTimedInvokeAll4() throws Exception {
1461 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1462 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1463 >        l.add(new NPETask());
1464 >        List<Future<String>> futures =
1465 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1466 >        assertEquals(1, futures.size());
1467          try {
1468 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1469 <            l.add(new NPETask());
1470 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1471 <            assertEquals(1, result.size());
1594 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1595 <                it.next().get();
1596 <        } catch(ExecutionException success) {
1597 <        } catch(Exception ex) {
1598 <            unexpectedException();
1468 >            futures.get(0).get();
1469 >            shouldThrow();
1470 >        } catch (ExecutionException success) {
1471 >            assertTrue(success.getCause() instanceof NullPointerException);
1472          } finally {
1473              joinPool(e);
1474          }
# Line 1604 | Line 1477 | public class ThreadPoolExecutorSubclassT
1477      /**
1478       * timed invokeAll(c) returns results of all completed tasks
1479       */
1480 <    public void testTimedInvokeAll5() {
1481 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1480 >    public void testTimedInvokeAll5() throws Exception {
1481 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1482          try {
1483 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1483 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1484              l.add(new StringTask());
1485              l.add(new StringTask());
1486 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1487 <            assertEquals(2, result.size());
1488 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1489 <                assertSame(TEST_STRING, it.next().get());
1490 <        } catch (ExecutionException success) {
1618 <        } catch(Exception ex) {
1619 <            unexpectedException();
1486 >            List<Future<String>> futures =
1487 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1488 >            assertEquals(2, futures.size());
1489 >            for (Future<String> future : futures)
1490 >                assertSame(TEST_STRING, future.get());
1491          } finally {
1492              joinPool(e);
1493          }
# Line 1625 | Line 1496 | public class ThreadPoolExecutorSubclassT
1496      /**
1497       * timed invokeAll(c) cancels tasks not completed by timeout
1498       */
1499 <    public void testTimedInvokeAll6() {
1500 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1499 >    public void testTimedInvokeAll6() throws Exception {
1500 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1501          try {
1502 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1502 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1503              l.add(new StringTask());
1504              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1505              l.add(new StringTask());
1506 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1507 <            assertEquals(3, result.size());
1508 <            Iterator<Future<String>> it = result.iterator();
1506 >            List<Future<String>> futures =
1507 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1508 >            assertEquals(3, futures.size());
1509 >            Iterator<Future<String>> it = futures.iterator();
1510              Future<String> f1 = it.next();
1511              Future<String> f2 = it.next();
1512              Future<String> f3 = it.next();
# Line 1643 | Line 1515 | public class ThreadPoolExecutorSubclassT
1515              assertTrue(f3.isDone());
1516              assertFalse(f1.isCancelled());
1517              assertTrue(f2.isCancelled());
1646        } catch(Exception ex) {
1647            unexpectedException();
1518          } finally {
1519              joinPool(e);
1520          }
# Line 1654 | Line 1524 | public class ThreadPoolExecutorSubclassT
1524       * Execution continues if there is at least one thread even if
1525       * thread factory fails to create more
1526       */
1527 <    public void testFailingThreadFactory() {
1528 <        ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1527 >    public void testFailingThreadFactory() throws InterruptedException {
1528 >        ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1529          try {
1660            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1530              for (int k = 0; k < 100; ++k) {
1531                  e.execute(new NoOpRunnable());
1532              }
1533              Thread.sleep(LONG_DELAY_MS);
1665        } catch(Exception ex) {
1666            unexpectedException();
1534          } finally {
1535              joinPool(e);
1536          }
# Line 1673 | Line 1540 | public class ThreadPoolExecutorSubclassT
1540       * allowsCoreThreadTimeOut is by default false.
1541       */
1542      public void testAllowsCoreThreadTimeOut() {
1543 <        ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1543 >        ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1544          assertFalse(tpe.allowsCoreThreadTimeOut());
1545          joinPool(tpe);
1546      }
# Line 1681 | Line 1548 | public class ThreadPoolExecutorSubclassT
1548      /**
1549       * allowCoreThreadTimeOut(true) causes idle threads to time out
1550       */
1551 <    public void testAllowCoreThreadTimeOut_true() {
1552 <        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1551 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1552 >        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1553          tpe.allowCoreThreadTimeOut(true);
1554          tpe.execute(new NoOpRunnable());
1555          try {
1556              Thread.sleep(MEDIUM_DELAY_MS);
1557              assertEquals(0, tpe.getPoolSize());
1691        } catch(InterruptedException e){
1692            unexpectedException();
1558          } finally {
1559              joinPool(tpe);
1560          }
# Line 1698 | Line 1563 | public class ThreadPoolExecutorSubclassT
1563      /**
1564       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1565       */
1566 <    public void testAllowCoreThreadTimeOut_false() {
1567 <        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1566 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1567 >        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1568          tpe.allowCoreThreadTimeOut(false);
1569          tpe.execute(new NoOpRunnable());
1570          try {
1571              Thread.sleep(MEDIUM_DELAY_MS);
1572              assertTrue(tpe.getPoolSize() >= 1);
1708        } catch(InterruptedException e){
1709            unexpectedException();
1573          } finally {
1574              joinPool(tpe);
1575          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines