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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.6 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 56 | Line 56 | public class ThreadPoolExecutorTest exte
56      }
57  
58      /**
59 <     *   getActiveCount gives correct values
59 >     *  getActiveCount increases but doesn't overestimate, when a
60 >     *  thread becomes active
61       */
62      public void testGetActiveCount() {
63          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 72 | Line 73 | public class ThreadPoolExecutorTest exte
73      }
74      
75      /**
76 <     *   getCompleteTaskCount gives correct values
76 >     *   getCompletedTaskCount increases, but doesn't overestimate,
77 >     *   when tasks complete
78       */
79      public void testGetCompletedTaskCount() {
80          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 89 | Line 91 | public class ThreadPoolExecutorTest exte
91      }
92      
93      /**
94 <     *   getCorePoolSize gives correct values
94 >     *   getCorePoolSize returns size given in constructor if not otherwise set
95       */
96      public void testGetCorePoolSize() {
97          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 98 | Line 100 | public class ThreadPoolExecutorTest exte
100      }
101      
102      /**
103 <     *   getKeepAliveTime gives correct values
103 >     *   getKeepAliveTime returns value given in constructor if not otherwise set
104       */
105      public void testGetKeepAliveTime() {
106          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 107 | Line 109 | public class ThreadPoolExecutorTest exte
109      }
110      
111      /**
112 <     *   getLargestPoolSize gives correct values
112 >     *   getLargestPoolSize increases, but doesn't overestimate, when
113 >     *   multiple threads active
114       */
115      public void testGetLargestPoolSize() {
116          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 124 | Line 127 | public class ThreadPoolExecutorTest exte
127      }
128      
129      /**
130 <     *   getMaximumPoolSize gives correct values
130 >     *   getMaximumPoolSize returns value given in constructor if not
131 >     *   otherwise set
132       */
133      public void testGetMaximumPoolSize() {
134          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 133 | Line 137 | public class ThreadPoolExecutorTest exte
137      }
138      
139      /**
140 <     *   getPoolSize gives correct values
140 >     *   getPoolSize increases, but doesn't overestimate, when threads
141 >     *   become active
142       */
143      public void testGetPoolSize() {
144          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 144 | Line 149 | public class ThreadPoolExecutorTest exte
149      }
150      
151      /**
152 <     *   getTaskCount gives correct values
152 >     *   getTaskCount increases, but doesn't overestimate, when tasks submitted
153       */
154      public void testGetTaskCount() {
155          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 160 | Line 165 | public class ThreadPoolExecutorTest exte
165      }
166      
167      /**
168 <     *   isShutDown gives correct values
168 >     *   isShutDown is false before shutdown, true after
169       */
170      public void testIsShutdown() {
171          
# Line 173 | Line 178 | public class ThreadPoolExecutorTest exte
178  
179          
180      /**
181 <     *   isTerminated gives correct values
177 <     *  Makes sure termination does not take an innapropriate
178 <     *  amount of time
181 >     *  isTerminated is false before termination, true after
182       */
183      public void testIsTerminated() {
184          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
185 +        assertFalse(p1.isTerminated());
186          try {
187              p1.execute(new MediumRunnable());
188          } finally {
# Line 193 | Line 197 | public class ThreadPoolExecutorTest exte
197      }
198  
199      /**
200 <     *  isTerminating gives correct values
200 >     *  isTerminating is not true when running or when terminated
201       */
202      public void testIsTerminating() {
203          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 214 | Line 218 | public class ThreadPoolExecutorTest exte
218      }
219  
220      /**
221 <     *   purge correctly removes cancelled tasks
218 <     *  from the queue
221 >     *   purge removes cancelled tasks from the queue
222       */
223      public void testPurge() {
224          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 233 | Line 236 | public class ThreadPoolExecutorTest exte
236      }
237  
238      /**
239 <     *   shutDownNow returns a list
237 <     *  containing the correct number of elements
239 >     *  shutDownNow returns a list containing tasks that were not run
240       */
241      public void testShutDownNow() {
242          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 253 | Line 255 | public class ThreadPoolExecutorTest exte
255      // Exception Tests
256      
257  
258 <    /** Throws if corePoolSize argument is less than zero */
258 >    /**
259 >     * Constructor throws if corePoolSize argument is less than zero
260 >     */
261      public void testConstructor1() {
262          try {
263              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 262 | Line 266 | public class ThreadPoolExecutorTest exte
266          catch (IllegalArgumentException success){}
267      }
268      
269 <    /** Throws if maximumPoolSize is less than zero */
269 >    /**
270 >     * Constructor throws if maximumPoolSize is less than zero
271 >     */
272      public void testConstructor2() {
273          try {
274              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 271 | Line 277 | public class ThreadPoolExecutorTest exte
277          catch (IllegalArgumentException success){}
278      }
279      
280 <    /** Throws if maximumPoolSize is equal to zero */
280 >    /**
281 >     * Constructor throws if maximumPoolSize is equal to zero
282 >     */
283      public void testConstructor3() {
284          try {
285              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 280 | Line 288 | public class ThreadPoolExecutorTest exte
288          catch (IllegalArgumentException success){}
289      }
290  
291 <    /** Throws if keepAliveTime is less than zero */
291 >    /**
292 >     * Constructor throws if keepAliveTime is less than zero
293 >     */
294      public void testConstructor4() {
295          try {
296              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 289 | Line 299 | public class ThreadPoolExecutorTest exte
299          catch (IllegalArgumentException success){}
300      }
301  
302 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
302 >    /**
303 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
304 >     */
305      public void testConstructor5() {
306          try {
307              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 298 | Line 310 | public class ThreadPoolExecutorTest exte
310          catch (IllegalArgumentException success){}
311      }
312          
313 <    /** Throws if workQueue is set to null */
313 >    /**
314 >     * Constructor throws if workQueue is set to null
315 >     */
316      public void testNullPointerException() {
317          try {
318              new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
# Line 309 | Line 323 | public class ThreadPoolExecutorTest exte
323      
324  
325      
326 <    /** Throws if corePoolSize argument is less than zero */
326 >    /**
327 >     * Constructor throws if corePoolSize argument is less than zero
328 >     */
329      public void testConstructor6() {
330          try {
331              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
# Line 317 | Line 333 | public class ThreadPoolExecutorTest exte
333          } catch (IllegalArgumentException success){}
334      }
335      
336 <    /** Throws if maximumPoolSize is less than zero */
336 >    /**
337 >     * Constructor throws if maximumPoolSize is less than zero
338 >     */
339      public void testConstructor7() {
340          try {
341              new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
# Line 326 | Line 344 | public class ThreadPoolExecutorTest exte
344          catch (IllegalArgumentException success){}
345      }
346  
347 <    /** Throws if maximumPoolSize is equal to zero */
347 >    /**
348 >     * Constructor throws if maximumPoolSize is equal to zero
349 >     */
350      public void testConstructor8() {
351          try {
352              new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
# Line 335 | Line 355 | public class ThreadPoolExecutorTest exte
355          catch (IllegalArgumentException success){}
356      }
357  
358 <    /** Throws if keepAliveTime is less than zero */
358 >    /**
359 >     * Constructor throws if keepAliveTime is less than zero
360 >     */
361      public void testConstructor9() {
362          try {
363              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
# Line 344 | Line 366 | public class ThreadPoolExecutorTest exte
366          catch (IllegalArgumentException success){}
367      }
368  
369 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
369 >    /**
370 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
371 >     */
372      public void testConstructor10() {
373          try {
374              new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory());
# Line 353 | Line 377 | public class ThreadPoolExecutorTest exte
377          catch (IllegalArgumentException success){}
378      }
379  
380 <    /** Throws if workQueue is set to null */
380 >    /**
381 >     * Constructor throws if workQueue is set to null
382 >     */
383      public void testNullPointerException2() {
384          try {
385              new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory());
# Line 362 | Line 388 | public class ThreadPoolExecutorTest exte
388          catch (NullPointerException success){}  
389      }
390  
391 <    /** Throws if threadFactory is set to null */
391 >    /**
392 >     * Constructor throws if threadFactory is set to null
393 >     */
394      public void testNullPointerException3() {
395          try {
396              ThreadFactory f = null;
# Line 373 | Line 401 | public class ThreadPoolExecutorTest exte
401      }
402  
403      
404 <    /** Throws if corePoolSize argument is less than zero */
404 >    /**
405 >     * Constructor throws if corePoolSize argument is less than zero
406 >     */
407      public void testConstructor11() {
408          try {
409              new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
# Line 382 | Line 412 | public class ThreadPoolExecutorTest exte
412          catch (IllegalArgumentException success){}
413      }
414  
415 <    /** Throws if maximumPoolSize is less than zero */
415 >    /**
416 >     * Constructor throws if maximumPoolSize is less than zero
417 >     */
418      public void testConstructor12() {
419          try {
420              new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
# Line 391 | Line 423 | public class ThreadPoolExecutorTest exte
423          catch (IllegalArgumentException success){}
424      }
425  
426 <    /** Throws if maximumPoolSize is equal to zero */
426 >    /**
427 >     * Constructor throws if maximumPoolSize is equal to zero
428 >     */
429      public void testConstructor13() {
430          try {
431              new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
# Line 400 | Line 434 | public class ThreadPoolExecutorTest exte
434          catch (IllegalArgumentException success){}
435      }
436  
437 <    /** Throws if keepAliveTime is less than zero */
437 >    /**
438 >     * Constructor throws if keepAliveTime is less than zero
439 >     */
440      public void testConstructor14() {
441          try {
442              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
# Line 409 | Line 445 | public class ThreadPoolExecutorTest exte
445          catch (IllegalArgumentException success){}
446      }
447  
448 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
448 >    /**
449 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
450 >     */
451      public void testConstructor15() {
452          try {
453              new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler());
# Line 418 | Line 456 | public class ThreadPoolExecutorTest exte
456          catch (IllegalArgumentException success){}
457      }
458  
459 <    /** Throws if workQueue is set to null */
459 >    /**
460 >     * Constructor throws if workQueue is set to null
461 >     */
462      public void testNullPointerException4() {
463          try {
464              new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler());
# Line 427 | Line 467 | public class ThreadPoolExecutorTest exte
467          catch (NullPointerException success){}  
468      }
469  
470 <    /** Throws if handler is set to null */
470 >    /**
471 >     * Constructor throws if handler is set to null
472 >     */
473      public void testNullPointerException5() {
474          try {
475              RejectedExecutionHandler r = null;
# Line 438 | Line 480 | public class ThreadPoolExecutorTest exte
480      }
481  
482      
483 <    /** Throws if corePoolSize argument is less than zero */
483 >    /**
484 >     * Constructor throws if corePoolSize argument is less than zero
485 >     */
486      public void testConstructor16() {
487          try {
488              new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
# Line 447 | Line 491 | public class ThreadPoolExecutorTest exte
491          catch (IllegalArgumentException success){}
492      }
493  
494 <    /** Throws if maximumPoolSize is less than zero */
494 >    /**
495 >     * Constructor throws if maximumPoolSize is less than zero
496 >     */
497      public void testConstructor17() {
498          try {
499              new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
# Line 456 | Line 502 | public class ThreadPoolExecutorTest exte
502          catch (IllegalArgumentException success){}
503      }
504  
505 <    /** Throws if maximumPoolSize is equal to zero */
505 >    /**
506 >     * Constructor throws if maximumPoolSize is equal to zero
507 >     */
508      public void testConstructor18() {
509          try {
510              new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
# Line 465 | Line 513 | public class ThreadPoolExecutorTest exte
513          catch (IllegalArgumentException success){}
514      }
515  
516 <    /** Throws if keepAliveTime is less than zero */
516 >    /**
517 >     * Constructor throws if keepAliveTime is less than zero
518 >     */
519      public void testConstructor19() {
520          try {
521              new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
# Line 474 | Line 524 | public class ThreadPoolExecutorTest exte
524          catch (IllegalArgumentException success){}
525      }
526  
527 <    /** Throws if corePoolSize is greater than the maximumPoolSize */
527 >    /**
528 >     * Constructor throws if corePoolSize is greater than the maximumPoolSize
529 >     */
530      public void testConstructor20() {
531          try {
532              new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler());
# Line 483 | Line 535 | public class ThreadPoolExecutorTest exte
535          catch (IllegalArgumentException success){}
536      }
537  
538 <    /** Throws if workQueue is set to null */
538 >    /**
539 >     * Constructor throws if workQueue is set to null
540 >     */
541      public void testNullPointerException6() {
542          try {
543              new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler());
# Line 492 | Line 546 | public class ThreadPoolExecutorTest exte
546          catch (NullPointerException success){}  
547      }
548  
549 <    /** Throws if handler is set to null */
549 >    /**
550 >     * Constructor throws if handler is set to null
551 >     */
552      public void testNullPointerException7() {
553          try {
554              RejectedExecutionHandler r = null;
# Line 502 | Line 558 | public class ThreadPoolExecutorTest exte
558          catch (NullPointerException success){}  
559      }
560  
561 <    /** Throws if ThreadFactory is set top null */
561 >    /**
562 >     * Constructor throws if ThreadFactory is set top null
563 >     */
564      public void testNullPointerException8() {
565          try {
566              ThreadFactory f = null;
# Line 514 | Line 572 | public class ThreadPoolExecutorTest exte
572      
573  
574      /**
575 <     *   execute will throw RejectedExcutionException
518 <     *  ThreadPoolExecutor will throw one when more runnables are
519 <     *  executed then will fit in the Queue.
575 >     *  execute throws RejectedExecutionException if shutdown
576       */
577      public void testRejectedExecutionException() {
578          ThreadPoolExecutor tpe = null;
# Line 531 | Line 587 | public class ThreadPoolExecutorTest exte
587          
588          joinPool(tpe);
589      }
590 +
591 +    /**
592 +     *  execute throws RejectedExecutionException
593 +     *  if saturated.
594 +     */
595 +    public void testSaturatedExecute() {
596 +        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
597 +        try {
598 +            
599 +            for(int i = 0; i < 5; ++i){
600 +                p.execute(new MediumRunnable());
601 +            }
602 +            shouldThrow();
603 +        } catch(RejectedExecutionException success){}
604 +        joinPool(p);
605 +    }
606 +
607 +    /**
608 +     *  execute (null) throws NPE
609 +     */
610 +    public void testExecuteNull() {
611 +        ThreadPoolExecutor tpe = null;
612 +        try {
613 +            tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
614 +            tpe.execute(null);
615 +            shouldThrow();
616 +        } catch(NullPointerException success){}
617 +        
618 +        joinPool(tpe);
619 +    }
620      
621      /**
622 <     *   setCorePoolSize will throw IllegalArgumentException
537 <     *  when given a negative
622 >     *  setCorePoolSize of netaitev value throws IllegalArgumentException
623       */
624      public void testCorePoolSizeIllegalArgumentException() {
625          ThreadPoolExecutor tpe = null;
# Line 551 | Line 636 | public class ThreadPoolExecutorTest exte
636          joinPool(tpe);
637      }  
638  
554    
639      /**
640 <     *   setMaximumPoolSize(int) will throw IllegalArgumentException
641 <     *  if given a value less the it's actual core pool size
640 >     *  setMaximumPoolSize(int) throws IllegalArgumentException if
641 >     *  given a value less the core pool size
642       */  
643      public void testMaximumPoolSizeIllegalArgumentException() {
644          ThreadPoolExecutor tpe = null;
# Line 572 | Line 656 | public class ThreadPoolExecutorTest exte
656      }
657      
658      /**
659 <     *   setMaximumPoolSize will throw IllegalArgumentException
660 <     *  if given a negative number
659 >     *  setMaximumPoolSize throws IllegalArgumentException
660 >     *  if given a negative value
661       */
662      public void testMaximumPoolSizeIllegalArgumentException2() {
663          ThreadPoolExecutor tpe = null;
# Line 592 | Line 676 | public class ThreadPoolExecutorTest exte
676      
677  
678      /**
679 <     *   setKeepAliveTime will throw IllegalArgumentException
679 >     *  setKeepAliveTime  throws IllegalArgumentException
680       *  when given a negative value
681       */
682      public void testKeepAliveTimeIllegalArgumentException() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines