[cvs] / jsr166 / src / test / tck / ThreadPoolExecutorSubclassTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Mon Nov 16 05:30:08 2009 UTC revision 1.5, Wed Nov 18 16:51:26 2009 UTC
# Line 188  Line 188 
188      /**      /**
189       *  execute successfully executes a runnable       *  execute successfully executes a runnable
190       */       */
191      public void testExecute() {      public void testExecute() throws InterruptedException {
192          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
193          try {          try {
194              p1.execute(new Runnable() {              p1.execute(new ShortRunnable());
                     public void run() {  
                         try {  
                             Thread.sleep(SHORT_DELAY_MS);  
                         } catch (InterruptedException e) {  
                             threadUnexpectedException();  
                         }  
                     }  
                 });  
195              Thread.sleep(SMALL_DELAY_MS);              Thread.sleep(SMALL_DELAY_MS);
196          } catch (InterruptedException e) {          } finally {
             unexpectedException();  
         }  
197          joinPool(p1);          joinPool(p1);
198      }      }
199        }
200    
201      /**      /**
202       *  getActiveCount increases but doesn't overestimate, when a       *  getActiveCount increases but doesn't overestimate, when a
203       *  thread becomes active       *  thread becomes active
204       */       */
205      public void testGetActiveCount() {      public void testGetActiveCount() throws InterruptedException {
206          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
207          assertEquals(0, p2.getActiveCount());          assertEquals(0, p2.getActiveCount());
208          p2.execute(new MediumRunnable());          p2.execute(new MediumRunnable());
         try {  
209              Thread.sleep(SHORT_DELAY_MS);              Thread.sleep(SHORT_DELAY_MS);
         } catch (Exception e) {  
             unexpectedException();  
         }  
210          assertEquals(1, p2.getActiveCount());          assertEquals(1, p2.getActiveCount());
211          joinPool(p2);          joinPool(p2);
212      }      }
# Line 256  Line 243 
243       *   getCompletedTaskCount increases, but doesn't overestimate,       *   getCompletedTaskCount increases, but doesn't overestimate,
244       *   when tasks complete       *   when tasks complete
245       */       */
246      public void testGetCompletedTaskCount() {      public void testGetCompletedTaskCount() throws InterruptedException {
247          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
248          assertEquals(0, p2.getCompletedTaskCount());          assertEquals(0, p2.getCompletedTaskCount());
249          p2.execute(new ShortRunnable());          p2.execute(new ShortRunnable());
         try {  
250              Thread.sleep(SMALL_DELAY_MS);              Thread.sleep(SMALL_DELAY_MS);
         } catch (Exception e) {  
             unexpectedException();  
         }  
251          assertEquals(1, p2.getCompletedTaskCount());          assertEquals(1, p2.getCompletedTaskCount());
252          try { p2.shutdown(); } catch (SecurityException ok) { return; }          try { p2.shutdown(); } catch (SecurityException ok) { return; }
253          joinPool(p2);          joinPool(p2);
# Line 367  Line 350 
350       *   getLargestPoolSize increases, but doesn't overestimate, when       *   getLargestPoolSize increases, but doesn't overestimate, when
351       *   multiple threads active       *   multiple threads active
352       */       */
353      public void testGetLargestPoolSize() {      public void testGetLargestPoolSize() throws InterruptedException {
354          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
         try {  
355              assertEquals(0, p2.getLargestPoolSize());              assertEquals(0, p2.getLargestPoolSize());
356              p2.execute(new MediumRunnable());              p2.execute(new MediumRunnable());
357              p2.execute(new MediumRunnable());              p2.execute(new MediumRunnable());
358              Thread.sleep(SHORT_DELAY_MS);              Thread.sleep(SHORT_DELAY_MS);
359              assertEquals(2, p2.getLargestPoolSize());              assertEquals(2, p2.getLargestPoolSize());
         } catch (Exception e) {  
             unexpectedException();  
         }  
360          joinPool(p2);          joinPool(p2);
361      }      }
362    
# Line 406  Line 385 
385      /**      /**
386       *  getTaskCount increases, but doesn't overestimate, when tasks submitted       *  getTaskCount increases, but doesn't overestimate, when tasks submitted
387       */       */
388      public void testGetTaskCount() {      public void testGetTaskCount() throws InterruptedException {
389          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
         try {  
390              assertEquals(0, p1.getTaskCount());              assertEquals(0, p1.getTaskCount());
391              p1.execute(new MediumRunnable());              p1.execute(new MediumRunnable());
392              Thread.sleep(SHORT_DELAY_MS);              Thread.sleep(SHORT_DELAY_MS);
393              assertEquals(1, p1.getTaskCount());              assertEquals(1, p1.getTaskCount());
         } catch (Exception e) {  
             unexpectedException();  
         }  
394          joinPool(p1);          joinPool(p1);
395      }      }
396    
# Line 435  Line 410 
410      /**      /**
411       *  isTerminated is false before termination, true after       *  isTerminated is false before termination, true after
412       */       */
413      public void testIsTerminated() {      public void testIsTerminated() throws InterruptedException {
414          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
415          assertFalse(p1.isTerminated());          assertFalse(p1.isTerminated());
416          try {          try {
# Line 443  Line 418 
418          } finally {          } finally {
419              try { p1.shutdown(); } catch (SecurityException ok) { return; }              try { p1.shutdown(); } catch (SecurityException ok) { return; }
420          }          }
         try {  
421              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
422              assertTrue(p1.isTerminated());              assertTrue(p1.isTerminated());
         } catch (Exception e) {  
             unexpectedException();  
         }  
423      }      }
424    
425      /**      /**
426       *  isTerminating is not true when running or when terminated       *  isTerminating is not true when running or when terminated
427       */       */
428      public void testIsTerminating() {      public void testIsTerminating() throws InterruptedException {
429          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
430          assertFalse(p1.isTerminating());          assertFalse(p1.isTerminating());
431          try {          try {
# Line 463  Line 434 
434          } finally {          } finally {
435              try { p1.shutdown(); } catch (SecurityException ok) { return; }              try { p1.shutdown(); } catch (SecurityException ok) { return; }
436          }          }
         try {  
437              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));              assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
438              assertTrue(p1.isTerminated());              assertTrue(p1.isTerminated());
439              assertFalse(p1.isTerminating());              assertFalse(p1.isTerminating());
         } catch (Exception e) {  
             unexpectedException();  
         }  
440      }      }
441    
442      /**      /**
443       * getQueue returns the work queue, which contains queued tasks       * getQueue returns the work queue, which contains queued tasks
444       */       */
445      public void testGetQueue() {      public void testGetQueue() throws InterruptedException {
446          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
447          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
448          FutureTask[] tasks = new FutureTask[5];          FutureTask[] tasks = new FutureTask[5];
# Line 492  Line 459 
459              for (int i = 1; i < 5; ++i)              for (int i = 1; i < 5; ++i)
460                  tasks[i].cancel(true);                  tasks[i].cancel(true);
461              p1.shutdownNow();              p1.shutdownNow();
         } catch (Exception e) {  
             unexpectedException();  
462          } finally {          } finally {
463              joinPool(p1);              joinPool(p1);
464          }          }
# Line 502  Line 467 
467      /**      /**
468       * remove(task) removes queued task, and fails to remove active task       * remove(task) removes queued task, and fails to remove active task
469       */       */
470      public void testRemove() {      public void testRemove() throws InterruptedException {
471          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
472          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
473          FutureTask[] tasks = new FutureTask[5];          FutureTask[] tasks = new FutureTask[5];
# Line 521  Line 486 
486              assertTrue(q.contains(tasks[3]));              assertTrue(q.contains(tasks[3]));
487              assertTrue(p1.remove(tasks[3]));              assertTrue(p1.remove(tasks[3]));
488              assertFalse(q.contains(tasks[3]));              assertFalse(q.contains(tasks[3]));
         } catch (Exception e) {  
             unexpectedException();  
489          } finally {          } finally {
490              joinPool(p1);              joinPool(p1);
491          }          }
# Line 576  Line 539 
539          try {          try {
540              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
541              shouldThrow();              shouldThrow();
542          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
543      }      }
544    
545      /**      /**
# Line 587  Line 549 
549          try {          try {
550              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
551              shouldThrow();              shouldThrow();
552          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
553      }      }
554    
555      /**      /**
# Line 598  Line 559 
559          try {          try {
560              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
561              shouldThrow();              shouldThrow();
562          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
563      }      }
564    
565      /**      /**
# Line 609  Line 569 
569          try {          try {
570              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
571              shouldThrow();              shouldThrow();
572          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
573      }      }
574    
575      /**      /**
# Line 620  Line 579 
579          try {          try {
580              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
581              shouldThrow();              shouldThrow();
582          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
583      }      }
584    
585      /**      /**
# Line 631  Line 589 
589          try {          try {
590              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
591              shouldThrow();              shouldThrow();
592          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
593      }      }
594    
595    
# Line 654  Line 611 
611          try {          try {
612              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
613              shouldThrow();              shouldThrow();
614          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
615      }      }
616    
617      /**      /**
# Line 665  Line 621 
621          try {          try {
622              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
623              shouldThrow();              shouldThrow();
624          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
625      }      }
626    
627      /**      /**
# Line 676  Line 631 
631          try {          try {
632              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
633              shouldThrow();              shouldThrow();
634          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
635      }      }
636    
637      /**      /**
# Line 687  Line 641 
641          try {          try {
642              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
643              shouldThrow();              shouldThrow();
644          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
645      }      }
646    
647      /**      /**
# Line 698  Line 651 
651          try {          try {
652              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
653              shouldThrow();              shouldThrow();
654          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
655      }      }
656    
657      /**      /**
# Line 710  Line 662 
662              ThreadFactory f = null;              ThreadFactory f = null;
663              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
664              shouldThrow();              shouldThrow();
665          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
666      }      }
667    
668    
# Line 722  Line 673 
673          try {          try {
674              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
675              shouldThrow();              shouldThrow();
676          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
677      }      }
678    
679      /**      /**
# Line 733  Line 683 
683          try {          try {
684              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
685              shouldThrow();              shouldThrow();
686          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
687      }      }
688    
689      /**      /**
# Line 744  Line 693 
693          try {          try {
694              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
695              shouldThrow();              shouldThrow();
696          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
697      }      }
698    
699      /**      /**
# Line 755  Line 703 
703          try {          try {
704              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
705              shouldThrow();              shouldThrow();
706          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
707      }      }
708    
709      /**      /**
# Line 766  Line 713 
713          try {          try {
714              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
715              shouldThrow();              shouldThrow();
716          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
717      }      }
718    
719      /**      /**
# Line 777  Line 723 
723          try {          try {
724              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
725              shouldThrow();              shouldThrow();
726          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
727      }      }
728    
729      /**      /**
# Line 789  Line 734 
734              RejectedExecutionHandler r = null;              RejectedExecutionHandler r = null;
735              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
736              shouldThrow();              shouldThrow();
737          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
738      }      }
739    
740    
# Line 801  Line 745 
745          try {          try {
746              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
747              shouldThrow();              shouldThrow();
748          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
749      }      }
750    
751      /**      /**
# Line 812  Line 755 
755          try {          try {
756              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
757              shouldThrow();              shouldThrow();
758          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
759      }      }
760    
761      /**      /**
# Line 823  Line 765 
765          try {          try {
766              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
767              shouldThrow();              shouldThrow();
768          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
769      }      }
770    
771      /**      /**
# Line 834  Line 775 
775          try {          try {
776              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
777              shouldThrow();              shouldThrow();
778          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
779      }      }
780    
781      /**      /**
# Line 845  Line 785 
785          try {          try {
786              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
787              shouldThrow();              shouldThrow();
788          }          } catch (IllegalArgumentException success) {}
         catch (IllegalArgumentException success) {}  
789      }      }
790    
791      /**      /**
# Line 856  Line 795 
795          try {          try {
796              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
797              shouldThrow();              shouldThrow();
798          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
799      }      }
800    
801      /**      /**
# Line 868  Line 806 
806              RejectedExecutionHandler r = null;              RejectedExecutionHandler r = null;
807              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
808              shouldThrow();              shouldThrow();
809          }          } catch (NullPointerException success) {}
         catch (NullPointerException success) {}  
810      }      }
811    
812      /**      /**
# Line 880  Line 817 
817              ThreadFactory f = null;              ThreadFactory f = null;
818              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
819              shouldThrow();              shouldThrow();
820          }          } catch (NullPointerException success) {}
         catch (NullPointerException successdn8) {}  
821      }      }
822    
823    
# Line 922  Line 858 
858                  assertTrue(tasks[i].done);                  assertTrue(tasks[i].done);
859              }              }
860              try { p.shutdownNow(); } catch (SecurityException ok) { return; }              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
         } catch (RejectedExecutionException ex) {  
             unexpectedException();  
861          } finally {          } finally {
862              joinPool(p);              joinPool(p);
863          }          }
# Line 949  Line 883 
883                  assertFalse(tasks[i].done);                  assertFalse(tasks[i].done);
884              }              }
885              try { p.shutdownNow(); } catch (SecurityException ok) { return; }              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
         } catch (RejectedExecutionException ex) {  
             unexpectedException();  
886          } finally {          } finally {
887              joinPool(p);              joinPool(p);
888          }          }
# Line 972  Line 904 
904              assertFalse(p.getQueue().contains(r2));              assertFalse(p.getQueue().contains(r2));
905              assertTrue(p.getQueue().contains(r3));              assertTrue(p.getQueue().contains(r3));
906              try { p.shutdownNow(); } catch (SecurityException ok) { return; }              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
         } catch (RejectedExecutionException ex) {  
             unexpectedException();  
907          } finally {          } finally {
908              joinPool(p);              joinPool(p);
909          }          }
# Line 1006  Line 936 
936              TrackedNoOpRunnable r = new TrackedNoOpRunnable();              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
937              p.execute(r);              p.execute(r);
938              assertFalse(r.done);              assertFalse(r.done);
         } catch (RejectedExecutionException success) {  
             unexpectedException();  
939          } finally {          } finally {
940              joinPool(p);              joinPool(p);
941          }          }
# Line 1025  Line 953 
953              TrackedNoOpRunnable r = new TrackedNoOpRunnable();              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
954              p.execute(r);              p.execute(r);
955              assertFalse(r.done);              assertFalse(r.done);
         } catch (RejectedExecutionException success) {  
             unexpectedException();  
956          } finally {          } finally {
957              joinPool(p);              joinPool(p);
958          }          }
# Line 1045  Line 971 
971              TrackedNoOpRunnable r = new TrackedNoOpRunnable();              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
972              p.execute(r);              p.execute(r);
973              assertFalse(r.done);              assertFalse(r.done);
         } catch (RejectedExecutionException success) {  
             unexpectedException();  
974          } finally {          } finally {
975              joinPool(p);              joinPool(p);
976          }          }
# Line 1157  Line 1081 
1081      /**      /**
1082       * beforeExecute and afterExecute are called when executing task       * beforeExecute and afterExecute are called when executing task
1083       */       */
1084      public void testBeforeAfter() {      public void testBeforeAfter() throws InterruptedException {
1085          CustomTPE tpe = new CustomTPE();          CustomTPE tpe = new CustomTPE();
1086          try {          try {
1087              TrackedNoOpRunnable r = new TrackedNoOpRunnable();              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1167  Line 1091 
1091              assertTrue(tpe.beforeCalled);              assertTrue(tpe.beforeCalled);
1092              assertTrue(tpe.afterCalled);              assertTrue(tpe.afterCalled);
1093              try { tpe.shutdown(); } catch (SecurityException ok) { return; }              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
         }  
         catch (Exception ex) {  
             unexpectedException();  
1094          } finally {          } finally {
1095              joinPool(tpe);              joinPool(tpe);
1096          }          }
# Line 1178  Line 1099 
1099      /**      /**
1100       * completed submit of callable returns result       * completed submit of callable returns result
1101       */       */
1102      public void testSubmitCallable() {      public void testSubmitCallable() throws Exception {
1103          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1104          try {          try {
1105              Future<String> future = e.submit(new StringTask());              Future<String> future = e.submit(new StringTask());
1106              String result = future.get();              String result = future.get();
1107              assertSame(TEST_STRING, result);              assertSame(TEST_STRING, result);
         }  
         catch (ExecutionException ex) {  
             unexpectedException();  
         }  
         catch (InterruptedException ex) {  
             unexpectedException();  
1108          } finally {          } finally {
1109              joinPool(e);              joinPool(e);
1110          }          }
# Line 1198  Line 1113 
1113      /**      /**
1114       * completed submit of runnable returns successfully       * completed submit of runnable returns successfully
1115       */       */
1116      public void testSubmitRunnable() {      public void testSubmitRunnable() throws Exception {
1117          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1118          try {          try {
1119              Future<?> future = e.submit(new NoOpRunnable());              Future<?> future = e.submit(new NoOpRunnable());
1120              future.get();              future.get();
1121              assertTrue(future.isDone());              assertTrue(future.isDone());
         }  
         catch (ExecutionException ex) {  
             unexpectedException();  
         }  
         catch (InterruptedException ex) {  
             unexpectedException();  
1122          } finally {          } finally {
1123              joinPool(e);              joinPool(e);
1124          }          }
# Line 1218  Line 1127 
1127      /**      /**
1128       * completed submit of (runnable, result) returns result       * completed submit of (runnable, result) returns result
1129       */       */
1130      public void testSubmitRunnable2() {      public void testSubmitRunnable2() throws Exception {
1131          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1132          try {          try {
1133              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1134              String result = future.get();              String result = future.get();
1135              assertSame(TEST_STRING, result);              assertSame(TEST_STRING, result);
         }  
         catch (ExecutionException ex) {  
             unexpectedException();  
         }  
         catch (InterruptedException ex) {  
             unexpectedException();  
1136          } finally {          } finally {
1137              joinPool(e);              joinPool(e);
1138          }          }
1139      }      }
1140    
1141    
   
   
   
1142      /**      /**
1143       * invokeAny(null) throws NPE       * invokeAny(null) throws NPE
1144       */       */
1145      public void testInvokeAny1() {      public void testInvokeAny1() throws Exception {
1146          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1147          try {          try {
1148              e.invokeAny(null);              e.invokeAny(null);
1149                shouldThrow();
1150          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1151          } finally {          } finally {
1152              joinPool(e);              joinPool(e);
1153          }          }
# Line 1257  Line 1156 
1156      /**      /**
1157       * invokeAny(empty collection) throws IAE       * invokeAny(empty collection) throws IAE
1158       */       */
1159      public void testInvokeAny2() {      public void testInvokeAny2() throws Exception {
1160          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1161          try {          try {
1162              e.invokeAny(new ArrayList<Callable<String>>());              e.invokeAny(new ArrayList<Callable<String>>());
1163                shouldThrow();
1164          } catch (IllegalArgumentException success) {          } catch (IllegalArgumentException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1165          } finally {          } finally {
1166              joinPool(e);              joinPool(e);
1167          }          }
# Line 1272  Line 1170 
1170      /**      /**
1171       * invokeAny(c) throws NPE if c has null elements       * invokeAny(c) throws NPE if c has null elements
1172       */       */
1173      public void testInvokeAny3() {      public void testInvokeAny3() throws Exception {
1174            final CountDownLatch latch = new CountDownLatch(1);
1175          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1176          try {          try {
1177              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1178              l.add(new StringTask());              l.add(new CheckedCallable<String>() {
1179                          public String realCall() throws InterruptedException {
1180                              latch.await();
1181                              return TEST_STRING;
1182                          }});
1183              l.add(null);              l.add(null);
1184              e.invokeAny(l);              e.invokeAny(l);
1185                shouldThrow();
1186          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1187          } finally {          } finally {
1188                latch.countDown();
1189              joinPool(e);              joinPool(e);
1190          }          }
1191      }      }
# Line 1290  Line 1193 
1193      /**      /**
1194       * invokeAny(c) throws ExecutionException if no task completes       * invokeAny(c) throws ExecutionException if no task completes
1195       */       */
1196      public void testInvokeAny4() {      public void testInvokeAny4() throws Exception {
1197          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1198          try {          try {
1199              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1200              l.add(new NPETask());              l.add(new NPETask());
1201              e.invokeAny(l);              e.invokeAny(l);
1202                shouldThrow();
1203          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1204          } finally {          } finally {
1205              joinPool(e);              joinPool(e);
1206          }          }
# Line 1307  Line 1209 
1209      /**      /**
1210       * invokeAny(c) returns result of some task       * invokeAny(c) returns result of some task
1211       */       */
1212      public void testInvokeAny5() {      public void testInvokeAny5() throws Exception {
1213          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1214          try {          try {
1215              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1315  Line 1217 
1217              l.add(new StringTask());              l.add(new StringTask());
1218              String result = e.invokeAny(l);              String result = e.invokeAny(l);
1219              assertSame(TEST_STRING, result);              assertSame(TEST_STRING, result);
         } catch (ExecutionException success) {  
         } catch (Exception ex) {  
             unexpectedException();  
1220          } finally {          } finally {
1221              joinPool(e);              joinPool(e);
1222          }          }
# Line 1326  Line 1225 
1225      /**      /**
1226       * invokeAll(null) throws NPE       * invokeAll(null) throws NPE
1227       */       */
1228      public void testInvokeAll1() {      public void testInvokeAll1() throws Exception {
1229          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1230          try {          try {
1231              e.invokeAll(null);              e.invokeAll(null);
1232                shouldThrow();
1233          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1234          } finally {          } finally {
1235              joinPool(e);              joinPool(e);
1236          }          }
# Line 1341  Line 1239 
1239      /**      /**
1240       * invokeAll(empty collection) returns empty collection       * invokeAll(empty collection) returns empty collection
1241       */       */
1242      public void testInvokeAll2() {      public void testInvokeAll2() throws Exception {
1243          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1244          try {          try {
1245              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1246              assertTrue(r.isEmpty());              assertTrue(r.isEmpty());
         } catch (Exception ex) {  
             unexpectedException();  
1247          } finally {          } finally {
1248              joinPool(e);              joinPool(e);
1249          }          }
# Line 1356  Line 1252 
1252      /**      /**
1253       * invokeAll(c) throws NPE if c has null elements       * invokeAll(c) throws NPE if c has null elements
1254       */       */
1255      public void testInvokeAll3() {      public void testInvokeAll3() throws Exception {
1256          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257          try {          try {
1258              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259              l.add(new StringTask());              l.add(new StringTask());
1260              l.add(null);              l.add(null);
1261              e.invokeAll(l);              e.invokeAll(l);
1262                shouldThrow();
1263          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1264          } finally {          } finally {
1265              joinPool(e);              joinPool(e);
1266          }          }
# Line 1374  Line 1269 
1269      /**      /**
1270       * get of element of invokeAll(c) throws exception on failed task       * get of element of invokeAll(c) throws exception on failed task
1271       */       */
1272      public void testInvokeAll4() {      public void testInvokeAll4() throws Exception {
1273          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1274          try {          try {
1275              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1383  Line 1278 
1278              assertEquals(1, result.size());              assertEquals(1, result.size());
1279              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1280                  it.next().get();                  it.next().get();
1281                shouldThrow();
1282          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1283          } finally {          } finally {
1284              joinPool(e);              joinPool(e);
1285          }          }
# Line 1394  Line 1288 
1288      /**      /**
1289       * invokeAll(c) returns results of all completed tasks       * invokeAll(c) returns results of all completed tasks
1290       */       */
1291      public void testInvokeAll5() {      public void testInvokeAll5() throws Exception {
1292          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1293          try {          try {
1294              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1404  Line 1298 
1298              assertEquals(2, result.size());              assertEquals(2, result.size());
1299              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1300                  assertSame(TEST_STRING, it.next().get());                  assertSame(TEST_STRING, it.next().get());
1301                shouldThrow();
1302          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1303          } finally {          } finally {
1304              joinPool(e);              joinPool(e);
1305          }          }
# Line 1417  Line 1310 
1310      /**      /**
1311       * timed invokeAny(null) throws NPE       * timed invokeAny(null) throws NPE
1312       */       */
1313      public void testTimedInvokeAny1() {      public void testTimedInvokeAny1() throws Exception {
1314          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1315          try {          try {
1316              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1317                shouldThrow();
1318          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1319          } finally {          } finally {
1320              joinPool(e);              joinPool(e);
1321          }          }
# Line 1432  Line 1324 
1324      /**      /**
1325       * timed invokeAny(,,null) throws NPE       * timed invokeAny(,,null) throws NPE
1326       */       */
1327      public void testTimedInvokeAnyNullTimeUnit() {      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1328          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1329          try {          try {
1330              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1331              l.add(new StringTask());              l.add(new StringTask());
1332              e.invokeAny(l, MEDIUM_DELAY_MS, null);              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1333                shouldThrow();
1334          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1335          } finally {          } finally {
1336              joinPool(e);              joinPool(e);
1337          }          }
# Line 1449  Line 1340 
1340      /**      /**
1341       * timed invokeAny(empty collection) throws IAE       * timed invokeAny(empty collection) throws IAE
1342       */       */
1343      public void testTimedInvokeAny2() {      public void testTimedInvokeAny2() throws Exception {
1344          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1345          try {          try {
1346              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1347                shouldThrow();
1348          } catch (IllegalArgumentException success) {          } catch (IllegalArgumentException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1349          } finally {          } finally {
1350              joinPool(e);              joinPool(e);
1351          }          }
# Line 1464  Line 1354 
1354      /**      /**
1355       * timed invokeAny(c) throws NPE if c has null elements       * timed invokeAny(c) throws NPE if c has null elements
1356       */       */
1357      public void testTimedInvokeAny3() {      public void testTimedInvokeAny3() throws Exception {
1358          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1359          try {          try {
1360              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1361              l.add(new StringTask());              l.add(new StringTask());
1362              l.add(null);              l.add(null);
1363              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1364                shouldThrow();
1365          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             ex.printStackTrace();  
             unexpectedException();  
1366          } finally {          } finally {
1367              joinPool(e);              joinPool(e);
1368          }          }
# Line 1483  Line 1371 
1371      /**      /**
1372       * timed invokeAny(c) throws ExecutionException if no task completes       * timed invokeAny(c) throws ExecutionException if no task completes
1373       */       */
1374      public void testTimedInvokeAny4() {      public void testTimedInvokeAny4() throws Exception {
1375          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1376          try {          try {
1377              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1378              l.add(new NPETask());              l.add(new NPETask());
1379              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1380                shouldThrow();
1381          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1382          } finally {          } finally {
1383              joinPool(e);              joinPool(e);
1384          }          }
# Line 1500  Line 1387 
1387      /**      /**
1388       * timed invokeAny(c) returns result of some task       * timed invokeAny(c) returns result of some task
1389       */       */
1390      public void testTimedInvokeAny5() {      public void testTimedInvokeAny5() throws Exception {
1391          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1392          try {          try {
1393              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1508  Line 1395 
1395              l.add(new StringTask());              l.add(new StringTask());
1396              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1397              assertSame(TEST_STRING, result);              assertSame(TEST_STRING, result);
1398                shouldThrow();
1399          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1400          } finally {          } finally {
1401              joinPool(e);              joinPool(e);
1402          }          }
# Line 1519  Line 1405 
1405      /**      /**
1406       * timed invokeAll(null) throws NPE       * timed invokeAll(null) throws NPE
1407       */       */
1408      public void testTimedInvokeAll1() {      public void testTimedInvokeAll1() throws Exception {
1409          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1410          try {          try {
1411              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1412                shouldThrow();
1413          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1414          } finally {          } finally {
1415              joinPool(e);              joinPool(e);
1416          }          }
# Line 1534  Line 1419 
1419      /**      /**
1420       * timed invokeAll(,,null) throws NPE       * timed invokeAll(,,null) throws NPE
1421       */       */
1422      public void testTimedInvokeAllNullTimeUnit() {      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1423          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1424          try {          try {
1425              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1426              l.add(new StringTask());              l.add(new StringTask());
1427              e.invokeAll(l, MEDIUM_DELAY_MS, null);              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1428                shouldThrow();
1429          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1430          } finally {          } finally {
1431              joinPool(e);              joinPool(e);
1432          }          }
# Line 1551  Line 1435 
1435      /**      /**
1436       * timed invokeAll(empty collection) returns empty collection       * timed invokeAll(empty collection) returns empty collection
1437       */       */
1438      public void testTimedInvokeAll2() {      public void testTimedInvokeAll2() throws Exception {
1439          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1440          try {          try {
1441              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1442              assertTrue(r.isEmpty());              assertTrue(r.isEmpty());
         } catch (Exception ex) {  
             unexpectedException();  
1443          } finally {          } finally {
1444              joinPool(e);              joinPool(e);
1445          }          }
# Line 1566  Line 1448 
1448      /**      /**
1449       * timed invokeAll(c) throws NPE if c has null elements       * timed invokeAll(c) throws NPE if c has null elements
1450       */       */
1451      public void testTimedInvokeAll3() {      public void testTimedInvokeAll3() throws Exception {
1452          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1453          try {          try {
1454              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1455              l.add(new StringTask());              l.add(new StringTask());
1456              l.add(null);              l.add(null);
1457              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1458                shouldThrow();
1459          } catch (NullPointerException success) {          } catch (NullPointerException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1460          } finally {          } finally {
1461              joinPool(e);              joinPool(e);
1462          }          }
# Line 1584  Line 1465 
1465      /**      /**
1466       * get of element of invokeAll(c) throws exception on failed task       * get of element of invokeAll(c) throws exception on failed task
1467       */       */
1468      public void testTimedInvokeAll4() {      public void testTimedInvokeAll4() throws Exception {
1469          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1470          try {          try {
1471              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1593  Line 1474 
1474              assertEquals(1, result.size());              assertEquals(1, result.size());
1475              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1476                  it.next().get();                  it.next().get();
1477                shouldThrow();
1478          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1479          } finally {          } finally {
1480              joinPool(e);              joinPool(e);
1481          }          }
# Line 1604  Line 1484 
1484      /**      /**
1485       * timed invokeAll(c) returns results of all completed tasks       * timed invokeAll(c) returns results of all completed tasks
1486       */       */
1487      public void testTimedInvokeAll5() {      public void testTimedInvokeAll5() throws Exception {
1488          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1489          try {          try {
1490              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1614  Line 1494 
1494              assertEquals(2, result.size());              assertEquals(2, result.size());
1495              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1496                  assertSame(TEST_STRING, it.next().get());                  assertSame(TEST_STRING, it.next().get());
1497                shouldThrow();
1498          } catch (ExecutionException success) {          } catch (ExecutionException success) {
         } catch (Exception ex) {  
             unexpectedException();  
1499          } finally {          } finally {
1500              joinPool(e);              joinPool(e);
1501          }          }
# Line 1625  Line 1504 
1504      /**      /**
1505       * timed invokeAll(c) cancels tasks not completed by timeout       * timed invokeAll(c) cancels tasks not completed by timeout
1506       */       */
1507      public void testTimedInvokeAll6() {      public void testTimedInvokeAll6() throws Exception {
1508          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1509          try {          try {
1510              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1643  Line 1522 
1522              assertTrue(f3.isDone());              assertTrue(f3.isDone());
1523              assertFalse(f1.isCancelled());              assertFalse(f1.isCancelled());
1524              assertTrue(f2.isCancelled());              assertTrue(f2.isCancelled());
         } catch (Exception ex) {  
             unexpectedException();  
1525          } finally {          } finally {
1526              joinPool(e);              joinPool(e);
1527          }          }
# Line 1654  Line 1531 
1531       * Execution continues if there is at least one thread even if       * Execution continues if there is at least one thread even if
1532       * thread factory fails to create more       * thread factory fails to create more
1533       */       */
1534      public void testFailingThreadFactory() {      public void testFailingThreadFactory() throws InterruptedException {
1535          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1536          try {          try {
1537              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1662  Line 1539 
1539                  e.execute(new NoOpRunnable());                  e.execute(new NoOpRunnable());
1540              }              }
1541              Thread.sleep(LONG_DELAY_MS);              Thread.sleep(LONG_DELAY_MS);
         } catch (Exception ex) {  
             unexpectedException();  
1542          } finally {          } finally {
1543              joinPool(e);              joinPool(e);
1544          }          }
# Line 1681  Line 1556 
1556      /**      /**
1557       * allowCoreThreadTimeOut(true) causes idle threads to time out       * allowCoreThreadTimeOut(true) causes idle threads to time out
1558       */       */
1559      public void testAllowCoreThreadTimeOut_true() {      public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1560          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1561          tpe.allowCoreThreadTimeOut(true);          tpe.allowCoreThreadTimeOut(true);
1562          tpe.execute(new NoOpRunnable());          tpe.execute(new NoOpRunnable());
1563          try {          try {
1564              Thread.sleep(MEDIUM_DELAY_MS);              Thread.sleep(MEDIUM_DELAY_MS);
1565              assertEquals(0, tpe.getPoolSize());              assertEquals(0, tpe.getPoolSize());
         } catch (InterruptedException e) {  
             unexpectedException();  
1566          } finally {          } finally {
1567              joinPool(tpe);              joinPool(tpe);
1568          }          }
# Line 1698  Line 1571 
1571      /**      /**
1572       * allowCoreThreadTimeOut(false) causes idle threads not to time out       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1573       */       */
1574      public void testAllowCoreThreadTimeOut_false() {      public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1575          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1576          tpe.allowCoreThreadTimeOut(false);          tpe.allowCoreThreadTimeOut(false);
1577          tpe.execute(new NoOpRunnable());          tpe.execute(new NoOpRunnable());
1578          try {          try {
1579              Thread.sleep(MEDIUM_DELAY_MS);              Thread.sleep(MEDIUM_DELAY_MS);
1580              assertTrue(tpe.getPoolSize() >= 1);              assertTrue(tpe.getPoolSize() >= 1);
         } catch (InterruptedException e) {  
             unexpectedException();  
1581          } finally {          } finally {
1582              joinPool(tpe);              joinPool(tpe);
1583          }          }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8