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.9 by dl, Sun Oct 5 23:55:03 2003 UTC

# 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 +    /**
182 +     * getRejectedExecutionHandler returns handler in constructor if not set
183 +     */
184 +    public void testGetRejectedExecutionHandler() {
185 +        RejectedExecutionHandler h = new NoOpREHandler();
186 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
187 +        assertSame(h, p.getRejectedExecutionHandler());
188 +        p.shutdown();
189 +        joinPool(p);
190 +    }
191 +
192 +    /**
193 +     * setRejectedExecutionHandler sets the handler returned by
194 +     * getRejectedExecutionHandler
195 +     */
196 +    public void testSetRejectedExecutionHandler() {
197 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
198 +        RejectedExecutionHandler h = new NoOpREHandler();
199 +        p.setRejectedExecutionHandler(h);
200 +        assertSame(h, p.getRejectedExecutionHandler());
201 +        p.shutdown();
202 +        joinPool(p);
203 +    }
204 +
205 +
206 +    /**
207 +     * setRejectedExecutionHandler(null) throws NPE
208 +     */
209 +    public void testSetRejectedExecutionHandlerNull() {
210 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
211 +        try {
212 +            p.setRejectedExecutionHandler(null);
213 +            shouldThrow();
214 +        } catch (NullPointerException success) {
215 +        } finally {
216 +            joinPool(p);
217 +        }
218 +    }
219 +
220      
221      /**
222 <     *   getLargestPoolSize gives correct values
222 >     *   getLargestPoolSize increases, but doesn't overestimate, when
223 >     *   multiple threads active
224       */
225      public void testGetLargestPoolSize() {
226 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
226 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
227          try {
228              assertEquals(0, p2.getLargestPoolSize());
229              p2.execute(new MediumRunnable());
# Line 124 | Line 237 | public class ThreadPoolExecutorTest exte
237      }
238      
239      /**
240 <     *   getMaximumPoolSize gives correct values
240 >     *   getMaximumPoolSize returns value given in constructor if not
241 >     *   otherwise set
242       */
243      public void testGetMaximumPoolSize() {
244 <        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
244 >        ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
245          assertEquals(2, p2.getMaximumPoolSize());
246          joinPool(p2);
247      }
248      
249      /**
250 <     *   getPoolSize gives correct values
250 >     *   getPoolSize increases, but doesn't overestimate, when threads
251 >     *   become active
252       */
253      public void testGetPoolSize() {
254 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
254 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
255          assertEquals(0, p1.getPoolSize());
256          p1.execute(new MediumRunnable());
257          assertEquals(1, p1.getPoolSize());
# Line 144 | Line 259 | public class ThreadPoolExecutorTest exte
259      }
260      
261      /**
262 <     *   getTaskCount gives correct values
262 >     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
263       */
264      public void testGetTaskCount() {
265 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
265 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
266          try {
267              assertEquals(0, p1.getTaskCount());
268              p1.execute(new MediumRunnable());
# Line 160 | Line 275 | public class ThreadPoolExecutorTest exte
275      }
276      
277      /**
278 <     *   isShutDown gives correct values
278 >     *   isShutDown is false before shutdown, true after
279       */
280      public void testIsShutdown() {
281          
282 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
282 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
283          assertFalse(p1.isShutdown());
284          p1.shutdown();
285          assertTrue(p1.isShutdown());
# Line 173 | Line 288 | public class ThreadPoolExecutorTest exte
288  
289          
290      /**
291 <     *   isTerminated gives correct values
177 <     *  Makes sure termination does not take an innapropriate
178 <     *  amount of time
291 >     *  isTerminated is false before termination, true after
292       */
293      public void testIsTerminated() {
294 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
294 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
295 >        assertFalse(p1.isTerminated());
296          try {
297              p1.execute(new MediumRunnable());
298          } finally {
# Line 193 | Line 307 | public class ThreadPoolExecutorTest exte
307      }
308  
309      /**
310 <     *  isTerminating gives correct values
310 >     *  isTerminating is not true when running or when terminated
311       */
312      public void testIsTerminating() {
313 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
313 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
314          assertFalse(p1.isTerminating());
315          try {
316              p1.execute(new SmallRunnable());
# Line 214 | Line 328 | public class ThreadPoolExecutorTest exte
328      }
329  
330      /**
331 <     *   purge correctly removes cancelled tasks
332 <     *  from the queue
331 >     * getQueue returns the work queue, which contains queued tasks
332 >     */
333 >    public void testGetQueue() {
334 >        BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
335 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
336 >        CancellableTask[] tasks = new CancellableTask[5];
337 >        for(int i = 0; i < 5; i++){
338 >            tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
339 >            p1.execute(tasks[i]);
340 >        }
341 >        try {
342 >            Thread.sleep(SHORT_DELAY_MS);
343 >            BlockingQueue<Runnable> wq = p1.getQueue();
344 >            assertSame(q, wq);
345 >            assertFalse(wq.contains(tasks[0]));
346 >            assertTrue(wq.contains(tasks[4]));
347 >            p1.shutdownNow();
348 >        } catch(Exception e) {
349 >            unexpectedException();
350 >        } finally {
351 >            joinPool(p1);
352 >        }
353 >    }
354 >
355 >    /**
356 >     * remove(task) removes queued task, and fails to remove active task
357 >     */
358 >    public void testRemove() {
359 >        BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
360 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
361 >        CancellableTask[] tasks = new CancellableTask[5];
362 >        for(int i = 0; i < 5; i++){
363 >            tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
364 >            p1.execute(tasks[i]);
365 >        }
366 >        try {
367 >            Thread.sleep(SHORT_DELAY_MS);
368 >            assertFalse(p1.remove(tasks[0]));
369 >            assertTrue(q.contains(tasks[4]));
370 >            assertTrue(q.contains(tasks[3]));
371 >            assertTrue(p1.remove(tasks[4]));
372 >            assertFalse(p1.remove(tasks[4]));
373 >            assertFalse(q.contains(tasks[4]));
374 >            assertTrue(q.contains(tasks[3]));
375 >            assertTrue(p1.remove(tasks[3]));
376 >            assertFalse(q.contains(tasks[3]));
377 >            p1.shutdownNow();
378 >        } catch(Exception e) {
379 >            unexpectedException();
380 >        } finally {
381 >            joinPool(p1);
382 >        }
383 >    }
384 >
385 >    /**
386 >     *   purge removes cancelled tasks from the queue
387       */
388      public void testPurge() {
389 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
389 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
390          CancellableTask[] tasks = new CancellableTask[5];
391          for(int i = 0; i < 5; i++){
392              tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
# Line 229 | Line 397 | public class ThreadPoolExecutorTest exte
397          p1.purge();
398          long count = p1.getTaskCount();
399          assertTrue(count >= 2 && count < 5);
400 +        p1.shutdownNow();
401          joinPool(p1);
402      }
403  
404      /**
405 <     *   shutDownNow returns a list
237 <     *  containing the correct number of elements
405 >     *  shutDownNow returns a list containing tasks that were not run
406       */
407      public void testShutDownNow() {
408 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
408 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
409          List l;
410          try {
411              for(int i = 0; i < 5; i++)
# Line 253 | Line 421 | public class ThreadPoolExecutorTest exte
421      // Exception Tests
422      
423  
424 <    /** Throws if corePoolSize argument is less than zero */
424 >    /**
425 >     * Constructor throws if corePoolSize argument is less than zero
426 >     */
427      public void testConstructor1() {
428          try {
429              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 262 | Line 432 | public class ThreadPoolExecutorTest exte
432          catch (IllegalArgumentException success){}
433      }
434      
435 <    /** Throws if maximumPoolSize is less than zero */
435 >    /**
436 >     * Constructor throws if maximumPoolSize is less than zero
437 >     */
438      public void testConstructor2() {
439          try {
440              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 271 | Line 443 | public class ThreadPoolExecutorTest exte
443          catch (IllegalArgumentException success){}
444      }
445      
446 <    /** Throws if maximumPoolSize is equal to zero */
446 >    /**
447 >     * Constructor throws if maximumPoolSize is equal to zero
448 >     */
449      public void testConstructor3() {
450          try {
451              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 280 | Line 454 | public class ThreadPoolExecutorTest exte
454          catch (IllegalArgumentException success){}
455      }
456  
457 <    /** Throws if keepAliveTime is less than zero */
457 >    /**
458 >     * Constructor throws if keepAliveTime is less than zero
459 >     */
460      public void testConstructor4() {
461          try {
462              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 289 | Line 465 | public class ThreadPoolExecutorTest exte
465          catch (IllegalArgumentException success){}
466      }
467  
468 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
468 >    /**
469 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
470 >     */
471      public void testConstructor5() {
472          try {
473              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 298 | Line 476 | public class ThreadPoolExecutorTest exte
476          catch (IllegalArgumentException success){}
477      }
478          
479 <    /** Throws if workQueue is set to null */
480 <    public void testNullPointerException() {
479 >    /**
480 >     * Constructor throws if workQueue is set to null
481 >     */
482 >    public void testConstructorNullPointerException() {
483          try {
484 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
484 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
485              shouldThrow();
486          }
487          catch (NullPointerException success){}  
# Line 309 | Line 489 | public class ThreadPoolExecutorTest exte
489      
490  
491      
492 <    /** Throws if corePoolSize argument is less than zero */
492 >    /**
493 >     * Constructor throws if corePoolSize argument is less than zero
494 >     */
495      public void testConstructor6() {
496          try {
497 <            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
497 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
498              shouldThrow();
499          } catch (IllegalArgumentException success){}
500      }
501      
502 <    /** Throws if maximumPoolSize is less than zero */
502 >    /**
503 >     * Constructor throws if maximumPoolSize is less than zero
504 >     */
505      public void testConstructor7() {
506          try {
507 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
507 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
508              shouldThrow();
509          }
510          catch (IllegalArgumentException success){}
511      }
512  
513 <    /** Throws if maximumPoolSize is equal to zero */
513 >    /**
514 >     * Constructor throws if maximumPoolSize is equal to zero
515 >     */
516      public void testConstructor8() {
517          try {
518 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
518 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
519              shouldThrow();
520          }
521          catch (IllegalArgumentException success){}
522      }
523  
524 <    /** Throws if keepAliveTime is less than zero */
524 >    /**
525 >     * Constructor throws if keepAliveTime is less than zero
526 >     */
527      public void testConstructor9() {
528          try {
529 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
529 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
530              shouldThrow();
531          }
532          catch (IllegalArgumentException success){}
533      }
534  
535 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
535 >    /**
536 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
537 >     */
538      public void testConstructor10() {
539          try {
540 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
540 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
541              shouldThrow();
542          }
543          catch (IllegalArgumentException success){}
544      }
545  
546 <    /** Throws if workQueue is set to null */
547 <    public void testNullPointerException2() {
546 >    /**
547 >     * Constructor throws if workQueue is set to null
548 >     */
549 >    public void testConstructorNullPointerException2() {
550          try {
551 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory());
551 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
552              shouldThrow();
553          }
554          catch (NullPointerException success){}  
555      }
556  
557 <    /** Throws if threadFactory is set to null */
558 <    public void testNullPointerException3() {
557 >    /**
558 >     * Constructor throws if threadFactory is set to null
559 >     */
560 >    public void testConstructorNullPointerException3() {
561          try {
562              ThreadFactory f = null;
563 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
563 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
564              shouldThrow();
565          }
566          catch (NullPointerException success){}  
567      }
568  
569      
570 <    /** Throws if corePoolSize argument is less than zero */
570 >    /**
571 >     * Constructor throws if corePoolSize argument is less than zero
572 >     */
573      public void testConstructor11() {
574          try {
575 <            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
575 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
576              shouldThrow();
577          }
578          catch (IllegalArgumentException success){}
579      }
580  
581 <    /** Throws if maximumPoolSize is less than zero */
581 >    /**
582 >     * Constructor throws if maximumPoolSize is less than zero
583 >     */
584      public void testConstructor12() {
585          try {
586 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
586 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
587              shouldThrow();
588          }
589          catch (IllegalArgumentException success){}
590      }
591  
592 <    /** Throws if maximumPoolSize is equal to zero */
592 >    /**
593 >     * Constructor throws if maximumPoolSize is equal to zero
594 >     */
595      public void testConstructor13() {
596          try {
597 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
597 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
598              shouldThrow();
599          }
600          catch (IllegalArgumentException success){}
601      }
602  
603 <    /** Throws if keepAliveTime is less than zero */
603 >    /**
604 >     * Constructor throws if keepAliveTime is less than zero
605 >     */
606      public void testConstructor14() {
607          try {
608 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
608 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
609              shouldThrow();
610          }
611          catch (IllegalArgumentException success){}
612      }
613  
614 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
614 >    /**
615 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
616 >     */
617      public void testConstructor15() {
618          try {
619 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
619 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
620              shouldThrow();
621          }
622          catch (IllegalArgumentException success){}
623      }
624  
625 <    /** Throws if workQueue is set to null */
626 <    public void testNullPointerException4() {
625 >    /**
626 >     * Constructor throws if workQueue is set to null
627 >     */
628 >    public void testConstructorNullPointerException4() {
629          try {
630 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler());
630 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
631              shouldThrow();
632          }
633          catch (NullPointerException success){}  
634      }
635  
636 <    /** Throws if handler is set to null */
637 <    public void testNullPointerException5() {
636 >    /**
637 >     * Constructor throws if handler is set to null
638 >     */
639 >    public void testConstructorNullPointerException5() {
640          try {
641              RejectedExecutionHandler r = null;
642 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
642 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
643              shouldThrow();
644          }
645          catch (NullPointerException success){}  
646      }
647  
648      
649 <    /** Throws if corePoolSize argument is less than zero */
649 >    /**
650 >     * Constructor throws if corePoolSize argument is less than zero
651 >     */
652      public void testConstructor16() {
653          try {
654 <            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
654 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
655              shouldThrow();
656          }
657          catch (IllegalArgumentException success){}
658      }
659  
660 <    /** Throws if maximumPoolSize is less than zero */
660 >    /**
661 >     * Constructor throws if maximumPoolSize is less than zero
662 >     */
663      public void testConstructor17() {
664          try {
665 <            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
665 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
666              shouldThrow();
667          }
668          catch (IllegalArgumentException success){}
669      }
670  
671 <    /** Throws if maximumPoolSize is equal to zero */
671 >    /**
672 >     * Constructor throws if maximumPoolSize is equal to zero
673 >     */
674      public void testConstructor18() {
675          try {
676 <            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
676 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
677              shouldThrow();
678          }
679          catch (IllegalArgumentException success){}
680      }
681  
682 <    /** Throws if keepAliveTime is less than zero */
682 >    /**
683 >     * Constructor throws if keepAliveTime is less than zero
684 >     */
685      public void testConstructor19() {
686          try {
687 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
687 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
688              shouldThrow();
689          }
690          catch (IllegalArgumentException success){}
691      }
692  
693 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
693 >    /**
694 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
695 >     */
696      public void testConstructor20() {
697          try {
698 <            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
698 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
699              shouldThrow();
700          }
701          catch (IllegalArgumentException success){}
702      }
703  
704 <    /** Throws if workQueue is set to null */
705 <    public void testNullPointerException6() {
704 >    /**
705 >     * Constructor throws if workQueue is set to null
706 >     */
707 >    public void testConstructorNullPointerException6() {
708          try {
709 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler());
709 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
710              shouldThrow();
711          }
712          catch (NullPointerException success){}  
713      }
714  
715 <    /** Throws if handler is set to null */
716 <    public void testNullPointerException7() {
715 >    /**
716 >     * Constructor throws if handler is set to null
717 >     */
718 >    public void testConstructorNullPointerException7() {
719          try {
720              RejectedExecutionHandler r = null;
721 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r);
721 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
722              shouldThrow();
723          }
724          catch (NullPointerException success){}  
725      }
726  
727 <    /** Throws if ThreadFactory is set top null */
728 <    public void testNullPointerException8() {
727 >    /**
728 >     * Constructor throws if ThreadFactory is set top null
729 >     */
730 >    public void testConstructorNullPointerException8() {
731          try {
732              ThreadFactory f = null;
733 <            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler());
733 >            new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
734              shouldThrow();
735          }
736          catch (NullPointerException successdn8){}  
# Line 514 | Line 738 | public class ThreadPoolExecutorTest exte
738      
739  
740      /**
741 <     *   execute will throw RejectedExcutionException
742 <     *  ThreadPoolExecutor will throw one when more runnables are
519 <     *  executed then will fit in the Queue.
741 >     *  execute throws RejectedExecutionException
742 >     *  if saturated.
743       */
744 <    public void testRejectedExecutionException() {
745 <        ThreadPoolExecutor tpe = null;
744 >    public void testSaturatedExecute() {
745 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
746          try {
747 <            tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
748 <        } catch(Exception e){}
747 >            
748 >            for(int i = 0; i < 5; ++i){
749 >                p.execute(new MediumRunnable());
750 >            }
751 >            shouldThrow();
752 >        } catch(RejectedExecutionException success){}
753 >        joinPool(p);
754 >    }
755 >
756 >    /**
757 >     *  executor using CallerRunsPolicy runs task if saturated.
758 >     */
759 >    public void testSaturatedExecute2() {
760 >        RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
761 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
762 >        try {
763 >            
764 >            TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
765 >            for(int i = 0; i < 5; ++i){
766 >                tasks[i] = new TrackedNoOpRunnable();
767 >            }
768 >            TrackedLongRunnable mr = new TrackedLongRunnable();
769 >            p.execute(mr);
770 >            for(int i = 0; i < 5; ++i){
771 >                p.execute(tasks[i]);
772 >            }
773 >            for(int i = 1; i < 5; ++i) {
774 >                assertTrue(tasks[i].done);
775 >            }
776 >            p.shutdownNow();
777 >        } catch(RejectedExecutionException ex){
778 >            unexpectedException();
779 >        } finally {
780 >            joinPool(p);
781 >        }
782 >    }
783 >
784 >    /**
785 >     *  executor using DiscardPolicy drops task if saturated.
786 >     */
787 >    public void testSaturatedExecute3() {
788 >        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
789 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
790 >        try {
791 >            
792 >            TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
793 >            for(int i = 0; i < 5; ++i){
794 >                tasks[i] = new TrackedNoOpRunnable();
795 >            }
796 >            p.execute(new TrackedLongRunnable());
797 >            for(int i = 0; i < 5; ++i){
798 >                p.execute(tasks[i]);
799 >            }
800 >            for(int i = 0; i < 5; ++i){
801 >                assertFalse(tasks[i].done);
802 >            }
803 >            p.shutdownNow();
804 >        } catch(RejectedExecutionException ex){
805 >            unexpectedException();
806 >        } finally {
807 >            joinPool(p);
808 >        }
809 >    }
810 >
811 >    /**
812 >     *  executor using DiscardOldestPolicy drops oldest task if saturated.
813 >     */
814 >    public void testSaturatedExecute4() {
815 >        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
816 >        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
817 >        try {
818 >            p.execute(new TrackedLongRunnable());
819 >            TrackedLongRunnable r2 = new TrackedLongRunnable();
820 >            p.execute(r2);
821 >            assertTrue(p.getQueue().contains(r2));
822 >            TrackedNoOpRunnable r3 = new TrackedNoOpRunnable();
823 >            p.execute(r3);
824 >            assertFalse(p.getQueue().contains(r2));
825 >            assertTrue(p.getQueue().contains(r3));
826 >            p.shutdownNow();
827 >        } catch(RejectedExecutionException ex){
828 >            unexpectedException();
829 >        } finally {
830 >            joinPool(p);
831 >        }
832 >    }
833 >
834 >    /**
835 >     *  execute throws RejectedExecutionException if shutdown
836 >     */
837 >    public void testRejectedExecutionExceptionOnShutdown() {
838 >        ThreadPoolExecutor tpe =
839 >            new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
840          tpe.shutdown();
841          try {
842              tpe.execute(new NoOpRunnable());
# Line 531 | Line 845 | public class ThreadPoolExecutorTest exte
845          
846          joinPool(tpe);
847      }
848 +
849 +    /**
850 +     *  execute using CallerRunsPolicy drops task on shutdown
851 +     */
852 +    public void testCallerRunsOnShutdown() {
853 +        RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
854 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
855 +
856 +        p.shutdown();
857 +        try {
858 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
859 +            p.execute(r);
860 +            assertFalse(r.done);
861 +        } catch(RejectedExecutionException success){
862 +            unexpectedException();
863 +        } finally {
864 +            joinPool(p);
865 +        }
866 +    }
867 +
868 +    /**
869 +     *  execute using DiscardPolicy drops task on shutdown
870 +     */
871 +    public void testDiscardOnShutdown() {
872 +        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
873 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
874 +
875 +        p.shutdown();
876 +        try {
877 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
878 +            p.execute(r);
879 +            assertFalse(r.done);
880 +        } catch(RejectedExecutionException success){
881 +            unexpectedException();
882 +        } finally {
883 +            joinPool(p);
884 +        }
885 +    }
886 +
887 +
888 +    /**
889 +     *  execute using DiscardOldestPolicy drops task on shutdown
890 +     */
891 +    public void testDiscardOldestOnShutdown() {
892 +        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
893 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
894 +
895 +        p.shutdown();
896 +        try {
897 +            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
898 +            p.execute(r);
899 +            assertFalse(r.done);
900 +        } catch(RejectedExecutionException success){
901 +            unexpectedException();
902 +        } finally {
903 +            joinPool(p);
904 +        }
905 +    }
906 +
907 +
908 +    /**
909 +     *  execute (null) throws NPE
910 +     */
911 +    public void testExecuteNull() {
912 +        ThreadPoolExecutor tpe = null;
913 +        try {
914 +            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
915 +            tpe.execute(null);
916 +            shouldThrow();
917 +        } catch(NullPointerException success){}
918 +        
919 +        joinPool(tpe);
920 +    }
921      
922      /**
923 <     *   setCorePoolSize will throw IllegalArgumentException
537 <     *  when given a negative
923 >     *  setCorePoolSize of negative value throws IllegalArgumentException
924       */
925      public void testCorePoolSizeIllegalArgumentException() {
926          ThreadPoolExecutor tpe = null;
927          try {
928 <            tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
928 >            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
929          } catch(Exception e){}
930          try {
931              tpe.setCorePoolSize(-1);
# Line 551 | Line 937 | public class ThreadPoolExecutorTest exte
937          joinPool(tpe);
938      }  
939  
554    
940      /**
941 <     *   setMaximumPoolSize(int) will throw IllegalArgumentException
942 <     *  if given a value less the it's actual core pool size
941 >     *  setMaximumPoolSize(int) throws IllegalArgumentException if
942 >     *  given a value less the core pool size
943       */  
944      public void testMaximumPoolSizeIllegalArgumentException() {
945          ThreadPoolExecutor tpe = null;
946          try {
947 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
947 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
948          } catch(Exception e){}
949          try {
950              tpe.setMaximumPoolSize(1);
# Line 572 | Line 957 | public class ThreadPoolExecutorTest exte
957      }
958      
959      /**
960 <     *   setMaximumPoolSize will throw IllegalArgumentException
961 <     *  if given a negative number
960 >     *  setMaximumPoolSize throws IllegalArgumentException
961 >     *  if given a negative value
962       */
963      public void testMaximumPoolSizeIllegalArgumentException2() {
964          ThreadPoolExecutor tpe = null;
965          try {
966 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
966 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
967          } catch(Exception e){}
968          try {
969              tpe.setMaximumPoolSize(-1);
# Line 592 | Line 977 | public class ThreadPoolExecutorTest exte
977      
978  
979      /**
980 <     *   setKeepAliveTime will throw IllegalArgumentException
980 >     *  setKeepAliveTime  throws IllegalArgumentException
981       *  when given a negative value
982       */
983      public void testKeepAliveTimeIllegalArgumentException() {
984          ThreadPoolExecutor tpe = null;
985          try {
986 <            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
986 >            tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
987          } catch(Exception e){}
988          
989          try {
# Line 610 | Line 995 | public class ThreadPoolExecutorTest exte
995          }
996          joinPool(tpe);
997      }
998 <  
998 >
999 >    /**
1000 >     * terminated() is called on termination
1001 >     */
1002 >    public void testTerminated() {
1003 >        ExtendedTPE tpe = new ExtendedTPE();
1004 >        tpe.shutdown();
1005 >        assertTrue(tpe.terminatedCalled);
1006 >        joinPool(tpe);
1007 >    }
1008 >
1009 >    /**
1010 >     * beforeExecute and afterExecute are called when executing task
1011 >     */
1012 >    public void testBeforeAfter() {
1013 >        ExtendedTPE tpe = new ExtendedTPE();
1014 >        try {
1015 >            TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1016 >            tpe.execute(r);
1017 >            Thread.sleep(SHORT_DELAY_MS);
1018 >            assertTrue(r.done);
1019 >            assertTrue(tpe.beforeCalled);
1020 >            assertTrue(tpe.afterCalled);
1021 >            tpe.shutdown();
1022 >        }
1023 >        catch(Exception ex) {
1024 >            unexpectedException();
1025 >        } finally {
1026 >            joinPool(tpe);
1027 >        }
1028 >    }
1029   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines