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.31 by jsr166, Sat Nov 21 02:07:27 2009 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 54 | Line 54 | public class ThreadPoolExecutorTest exte
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          }
# Line 261 | Line 261 | public class ThreadPoolExecutorTest exte
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  
# Line 273 | Line 273 | public class ThreadPoolExecutorTest exte
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 288 | Line 288 | public class ThreadPoolExecutorTest exte
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 375 | Line 375 | public class ThreadPoolExecutorTest exte
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 387 | Line 387 | public class ThreadPoolExecutorTest exte
387              } catch (SecurityException ok) { return; }
388  
389          }
390 <        assertTrue(p1.isShutdown());
391 <        assertTrue(l.size() <= 4);
390 >        assertTrue(p1.isShutdown());
391 >        assertTrue(l.size() <= 4);
392      }
393  
394      // Exception Tests
# Line 401 | Line 401 | public class ThreadPoolExecutorTest exte
401          try {
402              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
403              shouldThrow();
404 <        }
405 <        catch (IllegalArgumentException success) {}
404 >        } catch (IllegalArgumentException success) {}
405      }
406  
407      /**
# Line 412 | Line 411 | public class ThreadPoolExecutorTest exte
411          try {
412              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
413              shouldThrow();
414 <        }
416 <        catch (IllegalArgumentException success) {}
414 >        } catch (IllegalArgumentException success) {}
415      }
416  
417      /**
# Line 423 | Line 421 | public class ThreadPoolExecutorTest exte
421          try {
422              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
423              shouldThrow();
424 <        }
427 <        catch (IllegalArgumentException success) {}
424 >        } catch (IllegalArgumentException success) {}
425      }
426  
427      /**
# Line 434 | Line 431 | public class ThreadPoolExecutorTest exte
431          try {
432              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
433              shouldThrow();
434 <        }
438 <        catch (IllegalArgumentException success) {}
434 >        } catch (IllegalArgumentException success) {}
435      }
436  
437      /**
# Line 445 | Line 441 | public class ThreadPoolExecutorTest exte
441          try {
442              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
443              shouldThrow();
444 <        }
449 <        catch (IllegalArgumentException success) {}
444 >        } catch (IllegalArgumentException success) {}
445      }
446  
447      /**
# Line 456 | Line 451 | public class ThreadPoolExecutorTest exte
451          try {
452              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null);
453              shouldThrow();
454 <        }
460 <        catch (NullPointerException success) {}
454 >        } catch (NullPointerException success) {}
455      }
456  
457  
# Line 469 | Line 463 | public class ThreadPoolExecutorTest exte
463          try {
464              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
465              shouldThrow();
466 <        }
473 <        catch (IllegalArgumentException success) {}
466 >        } catch (IllegalArgumentException success) {}
467      }
468  
469      /**
# Line 480 | Line 473 | public class ThreadPoolExecutorTest exte
473          try {
474              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
475              shouldThrow();
476 <        }
484 <        catch (IllegalArgumentException success) {}
476 >        } catch (IllegalArgumentException success) {}
477      }
478  
479      /**
# Line 491 | Line 483 | public class ThreadPoolExecutorTest exte
483          try {
484              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
485              shouldThrow();
486 <        }
495 <        catch (IllegalArgumentException success) {}
486 >        } catch (IllegalArgumentException success) {}
487      }
488  
489      /**
# Line 502 | Line 493 | public class ThreadPoolExecutorTest exte
493          try {
494              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
495              shouldThrow();
496 <        }
506 <        catch (IllegalArgumentException success) {}
496 >        } catch (IllegalArgumentException success) {}
497      }
498  
499      /**
# Line 513 | Line 503 | public class ThreadPoolExecutorTest exte
503          try {
504              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
505              shouldThrow();
506 <        }
517 <        catch (IllegalArgumentException success) {}
506 >        } catch (IllegalArgumentException success) {}
507      }
508  
509      /**
# Line 524 | Line 513 | public class ThreadPoolExecutorTest exte
513          try {
514              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
515              shouldThrow();
516 <        }
528 <        catch (NullPointerException success) {}
516 >        } catch (NullPointerException success) {}
517      }
518  
519      /**
# Line 536 | Line 524 | public class ThreadPoolExecutorTest exte
524              ThreadFactory f = null;
525              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
526              shouldThrow();
527 <        }
540 <        catch (NullPointerException success) {}
527 >        } catch (NullPointerException success) {}
528      }
529  
530  
# Line 548 | Line 535 | public class ThreadPoolExecutorTest exte
535          try {
536              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
537              shouldThrow();
538 <        }
552 <        catch (IllegalArgumentException success) {}
538 >        } catch (IllegalArgumentException success) {}
539      }
540  
541      /**
# Line 559 | Line 545 | public class ThreadPoolExecutorTest exte
545          try {
546              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
547              shouldThrow();
548 <        }
563 <        catch (IllegalArgumentException success) {}
548 >        } catch (IllegalArgumentException success) {}
549      }
550  
551      /**
# Line 570 | Line 555 | public class ThreadPoolExecutorTest exte
555          try {
556              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
557              shouldThrow();
558 <        }
574 <        catch (IllegalArgumentException success) {}
558 >        } catch (IllegalArgumentException success) {}
559      }
560  
561      /**
# Line 581 | Line 565 | public class ThreadPoolExecutorTest exte
565          try {
566              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
567              shouldThrow();
568 <        }
585 <        catch (IllegalArgumentException success) {}
568 >        } catch (IllegalArgumentException success) {}
569      }
570  
571      /**
# Line 592 | Line 575 | public class ThreadPoolExecutorTest exte
575          try {
576              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
577              shouldThrow();
578 <        }
596 <        catch (IllegalArgumentException success) {}
578 >        } catch (IllegalArgumentException success) {}
579      }
580  
581      /**
# Line 603 | Line 585 | public class ThreadPoolExecutorTest exte
585          try {
586              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
587              shouldThrow();
588 <        }
607 <        catch (NullPointerException success) {}
588 >        } catch (NullPointerException success) {}
589      }
590  
591      /**
# Line 615 | Line 596 | public class ThreadPoolExecutorTest exte
596              RejectedExecutionHandler r = null;
597              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
598              shouldThrow();
599 <        }
619 <        catch (NullPointerException success) {}
599 >        } catch (NullPointerException success) {}
600      }
601  
602  
# Line 627 | Line 607 | public class ThreadPoolExecutorTest exte
607          try {
608              new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
609              shouldThrow();
610 <        }
631 <        catch (IllegalArgumentException success) {}
610 >        } catch (IllegalArgumentException success) {}
611      }
612  
613      /**
# Line 638 | Line 617 | public class ThreadPoolExecutorTest exte
617          try {
618              new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
619              shouldThrow();
620 <        }
642 <        catch (IllegalArgumentException success) {}
620 >        } catch (IllegalArgumentException success) {}
621      }
622  
623      /**
# Line 649 | Line 627 | public class ThreadPoolExecutorTest exte
627          try {
628              new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
629              shouldThrow();
630 <        }
653 <        catch (IllegalArgumentException success) {}
630 >        } catch (IllegalArgumentException success) {}
631      }
632  
633      /**
# Line 660 | Line 637 | public class ThreadPoolExecutorTest exte
637          try {
638              new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
639              shouldThrow();
640 <        }
664 <        catch (IllegalArgumentException success) {}
640 >        } catch (IllegalArgumentException success) {}
641      }
642  
643      /**
# Line 671 | Line 647 | public class ThreadPoolExecutorTest exte
647          try {
648              new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
649              shouldThrow();
650 <        }
675 <        catch (IllegalArgumentException success) {}
650 >        } catch (IllegalArgumentException success) {}
651      }
652  
653      /**
# Line 682 | Line 657 | public class ThreadPoolExecutorTest exte
657          try {
658              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
659              shouldThrow();
660 <        }
686 <        catch (NullPointerException success) {}
660 >        } catch (NullPointerException success) {}
661      }
662  
663      /**
# Line 694 | Line 668 | public class ThreadPoolExecutorTest exte
668              RejectedExecutionHandler r = null;
669              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
670              shouldThrow();
671 <        }
698 <        catch (NullPointerException success) {}
671 >        } catch (NullPointerException success) {}
672      }
673  
674      /**
# Line 706 | Line 679 | public class ThreadPoolExecutorTest exte
679              ThreadFactory f = null;
680              new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
681              shouldThrow();
682 <        }
710 <        catch (NullPointerException success) {}
682 >        } catch (NullPointerException success) {}
683      }
684  
685  
# Line 813 | Line 785 | public class ThreadPoolExecutorTest exte
785          ThreadPoolExecutor tpe =
786              new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
787          try { tpe.shutdown(); } catch (SecurityException ok) { return; }
788 <        try {
789 <            tpe.execute(new NoOpRunnable());
790 <            shouldThrow();
791 <        } catch (RejectedExecutionException success) {}
788 >        try {
789 >            tpe.execute(new NoOpRunnable());
790 >            shouldThrow();
791 >        } catch (RejectedExecutionException success) {}
792  
793 <        joinPool(tpe);
793 >        joinPool(tpe);
794      }
795  
796      /**
# Line 829 | Line 801 | public class ThreadPoolExecutorTest exte
801          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
802  
803          try { p.shutdown(); } catch (SecurityException ok) { return; }
804 <        try {
804 >        try {
805              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
806 <            p.execute(r);
806 >            p.execute(r);
807              assertFalse(r.done);
808          } finally {
809              joinPool(p);
# Line 846 | Line 818 | public class ThreadPoolExecutorTest exte
818          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
819  
820          try { p.shutdown(); } catch (SecurityException ok) { return; }
821 <        try {
821 >        try {
822              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
823 <            p.execute(r);
823 >            p.execute(r);
824              assertFalse(r.done);
825          } finally {
826              joinPool(p);
# Line 864 | Line 836 | public class ThreadPoolExecutorTest exte
836          ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
837  
838          try { p.shutdown(); } catch (SecurityException ok) { return; }
839 <        try {
839 >        try {
840              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
841 <            p.execute(r);
841 >            p.execute(r);
842              assertFalse(r.done);
843          } finally {
844              joinPool(p);
# Line 878 | Line 850 | public class ThreadPoolExecutorTest exte
850       *  execute (null) throws NPE
851       */
852      public void testExecuteNull() {
853 <        ThreadPoolExecutor tpe = null;
853 >        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
854          try {
855 <            tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
884 <            tpe.execute(null);
855 >            tpe.execute(null);
856              shouldThrow();
857 <        } catch (NullPointerException success) {}
857 >        } catch (NullPointerException success) {}
858  
859 <        joinPool(tpe);
859 >        joinPool(tpe);
860      }
861  
862      /**
863       *  setCorePoolSize of negative value throws IllegalArgumentException
864       */
865      public void testCorePoolSizeIllegalArgumentException() {
866 <        ThreadPoolExecutor tpe =
866 >        ThreadPoolExecutor tpe =
867              new ThreadPoolExecutor(1, 2,
868                                     LONG_DELAY_MS, MILLISECONDS,
869                                     new ArrayBlockingQueue<Runnable>(10));
870 <        try {
871 <            tpe.setCorePoolSize(-1);
872 <            shouldThrow();
873 <        } catch (IllegalArgumentException success) {
870 >        try {
871 >            tpe.setCorePoolSize(-1);
872 >            shouldThrow();
873 >        } catch (IllegalArgumentException success) {
874          } finally {
875              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
876          }
# Line 950 | Line 921 | public class ThreadPoolExecutorTest exte
921       *  when given a negative value
922       */
923      public void testKeepAliveTimeIllegalArgumentException() {
924 <        ThreadPoolExecutor tpe =
924 >        ThreadPoolExecutor tpe =
925              new ThreadPoolExecutor(2, 3,
926                                     LONG_DELAY_MS, MILLISECONDS,
927                                     new ArrayBlockingQueue<Runnable>(10));
928 <        try {
928 >        try {
929              tpe.setKeepAliveTime(-1,MILLISECONDS);
930              shouldThrow();
931          } catch (IllegalArgumentException success) {
# Line 1071 | Line 1042 | public class ThreadPoolExecutorTest exte
1042          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1043          try {
1044              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1045 <            l.add(new CheckedCallable<String>() {
1046 <                      public String realCall() throws InterruptedException {
1047 <                          latch.await();
1045 >            l.add(new Callable<String>() {
1046 >                      public String call() {
1047 >                          try {
1048 >                              latch.await();
1049 >                          } catch (InterruptedException ok) {}
1050                            return TEST_STRING;
1051                        }});
1052              l.add(null);
# Line 1255 | Line 1228 | public class ThreadPoolExecutorTest exte
1228       * timed invokeAny(c) throws NPE if c has null elements
1229       */
1230      public void testTimedInvokeAny3() throws Exception {
1231 +        final CountDownLatch latch = new CountDownLatch(1);
1232          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1233          try {
1234              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1235 <            l.add(new StringTask());
1235 >            l.add(new Callable<String>() {
1236 >                      public String call() {
1237 >                          try {
1238 >                              latch.await();
1239 >                          } catch (InterruptedException ok) {}
1240 >                          return TEST_STRING;
1241 >                      }});
1242              l.add(null);
1243              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1244              shouldThrow();
1245          } catch (NullPointerException success) {
1246          } finally {
1247 +            latch.countDown();
1248              joinPool(e);
1249          }
1250      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines