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.2 by dl, Sun Sep 7 20:39:11 2003 UTC vs.
Revision 1.3 by dl, Sun Sep 14 20:42:41 2003 UTC

# Line 9 | Line 9 | import java.util.concurrent.*;
9   import junit.framework.*;
10   import java.util.List;
11  
12 < public class ThreadPoolExecutorTest extends TestCase{
12 > public class ThreadPoolExecutorTest extends JSR166TestCase {
13      public static void main(String[] args) {
14          junit.textui.TestRunner.run (suite());  
15      }
16
17
16      public static Test suite() {
17          return new TestSuite(ThreadPoolExecutorTest.class);
18      }
19      
20 <    private static long SHORT_DELAY_MS = 100;
21 <    private static long MEDIUM_DELAY_MS = 1000;
22 <    private static long LONG_DELAY_MS = 10000;
23 <
26 < //---- testThread class to implement ThreadFactory for use in constructors
27 <    static class testThread implements ThreadFactory{
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          }  
27      }
28  
29 < //---- testReject class to implement RejectedExecutionHandler for use in the constructors
30 <    static class testReject implements RejectedExecutionHandler{
29 >    /**
30 >     * For use as RejectedExecutionHandler in constructors
31 >     */
32 >    static class MyREHandler implements RejectedExecutionHandler{
33          public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
34      }
37
38    public Runnable newRunnable(){
39        return new Runnable(){
40                public void run(){
41                    try{Thread.sleep(MEDIUM_DELAY_MS);
42                    } catch(Exception e){
43                    }
44                }
45            };
46    }
47
35  
36      /**
37 <     *  Test to verify that execute successfully executes a runnable
37 >     *   execute successfully executes a runnable
38       */
39      public void testExecute(){
40 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
40 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
41          try {
42              one.execute(new Runnable(){
43                      public void run(){
# Line 61 | Line 48 | public class ThreadPoolExecutorTest exte
48                          }
49                      }
50                  });
51 <            Thread.sleep(SHORT_DELAY_MS * 2);
51 >            Thread.sleep(SMALL_DELAY_MS);
52          } catch(InterruptedException e){
53              fail("unexpected exception");
54 <        } finally {
55 <            one.shutdown();
69 <        }
54 >        }
55 >        joinPool(one);
56      }
57  
58      /**
59 <     *  Test to verify getActiveCount gives correct values
59 >     *   getActiveCount gives correct values
60       */
61      public void testGetActiveCount(){
62 <        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
63 <        try {
64 <            assertEquals(0, two.getActiveCount());
65 <            two.execute(newRunnable());
66 <            try{Thread.sleep(10);} catch(Exception e){}
67 <            assertEquals(1, two.getActiveCount());
68 <        } finally {
83 <            two.shutdown();
62 >        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
63 >        assertEquals(0, two.getActiveCount());
64 >        two.execute(new MediumRunnable());
65 >        try{
66 >            Thread.sleep(SHORT_DELAY_MS);
67 >        } catch(Exception e){
68 >            fail("unexpected exception");
69          }
70 +        assertEquals(1, two.getActiveCount());
71 +        joinPool(two);
72      }
73      
74      /**
75 <     *  Test to verify getCompleteTaskCount gives correct values
75 >     *   getCompleteTaskCount gives correct values
76       */
77      public void testGetCompletedTaskCount(){
78 <        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
79 <        try {
80 <            assertEquals(0, two.getCompletedTaskCount());
81 <            two.execute(newRunnable());
82 <            try{Thread.sleep(2000);} catch(Exception e){}
83 <            assertEquals(1, two.getCompletedTaskCount());
84 <        } finally {
98 <            two.shutdown();
78 >        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
79 >        assertEquals(0, two.getCompletedTaskCount());
80 >        two.execute(new ShortRunnable());
81 >        try{
82 >            Thread.sleep(MEDIUM_DELAY_MS);
83 >        } catch(Exception e){
84 >            fail("unexpected exception");
85          }
86 +        assertEquals(1, two.getCompletedTaskCount());
87 +        two.shutdown();
88 +        joinPool(two);
89      }
90      
91      /**
92 <     *  Test to verify getCorePoolSize gives correct values
92 >     *   getCorePoolSize gives correct values
93       */
94      public void testGetCorePoolSize(){
95 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
96 <        try {
97 <            assertEquals(1, one.getCorePoolSize());
109 <        } finally {
110 <            one.shutdown();
111 <        }
95 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
96 >        assertEquals(1, one.getCorePoolSize());
97 >        joinPool(one);
98      }
99      
100      /**
101 <     *  Test to verify getKeepAliveTime gives correct values
101 >     *   getKeepAliveTime gives correct values
102       */
103      public void testGetKeepAliveTime(){
104 <        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
105 <        try {
106 <            assertEquals(1, two.getKeepAliveTime(TimeUnit.SECONDS));
121 <        } finally {
122 <            two.shutdown();
123 <        }
104 >        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
105 >        assertEquals(1, two.getKeepAliveTime(TimeUnit.SECONDS));
106 >        joinPool(two);
107      }
108      
109      /**
110 <     *  Test to verify getLargestPoolSize gives correct values
110 >     *   getLargestPoolSize gives correct values
111       */
112      public void testGetLargestPoolSize(){
113 <        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
113 >        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
114          try {
115              assertEquals(0, two.getLargestPoolSize());
116 <            two.execute(newRunnable());
117 <            two.execute(newRunnable());
118 <            try{Thread.sleep(SHORT_DELAY_MS);} catch(Exception e){}
116 >            two.execute(new MediumRunnable());
117 >            two.execute(new MediumRunnable());
118 >            Thread.sleep(SHORT_DELAY_MS);
119              assertEquals(2, two.getLargestPoolSize());
120 <        } finally {
121 <            two.shutdown();
122 <        }
120 >        } catch(Exception e){
121 >            fail("unexpected exception");
122 >        }
123 >        joinPool(two);
124      }
125      
126      /**
127 <     *  Test to verify getMaximumPoolSize gives correct values
127 >     *   getMaximumPoolSize gives correct values
128       */
129      public void testGetMaximumPoolSize(){
130 <        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
131 <        try {
132 <            assertEquals(2, two.getMaximumPoolSize());
149 <        } finally {
150 <            two.shutdown();
151 <        }
130 >        ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
131 >        assertEquals(2, two.getMaximumPoolSize());
132 >        joinPool(two);
133      }
134      
135      /**
136 <     *  Test to verify getPoolSize gives correct values
136 >     *   getPoolSize gives correct values
137       */
138      public void testGetPoolSize(){
139 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
140 <        try {
141 <            assertEquals(0, one.getPoolSize());
142 <            one.execute(newRunnable());
143 <            assertEquals(1, one.getPoolSize());
163 <        } finally {
164 <            one.shutdown();
165 <        }
139 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
140 >        assertEquals(0, one.getPoolSize());
141 >        one.execute(new MediumRunnable());
142 >        assertEquals(1, one.getPoolSize());
143 >        joinPool(one);
144      }
145      
146      /**
147 <     *  Test to verify getTaskCount gives correct values
147 >     *   getTaskCount gives correct values
148       */
149      public void testGetTaskCount(){
150 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
150 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
151          try {
152              assertEquals(0, one.getTaskCount());
153              for(int i = 0; i < 5; i++)
154 <                one.execute(newRunnable());
155 <            try{Thread.sleep(SHORT_DELAY_MS);} catch(Exception e){}
154 >                one.execute(new MediumRunnable());
155 >            Thread.sleep(SHORT_DELAY_MS);
156              assertEquals(5, one.getTaskCount());
157 <        } finally {
158 <            one.shutdown();
159 <        }
157 >        } catch(Exception e){
158 >            fail("unexpected exception");
159 >        }
160 >        joinPool(one);
161      }
162      
163      /**
164 <     *  Test to verify isShutDown gives correct values
164 >     *   isShutDown gives correct values
165       */
166      public void testIsShutdown(){
167          
168 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
169 <        try {
170 <            assertFalse(one.isShutdown());
192 <        }
193 <        finally {
194 <            one.shutdown();
195 <        }
168 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
169 >        assertFalse(one.isShutdown());
170 >        one.shutdown();
171          assertTrue(one.isShutdown());
172 +        joinPool(one);
173      }
174  
175          
176      /**
177 <     *  Test to verify isTerminated gives correct values
177 >     *   isTerminated gives correct values
178       *  Makes sure termination does not take an innapropriate
179       *  amount of time
180       */
181      public void testIsTerminated(){
182 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
182 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
183          try {
184 <            one.execute(newRunnable());
184 >            one.execute(new MediumRunnable());
185          } finally {
186              one.shutdown();
187          }
188 <        boolean flag = false;
189 <        try{
190 <            flag = one.awaitTermination(10, TimeUnit.SECONDS);
191 <        } catch(Exception e){}  
192 <        assertTrue(one.isTerminated());
193 <        if(!flag)
218 <            fail("ThreadPoolExecutor - thread pool did not terminate within suitable timeframe");
188 >        try {
189 >            assertTrue(one.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
190 >            assertTrue(one.isTerminated());
191 >        } catch(Exception e){
192 >            fail("unexpected exception");
193 >        }      
194      }
195  
196      /**
197 <     *  Test to verify that purge correctly removes cancelled tasks
197 >     *   purge correctly removes cancelled tasks
198       *  from the queue
199       */
200      public void testPurge(){
201 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
202 <        try {
203 <            CancellableTask[] tasks = new CancellableTask[5];
204 <            for(int i = 0; i < 5; i++){
205 <                tasks[i] = new CancellableTask(newRunnable());
206 <                one.execute(tasks[i]);
207 <            }
208 <            tasks[4].cancel(true);
209 <            tasks[3].cancel(true);
210 <            one.purge();
211 <            long count = one.getTaskCount();
212 <            assertTrue(count >= 2 && count < 5);
238 <        } finally {
239 <            one.shutdown();
240 <        }
201 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
202 >        CancellableTask[] tasks = new CancellableTask[5];
203 >        for(int i = 0; i < 5; i++){
204 >            tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
205 >            one.execute(tasks[i]);
206 >        }
207 >        tasks[4].cancel(true);
208 >        tasks[3].cancel(true);
209 >        one.purge();
210 >        long count = one.getTaskCount();
211 >        assertTrue(count >= 2 && count < 5);
212 >        joinPool(one);
213      }
214  
215      /**
216 <     *  Test to verify shutDownNow returns a list
216 >     *   shutDownNow returns a list
217       *  containing the correct number of elements
218       */
219      public void testShutDownNow(){
220 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
220 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
221          List l;
222          try {
223              for(int i = 0; i < 5; i++)
224 <                one.execute(newRunnable());
224 >                one.execute(new MediumPossiblyInterruptedRunnable());
225          }
226          finally {
227              l = one.shutdownNow();
# Line 258 | Line 230 | public class ThreadPoolExecutorTest exte
230          assertTrue(l.size() <= 4);
231      }
232  
261    
262
263    
264    
265      
233      // Exception Tests
234      
235  
236 <    //---- Tests if corePoolSize argument is less than zero
236 >    /** Throws if corePoolSize argument is less than zero */
237      public void testConstructor1() {
238          try{
239 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
239 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
240              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
241          }
242 <        catch (IllegalArgumentException i){}
242 >        catch (IllegalArgumentException success){}
243      }
244      
245 <    //---- Tests if maximumPoolSize is less than zero
245 >    /** Throws if maximumPoolSize is less than zero */
246      public void testConstructor2() {
247          try{
248 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
248 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
249              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
250          }
251 <        catch (IllegalArgumentException i2){}
251 >        catch (IllegalArgumentException success){}
252      }
253      
254 <    //---- Tests if maximumPoolSize is equal to zero
254 >    /** Throws if maximumPoolSize is equal to zero */
255      public void testConstructor3() {
256          try{
257 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
257 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
258              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
259          }
260 <        catch (IllegalArgumentException i3){}
260 >        catch (IllegalArgumentException success){}
261      }
262  
263 <    //---- Tests if keepAliveTime is less than zero
263 >    /** Throws if keepAliveTime is less than zero */
264      public void testConstructor4() {
265          try{
266              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
267              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
268          }
269 <        catch (IllegalArgumentException i4){}
269 >        catch (IllegalArgumentException success){}
270      }
271  
272 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
272 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
273      public void testConstructor5() {
274          try{
275 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
275 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
276              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
277          }
278 <        catch (IllegalArgumentException i5){}
278 >        catch (IllegalArgumentException success){}
279      }
280          
281 <    //---- Tests if workQueue is set to null
281 >    /** Throws if workQueue is set to null */
282      public void testNullPointerException() {
283          try{
284 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null);
284 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
285              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
286          }
287 <        catch (NullPointerException n){}  
287 >        catch (NullPointerException success){}  
288      }
289      
290  
291      
292 <    //---- Tests if corePoolSize argument is less than zero
292 >    /** Throws if corePoolSize argument is less than zero */
293      public void testConstructor6() {
294          try{
295 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
295 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
296              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
297 <        } catch (IllegalArgumentException i6){}
297 >        } catch (IllegalArgumentException success){}
298      }
299      
300 <    //---- Tests if maximumPoolSize is less than zero
300 >    /** Throws if maximumPoolSize is less than zero */
301      public void testConstructor7() {
302          try{
303 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
303 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
304              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
305          }
306 <        catch (IllegalArgumentException i7){}
306 >        catch (IllegalArgumentException success){}
307      }
308  
309 <    //---- Tests if maximumPoolSize is equal to zero
309 >    /** Throws if maximumPoolSize is equal to zero */
310      public void testConstructor8() {
311          try{
312 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
312 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
313              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
314          }
315 <        catch (IllegalArgumentException i8){}
315 >        catch (IllegalArgumentException success){}
316      }
317  
318 <    //---- Tests if keepAliveTime is less than zero
318 >    /** Throws if keepAliveTime is less than zero */
319      public void testConstructor9() {
320          try{
321 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
321 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
322              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
323          }
324 <        catch (IllegalArgumentException i9){}
324 >        catch (IllegalArgumentException success){}
325      }
326  
327 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
327 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
328      public void testConstructor10() {
329          try{
330 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
330 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
331              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
332          }
333 <        catch (IllegalArgumentException i10){}
333 >        catch (IllegalArgumentException success){}
334      }
335  
336 <    //---- Tests if workQueue is set to null
336 >    /** Throws if workQueue is set to null */
337      public void testNullPointerException2() {
338          try{
339 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread());
339 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory());
340              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
341          }
342 <        catch (NullPointerException n2){}  
342 >        catch (NullPointerException success){}  
343      }
344  
345 <    //---- Tests if threadFactory is set to null
345 >    /** Throws if threadFactory is set to null */
346      public void testNullPointerException3() {
347          try{
348              ThreadFactory f = null;
349 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
349 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
350              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
351          }
352 <        catch (NullPointerException n3){}  
352 >        catch (NullPointerException success){}  
353      }
354  
355      
356 <    //---- Tests if corePoolSize argument is less than zero
356 >    /** Throws if corePoolSize argument is less than zero */
357      public void testConstructor11() {
358          try{
359 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
359 >            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
360              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
361          }
362 <        catch (IllegalArgumentException i11){}
362 >        catch (IllegalArgumentException success){}
363      }
364  
365 <    //---- Tests if maximumPoolSize is less than zero
365 >    /** Throws if maximumPoolSize is less than zero */
366      public void testConstructor12() {
367          try{
368 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
368 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
369              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
370          }
371 <        catch (IllegalArgumentException i12){}
371 >        catch (IllegalArgumentException success){}
372      }
373  
374 <    //---- Tests if maximumPoolSize is equal to zero
374 >    /** Throws if maximumPoolSize is equal to zero */
375      public void testConstructor13() {
376          try{
377 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
377 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
378              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
379          }
380 <        catch (IllegalArgumentException i13){}
380 >        catch (IllegalArgumentException success){}
381      }
382  
383 <    //---- Tests if keepAliveTime is less than zero
383 >    /** Throws if keepAliveTime is less than zero */
384      public void testConstructor14() {
385          try{
386 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
386 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
387              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
388          }
389 <        catch (IllegalArgumentException i14){}
389 >        catch (IllegalArgumentException success){}
390      }
391  
392 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
392 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
393      public void testConstructor15() {
394          try{
395 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
395 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
396              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
397          }
398 <        catch (IllegalArgumentException i15){}
398 >        catch (IllegalArgumentException success){}
399      }
400  
401 <    //---- Tests if workQueue is set to null
401 >    /** Throws if workQueue is set to null */
402      public void testNullPointerException4() {
403          try{
404 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testReject());
404 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler());
405              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
406          }
407 <        catch (NullPointerException n4){}  
407 >        catch (NullPointerException success){}  
408      }
409  
410 <    //---- Tests if handler is set to null
410 >    /** Throws if handler is set to null */
411      public void testNullPointerException5() {
412          try{
413              RejectedExecutionHandler r = null;
414 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
414 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
415              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
416          }
417 <        catch (NullPointerException n5){}  
417 >        catch (NullPointerException success){}  
418      }
419  
420      
421 <    //---- Tests if corePoolSize argument is less than zero
421 >    /** Throws if corePoolSize argument is less than zero */
422      public void testConstructor16() {
423          try{
424 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
424 >            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
425              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
426          }
427 <        catch (IllegalArgumentException i16){}
427 >        catch (IllegalArgumentException success){}
428      }
429  
430 <    //---- Tests if maximumPoolSize is less than zero
430 >    /** Throws if maximumPoolSize is less than zero */
431      public void testConstructor17() {
432          try{
433 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
433 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
434              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
435          }
436 <        catch (IllegalArgumentException i17){}
436 >        catch (IllegalArgumentException success){}
437      }
438  
439 <    //---- Tests if maximumPoolSize is equal to zero
439 >    /** Throws if maximumPoolSize is equal to zero */
440      public void testConstructor18() {
441          try{
442 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
442 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
443              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
444          }
445 <        catch (IllegalArgumentException i18){}
445 >        catch (IllegalArgumentException success){}
446      }
447  
448 <    //---- Tests if keepAliveTime is less than zero
448 >    /** Throws if keepAliveTime is less than zero */
449      public void testConstructor19() {
450          try{
451 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
451 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
452              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
453          }
454 <        catch (IllegalArgumentException i19){}
454 >        catch (IllegalArgumentException success){}
455      }
456  
457 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
457 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
458      public void testConstructor20() {
459          try{
460 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
460 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
461              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
462          }
463 <        catch (IllegalArgumentException i20){}
463 >        catch (IllegalArgumentException success){}
464      }
465  
466 <    //---- Tests if workQueue is set to null
466 >    /** Throws if workQueue is set to null */
467      public void testNullPointerException6() {
468          try{
469 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread(),new testReject());
469 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler());
470              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
471          }
472 <        catch (NullPointerException n6){}  
472 >        catch (NullPointerException success){}  
473      }
474  
475 <    //---- Tests if handler is set to null
475 >    /** Throws if handler is set to null */
476      public void testNullPointerException7() {
477          try{
478              RejectedExecutionHandler r = null;
479 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new testThread(),r);
479 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r);
480              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
481          }
482 <        catch (NullPointerException n7){}  
482 >        catch (NullPointerException success){}  
483      }
484  
485 <    //---- Tests if ThradFactory is set top null
485 >    /** Throws if ThreadFactory is set top null */
486      public void testNullPointerException8() {
487          try{
488              ThreadFactory f = null;
489 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new testReject());
489 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler());
490              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
491          }
492 <        catch (NullPointerException n8){}  
492 >        catch (NullPointerException successdn8){}  
493      }
494      
495  
496      /**
497 <     *  Test to verify execute will throw RejectedExcutionException
497 >     *   execute will throw RejectedExcutionException
498       *  ThreadPoolExecutor will throw one when more runnables are
499       *  executed then will fit in the Queue.
500       */
501 <    public void testRejectedExecutedException(){
501 >    public void testRejectedExecutionException(){
502          ThreadPoolExecutor tpe = null;
503          try{
504 <            tpe = new ThreadPoolExecutor(1,1,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
504 >            tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
505          } catch(Exception e){}
506          tpe.shutdown();
507          try{
508 <            tpe.execute(new Runnable(){
542 <                    public void run(){
543 <                        try{
544 <                            Thread.sleep(1000);
545 <                        } catch(InterruptedException e){}
546 <                    }
547 <                });
508 >            tpe.execute(new NoOpRunnable());
509              fail("ThreadPoolExecutor - void execute(Runnable) should throw RejectedExecutionException");
510          } catch(RejectedExecutionException success){}
511          
512 <        
512 >        joinPool(tpe);
513      }
514      
515      /**
516 <     *  Test to verify setCorePoolSize will throw IllegalArgumentException
516 >     *   setCorePoolSize will throw IllegalArgumentException
517       *  when given a negative
518       */
519 <    public void testIllegalArgumentException1(){
519 >    public void testCorePoolSizeIllegalArgumentException(){
520          ThreadPoolExecutor tpe = null;
521          try{
522 <            tpe = new ThreadPoolExecutor(1,2,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
522 >            tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
523          } catch(Exception e){}
524          try{
525              tpe.setCorePoolSize(-1);
# Line 567 | Line 528 | public class ThreadPoolExecutorTest exte
528          } finally {
529              tpe.shutdown();
530          }
531 +        joinPool(tpe);
532      }  
533  
534      
535      /**
536 <     *  Test to verify setMaximumPoolSize(int) will throw IllegalArgumentException
536 >     *   setMaximumPoolSize(int) will throw IllegalArgumentException
537       *  if given a value less the it's actual core pool size
538       */  
539 <    public void testIllegalArgumentException2(){
539 >    public void testMaximumPoolSizeIllegalArgumentException(){
540          ThreadPoolExecutor tpe = null;
541          try{
542 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
542 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
543          } catch(Exception e){}
544          try{
545              tpe.setMaximumPoolSize(1);
# Line 586 | Line 548 | public class ThreadPoolExecutorTest exte
548          } finally {
549              tpe.shutdown();
550          }
551 +        joinPool(tpe);
552      }
553      
554      /**
555 <     *  Test to verify that setMaximumPoolSize will throw IllegalArgumentException
555 >     *   setMaximumPoolSize will throw IllegalArgumentException
556       *  if given a negative number
557       */
558 <    public void testIllegalArgumentException2SP(){
558 >    public void testMaximumPoolSizeIllegalArgumentException2(){
559          ThreadPoolExecutor tpe = null;
560          try{
561 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
561 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
562          } catch(Exception e){}
563          try{
564              tpe.setMaximumPoolSize(-1);
# Line 604 | Line 567 | public class ThreadPoolExecutorTest exte
567          } finally {
568              tpe.shutdown();
569          }
570 +        joinPool(tpe);
571      }
572      
573  
574      /**
575 <     *  Test to verify setKeepAliveTime will throw IllegalArgumentException
575 >     *   setKeepAliveTime will throw IllegalArgumentException
576       *  when given a negative value
577       */
578 <    public void testIllegalArgumentException3(){
578 >    public void testKeepAliveTimeIllegalArgumentException(){
579          ThreadPoolExecutor tpe = null;
580          try{
581 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
581 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
582          } catch(Exception e){}
583          
584          try{
# Line 624 | Line 588 | public class ThreadPoolExecutorTest exte
588          } finally {
589              tpe.shutdown();
590          }
591 +        joinPool(tpe);
592      }
593    
629    
630  
594   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines