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.27 by jsr166, Wed Nov 18 05:39:51 2009 UTC vs.
Revision 1.35 by jsr166, Sat Oct 9 19:30:35 2010 UTC

# Line 14 | Line 14 | import java.util.*;
14  
15   public class ThreadPoolExecutorTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20          return new TestSuite(ThreadPoolExecutorTest.class);
# Line 48 | Line 48 | public class ThreadPoolExecutorTest exte
48  
49  
50      /**
51 <     *  execute successfully executes a runnable
51 >     * execute successfully executes a runnable
52       */
53      public void testExecute() throws InterruptedException {
54          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
55          try {
56              p1.execute(new ShortRunnable());
57 <            Thread.sleep(SMALL_DELAY_MS);
57 >            Thread.sleep(SMALL_DELAY_MS);
58          } finally {
59              joinPool(p1);
60          }
61      }
62  
63      /**
64 <     *  getActiveCount increases but doesn't overestimate, when a
65 <     *  thread becomes active
64 >     * getActiveCount increases but doesn't overestimate, when a
65 >     * thread becomes active
66       */
67      public void testGetActiveCount() throws InterruptedException {
68          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 74 | Line 74 | public class ThreadPoolExecutorTest exte
74      }
75  
76      /**
77 <     *  prestartCoreThread starts a thread if under corePoolSize, else doesn't
77 >     * prestartCoreThread starts a thread if under corePoolSize, else doesn't
78       */
79      public void testPrestartCoreThread() {
80          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 89 | Line 89 | public class ThreadPoolExecutorTest exte
89      }
90  
91      /**
92 <     *  prestartAllCoreThreads starts all corePoolSize threads
92 >     * prestartAllCoreThreads starts all corePoolSize threads
93       */
94      public void testPrestartAllCoreThreads() {
95          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 102 | Line 102 | public class ThreadPoolExecutorTest exte
102      }
103  
104      /**
105 <     *   getCompletedTaskCount increases, but doesn't overestimate,
106 <     *   when tasks complete
105 >     * getCompletedTaskCount increases, but doesn't overestimate,
106 >     * when tasks complete
107       */
108      public void testGetCompletedTaskCount() throws InterruptedException {
109          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 116 | Line 116 | public class ThreadPoolExecutorTest exte
116      }
117  
118      /**
119 <     *   getCorePoolSize returns size given in constructor if not otherwise set
119 >     * getCorePoolSize returns size given in constructor if not otherwise set
120       */
121      public void testGetCorePoolSize() {
122          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 125 | Line 125 | public class ThreadPoolExecutorTest exte
125      }
126  
127      /**
128 <     *   getKeepAliveTime returns value given in constructor if not otherwise set
128 >     * getKeepAliveTime returns value given in constructor if not otherwise set
129       */
130      public void testGetKeepAliveTime() {
131          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 209 | Line 209 | public class ThreadPoolExecutorTest exte
209  
210  
211      /**
212 <     *   getLargestPoolSize increases, but doesn't overestimate, when
213 <     *   multiple threads active
212 >     * getLargestPoolSize increases, but doesn't overestimate, when
213 >     * multiple threads active
214       */
215      public void testGetLargestPoolSize() throws InterruptedException {
216          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 223 | Line 223 | public class ThreadPoolExecutorTest exte
223      }
224  
225      /**
226 <     *   getMaximumPoolSize returns value given in constructor if not
227 <     *   otherwise set
226 >     * getMaximumPoolSize returns value given in constructor if not
227 >     * otherwise set
228       */
229      public void testGetMaximumPoolSize() {
230          ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 233 | Line 233 | public class ThreadPoolExecutorTest exte
233      }
234  
235      /**
236 <     *   getPoolSize increases, but doesn't overestimate, when threads
237 <     *   become active
236 >     * getPoolSize increases, but doesn't overestimate, when threads
237 >     * become active
238       */
239      public void testGetPoolSize() {
240          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 245 | Line 245 | public class ThreadPoolExecutorTest exte
245      }
246  
247      /**
248 <     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
248 >     * getTaskCount increases, but doesn't overestimate, when tasks submitted
249       */
250      public void testGetTaskCount() throws InterruptedException {
251          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 257 | Line 257 | public class ThreadPoolExecutorTest exte
257      }
258  
259      /**
260 <     *   isShutDown is false before shutdown, true after
260 >     * isShutDown is false before shutdown, true after
261       */
262      public void testIsShutdown() {
263  
264 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
264 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
265          assertFalse(p1.isShutdown());
266          try { p1.shutdown(); } catch (SecurityException ok) { return; }
267 <        assertTrue(p1.isShutdown());
267 >        assertTrue(p1.isShutdown());
268          joinPool(p1);
269      }
270  
271  
272      /**
273 <     *  isTerminated is false before termination, true after
273 >     * isTerminated is false before termination, true after
274       */
275      public void testIsTerminated() throws InterruptedException {
276 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
276 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
277          assertFalse(p1.isTerminated());
278          try {
279              p1.execute(new MediumRunnable());
# Line 285 | Line 285 | public class ThreadPoolExecutorTest exte
285      }
286  
287      /**
288 <     *  isTerminating is not true when running or when terminated
288 >     * isTerminating is not true when running or when terminated
289       */
290      public void testIsTerminating() throws InterruptedException {
291 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
291 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
292          assertFalse(p1.isTerminating());
293          try {
294              p1.execute(new SmallRunnable());
# Line 354 | Line 354 | public class ThreadPoolExecutorTest exte
354      }
355  
356      /**
357 <     *   purge removes cancelled tasks from the queue
357 >     * purge removes cancelled tasks from the queue
358       */
359      public void testPurge() {
360          ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
# Line 372 | Line 372 | public class ThreadPoolExecutorTest exte
372      }
373  
374      /**
375 <     *  shutDownNow returns a list containing tasks that were not run
375 >     * shutDownNow returns a list containing tasks that were not run
376       */
377      public void testShutDownNow() {
378 <        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
378 >        ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
379          List l;
380          try {
381              for (int i = 0; i < 5; i++)
# Line 385 | Line 385 | public class ThreadPoolExecutorTest exte
385              try {
386                  l = p1.shutdownNow();
387              } catch (SecurityException ok) { return; }
388
388          }
389 <        assertTrue(p1.isShutdown());
390 <        assertTrue(l.size() <= 4);
389 >        assertTrue(p1.isShutdown());
390 >        assertTrue(l.size() <= 4);
391      }
392  
393      // Exception Tests
# Line 401 | Line 400 | public class ThreadPoolExecutorTest exte
400          try {
401              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
402              shouldThrow();
403 <        }
405 <        catch (IllegalArgumentException success) {}
403 >        } catch (IllegalArgumentException success) {}
404      }
405  
406      /**
# Line 412 | Line 410 | public class ThreadPoolExecutorTest exte
410          try {
411              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
412              shouldThrow();
413 <        }
416 <        catch (IllegalArgumentException success) {}
413 >        } catch (IllegalArgumentException success) {}
414      }
415  
416      /**
# Line 423 | Line 420 | public class ThreadPoolExecutorTest exte
420          try {
421              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
422              shouldThrow();
423 <        }
427 <        catch (IllegalArgumentException success) {}
423 >        } catch (IllegalArgumentException success) {}
424      }
425  
426      /**
# Line 434 | Line 430 | public class ThreadPoolExecutorTest exte
430          try {
431              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
432              shouldThrow();
433 <        }
438 <        catch (IllegalArgumentException success) {}
433 >        } catch (IllegalArgumentException success) {}
434      }
435  
436      /**
# Line 445 | Line 440 | public class ThreadPoolExecutorTest exte
440          try {
441              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
442              shouldThrow();
443 <        }
449 <        catch (IllegalArgumentException success) {}
443 >        } catch (IllegalArgumentException success) {}
444      }
445  
446      /**
# Line 456 | Line 450 | public class ThreadPoolExecutorTest exte
450          try {
451              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null);
452              shouldThrow();
453 <        }
460 <        catch (NullPointerException success) {}
453 >        } catch (NullPointerException success) {}
454      }
455  
456  
# Line 469 | Line 462 | public class ThreadPoolExecutorTest exte
462          try {
463              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
464              shouldThrow();
465 <        }
473 <        catch (IllegalArgumentException success) {}
465 >        } catch (IllegalArgumentException success) {}
466      }
467  
468      /**
# Line 480 | Line 472 | public class ThreadPoolExecutorTest exte
472          try {
473              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
474              shouldThrow();
475 <        }
484 <        catch (IllegalArgumentException success) {}
475 >        } catch (IllegalArgumentException success) {}
476      }
477  
478      /**
# Line 491 | Line 482 | public class ThreadPoolExecutorTest exte
482          try {
483              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
484              shouldThrow();
485 <        }
495 <        catch (IllegalArgumentException success) {}
485 >        } catch (IllegalArgumentException success) {}
486      }
487  
488      /**
# Line 502 | Line 492 | public class ThreadPoolExecutorTest exte
492          try {
493              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
494              shouldThrow();
495 <        }
506 <        catch (IllegalArgumentException success) {}
495 >        } catch (IllegalArgumentException success) {}
496      }
497  
498      /**
# Line 513 | Line 502 | public class ThreadPoolExecutorTest exte
502          try {
503              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
504              shouldThrow();
505 <        }
517 <        catch (IllegalArgumentException success) {}
505 >        } catch (IllegalArgumentException success) {}
506      }
507  
508      /**
# Line 524 | Line 512 | public class ThreadPoolExecutorTest exte
512          try {
513              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
514              shouldThrow();
515 <        }
528 <        catch (NullPointerException success) {}
515 >        } catch (NullPointerException success) {}
516      }
517  
518      /**
# Line 536 | Line 523 | public class ThreadPoolExecutorTest exte
523              ThreadFactory f = null;
524              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
525              shouldThrow();
526 <        }
540 <        catch (NullPointerException success) {}
526 >        } catch (NullPointerException success) {}
527      }
528  
529  
# Line 548 | Line 534 | public class ThreadPoolExecutorTest exte
534          try {
535              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
536              shouldThrow();
537 <        }
552 <        catch (IllegalArgumentException success) {}
537 >        } catch (IllegalArgumentException success) {}
538      }
539  
540      /**
# Line 559 | Line 544 | public class ThreadPoolExecutorTest exte
544          try {
545              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
546              shouldThrow();
547 <        }
563 <        catch (IllegalArgumentException success) {}
547 >        } catch (IllegalArgumentException success) {}
548      }
549  
550      /**
# Line 570 | Line 554 | public class ThreadPoolExecutorTest exte
554          try {
555              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
556              shouldThrow();
557 <        }
574 <        catch (IllegalArgumentException success) {}
557 >        } catch (IllegalArgumentException success) {}
558      }
559  
560      /**
# Line 581 | Line 564 | public class ThreadPoolExecutorTest exte
564          try {
565              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
566              shouldThrow();
567 <        }
585 <        catch (IllegalArgumentException success) {}
567 >        } catch (IllegalArgumentException success) {}
568      }
569  
570      /**
# Line 592 | Line 574 | public class ThreadPoolExecutorTest exte
574          try {
575              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
576              shouldThrow();
577 <        }
596 <        catch (IllegalArgumentException success) {}
577 >        } catch (IllegalArgumentException success) {}
578      }
579  
580      /**
# Line 603 | Line 584 | public class ThreadPoolExecutorTest exte
584          try {
585              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
586              shouldThrow();
587 <        }
607 <        catch (NullPointerException success) {}
587 >        } catch (NullPointerException success) {}
588      }
589  
590      /**
# Line 615 | Line 595 | public class ThreadPoolExecutorTest exte
595              RejectedExecutionHandler r = null;
596              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
597              shouldThrow();
598 <        }
619 <        catch (NullPointerException success) {}
598 >        } catch (NullPointerException success) {}
599      }
600  
601  
# Line 627 | Line 606 | public class ThreadPoolExecutorTest exte
606          try {
607              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
608              shouldThrow();
609 <        }
631 <        catch (IllegalArgumentException success) {}
609 >        } catch (IllegalArgumentException success) {}
610      }
611  
612      /**
# Line 638 | Line 616 | public class ThreadPoolExecutorTest exte
616          try {
617              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
618              shouldThrow();
619 <        }
642 <        catch (IllegalArgumentException success) {}
619 >        } catch (IllegalArgumentException success) {}
620      }
621  
622      /**
# Line 649 | Line 626 | public class ThreadPoolExecutorTest exte
626          try {
627              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
628              shouldThrow();
629 <        }
653 <        catch (IllegalArgumentException success) {}
629 >        } catch (IllegalArgumentException success) {}
630      }
631  
632      /**
# Line 660 | Line 636 | public class ThreadPoolExecutorTest exte
636          try {
637              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
638              shouldThrow();
639 <        }
664 <        catch (IllegalArgumentException success) {}
639 >        } catch (IllegalArgumentException success) {}
640      }
641  
642      /**
# Line 671 | Line 646 | public class ThreadPoolExecutorTest exte
646          try {
647              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
648              shouldThrow();
649 <        }
675 <        catch (IllegalArgumentException success) {}
649 >        } catch (IllegalArgumentException success) {}
650      }
651  
652      /**
# Line 682 | Line 656 | public class ThreadPoolExecutorTest exte
656          try {
657              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
658              shouldThrow();
659 <        }
686 <        catch (NullPointerException success) {}
659 >        } catch (NullPointerException success) {}
660      }
661  
662      /**
# Line 694 | Line 667 | public class ThreadPoolExecutorTest exte
667              RejectedExecutionHandler r = null;
668              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
669              shouldThrow();
670 <        }
698 <        catch (NullPointerException success) {}
670 >        } catch (NullPointerException success) {}
671      }
672  
673      /**
# Line 706 | Line 678 | public class ThreadPoolExecutorTest exte
678              ThreadFactory f = null;
679              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
680              shouldThrow();
681 <        }
710 <        catch (NullPointerException success) {}
681 >        } catch (NullPointerException success) {}
682      }
683  
684  
685      /**
686 <     *  execute throws RejectedExecutionException
716 <     *  if saturated.
686 >     * execute throws RejectedExecutionException if saturated.
687       */
688      public void testSaturatedExecute() {
689          ThreadPoolExecutor p =
# Line 735 | Line 705 | public class ThreadPoolExecutorTest exte
705      }
706  
707      /**
708 <     *  executor using CallerRunsPolicy runs task if saturated.
708 >     * executor using CallerRunsPolicy runs task if saturated.
709       */
710      public void testSaturatedExecute2() {
711          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
# Line 761 | Line 731 | public class ThreadPoolExecutorTest exte
731      }
732  
733      /**
734 <     *  executor using DiscardPolicy drops task if saturated.
734 >     * executor using DiscardPolicy drops task if saturated.
735       */
736      public void testSaturatedExecute3() {
737          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
# Line 786 | Line 756 | public class ThreadPoolExecutorTest exte
756      }
757  
758      /**
759 <     *  executor using DiscardOldestPolicy drops oldest task if saturated.
759 >     * executor using DiscardOldestPolicy drops oldest task if saturated.
760       */
761      public void testSaturatedExecute4() {
762          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
# Line 807 | Line 777 | public class ThreadPoolExecutorTest exte
777      }
778  
779      /**
780 <     *  execute throws RejectedExecutionException if shutdown
780 >     * execute throws RejectedExecutionException if shutdown
781       */
782      public void testRejectedExecutionExceptionOnShutdown() {
783          ThreadPoolExecutor tpe =
784              new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
785          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
786 <        try {
787 <            tpe.execute(new NoOpRunnable());
788 <            shouldThrow();
789 <        } catch (RejectedExecutionException success) {}
786 >        try {
787 >            tpe.execute(new NoOpRunnable());
788 >            shouldThrow();
789 >        } catch (RejectedExecutionException success) {}
790  
791 <        joinPool(tpe);
791 >        joinPool(tpe);
792      }
793  
794      /**
795 <     *  execute using CallerRunsPolicy drops task on shutdown
795 >     * execute using CallerRunsPolicy drops task on shutdown
796       */
797      public void testCallerRunsOnShutdown() {
798          RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
799          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
800  
801          try { p.shutdown(); } catch (SecurityException ok) { return; }
802 <        try {
802 >        try {
803              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
804 <            p.execute(r);
804 >            p.execute(r);
805              assertFalse(r.done);
806          } finally {
807              joinPool(p);
# Line 839 | Line 809 | public class ThreadPoolExecutorTest exte
809      }
810  
811      /**
812 <     *  execute using DiscardPolicy drops task on shutdown
812 >     * execute using DiscardPolicy drops task on shutdown
813       */
814      public void testDiscardOnShutdown() {
815          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
816          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
817  
818          try { p.shutdown(); } catch (SecurityException ok) { return; }
819 <        try {
819 >        try {
820              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
821 <            p.execute(r);
821 >            p.execute(r);
822              assertFalse(r.done);
823          } finally {
824              joinPool(p);
# Line 857 | Line 827 | public class ThreadPoolExecutorTest exte
827  
828  
829      /**
830 <     *  execute using DiscardOldestPolicy drops task on shutdown
830 >     * execute using DiscardOldestPolicy drops task on shutdown
831       */
832      public void testDiscardOldestOnShutdown() {
833          RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
834          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
835  
836          try { p.shutdown(); } catch (SecurityException ok) { return; }
837 <        try {
837 >        try {
838              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
839 <            p.execute(r);
839 >            p.execute(r);
840              assertFalse(r.done);
841          } finally {
842              joinPool(p);
# Line 875 | Line 845 | public class ThreadPoolExecutorTest exte
845  
846  
847      /**
848 <     *  execute (null) throws NPE
848 >     * execute(null) throws NPE
849       */
850      public void testExecuteNull() {
851 <        ThreadPoolExecutor tpe = null;
851 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
852          try {
853 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
884 <            tpe.execute(null);
853 >            tpe.execute(null);
854              shouldThrow();
855 <        } catch (NullPointerException success) {}
855 >        } catch (NullPointerException success) {}
856  
857 <        joinPool(tpe);
857 >        joinPool(tpe);
858      }
859  
860      /**
861 <     *  setCorePoolSize of negative value throws IllegalArgumentException
861 >     * setCorePoolSize of negative value throws IllegalArgumentException
862       */
863      public void testCorePoolSizeIllegalArgumentException() {
864 <        ThreadPoolExecutor tpe =
864 >        ThreadPoolExecutor tpe =
865              new ThreadPoolExecutor(1, 2,
866                                     LONG_DELAY_MS, MILLISECONDS,
867                                     new ArrayBlockingQueue<Runnable>(10));
868 <        try {
869 <            tpe.setCorePoolSize(-1);
870 <            shouldThrow();
871 <        } catch (IllegalArgumentException success) {
868 >        try {
869 >            tpe.setCorePoolSize(-1);
870 >            shouldThrow();
871 >        } catch (IllegalArgumentException success) {
872          } finally {
873              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
874          }
# Line 907 | Line 876 | public class ThreadPoolExecutorTest exte
876      }
877  
878      /**
879 <     *  setMaximumPoolSize(int) throws IllegalArgumentException if
880 <     *  given a value less the core pool size
879 >     * setMaximumPoolSize(int) throws IllegalArgumentException if
880 >     * given a value less the core pool size
881       */
882      public void testMaximumPoolSizeIllegalArgumentException() {
883          ThreadPoolExecutor tpe =
# Line 926 | Line 895 | public class ThreadPoolExecutorTest exte
895      }
896  
897      /**
898 <     *  setMaximumPoolSize throws IllegalArgumentException
899 <     *  if given a negative value
898 >     * setMaximumPoolSize throws IllegalArgumentException
899 >     * if given a negative value
900       */
901      public void testMaximumPoolSizeIllegalArgumentException2() {
902          ThreadPoolExecutor tpe =
# Line 946 | Line 915 | public class ThreadPoolExecutorTest exte
915  
916  
917      /**
918 <     *  setKeepAliveTime  throws IllegalArgumentException
919 <     *  when given a negative value
918 >     * setKeepAliveTime throws IllegalArgumentException
919 >     * when given a negative value
920       */
921      public void testKeepAliveTimeIllegalArgumentException() {
922 <        ThreadPoolExecutor tpe =
922 >        ThreadPoolExecutor tpe =
923              new ThreadPoolExecutor(2, 3,
924                                     LONG_DELAY_MS, MILLISECONDS,
925                                     new ArrayBlockingQueue<Runnable>(10));
926 <        try {
926 >        try {
927              tpe.setKeepAliveTime(-1,MILLISECONDS);
928              shouldThrow();
929          } catch (IllegalArgumentException success) {
# Line 1067 | Line 1036 | public class ThreadPoolExecutorTest exte
1036       * invokeAny(c) throws NPE if c has null elements
1037       */
1038      public void testInvokeAny3() throws Exception {
1039 <        final CountDownLatch latch = new CountDownLatch(1);
1039 >        CountDownLatch latch = new CountDownLatch(1);
1040          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1041 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1042 +        l.add(latchAwaitingStringTask(latch));
1043 +        l.add(null);
1044          try {
1073            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1074            l.add(new CheckedCallable<String>() {
1075                      public String realCall() throws InterruptedException {
1076                          latch.await();
1077                          return TEST_STRING;
1078                      }});
1079            l.add(null);
1045              e.invokeAny(l);
1046              shouldThrow();
1047          } catch (NullPointerException success) {
# Line 1091 | Line 1056 | public class ThreadPoolExecutorTest exte
1056       */
1057      public void testInvokeAny4() throws Exception {
1058          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1059 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1060 +        l.add(new NPETask());
1061          try {
1095            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1096            l.add(new NPETask());
1062              e.invokeAny(l);
1063              shouldThrow();
1064          } catch (ExecutionException success) {
# Line 1109 | Line 1074 | public class ThreadPoolExecutorTest exte
1074      public void testInvokeAny5() throws Exception {
1075          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1076          try {
1077 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1077 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1078              l.add(new StringTask());
1079              l.add(new StringTask());
1080              String result = e.invokeAny(l);
# Line 1151 | Line 1116 | public class ThreadPoolExecutorTest exte
1116       */
1117      public void testInvokeAll3() throws Exception {
1118          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1119 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1120 +        l.add(new StringTask());
1121 +        l.add(null);
1122          try {
1155            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1156            l.add(new StringTask());
1157            l.add(null);
1123              e.invokeAll(l);
1124              shouldThrow();
1125          } catch (NullPointerException success) {
# Line 1169 | Line 1134 | public class ThreadPoolExecutorTest exte
1134      public void testInvokeAll4() throws Exception {
1135          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1136          try {
1137 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1137 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1138              l.add(new NPETask());
1139 <            List<Future<String>> result = e.invokeAll(l);
1140 <            assertEquals(1, result.size());
1141 <            for (Future<String> future : result) {
1142 <                try {
1143 <                    future.get();
1144 <                    shouldThrow();
1145 <                } catch (ExecutionException success) {
1181 <                    Throwable cause = success.getCause();
1182 <                    assertTrue(cause instanceof NullPointerException);
1183 <                }
1139 >            List<Future<String>> futures = e.invokeAll(l);
1140 >            assertEquals(1, futures.size());
1141 >            try {
1142 >                futures.get(0).get();
1143 >                shouldThrow();
1144 >            } catch (ExecutionException success) {
1145 >                assertTrue(success.getCause() instanceof NullPointerException);
1146              }
1147          } finally {
1148              joinPool(e);
# Line 1193 | Line 1155 | public class ThreadPoolExecutorTest exte
1155      public void testInvokeAll5() throws Exception {
1156          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1157          try {
1158 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1158 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1159              l.add(new StringTask());
1160              l.add(new StringTask());
1161 <            List<Future<String>> result = e.invokeAll(l);
1162 <            assertEquals(2, result.size());
1163 <            for (Future<String> future : result)
1161 >            List<Future<String>> futures = e.invokeAll(l);
1162 >            assertEquals(2, futures.size());
1163 >            for (Future<String> future : futures)
1164                  assertSame(TEST_STRING, future.get());
1165          } finally {
1166              joinPool(e);
# Line 1226 | Line 1188 | public class ThreadPoolExecutorTest exte
1188       */
1189      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1190          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1191 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1192 +        l.add(new StringTask());
1193          try {
1230            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1231            l.add(new StringTask());
1194              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1195              shouldThrow();
1196          } catch (NullPointerException success) {
# Line 1255 | Line 1217 | public class ThreadPoolExecutorTest exte
1217       * timed invokeAny(c) throws NPE if c has null elements
1218       */
1219      public void testTimedInvokeAny3() throws Exception {
1220 +        CountDownLatch latch = new CountDownLatch(1);
1221          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1222 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1223 +        l.add(latchAwaitingStringTask(latch));
1224 +        l.add(null);
1225          try {
1260            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1261            l.add(new StringTask());
1262            l.add(null);
1226              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1227              shouldThrow();
1228          } catch (NullPointerException success) {
1229          } finally {
1230 +            latch.countDown();
1231              joinPool(e);
1232          }
1233      }
# Line 1273 | Line 1237 | public class ThreadPoolExecutorTest exte
1237       */
1238      public void testTimedInvokeAny4() throws Exception {
1239          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1240 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1241 +        l.add(new NPETask());
1242          try {
1277            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1278            l.add(new NPETask());
1243              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1244              shouldThrow();
1245          } catch (ExecutionException success) {
# Line 1291 | Line 1255 | public class ThreadPoolExecutorTest exte
1255      public void testTimedInvokeAny5() throws Exception {
1256          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257          try {
1258 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1258 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1259              l.add(new StringTask());
1260              l.add(new StringTask());
1261              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 1320 | Line 1284 | public class ThreadPoolExecutorTest exte
1284       */
1285      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1286          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1287 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1288 +        l.add(new StringTask());
1289          try {
1324            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1325            l.add(new StringTask());
1290              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1291              shouldThrow();
1292          } catch (NullPointerException success) {
# Line 1349 | Line 1313 | public class ThreadPoolExecutorTest exte
1313       */
1314      public void testTimedInvokeAll3() throws Exception {
1315          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1316 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1317 +        l.add(new StringTask());
1318 +        l.add(null);
1319          try {
1353            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1354            l.add(new StringTask());
1355            l.add(null);
1320              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1321              shouldThrow();
1322          } catch (NullPointerException success) {
# Line 1366 | Line 1330 | public class ThreadPoolExecutorTest exte
1330       */
1331      public void testTimedInvokeAll4() throws Exception {
1332          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1333 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1334 +        l.add(new NPETask());
1335 +        List<Future<String>> futures =
1336 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1337 +        assertEquals(1, futures.size());
1338          try {
1339 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1371 <            l.add(new NPETask());
1372 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1373 <            assertEquals(1, result.size());
1374 <            for (Future<String> future : result)
1375 <                future.get();
1339 >            futures.get(0).get();
1340              shouldThrow();
1341          } catch (ExecutionException success) {
1342              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1387 | Line 1351 | public class ThreadPoolExecutorTest exte
1351      public void testTimedInvokeAll5() throws Exception {
1352          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1353          try {
1354 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1354 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1355              l.add(new StringTask());
1356              l.add(new StringTask());
1357 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1358 <            assertEquals(2, result.size());
1359 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1360 <                assertSame(TEST_STRING, it.next().get());
1357 >            List<Future<String>> futures =
1358 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1359 >            assertEquals(2, futures.size());
1360 >            for (Future<String> future : futures)
1361 >                assertSame(TEST_STRING, future.get());
1362          } finally {
1363              joinPool(e);
1364          }
# Line 1405 | Line 1370 | public class ThreadPoolExecutorTest exte
1370      public void testTimedInvokeAll6() throws Exception {
1371          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1372          try {
1373 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1373 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1374              l.add(new StringTask());
1375              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1376              l.add(new StringTask());
1377 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1378 <            assertEquals(3, result.size());
1379 <            Iterator<Future<String>> it = result.iterator();
1377 >            List<Future<String>> futures =
1378 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1379 >            assertEquals(3, futures.size());
1380 >            Iterator<Future<String>> it = futures.iterator();
1381              Future<String> f1 = it.next();
1382              Future<String> f2 = it.next();
1383              Future<String> f3 = it.next();
# Line 1432 | Line 1398 | public class ThreadPoolExecutorTest exte
1398      public void testFailingThreadFactory() throws InterruptedException {
1399          ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1400          try {
1401 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1401 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1402              for (int k = 0; k < 100; ++k) {
1403                  e.execute(new NoOpRunnable());
1404              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines