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.1 by dl, Fri May 20 16:30:17 2005 UTC vs.
Revision 1.5 by jsr166, Wed Nov 18 16:51:26 2009 UTC

# Line 2 | Line 2
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5 < * Other contributors include Andrew Wright, Jeffrey Hayes,
6 < * Pat Fisher, Mike Judd.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import java.util.concurrent.*;
# Line 14 | Line 14 | import java.util.*;
14  
15   public class ThreadPoolExecutorSubclassTest 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 31 | Line 31 | public class ThreadPoolExecutorSubclassT
31          Exception exception;
32          CustomTask(Callable<V> c) { callable = c; }
33          CustomTask(final Runnable r, final V res) { callable = new Callable<V>() {
34 <            public V call() throws Exception { r.run(); return res; }};
34 >            public V call() throws Exception { r.run(); return res; }};
35          }
36          public boolean isDone() {
37              lock.lock(); try { return done; } finally { lock.unlock() ; }
# Line 45 | Line 45 | public class ThreadPoolExecutorSubclassT
45                  if (!done) {
46                      cancelled = true;
47                      done = true;
48 <                    if (mayInterrupt && thread != null)
48 >                    if (mayInterrupt && thread != null)
49                          thread.interrupt();
50                      return true;
51                  }
# Line 68 | Line 68 | public class ThreadPoolExecutorSubclassT
68              try {
69                  v = callable.call();
70              }
71 <            catch(Exception ex) {
71 >            catch (Exception ex) {
72                  e = ex;
73              }
74              lock.lock();
# Line 84 | Line 84 | public class ThreadPoolExecutorSubclassT
84          public V get() throws InterruptedException, ExecutionException {
85              lock.lock();
86              try {
87 <                while (!done)
87 >                while (!done)
88                      cond.await();
89                  if (exception != null)
90                      throw new ExecutionException(exception);
# Line 93 | Line 93 | public class ThreadPoolExecutorSubclassT
93              finally { lock.unlock(); }
94          }
95          public V get(long timeout, TimeUnit unit)
96 <            throws InterruptedException, ExecutionException, TimeoutException{
96 >            throws InterruptedException, ExecutionException, TimeoutException {
97              long nanos = unit.toNanos(timeout);
98              lock.lock();
99              try {
# Line 109 | Line 109 | public class ThreadPoolExecutorSubclassT
109              }
110              finally { lock.unlock(); }
111          }
112 <    }            
112 >    }
113 >
114  
114    
115      static class CustomTPE extends ThreadPoolExecutor {
116          protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
117              return new CustomTask<V>(c);
118          }
119          protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
120              return new CustomTask<V>(r, v);
121 <        }
122 <        
121 >        }
122 >
123          CustomTPE(int corePoolSize,
124                    int maximumPoolSize,
125                    long keepAliveTime,
126                    TimeUnit unit,
127                    BlockingQueue<Runnable> workQueue) {
128 <            super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
128 >            super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
129                    workQueue);
130          }
131          CustomTPE(int corePoolSize,
# Line 154 | Line 154 | public class ThreadPoolExecutorSubclassT
154                    BlockingQueue<Runnable> workQueue,
155                    ThreadFactory threadFactory,
156                    RejectedExecutionHandler handler) {
157 <            super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
157 >            super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
158                workQueue, threadFactory, handler);
159          }
160  
# Line 173 | Line 173 | public class ThreadPoolExecutorSubclassT
173          protected void terminated() {
174              terminatedCalled = true;
175          }
176 <        
176 >
177      }
178  
179 <    static class FailingThreadFactory implements ThreadFactory{
179 >    static class FailingThreadFactory implements ThreadFactory {
180          int calls = 0;
181 <        public Thread newThread(Runnable r){
181 >        public Thread newThread(Runnable r) {
182              if (++calls > 1) return null;
183              return new Thread(r);
184 <        }  
184 >        }
185      }
186 <    
186 >
187  
188      /**
189       *  execute successfully executes a runnable
190       */
191 <    public void testExecute() {
191 >    public void testExecute() throws InterruptedException {
192          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
193          try {
194 <            p1.execute(new Runnable() {
195 <                    public void run() {
196 <                        try {
197 <                            Thread.sleep(SHORT_DELAY_MS);
198 <                        } catch(InterruptedException e){
199 <                            threadUnexpectedException();
200 <                        }
201 <                    }
202 <                });
194 >            p1.execute(new ShortRunnable());
195              Thread.sleep(SMALL_DELAY_MS);
196 <        } catch(InterruptedException e){
197 <            unexpectedException();
198 <        }
207 <        joinPool(p1);
196 >        } finally {
197 >            joinPool(p1);
198 >        }
199      }
200  
201      /**
202       *  getActiveCount increases but doesn't overestimate, when a
203       *  thread becomes active
204       */
205 <    public void testGetActiveCount() {
205 >    public void testGetActiveCount() throws InterruptedException {
206          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
207          assertEquals(0, p2.getActiveCount());
208          p2.execute(new MediumRunnable());
209 <        try {
219 <            Thread.sleep(SHORT_DELAY_MS);
220 <        } catch(Exception e){
221 <            unexpectedException();
222 <        }
209 >        Thread.sleep(SHORT_DELAY_MS);
210          assertEquals(1, p2.getActiveCount());
211          joinPool(p2);
212      }
# Line 251 | Line 238 | public class ThreadPoolExecutorSubclassT
238          assertEquals(2, p2.getPoolSize());
239          joinPool(p2);
240      }
241 <    
241 >
242      /**
243       *   getCompletedTaskCount increases, but doesn't overestimate,
244       *   when tasks complete
245       */
246 <    public void testGetCompletedTaskCount() {
246 >    public void testGetCompletedTaskCount() throws InterruptedException {
247          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
248          assertEquals(0, p2.getCompletedTaskCount());
249          p2.execute(new ShortRunnable());
250 <        try {
264 <            Thread.sleep(SMALL_DELAY_MS);
265 <        } catch(Exception e){
266 <            unexpectedException();
267 <        }
250 >        Thread.sleep(SMALL_DELAY_MS);
251          assertEquals(1, p2.getCompletedTaskCount());
252 <        try { p2.shutdown(); } catch(SecurityException ok) { return; }
252 >        try { p2.shutdown(); } catch (SecurityException ok) { return; }
253          joinPool(p2);
254      }
255 <    
255 >
256      /**
257       *   getCorePoolSize returns size given in constructor if not otherwise set
258       */
# Line 278 | Line 261 | public class ThreadPoolExecutorSubclassT
261          assertEquals(1, p1.getCorePoolSize());
262          joinPool(p1);
263      }
264 <    
264 >
265      /**
266       *   getKeepAliveTime returns value given in constructor if not otherwise set
267       */
# Line 289 | Line 272 | public class ThreadPoolExecutorSubclassT
272      }
273  
274  
275 <    /**
275 >    /**
276       * getThreadFactory returns factory in constructor if not set
277       */
278      public void testGetThreadFactory() {
# Line 299 | Line 282 | public class ThreadPoolExecutorSubclassT
282          joinPool(p);
283      }
284  
285 <    /**
285 >    /**
286       * setThreadFactory sets the thread factory returned by getThreadFactory
287       */
288      public void testSetThreadFactory() {
# Line 311 | Line 294 | public class ThreadPoolExecutorSubclassT
294      }
295  
296  
297 <    /**
297 >    /**
298       * setThreadFactory(null) throws NPE
299       */
300      public void testSetThreadFactoryNull() {
# Line 325 | Line 308 | public class ThreadPoolExecutorSubclassT
308          }
309      }
310  
311 <    /**
311 >    /**
312       * getRejectedExecutionHandler returns handler in constructor if not set
313       */
314      public void testGetRejectedExecutionHandler() {
# Line 335 | Line 318 | public class ThreadPoolExecutorSubclassT
318          joinPool(p);
319      }
320  
321 <    /**
321 >    /**
322       * setRejectedExecutionHandler sets the handler returned by
323       * getRejectedExecutionHandler
324       */
# Line 348 | Line 331 | public class ThreadPoolExecutorSubclassT
331      }
332  
333  
334 <    /**
334 >    /**
335       * setRejectedExecutionHandler(null) throws NPE
336       */
337      public void testSetRejectedExecutionHandlerNull() {
# Line 362 | Line 345 | public class ThreadPoolExecutorSubclassT
345          }
346      }
347  
348 <    
348 >
349      /**
350       *   getLargestPoolSize increases, but doesn't overestimate, when
351       *   multiple threads active
352       */
353 <    public void testGetLargestPoolSize() {
353 >    public void testGetLargestPoolSize() throws InterruptedException {
354          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
355 <        try {
356 <            assertEquals(0, p2.getLargestPoolSize());
357 <            p2.execute(new MediumRunnable());
358 <            p2.execute(new MediumRunnable());
359 <            Thread.sleep(SHORT_DELAY_MS);
377 <            assertEquals(2, p2.getLargestPoolSize());
378 <        } catch(Exception e){
379 <            unexpectedException();
380 <        }
355 >        assertEquals(0, p2.getLargestPoolSize());
356 >        p2.execute(new MediumRunnable());
357 >        p2.execute(new MediumRunnable());
358 >        Thread.sleep(SHORT_DELAY_MS);
359 >        assertEquals(2, p2.getLargestPoolSize());
360          joinPool(p2);
361      }
362 <    
362 >
363      /**
364       *   getMaximumPoolSize returns value given in constructor if not
365       *   otherwise set
# Line 390 | Line 369 | public class ThreadPoolExecutorSubclassT
369          assertEquals(2, p2.getMaximumPoolSize());
370          joinPool(p2);
371      }
372 <    
372 >
373      /**
374       *   getPoolSize increases, but doesn't overestimate, when threads
375       *   become active
# Line 402 | Line 381 | public class ThreadPoolExecutorSubclassT
381          assertEquals(1, p1.getPoolSize());
382          joinPool(p1);
383      }
384 <    
384 >
385      /**
386       *  getTaskCount increases, but doesn't overestimate, when tasks submitted
387       */
388 <    public void testGetTaskCount() {
388 >    public void testGetTaskCount() throws InterruptedException {
389          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
390 <        try {
391 <            assertEquals(0, p1.getTaskCount());
392 <            p1.execute(new MediumRunnable());
393 <            Thread.sleep(SHORT_DELAY_MS);
415 <            assertEquals(1, p1.getTaskCount());
416 <        } catch(Exception e){
417 <            unexpectedException();
418 <        }
390 >        assertEquals(0, p1.getTaskCount());
391 >        p1.execute(new MediumRunnable());
392 >        Thread.sleep(SHORT_DELAY_MS);
393 >        assertEquals(1, p1.getTaskCount());
394          joinPool(p1);
395      }
396 <    
396 >
397      /**
398       *   isShutDown is false before shutdown, true after
399       */
400      public void testIsShutdown() {
401 <        
401 >
402          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
403          assertFalse(p1.isShutdown());
404 <        try { p1.shutdown(); } catch(SecurityException ok) { return; }
404 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
405          assertTrue(p1.isShutdown());
406          joinPool(p1);
407      }
408  
409 <        
409 >
410      /**
411       *  isTerminated is false before termination, true after
412       */
413 <    public void testIsTerminated() {
413 >    public void testIsTerminated() throws InterruptedException {
414          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
415          assertFalse(p1.isTerminated());
416          try {
417              p1.execute(new MediumRunnable());
418          } finally {
419 <            try { p1.shutdown(); } catch(SecurityException ok) { return; }
419 >            try { p1.shutdown(); } catch (SecurityException ok) { return; }
420          }
421 <        try {
422 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
448 <            assertTrue(p1.isTerminated());
449 <        } catch(Exception e){
450 <            unexpectedException();
451 <        }      
421 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
422 >        assertTrue(p1.isTerminated());
423      }
424  
425      /**
426       *  isTerminating is not true when running or when terminated
427       */
428 <    public void testIsTerminating() {
428 >    public void testIsTerminating() throws InterruptedException {
429          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
430          assertFalse(p1.isTerminating());
431          try {
432              p1.execute(new SmallRunnable());
433              assertFalse(p1.isTerminating());
434          } finally {
435 <            try { p1.shutdown(); } catch(SecurityException ok) { return; }
435 >            try { p1.shutdown(); } catch (SecurityException ok) { return; }
436          }
437 <        try {
438 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
439 <            assertTrue(p1.isTerminated());
469 <            assertFalse(p1.isTerminating());
470 <        } catch(Exception e){
471 <            unexpectedException();
472 <        }      
437 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
438 >        assertTrue(p1.isTerminated());
439 >        assertFalse(p1.isTerminating());
440      }
441  
442      /**
443       * getQueue returns the work queue, which contains queued tasks
444       */
445 <    public void testGetQueue() {
445 >    public void testGetQueue() throws InterruptedException {
446          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
447          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
448          FutureTask[] tasks = new FutureTask[5];
449 <        for(int i = 0; i < 5; i++){
449 >        for (int i = 0; i < 5; i++) {
450              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
451              p1.execute(tasks[i]);
452          }
# Line 492 | Line 459 | public class ThreadPoolExecutorSubclassT
459              for (int i = 1; i < 5; ++i)
460                  tasks[i].cancel(true);
461              p1.shutdownNow();
495        } catch(Exception e) {
496            unexpectedException();
462          } finally {
463              joinPool(p1);
464          }
# Line 502 | Line 467 | public class ThreadPoolExecutorSubclassT
467      /**
468       * remove(task) removes queued task, and fails to remove active task
469       */
470 <    public void testRemove() {
470 >    public void testRemove() throws InterruptedException {
471          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
472          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
473          FutureTask[] tasks = new FutureTask[5];
474 <        for(int i = 0; i < 5; i++){
474 >        for (int i = 0; i < 5; i++) {
475              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
476              p1.execute(tasks[i]);
477          }
# Line 521 | Line 486 | public class ThreadPoolExecutorSubclassT
486              assertTrue(q.contains(tasks[3]));
487              assertTrue(p1.remove(tasks[3]));
488              assertFalse(q.contains(tasks[3]));
524        } catch(Exception e) {
525            unexpectedException();
489          } finally {
490              joinPool(p1);
491          }
# Line 534 | Line 497 | public class ThreadPoolExecutorSubclassT
497      public void testPurge() {
498          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
499          FutureTask[] tasks = new FutureTask[5];
500 <        for(int i = 0; i < 5; i++){
500 >        for (int i = 0; i < 5; i++) {
501              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
502              p1.execute(tasks[i]);
503          }
# Line 553 | Line 516 | public class ThreadPoolExecutorSubclassT
516          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
517          List l;
518          try {
519 <            for(int i = 0; i < 5; i++)
519 >            for (int i = 0; i < 5; i++)
520                  p1.execute(new MediumPossiblyInterruptedRunnable());
521          }
522          finally {
523              try {
524                  l = p1.shutdownNow();
525              } catch (SecurityException ok) { return; }
526 <            
526 >
527          }
528          assertTrue(p1.isShutdown());
529          assertTrue(l.size() <= 4);
530      }
531  
532      // Exception Tests
570    
533  
534 <    /**
535 <     * Constructor throws if corePoolSize argument is less than zero
534 >
535 >    /**
536 >     * Constructor throws if corePoolSize argument is less than zero
537       */
538      public void testConstructor1() {
539          try {
540              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
541              shouldThrow();
542 <        }
580 <        catch (IllegalArgumentException success){}
542 >        } catch (IllegalArgumentException success) {}
543      }
544 <    
545 <    /**
546 <     * Constructor throws if maximumPoolSize is less than zero
544 >
545 >    /**
546 >     * Constructor throws if maximumPoolSize is less than zero
547       */
548      public void testConstructor2() {
549          try {
550              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
551              shouldThrow();
552 <        }
591 <        catch (IllegalArgumentException success){}
552 >        } catch (IllegalArgumentException success) {}
553      }
554 <    
555 <    /**
556 <     * Constructor throws if maximumPoolSize is equal to zero
554 >
555 >    /**
556 >     * Constructor throws if maximumPoolSize is equal to zero
557       */
558      public void testConstructor3() {
559          try {
560              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
561              shouldThrow();
562 <        }
602 <        catch (IllegalArgumentException success){}
562 >        } catch (IllegalArgumentException success) {}
563      }
564  
565 <    /**
566 <     * Constructor throws if keepAliveTime is less than zero
565 >    /**
566 >     * Constructor throws if keepAliveTime is less than zero
567       */
568      public void testConstructor4() {
569          try {
570              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
571              shouldThrow();
572 <        }
613 <        catch (IllegalArgumentException success){}
572 >        } catch (IllegalArgumentException success) {}
573      }
574  
575 <    /**
576 <     * Constructor throws if corePoolSize is greater than the maximumPoolSize
575 >    /**
576 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
577       */
578      public void testConstructor5() {
579          try {
580              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
581              shouldThrow();
582 <        }
624 <        catch (IllegalArgumentException success){}
582 >        } catch (IllegalArgumentException success) {}
583      }
584 <        
585 <    /**
586 <     * Constructor throws if workQueue is set to null
584 >
585 >    /**
586 >     * Constructor throws if workQueue is set to null
587       */
588      public void testConstructorNullPointerException() {
589          try {
590              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
591              shouldThrow();
592 <        }
635 <        catch (NullPointerException success){}  
592 >        } catch (NullPointerException success) {}
593      }
637    
594  
595 <    
596 <    /**
597 <     * Constructor throws if corePoolSize argument is less than zero
595 >
596 >
597 >    /**
598 >     * Constructor throws if corePoolSize argument is less than zero
599       */
600      public void testConstructor6() {
601          try {
602              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
603              shouldThrow();
604 <        } catch (IllegalArgumentException success){}
604 >        } catch (IllegalArgumentException success) {}
605      }
606 <    
607 <    /**
608 <     * Constructor throws if maximumPoolSize is less than zero
606 >
607 >    /**
608 >     * Constructor throws if maximumPoolSize is less than zero
609       */
610      public void testConstructor7() {
611          try {
612              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
613              shouldThrow();
614 <        }
658 <        catch (IllegalArgumentException success){}
614 >        } catch (IllegalArgumentException success) {}
615      }
616  
617 <    /**
618 <     * Constructor throws if maximumPoolSize is equal to zero
617 >    /**
618 >     * Constructor throws if maximumPoolSize is equal to zero
619       */
620      public void testConstructor8() {
621          try {
622              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
623              shouldThrow();
624 <        }
669 <        catch (IllegalArgumentException success){}
624 >        } catch (IllegalArgumentException success) {}
625      }
626  
627 <    /**
628 <     * Constructor throws if keepAliveTime is less than zero
627 >    /**
628 >     * Constructor throws if keepAliveTime is less than zero
629       */
630      public void testConstructor9() {
631          try {
632              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
633              shouldThrow();
634 <        }
680 <        catch (IllegalArgumentException success){}
634 >        } catch (IllegalArgumentException success) {}
635      }
636  
637 <    /**
638 <     * Constructor throws if corePoolSize is greater than the maximumPoolSize
637 >    /**
638 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
639       */
640      public void testConstructor10() {
641          try {
642              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
643              shouldThrow();
644 <        }
691 <        catch (IllegalArgumentException success){}
644 >        } catch (IllegalArgumentException success) {}
645      }
646  
647 <    /**
648 <     * Constructor throws if workQueue is set to null
647 >    /**
648 >     * Constructor throws if workQueue is set to null
649       */
650      public void testConstructorNullPointerException2() {
651          try {
652              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
653              shouldThrow();
654 <        }
702 <        catch (NullPointerException success){}  
654 >        } catch (NullPointerException success) {}
655      }
656  
657 <    /**
658 <     * Constructor throws if threadFactory is set to null
657 >    /**
658 >     * Constructor throws if threadFactory is set to null
659       */
660      public void testConstructorNullPointerException3() {
661          try {
662              ThreadFactory f = null;
663              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
664              shouldThrow();
665 <        }
714 <        catch (NullPointerException success){}  
665 >        } catch (NullPointerException success) {}
666      }
667 <
668 <    
669 <    /**
670 <     * Constructor throws if corePoolSize argument is less than zero
667 >
668 >
669 >    /**
670 >     * Constructor throws if corePoolSize argument is less than zero
671       */
672      public void testConstructor11() {
673          try {
674              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
675              shouldThrow();
676 <        }
726 <        catch (IllegalArgumentException success){}
676 >        } catch (IllegalArgumentException success) {}
677      }
678  
679 <    /**
680 <     * Constructor throws if maximumPoolSize is less than zero
679 >    /**
680 >     * Constructor throws if maximumPoolSize is less than zero
681       */
682      public void testConstructor12() {
683          try {
684              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
685              shouldThrow();
686 <        }
737 <        catch (IllegalArgumentException success){}
686 >        } catch (IllegalArgumentException success) {}
687      }
688  
689 <    /**
690 <     * Constructor throws if maximumPoolSize is equal to zero
689 >    /**
690 >     * Constructor throws if maximumPoolSize is equal to zero
691       */
692      public void testConstructor13() {
693          try {
694              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
695              shouldThrow();
696 <        }
748 <        catch (IllegalArgumentException success){}
696 >        } catch (IllegalArgumentException success) {}
697      }
698  
699 <    /**
700 <     * Constructor throws if keepAliveTime is less than zero
699 >    /**
700 >     * Constructor throws if keepAliveTime is less than zero
701       */
702      public void testConstructor14() {
703          try {
704              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
705              shouldThrow();
706 <        }
759 <        catch (IllegalArgumentException success){}
706 >        } catch (IllegalArgumentException success) {}
707      }
708  
709 <    /**
710 <     * Constructor throws if corePoolSize is greater than the maximumPoolSize
709 >    /**
710 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
711       */
712      public void testConstructor15() {
713          try {
714              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
715              shouldThrow();
716 <        }
770 <        catch (IllegalArgumentException success){}
716 >        } catch (IllegalArgumentException success) {}
717      }
718  
719 <    /**
720 <     * Constructor throws if workQueue is set to null
719 >    /**
720 >     * Constructor throws if workQueue is set to null
721       */
722      public void testConstructorNullPointerException4() {
723          try {
724              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
725              shouldThrow();
726 <        }
781 <        catch (NullPointerException success){}  
726 >        } catch (NullPointerException success) {}
727      }
728  
729 <    /**
730 <     * Constructor throws if handler is set to null
729 >    /**
730 >     * Constructor throws if handler is set to null
731       */
732      public void testConstructorNullPointerException5() {
733          try {
734              RejectedExecutionHandler r = null;
735              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
736              shouldThrow();
737 <        }
793 <        catch (NullPointerException success){}  
737 >        } catch (NullPointerException success) {}
738      }
739  
740 <    
741 <    /**
742 <     * Constructor throws if corePoolSize argument is less than zero
740 >
741 >    /**
742 >     * Constructor throws if corePoolSize argument is less than zero
743       */
744      public void testConstructor16() {
745          try {
746              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
747              shouldThrow();
748 <        }
805 <        catch (IllegalArgumentException success){}
748 >        } catch (IllegalArgumentException success) {}
749      }
750  
751 <    /**
752 <     * Constructor throws if maximumPoolSize is less than zero
751 >    /**
752 >     * Constructor throws if maximumPoolSize is less than zero
753       */
754      public void testConstructor17() {
755          try {
756              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
757              shouldThrow();
758 <        }
816 <        catch (IllegalArgumentException success){}
758 >        } catch (IllegalArgumentException success) {}
759      }
760  
761 <    /**
762 <     * Constructor throws if maximumPoolSize is equal to zero
761 >    /**
762 >     * Constructor throws if maximumPoolSize is equal to zero
763       */
764      public void testConstructor18() {
765          try {
766              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
767              shouldThrow();
768 <        }
827 <        catch (IllegalArgumentException success){}
768 >        } catch (IllegalArgumentException success) {}
769      }
770  
771 <    /**
772 <     * Constructor throws if keepAliveTime is less than zero
771 >    /**
772 >     * Constructor throws if keepAliveTime is less than zero
773       */
774      public void testConstructor19() {
775          try {
776              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
777              shouldThrow();
778 <        }
838 <        catch (IllegalArgumentException success){}
778 >        } catch (IllegalArgumentException success) {}
779      }
780  
781 <    /**
782 <     * Constructor throws if corePoolSize is greater than the maximumPoolSize
781 >    /**
782 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
783       */
784      public void testConstructor20() {
785          try {
786              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
787              shouldThrow();
788 <        }
849 <        catch (IllegalArgumentException success){}
788 >        } catch (IllegalArgumentException success) {}
789      }
790  
791 <    /**
792 <     * Constructor throws if workQueue is set to null
791 >    /**
792 >     * Constructor throws if workQueue is set to null
793       */
794      public void testConstructorNullPointerException6() {
795          try {
796              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
797              shouldThrow();
798 <        }
860 <        catch (NullPointerException success){}  
798 >        } catch (NullPointerException success) {}
799      }
800  
801 <    /**
802 <     * Constructor throws if handler is set to null
801 >    /**
802 >     * Constructor throws if handler is set to null
803       */
804      public void testConstructorNullPointerException7() {
805          try {
806              RejectedExecutionHandler r = null;
807              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
808              shouldThrow();
809 <        }
872 <        catch (NullPointerException success){}  
809 >        } catch (NullPointerException success) {}
810      }
811  
812 <    /**
813 <     * Constructor throws if ThreadFactory is set top null
812 >    /**
813 >     * Constructor throws if ThreadFactory is set top null
814       */
815      public void testConstructorNullPointerException8() {
816          try {
817              ThreadFactory f = null;
818              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
819              shouldThrow();
820 <        }
884 <        catch (NullPointerException successdn8){}  
820 >        } catch (NullPointerException success) {}
821      }
822 <    
822 >
823  
824      /**
825       *  execute throws RejectedExecutionException
# Line 892 | Line 828 | public class ThreadPoolExecutorSubclassT
828      public void testSaturatedExecute() {
829          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
830          try {
831 <            
832 <            for(int i = 0; i < 5; ++i){
831 >
832 >            for (int i = 0; i < 5; ++i) {
833                  p.execute(new MediumRunnable());
834              }
835              shouldThrow();
836 <        } catch(RejectedExecutionException success){}
836 >        } catch (RejectedExecutionException success) {}
837          joinPool(p);
838      }
839  
# Line 908 | Line 844 | public class ThreadPoolExecutorSubclassT
844          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
845          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
846          try {
847 <            
847 >
848              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
849 <            for(int i = 0; i < 5; ++i){
849 >            for (int i = 0; i < 5; ++i) {
850                  tasks[i] = new TrackedNoOpRunnable();
851              }
852              TrackedLongRunnable mr = new TrackedLongRunnable();
853              p.execute(mr);
854 <            for(int i = 0; i < 5; ++i){
854 >            for (int i = 0; i < 5; ++i) {
855                  p.execute(tasks[i]);
856              }
857 <            for(int i = 1; i < 5; ++i) {
857 >            for (int i = 1; i < 5; ++i) {
858                  assertTrue(tasks[i].done);
859              }
860 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
925 <        } catch(RejectedExecutionException ex){
926 <            unexpectedException();
860 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
861          } finally {
862              joinPool(p);
863          }
# Line 936 | Line 870 | public class ThreadPoolExecutorSubclassT
870          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
871          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
872          try {
873 <            
873 >
874              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
875 <            for(int i = 0; i < 5; ++i){
875 >            for (int i = 0; i < 5; ++i) {
876                  tasks[i] = new TrackedNoOpRunnable();
877              }
878              p.execute(new TrackedLongRunnable());
879 <            for(int i = 0; i < 5; ++i){
879 >            for (int i = 0; i < 5; ++i) {
880                  p.execute(tasks[i]);
881              }
882 <            for(int i = 0; i < 5; ++i){
882 >            for (int i = 0; i < 5; ++i) {
883                  assertFalse(tasks[i].done);
884              }
885 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
952 <        } catch(RejectedExecutionException ex){
953 <            unexpectedException();
885 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
886          } finally {
887              joinPool(p);
888          }
# Line 971 | Line 903 | public class ThreadPoolExecutorSubclassT
903              p.execute(r3);
904              assertFalse(p.getQueue().contains(r2));
905              assertTrue(p.getQueue().contains(r3));
906 <            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
975 <        } catch(RejectedExecutionException ex){
976 <            unexpectedException();
906 >            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
907          } finally {
908              joinPool(p);
909          }
# Line 983 | Line 913 | public class ThreadPoolExecutorSubclassT
913       *  execute throws RejectedExecutionException if shutdown
914       */
915      public void testRejectedExecutionExceptionOnShutdown() {
916 <        ThreadPoolExecutor tpe =
916 >        ThreadPoolExecutor tpe =
917              new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
918 <        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
918 >        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
919          try {
920              tpe.execute(new NoOpRunnable());
921              shouldThrow();
922 <        } catch(RejectedExecutionException success){}
923 <        
922 >        } catch (RejectedExecutionException success) {}
923 >
924          joinPool(tpe);
925      }
926  
# Line 1001 | Line 931 | public class ThreadPoolExecutorSubclassT
931          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
932          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
933  
934 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
934 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
935          try {
936              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
937              p.execute(r);
938              assertFalse(r.done);
1009        } catch(RejectedExecutionException success){
1010            unexpectedException();
939          } finally {
940              joinPool(p);
941          }
# Line 1020 | Line 948 | public class ThreadPoolExecutorSubclassT
948          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
949          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
950  
951 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
951 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
952          try {
953              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
954              p.execute(r);
955              assertFalse(r.done);
1028        } catch(RejectedExecutionException success){
1029            unexpectedException();
956          } finally {
957              joinPool(p);
958          }
# Line 1040 | Line 966 | public class ThreadPoolExecutorSubclassT
966          RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy();
967          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
968  
969 <        try { p.shutdown(); } catch(SecurityException ok) { return; }
969 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
970          try {
971              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
972              p.execute(r);
973              assertFalse(r.done);
1048        } catch(RejectedExecutionException success){
1049            unexpectedException();
974          } finally {
975              joinPool(p);
976          }
# Line 1062 | Line 986 | public class ThreadPoolExecutorSubclassT
986              tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
987              tpe.execute(null);
988              shouldThrow();
989 <        } catch(NullPointerException success){}
990 <        
989 >        } catch (NullPointerException success) {}
990 >
991          joinPool(tpe);
992      }
993 <    
993 >
994      /**
995       *  setCorePoolSize of negative value throws IllegalArgumentException
996       */
# Line 1074 | Line 998 | public class ThreadPoolExecutorSubclassT
998          ThreadPoolExecutor tpe = null;
999          try {
1000              tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1001 <        } catch(Exception e){}
1001 >        } catch (Exception e) {}
1002          try {
1003              tpe.setCorePoolSize(-1);
1004              shouldThrow();
1005 <        } catch(IllegalArgumentException success){
1005 >        } catch (IllegalArgumentException success) {
1006          } finally {
1007 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1007 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1008          }
1009          joinPool(tpe);
1010 <    }  
1010 >    }
1011  
1012      /**
1013       *  setMaximumPoolSize(int) throws IllegalArgumentException if
1014       *  given a value less the core pool size
1015 <     */  
1015 >     */
1016      public void testMaximumPoolSizeIllegalArgumentException() {
1017          ThreadPoolExecutor tpe = null;
1018          try {
1019              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1020 <        } catch(Exception e){}
1020 >        } catch (Exception e) {}
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 <    
1030 >
1031      /**
1032       *  setMaximumPoolSize throws IllegalArgumentException
1033       *  if given a negative value
# Line 1112 | Line 1036 | public class ThreadPoolExecutorSubclassT
1036          ThreadPoolExecutor tpe = null;
1037          try {
1038              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1039 <        } catch(Exception e){}
1039 >        } catch (Exception e) {}
1040          try {
1041              tpe.setMaximumPoolSize(-1);
1042              shouldThrow();
1043 <        } catch(IllegalArgumentException success){
1043 >        } catch (IllegalArgumentException success) {
1044          } finally {
1045 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1045 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1046          }
1047          joinPool(tpe);
1048      }
1049 <    
1049 >
1050  
1051      /**
1052       *  setKeepAliveTime  throws IllegalArgumentException
# Line 1132 | Line 1056 | public class ThreadPoolExecutorSubclassT
1056          ThreadPoolExecutor tpe = null;
1057          try {
1058              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1059 <        } catch(Exception e){}
1060 <        
1059 >        } catch (Exception e) {}
1060 >
1061          try {
1062              tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
1063              shouldThrow();
1064 <        } catch(IllegalArgumentException success){
1064 >        } catch (IllegalArgumentException success) {
1065          } finally {
1066 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1066 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1067          }
1068          joinPool(tpe);
1069      }
# Line 1149 | Line 1073 | public class ThreadPoolExecutorSubclassT
1073       */
1074      public void testTerminated() {
1075          CustomTPE tpe = new CustomTPE();
1076 <        try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1076 >        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1077          assertTrue(tpe.terminatedCalled);
1078          joinPool(tpe);
1079      }
# Line 1157 | Line 1081 | public class ThreadPoolExecutorSubclassT
1081      /**
1082       * beforeExecute and afterExecute are called when executing task
1083       */
1084 <    public void testBeforeAfter() {
1084 >    public void testBeforeAfter() throws InterruptedException {
1085          CustomTPE tpe = new CustomTPE();
1086          try {
1087              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1166 | Line 1090 | public class ThreadPoolExecutorSubclassT
1090              assertTrue(r.done);
1091              assertTrue(tpe.beforeCalled);
1092              assertTrue(tpe.afterCalled);
1093 <            try { tpe.shutdown(); } catch(SecurityException ok) { return; }
1170 <        }
1171 <        catch(Exception ex) {
1172 <            unexpectedException();
1093 >            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1094          } finally {
1095              joinPool(tpe);
1096          }
# Line 1178 | Line 1099 | public class ThreadPoolExecutorSubclassT
1099      /**
1100       * completed submit of callable returns result
1101       */
1102 <    public void testSubmitCallable() {
1102 >    public void testSubmitCallable() throws Exception {
1103          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1104          try {
1105              Future<String> future = e.submit(new StringTask());
1106              String result = future.get();
1107              assertSame(TEST_STRING, result);
1187        }
1188        catch (ExecutionException ex) {
1189            unexpectedException();
1190        }
1191        catch (InterruptedException ex) {
1192            unexpectedException();
1108          } finally {
1109              joinPool(e);
1110          }
# Line 1198 | Line 1113 | public class ThreadPoolExecutorSubclassT
1113      /**
1114       * completed submit of runnable returns successfully
1115       */
1116 <    public void testSubmitRunnable() {
1116 >    public void testSubmitRunnable() throws Exception {
1117          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1118          try {
1119              Future<?> future = e.submit(new NoOpRunnable());
1120              future.get();
1121              assertTrue(future.isDone());
1207        }
1208        catch (ExecutionException ex) {
1209            unexpectedException();
1210        }
1211        catch (InterruptedException ex) {
1212            unexpectedException();
1122          } finally {
1123              joinPool(e);
1124          }
# Line 1218 | Line 1127 | public class ThreadPoolExecutorSubclassT
1127      /**
1128       * completed submit of (runnable, result) returns result
1129       */
1130 <    public void testSubmitRunnable2() {
1130 >    public void testSubmitRunnable2() throws Exception {
1131          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1132          try {
1133              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1134              String result = future.get();
1135              assertSame(TEST_STRING, result);
1227        }
1228        catch (ExecutionException ex) {
1229            unexpectedException();
1230        }
1231        catch (InterruptedException ex) {
1232            unexpectedException();
1136          } finally {
1137              joinPool(e);
1138          }
1139      }
1140  
1141  
1239
1240
1241
1142      /**
1143       * invokeAny(null) throws NPE
1144       */
1145 <    public void testInvokeAny1() {
1145 >    public void testInvokeAny1() throws Exception {
1146          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1147          try {
1148              e.invokeAny(null);
1149 +            shouldThrow();
1150          } catch (NullPointerException success) {
1250        } catch(Exception ex) {
1251            unexpectedException();
1151          } finally {
1152              joinPool(e);
1153          }
# Line 1257 | Line 1156 | public class ThreadPoolExecutorSubclassT
1156      /**
1157       * invokeAny(empty collection) throws IAE
1158       */
1159 <    public void testInvokeAny2() {
1159 >    public void testInvokeAny2() throws Exception {
1160          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1161          try {
1162              e.invokeAny(new ArrayList<Callable<String>>());
1163 +            shouldThrow();
1164          } catch (IllegalArgumentException success) {
1265        } catch(Exception ex) {
1266            unexpectedException();
1165          } finally {
1166              joinPool(e);
1167          }
# Line 1272 | Line 1170 | public class ThreadPoolExecutorSubclassT
1170      /**
1171       * invokeAny(c) throws NPE if c has null elements
1172       */
1173 <    public void testInvokeAny3() {
1173 >    public void testInvokeAny3() throws Exception {
1174 >        final CountDownLatch latch = new CountDownLatch(1);
1175          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1176          try {
1177              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1178 <            l.add(new StringTask());
1178 >            l.add(new CheckedCallable<String>() {
1179 >                      public String realCall() throws InterruptedException {
1180 >                          latch.await();
1181 >                          return TEST_STRING;
1182 >                      }});
1183              l.add(null);
1184              e.invokeAny(l);
1185 +            shouldThrow();
1186          } catch (NullPointerException success) {
1283        } catch(Exception ex) {
1284            unexpectedException();
1187          } finally {
1188 +            latch.countDown();
1189              joinPool(e);
1190          }
1191      }
# Line 1290 | Line 1193 | public class ThreadPoolExecutorSubclassT
1193      /**
1194       * invokeAny(c) throws ExecutionException if no task completes
1195       */
1196 <    public void testInvokeAny4() {
1196 >    public void testInvokeAny4() throws Exception {
1197          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1198          try {
1199              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1200              l.add(new NPETask());
1201              e.invokeAny(l);
1202 +            shouldThrow();
1203          } catch (ExecutionException success) {
1300        } catch(Exception ex) {
1301            unexpectedException();
1204          } finally {
1205              joinPool(e);
1206          }
# Line 1307 | Line 1209 | public class ThreadPoolExecutorSubclassT
1209      /**
1210       * invokeAny(c) returns result of some task
1211       */
1212 <    public void testInvokeAny5() {
1212 >    public void testInvokeAny5() throws Exception {
1213          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1214          try {
1215              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1315 | Line 1217 | public class ThreadPoolExecutorSubclassT
1217              l.add(new StringTask());
1218              String result = e.invokeAny(l);
1219              assertSame(TEST_STRING, result);
1318        } catch (ExecutionException success) {
1319        } catch(Exception ex) {
1320            unexpectedException();
1220          } finally {
1221              joinPool(e);
1222          }
# Line 1326 | Line 1225 | public class ThreadPoolExecutorSubclassT
1225      /**
1226       * invokeAll(null) throws NPE
1227       */
1228 <    public void testInvokeAll1() {
1228 >    public void testInvokeAll1() throws Exception {
1229          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1230          try {
1231              e.invokeAll(null);
1232 +            shouldThrow();
1233          } catch (NullPointerException success) {
1334        } catch(Exception ex) {
1335            unexpectedException();
1234          } finally {
1235              joinPool(e);
1236          }
# Line 1341 | Line 1239 | public class ThreadPoolExecutorSubclassT
1239      /**
1240       * invokeAll(empty collection) returns empty collection
1241       */
1242 <    public void testInvokeAll2() {
1242 >    public void testInvokeAll2() throws Exception {
1243          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1244          try {
1245              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1246              assertTrue(r.isEmpty());
1349        } catch(Exception ex) {
1350            unexpectedException();
1247          } finally {
1248              joinPool(e);
1249          }
# Line 1356 | Line 1252 | public class ThreadPoolExecutorSubclassT
1252      /**
1253       * invokeAll(c) throws NPE if c has null elements
1254       */
1255 <    public void testInvokeAll3() {
1255 >    public void testInvokeAll3() throws Exception {
1256          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257          try {
1258              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259              l.add(new StringTask());
1260              l.add(null);
1261              e.invokeAll(l);
1262 +            shouldThrow();
1263          } catch (NullPointerException success) {
1367        } catch(Exception ex) {
1368            unexpectedException();
1264          } finally {
1265              joinPool(e);
1266          }
# Line 1374 | Line 1269 | public class ThreadPoolExecutorSubclassT
1269      /**
1270       * get of element of invokeAll(c) throws exception on failed task
1271       */
1272 <    public void testInvokeAll4() {
1272 >    public void testInvokeAll4() throws Exception {
1273          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1274          try {
1275              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1276              l.add(new NPETask());
1277              List<Future<String>> result = e.invokeAll(l);
1278              assertEquals(1, result.size());
1279 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1279 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1280                  it.next().get();
1281 <        } catch(ExecutionException success) {
1282 <        } catch(Exception ex) {
1388 <            unexpectedException();
1281 >            shouldThrow();
1282 >        } catch (ExecutionException success) {
1283          } finally {
1284              joinPool(e);
1285          }
# Line 1394 | Line 1288 | public class ThreadPoolExecutorSubclassT
1288      /**
1289       * invokeAll(c) returns results of all completed tasks
1290       */
1291 <    public void testInvokeAll5() {
1291 >    public void testInvokeAll5() throws Exception {
1292          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1293          try {
1294              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1402 | Line 1296 | public class ThreadPoolExecutorSubclassT
1296              l.add(new StringTask());
1297              List<Future<String>> result = e.invokeAll(l);
1298              assertEquals(2, result.size());
1299 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1299 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1300                  assertSame(TEST_STRING, it.next().get());
1301 +            shouldThrow();
1302          } catch (ExecutionException success) {
1408        } catch(Exception ex) {
1409            unexpectedException();
1303          } finally {
1304              joinPool(e);
1305          }
# Line 1417 | Line 1310 | public class ThreadPoolExecutorSubclassT
1310      /**
1311       * timed invokeAny(null) throws NPE
1312       */
1313 <    public void testTimedInvokeAny1() {
1313 >    public void testTimedInvokeAny1() throws Exception {
1314          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1315          try {
1316              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1317 +            shouldThrow();
1318          } catch (NullPointerException success) {
1425        } catch(Exception ex) {
1426            unexpectedException();
1319          } finally {
1320              joinPool(e);
1321          }
# Line 1432 | Line 1324 | public class ThreadPoolExecutorSubclassT
1324      /**
1325       * timed invokeAny(,,null) throws NPE
1326       */
1327 <    public void testTimedInvokeAnyNullTimeUnit() {
1327 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1328          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1329          try {
1330              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1331              l.add(new StringTask());
1332              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1333 +            shouldThrow();
1334          } catch (NullPointerException success) {
1442        } catch(Exception ex) {
1443            unexpectedException();
1335          } finally {
1336              joinPool(e);
1337          }
# Line 1449 | Line 1340 | public class ThreadPoolExecutorSubclassT
1340      /**
1341       * timed invokeAny(empty collection) throws IAE
1342       */
1343 <    public void testTimedInvokeAny2() {
1343 >    public void testTimedInvokeAny2() throws Exception {
1344          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1345          try {
1346              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1347 +            shouldThrow();
1348          } catch (IllegalArgumentException success) {
1457        } catch(Exception ex) {
1458            unexpectedException();
1349          } finally {
1350              joinPool(e);
1351          }
# Line 1464 | Line 1354 | public class ThreadPoolExecutorSubclassT
1354      /**
1355       * timed invokeAny(c) throws NPE if c has null elements
1356       */
1357 <    public void testTimedInvokeAny3() {
1357 >    public void testTimedInvokeAny3() throws Exception {
1358          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1359          try {
1360              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1361              l.add(new StringTask());
1362              l.add(null);
1363              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1364 +            shouldThrow();
1365          } catch (NullPointerException success) {
1475        } catch(Exception ex) {
1476            ex.printStackTrace();
1477            unexpectedException();
1366          } finally {
1367              joinPool(e);
1368          }
# Line 1483 | Line 1371 | public class ThreadPoolExecutorSubclassT
1371      /**
1372       * timed invokeAny(c) throws ExecutionException if no task completes
1373       */
1374 <    public void testTimedInvokeAny4() {
1374 >    public void testTimedInvokeAny4() throws Exception {
1375          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1376          try {
1377              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1378              l.add(new NPETask());
1379              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1380 <        } catch(ExecutionException success) {
1381 <        } catch(Exception ex) {
1494 <            unexpectedException();
1380 >            shouldThrow();
1381 >        } catch (ExecutionException success) {
1382          } finally {
1383              joinPool(e);
1384          }
# Line 1500 | Line 1387 | public class ThreadPoolExecutorSubclassT
1387      /**
1388       * timed invokeAny(c) returns result of some task
1389       */
1390 <    public void testTimedInvokeAny5() {
1390 >    public void testTimedInvokeAny5() throws Exception {
1391          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1392          try {
1393              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1508 | Line 1395 | public class ThreadPoolExecutorSubclassT
1395              l.add(new StringTask());
1396              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1397              assertSame(TEST_STRING, result);
1398 +            shouldThrow();
1399          } catch (ExecutionException success) {
1512        } catch(Exception ex) {
1513            unexpectedException();
1400          } finally {
1401              joinPool(e);
1402          }
# Line 1519 | Line 1405 | public class ThreadPoolExecutorSubclassT
1405      /**
1406       * timed invokeAll(null) throws NPE
1407       */
1408 <    public void testTimedInvokeAll1() {
1408 >    public void testTimedInvokeAll1() throws Exception {
1409          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1410          try {
1411              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1412 +            shouldThrow();
1413          } catch (NullPointerException success) {
1527        } catch(Exception ex) {
1528            unexpectedException();
1414          } finally {
1415              joinPool(e);
1416          }
# Line 1534 | Line 1419 | public class ThreadPoolExecutorSubclassT
1419      /**
1420       * timed invokeAll(,,null) throws NPE
1421       */
1422 <    public void testTimedInvokeAllNullTimeUnit() {
1422 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1423          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1424          try {
1425              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1426              l.add(new StringTask());
1427              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1428 +            shouldThrow();
1429          } catch (NullPointerException success) {
1544        } catch(Exception ex) {
1545            unexpectedException();
1430          } finally {
1431              joinPool(e);
1432          }
# Line 1551 | Line 1435 | public class ThreadPoolExecutorSubclassT
1435      /**
1436       * timed invokeAll(empty collection) returns empty collection
1437       */
1438 <    public void testTimedInvokeAll2() {
1438 >    public void testTimedInvokeAll2() throws Exception {
1439          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1440          try {
1441              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1442              assertTrue(r.isEmpty());
1559        } catch(Exception ex) {
1560            unexpectedException();
1443          } finally {
1444              joinPool(e);
1445          }
# Line 1566 | Line 1448 | public class ThreadPoolExecutorSubclassT
1448      /**
1449       * timed invokeAll(c) throws NPE if c has null elements
1450       */
1451 <    public void testTimedInvokeAll3() {
1451 >    public void testTimedInvokeAll3() throws Exception {
1452          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1453          try {
1454              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1455              l.add(new StringTask());
1456              l.add(null);
1457              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1458 +            shouldThrow();
1459          } catch (NullPointerException success) {
1577        } catch(Exception ex) {
1578            unexpectedException();
1460          } finally {
1461              joinPool(e);
1462          }
# Line 1584 | Line 1465 | public class ThreadPoolExecutorSubclassT
1465      /**
1466       * get of element of invokeAll(c) throws exception on failed task
1467       */
1468 <    public void testTimedInvokeAll4() {
1468 >    public void testTimedInvokeAll4() throws Exception {
1469          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1470          try {
1471              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1472              l.add(new NPETask());
1473              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1474              assertEquals(1, result.size());
1475 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1475 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1476                  it.next().get();
1477 <        } catch(ExecutionException success) {
1478 <        } catch(Exception ex) {
1598 <            unexpectedException();
1477 >            shouldThrow();
1478 >        } catch (ExecutionException success) {
1479          } finally {
1480              joinPool(e);
1481          }
# Line 1604 | Line 1484 | public class ThreadPoolExecutorSubclassT
1484      /**
1485       * timed invokeAll(c) returns results of all completed tasks
1486       */
1487 <    public void testTimedInvokeAll5() {
1487 >    public void testTimedInvokeAll5() throws Exception {
1488          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1489          try {
1490              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1612 | Line 1492 | public class ThreadPoolExecutorSubclassT
1492              l.add(new StringTask());
1493              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1494              assertEquals(2, result.size());
1495 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1495 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1496                  assertSame(TEST_STRING, it.next().get());
1497 +            shouldThrow();
1498          } catch (ExecutionException success) {
1618        } catch(Exception ex) {
1619            unexpectedException();
1499          } finally {
1500              joinPool(e);
1501          }
# Line 1625 | Line 1504 | public class ThreadPoolExecutorSubclassT
1504      /**
1505       * timed invokeAll(c) cancels tasks not completed by timeout
1506       */
1507 <    public void testTimedInvokeAll6() {
1507 >    public void testTimedInvokeAll6() throws Exception {
1508          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1509          try {
1510              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1634 | Line 1513 | public class ThreadPoolExecutorSubclassT
1513              l.add(new StringTask());
1514              List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1515              assertEquals(3, result.size());
1516 <            Iterator<Future<String>> it = result.iterator();
1516 >            Iterator<Future<String>> it = result.iterator();
1517              Future<String> f1 = it.next();
1518              Future<String> f2 = it.next();
1519              Future<String> f3 = it.next();
# Line 1643 | Line 1522 | public class ThreadPoolExecutorSubclassT
1522              assertTrue(f3.isDone());
1523              assertFalse(f1.isCancelled());
1524              assertTrue(f2.isCancelled());
1646        } catch(Exception ex) {
1647            unexpectedException();
1525          } finally {
1526              joinPool(e);
1527          }
# Line 1654 | Line 1531 | public class ThreadPoolExecutorSubclassT
1531       * Execution continues if there is at least one thread even if
1532       * thread factory fails to create more
1533       */
1534 <    public void testFailingThreadFactory() {
1534 >    public void testFailingThreadFactory() throws InterruptedException {
1535          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1536          try {
1537              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1662 | Line 1539 | public class ThreadPoolExecutorSubclassT
1539                  e.execute(new NoOpRunnable());
1540              }
1541              Thread.sleep(LONG_DELAY_MS);
1665        } catch(Exception ex) {
1666            unexpectedException();
1542          } finally {
1543              joinPool(e);
1544          }
# Line 1681 | Line 1556 | public class ThreadPoolExecutorSubclassT
1556      /**
1557       * allowCoreThreadTimeOut(true) causes idle threads to time out
1558       */
1559 <    public void testAllowCoreThreadTimeOut_true() {
1559 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1560          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1561          tpe.allowCoreThreadTimeOut(true);
1562          tpe.execute(new NoOpRunnable());
1563          try {
1564              Thread.sleep(MEDIUM_DELAY_MS);
1565              assertEquals(0, tpe.getPoolSize());
1691        } catch(InterruptedException e){
1692            unexpectedException();
1566          } finally {
1567              joinPool(tpe);
1568          }
# Line 1698 | Line 1571 | public class ThreadPoolExecutorSubclassT
1571      /**
1572       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1573       */
1574 <    public void testAllowCoreThreadTimeOut_false() {
1574 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1575          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1576          tpe.allowCoreThreadTimeOut(false);
1577          tpe.execute(new NoOpRunnable());
1578          try {
1579              Thread.sleep(MEDIUM_DELAY_MS);
1580              assertTrue(tpe.getPoolSize() >= 1);
1708        } catch(InterruptedException e){
1709            unexpectedException();
1581          } finally {
1582              joinPool(tpe);
1583          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines