ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
Revision: 1.4
Committed: Sat Sep 20 00:31:57 2003 UTC (20 years, 8 months ago) by dl
Branch: MAIN
Changes since 1.3: +2 -3 lines
Log Message:
Added tests

File Contents

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