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.1 by dl, Sun Aug 31 19:24:56 2003 UTC vs.
Revision 1.4 by dl, Sat Sep 20 00:31:57 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(){
44                          try{
45                              Thread.sleep(SHORT_DELAY_MS);
46 <                        }catch(InterruptedException e){
46 >                        } catch(InterruptedException e){
47                              fail("unexpected exception");
48                          }
49                      }
50                  });
51 <            Thread.sleep(SHORT_DELAY_MS * 2);
52 <        }catch(InterruptedException e){
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){}
156 <            assertEquals(5, one.getTaskCount());
157 <        } finally {
158 <            one.shutdown();
159 <        }
153 >            one.execute(new MediumRunnable());
154 >            Thread.sleep(SHORT_DELAY_MS);
155 >            assertEquals(1, one.getTaskCount());
156 >        } catch(Exception e){
157 >            fail("unexpected exception");
158 >        }
159 >        joinPool(one);
160      }
161      
162      /**
163 <     *  Test to verify isShutDown gives correct values
163 >     *   isShutDown gives correct values
164       */
165      public void testIsShutdown(){
166          
167 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
168 <        try {
169 <            assertFalse(one.isShutdown());
192 <        }
193 <        finally {
194 <            one.shutdown();
195 <        }
167 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
168 >        assertFalse(one.isShutdown());
169 >        one.shutdown();
170          assertTrue(one.isShutdown());
171 +        joinPool(one);
172      }
173  
174          
175      /**
176 <     *  Test to verify isTerminated gives correct values
176 >     *   isTerminated gives correct values
177       *  Makes sure termination does not take an innapropriate
178       *  amount of time
179       */
180      public void testIsTerminated(){
181 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
181 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
182          try {
183 <            one.execute(newRunnable());
183 >            one.execute(new MediumRunnable());
184          } finally {
185              one.shutdown();
186          }
187 <        boolean flag = false;
188 <        try{
189 <            flag = one.awaitTermination(10, TimeUnit.SECONDS);
190 <        }catch(Exception e){}  
191 <        assertTrue(one.isTerminated());
192 <        if(!flag)
218 <            fail("ThreadPoolExecutor - thread pool did not terminate within suitable timeframe");
187 >        try {
188 >            assertTrue(one.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
189 >            assertTrue(one.isTerminated());
190 >        } catch(Exception e){
191 >            fail("unexpected exception");
192 >        }      
193      }
194  
195      /**
196 <     *  Test to verify that purge correctly removes cancelled tasks
196 >     *   purge correctly removes cancelled tasks
197       *  from the queue
198       */
199      public void testPurge(){
200 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
201 <        try {
202 <            CancellableTask[] tasks = new CancellableTask[5];
203 <            for(int i = 0; i < 5; i++){
204 <                tasks[i] = new CancellableTask(newRunnable());
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);
238 <        } finally {
239 <            one.shutdown();
240 <        }
200 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
201 >        CancellableTask[] tasks = new CancellableTask[5];
202 >        for(int i = 0; i < 5; i++){
203 >            tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
204 >            one.execute(tasks[i]);
205 >        }
206 >        tasks[4].cancel(true);
207 >        tasks[3].cancel(true);
208 >        one.purge();
209 >        long count = one.getTaskCount();
210 >        assertTrue(count >= 2 && count < 5);
211 >        joinPool(one);
212      }
213  
214      /**
215 <     *  Test to verify shutDownNow returns a list
215 >     *   shutDownNow returns a list
216       *  containing the correct number of elements
217       */
218      public void testShutDownNow(){
219 <        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
219 >        ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
220          List l;
221          try {
222              for(int i = 0; i < 5; i++)
223 <                one.execute(newRunnable());
223 >                one.execute(new MediumPossiblyInterruptedRunnable());
224          }
225          finally {
226              l = one.shutdownNow();
# Line 258 | Line 229 | public class ThreadPoolExecutorTest exte
229          assertTrue(l.size() <= 4);
230      }
231  
261    
262
263    
264    
265      
232      // Exception Tests
233      
234  
235 <    //---- Tests if corePoolSize argument is less than zero
235 >    /** Throws if corePoolSize argument is less than zero */
236      public void testConstructor1() {
237          try{
238 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
238 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
239              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
240          }
241 <        catch (IllegalArgumentException i){}
241 >        catch (IllegalArgumentException success){}
242      }
243      
244 <    //---- Tests if maximumPoolSize is less than zero
244 >    /** Throws if maximumPoolSize is less than zero */
245      public void testConstructor2() {
246          try{
247 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
247 >            new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
248              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
249          }
250 <        catch (IllegalArgumentException i2){}
250 >        catch (IllegalArgumentException success){}
251      }
252      
253 <    //---- Tests if maximumPoolSize is equal to zero
253 >    /** Throws if maximumPoolSize is equal to zero */
254      public void testConstructor3() {
255          try{
256 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
256 >            new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
257              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
258          }
259 <        catch (IllegalArgumentException i3){}
259 >        catch (IllegalArgumentException success){}
260      }
261  
262 <    //---- Tests if keepAliveTime is less than zero
262 >    /** Throws if keepAliveTime is less than zero */
263      public void testConstructor4() {
264          try{
265              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
266              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
267          }
268 <        catch (IllegalArgumentException i4){}
268 >        catch (IllegalArgumentException success){}
269      }
270  
271 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
271 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
272      public void testConstructor5() {
273          try{
274 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
274 >            new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
275              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
276          }
277 <        catch (IllegalArgumentException i5){}
277 >        catch (IllegalArgumentException success){}
278      }
279          
280 <    //---- Tests if workQueue is set to null
280 >    /** Throws if workQueue is set to null */
281      public void testNullPointerException() {
282          try{
283 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null);
283 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
284              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
285          }
286 <        catch (NullPointerException n){}  
286 >        catch (NullPointerException success){}  
287      }
288      
289  
290      
291 <    //---- Tests if corePoolSize argument is less than zero
291 >    /** Throws if corePoolSize argument is less than zero */
292      public void testConstructor6() {
293          try{
294 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
294 >            new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
295              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
296 <        }catch (IllegalArgumentException i6){}
296 >        } catch (IllegalArgumentException success){}
297      }
298      
299 <    //---- Tests if maximumPoolSize is less than zero
299 >    /** Throws if maximumPoolSize is less than zero */
300      public void testConstructor7() {
301          try{
302 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
302 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
303              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
304          }
305 <        catch (IllegalArgumentException i7){}
305 >        catch (IllegalArgumentException success){}
306      }
307  
308 <    //---- Tests if maximumPoolSize is equal to zero
308 >    /** Throws if maximumPoolSize is equal to zero */
309      public void testConstructor8() {
310          try{
311 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
311 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
312              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
313          }
314 <        catch (IllegalArgumentException i8){}
314 >        catch (IllegalArgumentException success){}
315      }
316  
317 <    //---- Tests if keepAliveTime is less than zero
317 >    /** Throws if keepAliveTime is less than zero */
318      public void testConstructor9() {
319          try{
320 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
320 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
321              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
322          }
323 <        catch (IllegalArgumentException i9){}
323 >        catch (IllegalArgumentException success){}
324      }
325  
326 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
326 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
327      public void testConstructor10() {
328          try{
329 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread());
329 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
330              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
331          }
332 <        catch (IllegalArgumentException i10){}
332 >        catch (IllegalArgumentException success){}
333      }
334  
335 <    //---- Tests if workQueue is set to null
335 >    /** Throws if workQueue is set to null */
336      public void testNullPointerException2() {
337          try{
338 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread());
338 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory());
339              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
340          }
341 <        catch (NullPointerException n2){}  
341 >        catch (NullPointerException success){}  
342      }
343  
344 <    //---- Tests if threadFactory is set to null
344 >    /** Throws if threadFactory is set to null */
345      public void testNullPointerException3() {
346          try{
347              ThreadFactory f = null;
348 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
348 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
349              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
350          }
351 <        catch (NullPointerException n3){}  
351 >        catch (NullPointerException success){}  
352      }
353  
354      
355 <    //---- Tests if corePoolSize argument is less than zero
355 >    /** Throws if corePoolSize argument is less than zero */
356      public void testConstructor11() {
357          try{
358 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
358 >            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
359              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
360          }
361 <        catch (IllegalArgumentException i11){}
361 >        catch (IllegalArgumentException success){}
362      }
363  
364 <    //---- Tests if maximumPoolSize is less than zero
364 >    /** Throws if maximumPoolSize is less than zero */
365      public void testConstructor12() {
366          try{
367 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
367 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
368              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
369          }
370 <        catch (IllegalArgumentException i12){}
370 >        catch (IllegalArgumentException success){}
371      }
372  
373 <    //---- Tests if maximumPoolSize is equal to zero
373 >    /** Throws if maximumPoolSize is equal to zero */
374      public void testConstructor13() {
375          try{
376 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
376 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
377              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
378          }
379 <        catch (IllegalArgumentException i13){}
379 >        catch (IllegalArgumentException success){}
380      }
381  
382 <    //---- Tests if keepAliveTime is less than zero
382 >    /** Throws if keepAliveTime is less than zero */
383      public void testConstructor14() {
384          try{
385 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
385 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
386              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
387          }
388 <        catch (IllegalArgumentException i14){}
388 >        catch (IllegalArgumentException success){}
389      }
390  
391 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
391 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
392      public void testConstructor15() {
393          try{
394 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject());
394 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
395              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
396          }
397 <        catch (IllegalArgumentException i15){}
397 >        catch (IllegalArgumentException success){}
398      }
399  
400 <    //---- Tests if workQueue is set to null
400 >    /** Throws if workQueue is set to null */
401      public void testNullPointerException4() {
402          try{
403 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testReject());
403 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler());
404              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
405          }
406 <        catch (NullPointerException n4){}  
406 >        catch (NullPointerException success){}  
407      }
408  
409 <    //---- Tests if handler is set to null
409 >    /** Throws if handler is set to null */
410      public void testNullPointerException5() {
411          try{
412              RejectedExecutionHandler r = null;
413 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
413 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
414              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
415          }
416 <        catch (NullPointerException n5){}  
416 >        catch (NullPointerException success){}  
417      }
418  
419      
420 <    //---- Tests if corePoolSize argument is less than zero
420 >    /** Throws if corePoolSize argument is less than zero */
421      public void testConstructor16() {
422          try{
423 <            new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
423 >            new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
424              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
425          }
426 <        catch (IllegalArgumentException i16){}
426 >        catch (IllegalArgumentException success){}
427      }
428  
429 <    //---- Tests if maximumPoolSize is less than zero
429 >    /** Throws if maximumPoolSize is less than zero */
430      public void testConstructor17() {
431          try{
432 <            new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
432 >            new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
433              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
434          }
435 <        catch (IllegalArgumentException i17){}
435 >        catch (IllegalArgumentException success){}
436      }
437  
438 <    //---- Tests if maximumPoolSize is equal to zero
438 >    /** Throws if maximumPoolSize is equal to zero */
439      public void testConstructor18() {
440          try{
441 <            new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
441 >            new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
442              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
443          }
444 <        catch (IllegalArgumentException i18){}
444 >        catch (IllegalArgumentException success){}
445      }
446  
447 <    //---- Tests if keepAliveTime is less than zero
447 >    /** Throws if keepAliveTime is less than zero */
448      public void testConstructor19() {
449          try{
450 <            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
450 >            new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
451              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
452          }
453 <        catch (IllegalArgumentException i19){}
453 >        catch (IllegalArgumentException success){}
454      }
455  
456 <    //---- Tests if corePoolSize is greater than the maximumPoolSize
456 >    /** Throws if corePoolSize is greater than the maximumPoolSize */
457      public void testConstructor20() {
458          try{
459 <            new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject());
459 >            new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
460              fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException");            
461          }
462 <        catch (IllegalArgumentException i20){}
462 >        catch (IllegalArgumentException success){}
463      }
464  
465 <    //---- Tests if workQueue is set to null
465 >    /** Throws if workQueue is set to null */
466      public void testNullPointerException6() {
467          try{
468 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread(),new testReject());
468 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler());
469              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
470          }
471 <        catch (NullPointerException n6){}  
471 >        catch (NullPointerException success){}  
472      }
473  
474 <    //---- Tests if handler is set to null
474 >    /** Throws if handler is set to null */
475      public void testNullPointerException7() {
476          try{
477              RejectedExecutionHandler r = null;
478 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new testThread(),r);
478 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r);
479              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
480          }
481 <        catch (NullPointerException n7){}  
481 >        catch (NullPointerException success){}  
482      }
483  
484 <    //---- Tests if ThradFactory is set top null
484 >    /** Throws if ThreadFactory is set top null */
485      public void testNullPointerException8() {
486          try{
487              ThreadFactory f = null;
488 <            new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new testReject());
488 >            new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler());
489              fail("ThreadPoolExecutor constructor should throw a NullPointerException");        
490          }
491 <        catch (NullPointerException n8){}  
491 >        catch (NullPointerException successdn8){}  
492      }
493      
494  
495      /**
496 <     *  Test to verify execute will throw RejectedExcutionException
496 >     *   execute will throw RejectedExcutionException
497       *  ThreadPoolExecutor will throw one when more runnables are
498       *  executed then will fit in the Queue.
499       */
500 <    public void testRejectedExecutedException(){
500 >    public void testRejectedExecutionException(){
501          ThreadPoolExecutor tpe = null;
502          try{
503 <            tpe = new ThreadPoolExecutor(1,1,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
504 <        }catch(Exception e){}
503 >            tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
504 >        } catch(Exception e){}
505          tpe.shutdown();
506          try{
507 <            tpe.execute(new Runnable(){
542 <                    public void run(){
543 <                        try{
544 <                            Thread.sleep(1000);
545 <                        }catch(InterruptedException e){}
546 <                    }
547 <                });
507 >            tpe.execute(new NoOpRunnable());
508              fail("ThreadPoolExecutor - void execute(Runnable) should throw RejectedExecutionException");
509 <        }catch(RejectedExecutionException sucess){}
550 <        
509 >        } catch(RejectedExecutionException success){}
510          
511 +        joinPool(tpe);
512      }
513      
514      /**
515 <     *  Test to verify setCorePoolSize will throw IllegalArgumentException
515 >     *   setCorePoolSize will throw IllegalArgumentException
516       *  when given a negative
517       */
518 <    public void testIllegalArgumentException1(){
518 >    public void testCorePoolSizeIllegalArgumentException(){
519          ThreadPoolExecutor tpe = null;
520          try{
521 <            tpe = new ThreadPoolExecutor(1,2,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
522 <        }catch(Exception e){}
521 >            tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
522 >        } catch(Exception e){}
523          try{
524              tpe.setCorePoolSize(-1);
525              fail("ThreadPoolExecutor - void setCorePoolSize(int) should throw IllegalArgumentException");
526 <        }catch(IllegalArgumentException sucess){
526 >        } catch(IllegalArgumentException success){
527          } finally {
528              tpe.shutdown();
529          }
530 +        joinPool(tpe);
531      }  
532  
533      
534      /**
535 <     *  Test to verify setMaximumPoolSize(int) will throw IllegalArgumentException
535 >     *   setMaximumPoolSize(int) will throw IllegalArgumentException
536       *  if given a value less the it's actual core pool size
537       */  
538 <    public void testIllegalArgumentException2(){
538 >    public void testMaximumPoolSizeIllegalArgumentException(){
539          ThreadPoolExecutor tpe = null;
540          try{
541 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
542 <        }catch(Exception e){}
541 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
542 >        } catch(Exception e){}
543          try{
544              tpe.setMaximumPoolSize(1);
545              fail("ThreadPoolExecutor - void setMaximumPoolSize(int) should throw IllegalArgumentException");
546 <        }catch(IllegalArgumentException sucess){
546 >        } catch(IllegalArgumentException success){
547          } finally {
548              tpe.shutdown();
549          }
550 +        joinPool(tpe);
551      }
552      
553      /**
554 <     *  Test to verify that setMaximumPoolSize will throw IllegalArgumentException
554 >     *   setMaximumPoolSize will throw IllegalArgumentException
555       *  if given a negative number
556       */
557 <    public void testIllegalArgumentException2SP(){
557 >    public void testMaximumPoolSizeIllegalArgumentException2(){
558          ThreadPoolExecutor tpe = null;
559          try{
560 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
561 <        }catch(Exception e){}
560 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
561 >        } catch(Exception e){}
562          try{
563              tpe.setMaximumPoolSize(-1);
564              fail("ThreadPoolExecutor - void setMaximumPoolSize(int) should throw IllegalArgumentException");
565 <        }catch(IllegalArgumentException sucess){
565 >        } catch(IllegalArgumentException success){
566          } finally {
567              tpe.shutdown();
568          }
569 +        joinPool(tpe);
570      }
571      
572  
573      /**
574 <     *  Test to verify setKeepAliveTime will throw IllegalArgumentException
574 >     *   setKeepAliveTime will throw IllegalArgumentException
575       *  when given a negative value
576       */
577 <    public void testIllegalArgumentException3(){
577 >    public void testKeepAliveTimeIllegalArgumentException(){
578          ThreadPoolExecutor tpe = null;
579          try{
580 <            tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
581 <        }catch(Exception e){}
580 >            tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
581 >        } catch(Exception e){}
582          
583          try{
584              tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
585              fail("ThreadPoolExecutor - void setKeepAliveTime(long, TimeUnit) should throw IllegalArgumentException");
586 <        }catch(IllegalArgumentException sucess){
586 >        } catch(IllegalArgumentException success){
587          } finally {
588              tpe.shutdown();
589          }
590 +        joinPool(tpe);
591      }
592    
629    
630  
593   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines