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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.13 by dl, Tue Dec 23 19:40:24 2003 UTC

# Line 7 | Line 7
7  
8   import java.util.concurrent.*;
9   import junit.framework.*;
10 < import java.util.List;
10 > import java.util.*;
11  
12   public class ThreadPoolExecutorTest extends JSR166TestCase {
13      public static void main(String[] args) {
# Line 17 | Line 17 | public class ThreadPoolExecutorTest exte
17          return new TestSuite(ThreadPoolExecutorTest.class);
18      }
19      
20 <    /**
21 <     * For use as ThreadFactory in constructors
22 <     */
23 <    static class MyThreadFactory implements ThreadFactory{
24 <        public Thread newThread(Runnable r){
25 <            return new Thread(r);
26 <        }  
20 >    static class ExtendedTPE extends ThreadPoolExecutor {
21 >        volatile boolean beforeCalled = false;
22 >        volatile boolean afterCalled = false;
23 >        volatile boolean terminatedCalled = false;
24 >        public ExtendedTPE() {
25 >            super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
26 >        }
27 >        protected void beforeExecute(Thread t, Runnable r) {
28 >            beforeCalled = true;
29 >        }
30 >        protected void afterExecute(Runnable r, Throwable t) {
31 >            afterCalled = true;
32 >        }
33 >        protected void terminated() {
34 >            terminatedCalled = true;
35 >        }
36      }
37  
38      /**
39 <     * For use as RejectedExecutionHandler in constructors
31 <     */
32 <    static class MyREHandler implements RejectedExecutionHandler{
33 <        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
34 <    }
35 <
36 <    /**
37 <     *   execute successfully executes a runnable
39 >     *  execute successfully executes a runnable
40       */
41      public void testExecute() {
42 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
42 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
43          try {
44              p1.execute(new Runnable() {
45                      public void run() {
# Line 56 | Line 58 | public class ThreadPoolExecutorTest exte
58      }
59  
60      /**
61 <     *   getActiveCount gives correct values
61 >     *  getActiveCount increases but doesn't overestimate, when a
62 >     *  thread becomes active
63       */
64      public void testGetActiveCount() {
65 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
65 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
66          assertEquals(0, p2.getActiveCount());
67          p2.execute(new MediumRunnable());
68          try {
# Line 70 | Line 73 | public class ThreadPoolExecutorTest exte
73          assertEquals(1, p2.getActiveCount());
74          joinPool(p2);
75      }
76 +
77 +    /**
78 +     *  prestartCoreThread starts a thread if under corePoolSize, else doesn't
79 +     */
80 +    public void testPrestartCoreThread() {
81 +        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
82 +        assertEquals(0, p2.getPoolSize());
83 +        assertTrue(p2.prestartCoreThread());
84 +        assertEquals(1, p2.getPoolSize());
85 +        assertTrue(p2.prestartCoreThread());
86 +        assertEquals(2, p2.getPoolSize());
87 +        assertFalse(p2.prestartCoreThread());
88 +        assertEquals(2, p2.getPoolSize());
89 +        joinPool(p2);
90 +    }
91 +
92 +    /**
93 +     *  prestartAllCoreThreads starts all corePoolSize threads
94 +     */
95 +    public void testPrestartAllCoreThreads() {
96 +        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
97 +        assertEquals(0, p2.getPoolSize());
98 +        p2.prestartAllCoreThreads();
99 +        assertEquals(2, p2.getPoolSize());
100 +        p2.prestartAllCoreThreads();
101 +        assertEquals(2, p2.getPoolSize());
102 +        joinPool(p2);
103 +    }
104      
105      /**
106 <     *   getCompleteTaskCount gives correct values
106 >     *   getCompletedTaskCount increases, but doesn't overestimate,
107 >     *   when tasks complete
108       */
109      public void testGetCompletedTaskCount() {
110 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
110 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
111          assertEquals(0, p2.getCompletedTaskCount());
112          p2.execute(new ShortRunnable());
113          try {
114 <            Thread.sleep(MEDIUM_DELAY_MS);
114 >            Thread.sleep(SMALL_DELAY_MS);
115          } catch(Exception e){
116              unexpectedException();
117          }
# Line 89 | Line 121 | public class ThreadPoolExecutorTest exte
121      }
122      
123      /**
124 <     *   getCorePoolSize gives correct values
124 >     *   getCorePoolSize returns size given in constructor if not otherwise set
125       */
126      public void testGetCorePoolSize() {
127 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
127 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
128          assertEquals(1, p1.getCorePoolSize());
129          joinPool(p1);
130      }
131      
132      /**
133 <     *   getKeepAliveTime gives correct values
133 >     *   getKeepAliveTime returns value given in constructor if not otherwise set
134       */
135      public void testGetKeepAliveTime() {
136          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
137          assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS));
138          joinPool(p2);
139      }
140 +
141 +
142 +    /**
143 +     * getThreadFactory returns factory in constructor if not set
144 +     */
145 +    public void testGetThreadFactory() {
146 +        ThreadFactory tf = new SimpleThreadFactory();
147 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
148 +        assertSame(tf, p.getThreadFactory());
149 +        p.shutdown();
150 +        joinPool(p);
151 +    }
152 +
153 +    /**
154 +     * setThreadFactory sets the thread factory returned by getThreadFactory
155 +     */
156 +    public void testSetThreadFactory() {
157 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
158 +        ThreadFactory tf = new SimpleThreadFactory();
159 +        p.setThreadFactory(tf);
160 +        assertSame(tf, p.getThreadFactory());
161 +        p.shutdown();
162 +        joinPool(p);
163 +    }
164 +
165 +
166 +    /**
167 +     * setThreadFactory(null) throws NPE
168 +     */
169 +    public void testSetThreadFactoryNull() {
170 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
171 +        try {
172 +            p.setThreadFactory(null);
173 +            shouldThrow();
174 +        } catch (NullPointerException success) {
175 +        } finally {
176 +            joinPool(p);
177 +        }
178 +    }
179 +
180 +    /**
181 +     * getRejectedExecutionHandler returns handler in constructor if not set
182 +     */
183 +    public void testGetRejectedExecutionHandler() {
184 +        RejectedExecutionHandler h = new NoOpREHandler();
185 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
186 +        assertSame(h, p.getRejectedExecutionHandler());
187 +        p.shutdown();
188 +        joinPool(p);
189 +    }
190 +
191 +    /**
192 +     * setRejectedExecutionHandler sets the handler returned by
193 +     * getRejectedExecutionHandler
194 +     */
195 +    public void testSetRejectedExecutionHandler() {
196 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
197 +        RejectedExecutionHandler h = new NoOpREHandler();
198 +        p.setRejectedExecutionHandler(h);
199 +        assertSame(h, p.getRejectedExecutionHandler());
200 +        p.shutdown();
201 +        joinPool(p);
202 +    }
203 +
204 +
205 +    /**
206 +     * setRejectedExecutionHandler(null) throws NPE
207 +     */
208 +    public void testSetRejectedExecutionHandlerNull() {
209 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
210 +        try {
211 +            p.setRejectedExecutionHandler(null);
212 +            shouldThrow();
213 +        } catch (NullPointerException success) {
214 +        } finally {
215 +            joinPool(p);
216 +        }
217 +    }
218 +
219      
220      /**
221 <     *   getLargestPoolSize gives correct values
221 >     *   getLargestPoolSize increases, but doesn't overestimate, when
222 >     *   multiple threads active
223       */
224      public void testGetLargestPoolSize() {
225 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
225 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
226          try {
227              assertEquals(0, p2.getLargestPoolSize());
228              p2.execute(new MediumRunnable());
# Line 124 | Line 236 | public class ThreadPoolExecutorTest exte
236      }
237      
238      /**
239 <     *   getMaximumPoolSize gives correct values
239 >     *   getMaximumPoolSize returns value given in constructor if not
240 >     *   otherwise set
241       */
242      public void testGetMaximumPoolSize() {
243 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
243 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
244          assertEquals(2, p2.getMaximumPoolSize());
245          joinPool(p2);
246      }
247      
248      /**
249 <     *   getPoolSize gives correct values
249 >     *   getPoolSize increases, but doesn't overestimate, when threads
250 >     *   become active
251       */
252      public void testGetPoolSize() {
253 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
253 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
254          assertEquals(0, p1.getPoolSize());
255          p1.execute(new MediumRunnable());
256          assertEquals(1, p1.getPoolSize());
# Line 144 | Line 258 | public class ThreadPoolExecutorTest exte
258      }
259      
260      /**
261 <     *   getTaskCount gives correct values
261 >     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
262       */
263      public void testGetTaskCount() {
264 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
264 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
265          try {
266              assertEquals(0, p1.getTaskCount());
267              p1.execute(new MediumRunnable());
# Line 160 | Line 274 | public class ThreadPoolExecutorTest exte
274      }
275      
276      /**
277 <     *   isShutDown gives correct values
277 >     *   isShutDown is false before shutdown, true after
278       */
279      public void testIsShutdown() {
280          
281 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
281 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
282          assertFalse(p1.isShutdown());
283          p1.shutdown();
284          assertTrue(p1.isShutdown());
# Line 173 | Line 287 | public class ThreadPoolExecutorTest exte
287  
288          
289      /**
290 <     *   isTerminated gives correct values
177 <     *  Makes sure termination does not take an innapropriate
178 <     *  amount of time
290 >     *  isTerminated is false before termination, true after
291       */
292      public void testIsTerminated() {
293 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
293 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
294 >        assertFalse(p1.isTerminated());
295          try {
296              p1.execute(new MediumRunnable());
297          } finally {
# Line 193 | Line 306 | public class ThreadPoolExecutorTest exte
306      }
307  
308      /**
309 <     *  isTerminating gives correct values
309 >     *  isTerminating is not true when running or when terminated
310       */
311      public void testIsTerminating() {
312 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
312 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
313          assertFalse(p1.isTerminating());
314          try {
315              p1.execute(new SmallRunnable());
# Line 214 | Line 327 | public class ThreadPoolExecutorTest exte
327      }
328  
329      /**
330 <     *   purge correctly removes cancelled tasks
331 <     *  from the queue
330 >     * getQueue returns the work queue, which contains queued tasks
331 >     */
332 >    public void testGetQueue() {
333 >        BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
334 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
335 >        FutureTask[] tasks = new FutureTask[5];
336 >        for(int i = 0; i < 5; i++){
337 >            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
338 >            p1.execute(tasks[i]);
339 >        }
340 >        try {
341 >            Thread.sleep(SHORT_DELAY_MS);
342 >            BlockingQueue<Runnable> wq = p1.getQueue();
343 >            assertSame(q, wq);
344 >            assertFalse(wq.contains(tasks[0]));
345 >            assertTrue(wq.contains(tasks[4]));
346 >            p1.shutdownNow();
347 >        } catch(Exception e) {
348 >            unexpectedException();
349 >        } finally {
350 >            joinPool(p1);
351 >        }
352 >    }
353 >
354 >    /**
355 >     * remove(task) removes queued task, and fails to remove active task
356 >     */
357 >    public void testRemove() {
358 >        BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
359 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
360 >        FutureTask[] tasks = new FutureTask[5];
361 >        for(int i = 0; i < 5; i++){
362 >            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
363 >            p1.execute(tasks[i]);
364 >        }
365 >        try {
366 >            Thread.sleep(SHORT_DELAY_MS);
367 >            assertFalse(p1.remove(tasks[0]));
368 >            assertTrue(q.contains(tasks[4]));
369 >            assertTrue(q.contains(tasks[3]));
370 >            assertTrue(p1.remove(tasks[4]));
371 >            assertFalse(p1.remove(tasks[4]));
372 >            assertFalse(q.contains(tasks[4]));
373 >            assertTrue(q.contains(tasks[3]));
374 >            assertTrue(p1.remove(tasks[3]));
375 >            assertFalse(q.contains(tasks[3]));
376 >            p1.shutdownNow();
377 >        } catch(Exception e) {
378 >            unexpectedException();
379 >        } finally {
380 >            joinPool(p1);
381 >        }
382 >    }
383 >
384 >    /**
385 >     *   purge removes cancelled tasks from the queue
386       */
387      public void testPurge() {
388 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
389 <        CancellableTask[] tasks = new CancellableTask[5];
388 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
389 >        FutureTask[] tasks = new FutureTask[5];
390          for(int i = 0; i < 5; i++){
391 <            tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
391 >            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
392              p1.execute(tasks[i]);
393          }
394          tasks[4].cancel(true);
# Line 229 | Line 396 | public class ThreadPoolExecutorTest exte
396          p1.purge();
397          long count = p1.getTaskCount();
398          assertTrue(count >= 2 && count < 5);
399 +        p1.shutdownNow();
400          joinPool(p1);
401      }
402  
403      /**
404 <     *   shutDownNow returns a list
237 <     *  containing the correct number of elements
404 >     *  shutDownNow returns a list containing tasks that were not run
405       */
406      public void testShutDownNow() {
407 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
407 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
408          List l;
409          try {
410              for(int i = 0; i < 5; i++)
# Line 253 | Line 420 | public class ThreadPoolExecutorTest exte
420      // Exception Tests
421      
422  
423 <    /** Throws if corePoolSize argument is less than zero */
423 >    /**
424 >     * Constructor throws if corePoolSize argument is less than zero
425 >     */
426      public void testConstructor1() {
427          try {
428              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 262 | Line 431 | public class ThreadPoolExecutorTest exte
431          catch (IllegalArgumentException success){}
432      }
433      
434 <    /** Throws if maximumPoolSize is less than zero */
434 >    /**
435 >     * Constructor throws if maximumPoolSize is less than zero
436 >     */
437      public void testConstructor2() {
438          try {
439              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 271 | Line 442 | public class ThreadPoolExecutorTest exte
442          catch (IllegalArgumentException success){}
443      }
444      
445 <    /** Throws if maximumPoolSize is equal to zero */
445 >    /**
446 >     * Constructor throws if maximumPoolSize is equal to zero
447 >     */
448      public void testConstructor3() {
449          try {
450              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 280 | Line 453 | public class ThreadPoolExecutorTest exte
453          catch (IllegalArgumentException success){}
454      }
455  
456 <    /** Throws if keepAliveTime is less than zero */
456 >    /**
457 >     * Constructor throws if keepAliveTime is less than zero
458 >     */
459      public void testConstructor4() {
460          try {
461              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 289 | Line 464 | public class ThreadPoolExecutorTest exte
464          catch (IllegalArgumentException success){}
465      }
466  
467 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
467 >    /**
468 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
469 >     */
470      public void testConstructor5() {
471          try {
472              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 298 | Line 475 | public class ThreadPoolExecutorTest exte
475          catch (IllegalArgumentException success){}
476      }
477          
478 <    /** Throws if workQueue is set to null */
479 <    public void testNullPointerException() {
478 >    /**
479 >     * Constructor throws if workQueue is set to null
480 >     */
481 >    public void testConstructorNullPointerException() {
482          try {
483 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
483 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
484              shouldThrow();
485          }
486          catch (NullPointerException success){}  
# Line 309 | Line 488 | public class ThreadPoolExecutorTest exte
488      
489  
490      
491 <    /** Throws if corePoolSize argument is less than zero */
491 >    /**
492 >     * Constructor throws if corePoolSize argument is less than zero
493 >     */
494      public void testConstructor6() {
495          try {
496 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
496 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
497              shouldThrow();
498          } catch (IllegalArgumentException success){}
499      }
500      
501 <    /** Throws if maximumPoolSize is less than zero */
501 >    /**
502 >     * Constructor throws if maximumPoolSize is less than zero
503 >     */
504      public void testConstructor7() {
505          try {
506 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
506 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
507              shouldThrow();
508          }
509          catch (IllegalArgumentException success){}
510      }
511  
512 <    /** Throws if maximumPoolSize is equal to zero */
512 >    /**
513 >     * Constructor throws if maximumPoolSize is equal to zero
514 >     */
515      public void testConstructor8() {
516          try {
517 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
517 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
518              shouldThrow();
519          }
520          catch (IllegalArgumentException success){}
521      }
522  
523 <    /** Throws if keepAliveTime is less than zero */
523 >    /**
524 >     * Constructor throws if keepAliveTime is less than zero
525 >     */
526      public void testConstructor9() {
527          try {
528 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
528 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
529              shouldThrow();
530          }
531          catch (IllegalArgumentException success){}
532      }
533  
534 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
534 >    /**
535 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
536 >     */
537      public void testConstructor10() {
538          try {
539 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
539 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
540              shouldThrow();
541          }
542          catch (IllegalArgumentException success){}
543      }
544  
545 <    /** Throws if workQueue is set to null */
546 <    public void testNullPointerException2() {
545 >    /**
546 >     * Constructor throws if workQueue is set to null
547 >     */
548 >    public void testConstructorNullPointerException2() {
549          try {
550 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory());
550 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
551              shouldThrow();
552          }
553          catch (NullPointerException success){}  
554      }
555  
556 <    /** Throws if threadFactory is set to null */
557 <    public void testNullPointerException3() {
556 >    /**
557 >     * Constructor throws if threadFactory is set to null
558 >     */
559 >    public void testConstructorNullPointerException3() {
560          try {
561              ThreadFactory f = null;
562 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
562 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
563              shouldThrow();
564          }
565          catch (NullPointerException success){}  
566      }
567  
568      
569 <    /** Throws if corePoolSize argument is less than zero */
569 >    /**
570 >     * Constructor throws if corePoolSize argument is less than zero
571 >     */
572      public void testConstructor11() {
573          try {
574 <            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
574 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
575              shouldThrow();
576          }
577          catch (IllegalArgumentException success){}
578      }
579  
580 <    /** Throws if maximumPoolSize is less than zero */
580 >    /**
581 >     * Constructor throws if maximumPoolSize is less than zero
582 >     */
583      public void testConstructor12() {
584          try {
585 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
585 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
586              shouldThrow();
587          }
588          catch (IllegalArgumentException success){}
589      }
590  
591 <    /** Throws if maximumPoolSize is equal to zero */
591 >    /**
592 >     * Constructor throws if maximumPoolSize is equal to zero
593 >     */
594      public void testConstructor13() {
595          try {
596 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
596 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
597              shouldThrow();
598          }
599          catch (IllegalArgumentException success){}
600      }
601  
602 <    /** Throws if keepAliveTime is less than zero */
602 >    /**
603 >     * Constructor throws if keepAliveTime is less than zero
604 >     */
605      public void testConstructor14() {
606          try {
607 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
607 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
608              shouldThrow();
609          }
610          catch (IllegalArgumentException success){}
611      }
612  
613 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
613 >    /**
614 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
615 >     */
616      public void testConstructor15() {
617          try {
618 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
618 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
619              shouldThrow();
620          }
621          catch (IllegalArgumentException success){}
622      }
623  
624 <    /** Throws if workQueue is set to null */
625 <    public void testNullPointerException4() {
624 >    /**
625 >     * Constructor throws if workQueue is set to null
626 >     */
627 >    public void testConstructorNullPointerException4() {
628          try {
629 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler());
629 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
630              shouldThrow();
631          }
632          catch (NullPointerException success){}  
633      }
634  
635 <    /** Throws if handler is set to null */
636 <    public void testNullPointerException5() {
635 >    /**
636 >     * Constructor throws if handler is set to null
637 >     */
638 >    public void testConstructorNullPointerException5() {
639          try {
640              RejectedExecutionHandler r = null;
641 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
641 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
642              shouldThrow();
643          }
644          catch (NullPointerException success){}  
645      }
646  
647      
648 <    /** Throws if corePoolSize argument is less than zero */
648 >    /**
649 >     * Constructor throws if corePoolSize argument is less than zero
650 >     */
651      public void testConstructor16() {
652          try {
653 <            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
653 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
654              shouldThrow();
655          }
656          catch (IllegalArgumentException success){}
657      }
658  
659 <    /** Throws if maximumPoolSize is less than zero */
659 >    /**
660 >     * Constructor throws if maximumPoolSize is less than zero
661 >     */
662      public void testConstructor17() {
663          try {
664 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
664 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
665              shouldThrow();
666          }
667          catch (IllegalArgumentException success){}
668      }
669  
670 <    /** Throws if maximumPoolSize is equal to zero */
670 >    /**
671 >     * Constructor throws if maximumPoolSize is equal to zero
672 >     */
673      public void testConstructor18() {
674          try {
675 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
675 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
676              shouldThrow();
677          }
678          catch (IllegalArgumentException success){}
679      }
680  
681 <    /** Throws if keepAliveTime is less than zero */
681 >    /**
682 >     * Constructor throws if keepAliveTime is less than zero
683 >     */
684      public void testConstructor19() {
685          try {
686 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
686 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
687              shouldThrow();
688          }
689          catch (IllegalArgumentException success){}
690      }
691  
692 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
692 >    /**
693 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
694 >     */
695      public void testConstructor20() {
696          try {
697 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
697 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
698              shouldThrow();
699          }
700          catch (IllegalArgumentException success){}
701      }
702  
703 <    /** Throws if workQueue is set to null */
704 <    public void testNullPointerException6() {
703 >    /**
704 >     * Constructor throws if workQueue is set to null
705 >     */
706 >    public void testConstructorNullPointerException6() {
707          try {
708 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler());
708 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
709              shouldThrow();
710          }
711          catch (NullPointerException success){}  
712      }
713  
714 <    /** Throws if handler is set to null */
715 <    public void testNullPointerException7() {
714 >    /**
715 >     * Constructor throws if handler is set to null
716 >     */
717 >    public void testConstructorNullPointerException7() {
718          try {
719              RejectedExecutionHandler r = null;
720 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r);
720 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
721              shouldThrow();
722          }
723          catch (NullPointerException success){}  
724      }
725  
726 <    /** Throws if ThreadFactory is set top null */
727 <    public void testNullPointerException8() {
726 >    /**
727 >     * Constructor throws if ThreadFactory is set top null
728 >     */
729 >    public void testConstructorNullPointerException8() {
730          try {
731              ThreadFactory f = null;
732 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler());
732 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
733              shouldThrow();
734          }
735          catch (NullPointerException successdn8){}  
# Line 514 | Line 737 | public class ThreadPoolExecutorTest exte
737      
738  
739      /**
740 <     *   execute will throw RejectedExcutionException
741 <     *  ThreadPoolExecutor will throw one when more runnables are
519 <     *  executed then will fit in the Queue.
740 >     *  execute throws RejectedExecutionException
741 >     *  if saturated.
742       */
743 <    public void testRejectedExecutionException() {
744 <        ThreadPoolExecutor tpe = null;
743 >    public void testSaturatedExecute() {
744 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
745          try {
746 <            tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
747 <        } catch(Exception e){}
746 >            
747 >            for(int i = 0; i < 5; ++i){
748 >                p.execute(new MediumRunnable());
749 >            }
750 >            shouldThrow();
751 >        } catch(RejectedExecutionException success){}
752 >        joinPool(p);
753 >    }
754 >
755 >    /**
756 >     *  executor using CallerRunsPolicy runs task if saturated.
757 >     */
758 >    public void testSaturatedExecute2() {
759 >        RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
760 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
761 >        try {
762 >            
763 >            TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
764 >            for(int i = 0; i < 5; ++i){
765 >                tasks[i] = new TrackedNoOpRunnable();
766 >            }
767 >            TrackedLongRunnable mr = new TrackedLongRunnable();
768 >            p.execute(mr);
769 >            for(int i = 0; i < 5; ++i){
770 >                p.execute(tasks[i]);
771 >            }
772 >            for(int i = 1; i < 5; ++i) {
773 >                assertTrue(tasks[i].done);
774 >            }
775 >            p.shutdownNow();
776 >        } catch(RejectedExecutionException ex){
777 >            unexpectedException();
778 >        } finally {
779 >            joinPool(p);
780 >        }
781 >    }
782 >
783 >    /**
784 >     *  executor using DiscardPolicy drops task if saturated.
785 >     */
786 >    public void testSaturatedExecute3() {
787 >        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
788 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
789 >        try {
790 >            
791 >            TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
792 >            for(int i = 0; i < 5; ++i){
793 >                tasks[i] = new TrackedNoOpRunnable();
794 >            }
795 >            p.execute(new TrackedLongRunnable());
796 >            for(int i = 0; i < 5; ++i){
797 >                p.execute(tasks[i]);
798 >            }
799 >            for(int i = 0; i < 5; ++i){
800 >                assertFalse(tasks[i].done);
801 >            }
802 >            p.shutdownNow();
803 >        } catch(RejectedExecutionException ex){
804 >            unexpectedException();
805 >        } finally {
806 >            joinPool(p);
807 >        }
808 >    }
809 >
810 >    /**
811 >     *  executor using DiscardOldestPolicy drops oldest task if saturated.
812 >     */
813 >    public void testSaturatedExecute4() {
814 >        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
815 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
816 >        try {
817 >            p.execute(new TrackedLongRunnable());
818 >            TrackedLongRunnable r2 = new TrackedLongRunnable();
819 >            p.execute(r2);
820 >            assertTrue(p.getQueue().contains(r2));
821 >            TrackedNoOpRunnable r3 = new TrackedNoOpRunnable();
822 >            p.execute(r3);
823 >            assertFalse(p.getQueue().contains(r2));
824 >            assertTrue(p.getQueue().contains(r3));
825 >            p.shutdownNow();
826 >        } catch(RejectedExecutionException ex){
827 >            unexpectedException();
828 >        } finally {
829 >            joinPool(p);
830 >        }
831 >    }
832 >
833 >    /**
834 >     *  execute throws RejectedExecutionException if shutdown
835 >     */
836 >    public void testRejectedExecutionExceptionOnShutdown() {
837 >        ThreadPoolExecutor tpe =
838 >            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
839          tpe.shutdown();
840          try {
841              tpe.execute(new NoOpRunnable());
# Line 531 | Line 844 | public class ThreadPoolExecutorTest exte
844          
845          joinPool(tpe);
846      }
847 +
848 +    /**
849 +     *  execute using CallerRunsPolicy drops task on shutdown
850 +     */
851 +    public void testCallerRunsOnShutdown() {
852 +        RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
853 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
854 +
855 +        p.shutdown();
856 +        try {
857 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
858 +            p.execute(r);
859 +            assertFalse(r.done);
860 +        } catch(RejectedExecutionException success){
861 +            unexpectedException();
862 +        } finally {
863 +            joinPool(p);
864 +        }
865 +    }
866 +
867 +    /**
868 +     *  execute using DiscardPolicy drops task on shutdown
869 +     */
870 +    public void testDiscardOnShutdown() {
871 +        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
872 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
873 +
874 +        p.shutdown();
875 +        try {
876 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
877 +            p.execute(r);
878 +            assertFalse(r.done);
879 +        } catch(RejectedExecutionException success){
880 +            unexpectedException();
881 +        } finally {
882 +            joinPool(p);
883 +        }
884 +    }
885 +
886 +
887 +    /**
888 +     *  execute using DiscardOldestPolicy drops task on shutdown
889 +     */
890 +    public void testDiscardOldestOnShutdown() {
891 +        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
892 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
893 +
894 +        p.shutdown();
895 +        try {
896 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
897 +            p.execute(r);
898 +            assertFalse(r.done);
899 +        } catch(RejectedExecutionException success){
900 +            unexpectedException();
901 +        } finally {
902 +            joinPool(p);
903 +        }
904 +    }
905 +
906 +
907 +    /**
908 +     *  execute (null) throws NPE
909 +     */
910 +    public void testExecuteNull() {
911 +        ThreadPoolExecutor tpe = null;
912 +        try {
913 +            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
914 +            tpe.execute(null);
915 +            shouldThrow();
916 +        } catch(NullPointerException success){}
917 +        
918 +        joinPool(tpe);
919 +    }
920      
921      /**
922 <     *   setCorePoolSize will throw IllegalArgumentException
537 <     *  when given a negative
922 >     *  setCorePoolSize of negative value throws IllegalArgumentException
923       */
924      public void testCorePoolSizeIllegalArgumentException() {
925          ThreadPoolExecutor tpe = null;
926          try {
927 <            tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
927 >            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
928          } catch(Exception e){}
929          try {
930              tpe.setCorePoolSize(-1);
# Line 551 | Line 936 | public class ThreadPoolExecutorTest exte
936          joinPool(tpe);
937      }  
938  
554    
939      /**
940 <     *   setMaximumPoolSize(int) will throw IllegalArgumentException
941 <     *  if given a value less the it's actual core pool size
940 >     *  setMaximumPoolSize(int) throws IllegalArgumentException if
941 >     *  given a value less the core pool size
942       */  
943      public void testMaximumPoolSizeIllegalArgumentException() {
944          ThreadPoolExecutor tpe = null;
945          try {
946 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
946 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
947          } catch(Exception e){}
948          try {
949              tpe.setMaximumPoolSize(1);
# Line 572 | Line 956 | public class ThreadPoolExecutorTest exte
956      }
957      
958      /**
959 <     *   setMaximumPoolSize will throw IllegalArgumentException
960 <     *  if given a negative number
959 >     *  setMaximumPoolSize throws IllegalArgumentException
960 >     *  if given a negative value
961       */
962      public void testMaximumPoolSizeIllegalArgumentException2() {
963          ThreadPoolExecutor tpe = null;
964          try {
965 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
965 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
966          } catch(Exception e){}
967          try {
968              tpe.setMaximumPoolSize(-1);
# Line 592 | Line 976 | public class ThreadPoolExecutorTest exte
976      
977  
978      /**
979 <     *   setKeepAliveTime will throw IllegalArgumentException
979 >     *  setKeepAliveTime  throws IllegalArgumentException
980       *  when given a negative value
981       */
982      public void testKeepAliveTimeIllegalArgumentException() {
983          ThreadPoolExecutor tpe = null;
984          try {
985 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
985 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
986          } catch(Exception e){}
987          
988          try {
# Line 610 | Line 994 | public class ThreadPoolExecutorTest exte
994          }
995          joinPool(tpe);
996      }
997 <  
997 >
998 >    /**
999 >     * terminated() is called on termination
1000 >     */
1001 >    public void testTerminated() {
1002 >        ExtendedTPE tpe = new ExtendedTPE();
1003 >        tpe.shutdown();
1004 >        assertTrue(tpe.terminatedCalled);
1005 >        joinPool(tpe);
1006 >    }
1007 >
1008 >    /**
1009 >     * beforeExecute and afterExecute are called when executing task
1010 >     */
1011 >    public void testBeforeAfter() {
1012 >        ExtendedTPE tpe = new ExtendedTPE();
1013 >        try {
1014 >            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1015 >            tpe.execute(r);
1016 >            Thread.sleep(SHORT_DELAY_MS);
1017 >            assertTrue(r.done);
1018 >            assertTrue(tpe.beforeCalled);
1019 >            assertTrue(tpe.afterCalled);
1020 >            tpe.shutdown();
1021 >        }
1022 >        catch(Exception ex) {
1023 >            unexpectedException();
1024 >        } finally {
1025 >            joinPool(tpe);
1026 >        }
1027 >    }
1028 >
1029 >    /**
1030 >     * completed submit of callable returns result
1031 >     */
1032 >    public void testSubmitCallable() {
1033 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1034 >        try {
1035 >            Future<String> future = e.submit(new StringTask());
1036 >            String result = future.get();
1037 >            assertSame(TEST_STRING, result);
1038 >        }
1039 >        catch (ExecutionException ex) {
1040 >            unexpectedException();
1041 >        }
1042 >        catch (InterruptedException ex) {
1043 >            unexpectedException();
1044 >        } finally {
1045 >            joinPool(e);
1046 >        }
1047 >    }
1048 >
1049 >    /**
1050 >     * completed submit of runnable returns successfully
1051 >     */
1052 >    public void testSubmitRunnable() {
1053 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1054 >        try {
1055 >            Future<?> future = e.submit(new NoOpRunnable());
1056 >            future.get();
1057 >            assertTrue(future.isDone());
1058 >        }
1059 >        catch (ExecutionException ex) {
1060 >            unexpectedException();
1061 >        }
1062 >        catch (InterruptedException ex) {
1063 >            unexpectedException();
1064 >        } finally {
1065 >            joinPool(e);
1066 >        }
1067 >    }
1068 >
1069 >    /**
1070 >     * completed submit of (runnable, result) returns result
1071 >     */
1072 >    public void testSubmitRunnable2() {
1073 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1074 >        try {
1075 >            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1076 >            String result = future.get();
1077 >            assertSame(TEST_STRING, result);
1078 >        }
1079 >        catch (ExecutionException ex) {
1080 >            unexpectedException();
1081 >        }
1082 >        catch (InterruptedException ex) {
1083 >            unexpectedException();
1084 >        } finally {
1085 >            joinPool(e);
1086 >        }
1087 >    }
1088 >
1089 >
1090 >
1091 >
1092 >
1093 >    /**
1094 >     * invokeAny(null) throws NPE
1095 >     */
1096 >    public void testInvokeAny1() {
1097 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1098 >        try {
1099 >            e.invokeAny(null);
1100 >        } catch (NullPointerException success) {
1101 >        } catch(Exception ex) {
1102 >            unexpectedException();
1103 >        } finally {
1104 >            joinPool(e);
1105 >        }
1106 >    }
1107 >
1108 >    /**
1109 >     * invokeAny(empty collection) throws IAE
1110 >     */
1111 >    public void testInvokeAny2() {
1112 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1113 >        try {
1114 >            e.invokeAny(new ArrayList<Callable<String>>());
1115 >        } catch (IllegalArgumentException success) {
1116 >        } catch(Exception ex) {
1117 >            unexpectedException();
1118 >        } finally {
1119 >            joinPool(e);
1120 >        }
1121 >    }
1122 >
1123 >    /**
1124 >     * invokeAny(c) throws NPE if c has null elements
1125 >     */
1126 >    public void testInvokeAny3() {
1127 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1128 >        try {
1129 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1130 >            l.add(new StringTask());
1131 >            l.add(null);
1132 >            e.invokeAny(l);
1133 >        } catch (NullPointerException success) {
1134 >        } catch(Exception ex) {
1135 >            unexpectedException();
1136 >        } finally {
1137 >            joinPool(e);
1138 >        }
1139 >    }
1140 >
1141 >    /**
1142 >     * invokeAny(c) throws ExecutionException if no task completes
1143 >     */
1144 >    public void testInvokeAny4() {
1145 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1146 >        try {
1147 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1148 >            l.add(new NPETask());
1149 >            e.invokeAny(l);
1150 >        } catch (ExecutionException success) {
1151 >        } catch(Exception ex) {
1152 >            unexpectedException();
1153 >        } finally {
1154 >            joinPool(e);
1155 >        }
1156 >    }
1157 >
1158 >    /**
1159 >     * invokeAny(c) returns result of some task
1160 >     */
1161 >    public void testInvokeAny5() {
1162 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1163 >        try {
1164 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1165 >            l.add(new StringTask());
1166 >            l.add(new StringTask());
1167 >            String result = e.invokeAny(l);
1168 >            assertSame(TEST_STRING, result);
1169 >        } catch (ExecutionException success) {
1170 >        } catch(Exception ex) {
1171 >            unexpectedException();
1172 >        } finally {
1173 >            joinPool(e);
1174 >        }
1175 >    }
1176 >
1177 >    /**
1178 >     * invokeAll(null) throws NPE
1179 >     */
1180 >    public void testInvokeAll1() {
1181 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1182 >        try {
1183 >            e.invokeAll(null);
1184 >        } catch (NullPointerException success) {
1185 >        } catch(Exception ex) {
1186 >            unexpectedException();
1187 >        } finally {
1188 >            joinPool(e);
1189 >        }
1190 >    }
1191 >
1192 >    /**
1193 >     * invokeAll(empty collection) returns empty collection
1194 >     */
1195 >    public void testInvokeAll2() {
1196 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1197 >        try {
1198 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1199 >            assertTrue(r.isEmpty());
1200 >        } catch(Exception ex) {
1201 >            unexpectedException();
1202 >        } finally {
1203 >            joinPool(e);
1204 >        }
1205 >    }
1206 >
1207 >    /**
1208 >     * invokeAll(c) throws NPE if c has null elements
1209 >     */
1210 >    public void testInvokeAll3() {
1211 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1212 >        try {
1213 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1214 >            l.add(new StringTask());
1215 >            l.add(null);
1216 >            e.invokeAll(l);
1217 >        } catch (NullPointerException success) {
1218 >        } catch(Exception ex) {
1219 >            unexpectedException();
1220 >        } finally {
1221 >            joinPool(e);
1222 >        }
1223 >    }
1224 >
1225 >    /**
1226 >     * get of element of invokeAll(c) throws exception on failed task
1227 >     */
1228 >    public void testInvokeAll4() {
1229 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1230 >        try {
1231 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1232 >            l.add(new NPETask());
1233 >            List<Future<String>> result = e.invokeAll(l);
1234 >            assertEquals(1, result.size());
1235 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1236 >                it.next().get();
1237 >        } catch(ExecutionException success) {
1238 >        } catch(Exception ex) {
1239 >            unexpectedException();
1240 >        } finally {
1241 >            joinPool(e);
1242 >        }
1243 >    }
1244 >
1245 >    /**
1246 >     * invokeAll(c) returns results of all completed tasks
1247 >     */
1248 >    public void testInvokeAll5() {
1249 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1250 >        try {
1251 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1252 >            l.add(new StringTask());
1253 >            l.add(new StringTask());
1254 >            List<Future<String>> result = e.invokeAll(l);
1255 >            assertEquals(2, result.size());
1256 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1257 >                assertSame(TEST_STRING, it.next().get());
1258 >        } catch (ExecutionException success) {
1259 >        } catch(Exception ex) {
1260 >            unexpectedException();
1261 >        } finally {
1262 >            joinPool(e);
1263 >        }
1264 >    }
1265 >
1266 >
1267 >
1268 >    /**
1269 >     * timed invokeAny(null) throws NPE
1270 >     */
1271 >    public void testTimedInvokeAny1() {
1272 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1273 >        try {
1274 >            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1275 >        } catch (NullPointerException success) {
1276 >        } catch(Exception ex) {
1277 >            unexpectedException();
1278 >        } finally {
1279 >            joinPool(e);
1280 >        }
1281 >    }
1282 >
1283 >    /**
1284 >     * timed invokeAny(,,null) throws NPE
1285 >     */
1286 >    public void testTimedInvokeAnyNullTimeUnit() {
1287 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1288 >        try {
1289 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1290 >            l.add(new StringTask());
1291 >            e.invokeAny(l, MEDIUM_DELAY_MS, null);
1292 >        } catch (NullPointerException success) {
1293 >        } catch(Exception ex) {
1294 >            unexpectedException();
1295 >        } finally {
1296 >            joinPool(e);
1297 >        }
1298 >    }
1299 >
1300 >    /**
1301 >     * timed invokeAny(empty collection) throws IAE
1302 >     */
1303 >    public void testTimedInvokeAny2() {
1304 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1305 >        try {
1306 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1307 >        } catch (IllegalArgumentException success) {
1308 >        } catch(Exception ex) {
1309 >            unexpectedException();
1310 >        } finally {
1311 >            joinPool(e);
1312 >        }
1313 >    }
1314 >
1315 >    /**
1316 >     * timed invokeAny(c) throws NPE if c has null elements
1317 >     */
1318 >    public void testTimedInvokeAny3() {
1319 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1320 >        try {
1321 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1322 >            l.add(new StringTask());
1323 >            l.add(null);
1324 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1325 >        } catch (NullPointerException success) {
1326 >        } catch(Exception ex) {
1327 >            ex.printStackTrace();
1328 >            unexpectedException();
1329 >        } finally {
1330 >            joinPool(e);
1331 >        }
1332 >    }
1333 >
1334 >    /**
1335 >     * timed invokeAny(c) throws ExecutionException if no task completes
1336 >     */
1337 >    public void testTimedInvokeAny4() {
1338 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1339 >        try {
1340 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1341 >            l.add(new NPETask());
1342 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1343 >        } catch(ExecutionException success) {
1344 >        } catch(Exception ex) {
1345 >            unexpectedException();
1346 >        } finally {
1347 >            joinPool(e);
1348 >        }
1349 >    }
1350 >
1351 >    /**
1352 >     * timed invokeAny(c) returns result of some task
1353 >     */
1354 >    public void testTimedInvokeAny5() {
1355 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1356 >        try {
1357 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1358 >            l.add(new StringTask());
1359 >            l.add(new StringTask());
1360 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1361 >            assertSame(TEST_STRING, result);
1362 >        } catch (ExecutionException success) {
1363 >        } catch(Exception ex) {
1364 >            unexpectedException();
1365 >        } finally {
1366 >            joinPool(e);
1367 >        }
1368 >    }
1369 >
1370 >    /**
1371 >     * timed invokeAll(null) throws NPE
1372 >     */
1373 >    public void testTimedInvokeAll1() {
1374 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1375 >        try {
1376 >            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1377 >        } catch (NullPointerException success) {
1378 >        } catch(Exception ex) {
1379 >            unexpectedException();
1380 >        } finally {
1381 >            joinPool(e);
1382 >        }
1383 >    }
1384 >
1385 >    /**
1386 >     * timed invokeAll(,,null) throws NPE
1387 >     */
1388 >    public void testTimedInvokeAllNullTimeUnit() {
1389 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1390 >        try {
1391 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1392 >            l.add(new StringTask());
1393 >            e.invokeAll(l, MEDIUM_DELAY_MS, null);
1394 >        } catch (NullPointerException success) {
1395 >        } catch(Exception ex) {
1396 >            unexpectedException();
1397 >        } finally {
1398 >            joinPool(e);
1399 >        }
1400 >    }
1401 >
1402 >    /**
1403 >     * timed invokeAll(empty collection) returns empty collection
1404 >     */
1405 >    public void testTimedInvokeAll2() {
1406 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1407 >        try {
1408 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1409 >            assertTrue(r.isEmpty());
1410 >        } catch(Exception ex) {
1411 >            unexpectedException();
1412 >        } finally {
1413 >            joinPool(e);
1414 >        }
1415 >    }
1416 >
1417 >    /**
1418 >     * timed invokeAll(c) throws NPE if c has null elements
1419 >     */
1420 >    public void testTimedInvokeAll3() {
1421 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1422 >        try {
1423 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1424 >            l.add(new StringTask());
1425 >            l.add(null);
1426 >            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1427 >        } catch (NullPointerException success) {
1428 >        } catch(Exception ex) {
1429 >            unexpectedException();
1430 >        } finally {
1431 >            joinPool(e);
1432 >        }
1433 >    }
1434 >
1435 >    /**
1436 >     * get of element of invokeAll(c) throws exception on failed task
1437 >     */
1438 >    public void testTimedInvokeAll4() {
1439 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1440 >        try {
1441 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1442 >            l.add(new NPETask());
1443 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1444 >            assertEquals(1, result.size());
1445 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1446 >                it.next().get();
1447 >        } catch(ExecutionException success) {
1448 >        } catch(Exception ex) {
1449 >            unexpectedException();
1450 >        } finally {
1451 >            joinPool(e);
1452 >        }
1453 >    }
1454 >
1455 >    /**
1456 >     * timed invokeAll(c) returns results of all completed tasks
1457 >     */
1458 >    public void testTimedInvokeAll5() {
1459 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1460 >        try {
1461 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1462 >            l.add(new StringTask());
1463 >            l.add(new StringTask());
1464 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1465 >            assertEquals(2, result.size());
1466 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1467 >                assertSame(TEST_STRING, it.next().get());
1468 >        } catch (ExecutionException success) {
1469 >        } catch(Exception ex) {
1470 >            unexpectedException();
1471 >        } finally {
1472 >            joinPool(e);
1473 >        }
1474 >    }
1475 >
1476 >    /**
1477 >     * timed invokeAll(c) cancels tasks not completed by timeout
1478 >     */
1479 >    public void testTimedInvokeAll6() {
1480 >        ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1481 >        try {
1482 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1483 >            l.add(new StringTask());
1484 >            l.add(Executors.callable(new MediumInterruptedRunnable(), TEST_STRING));
1485 >            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1486 >            assertEquals(2, result.size());
1487 >            Iterator<Future<String>> it = result.iterator();
1488 >            Future<String> f1 = it.next();
1489 >            Future<String> f2 = it.next();
1490 >            assertTrue(f1.isDone());
1491 >            assertFalse(f1.isCancelled());
1492 >            assertTrue(f2.isDone());
1493 >            assertTrue(f2.isCancelled());
1494 >        } catch(Exception ex) {
1495 >            unexpectedException();
1496 >        } finally {
1497 >            joinPool(e);
1498 >        }
1499 >    }
1500 >
1501 >
1502   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines