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

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.66 by jsr166, Sun Oct 4 02:21:43 2015 UTC vs.
Revision 1.73 by jsr166, Sun Oct 4 02:49:18 2015 UTC

# Line 549 | Line 549 | public class ThreadPoolExecutorSubclassT
549              new CustomTPE(1, 1,
550                            LONG_DELAY_MS, MILLISECONDS,
551                            new ArrayBlockingQueue<Runnable>(10));
552 <        final CountDownLatch threadStarted = new CountDownLatch(1);
553 <        final CountDownLatch done = new CountDownLatch(1);
554 <        try {
552 >        try (PoolCleaner cleaner = cleaner(p)) {
553 >            final CountDownLatch threadStarted = new CountDownLatch(1);
554 >            final CountDownLatch done = new CountDownLatch(1);
555              assertEquals(0, p.getTaskCount());
556              p.execute(new CheckedRunnable() {
557                  public void realRun() throws InterruptedException {
# Line 561 | Line 561 | public class ThreadPoolExecutorSubclassT
561                  }});
562              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
563              assertEquals(1, p.getTaskCount());
564        } finally {
564              done.countDown();
566            joinPool(p);
565          }
566      }
567  
# Line 571 | Line 569 | public class ThreadPoolExecutorSubclassT
569       * isShutdown is false before shutdown, true after
570       */
571      public void testIsShutdown() {
572 <
573 <        ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
574 <        assertFalse(p.isShutdown());
575 <        try { p.shutdown(); } catch (SecurityException ok) { return; }
576 <        assertTrue(p.isShutdown());
577 <        joinPool(p);
572 >        final ThreadPoolExecutor p =
573 >            new CustomTPE(1, 1,
574 >                          LONG_DELAY_MS, MILLISECONDS,
575 >                          new ArrayBlockingQueue<Runnable>(10));
576 >        try (PoolCleaner cleaner = cleaner(p)) {
577 >            assertFalse(p.isShutdown());
578 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
579 >            assertTrue(p.isShutdown());
580 >        }
581      }
582  
583      /**
# Line 587 | Line 588 | public class ThreadPoolExecutorSubclassT
588              new CustomTPE(1, 1,
589                            LONG_DELAY_MS, MILLISECONDS,
590                            new ArrayBlockingQueue<Runnable>(10));
591 <        final CountDownLatch threadStarted = new CountDownLatch(1);
592 <        final CountDownLatch done = new CountDownLatch(1);
593 <        try {
591 >        try (PoolCleaner cleaner = cleaner(p)) {
592 >            final CountDownLatch threadStarted = new CountDownLatch(1);
593 >            final CountDownLatch done = new CountDownLatch(1);
594              assertFalse(p.isTerminating());
595              p.execute(new CheckedRunnable() {
596                  public void realRun() throws InterruptedException {
# Line 600 | Line 601 | public class ThreadPoolExecutorSubclassT
601              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
602              assertFalse(p.isTerminating());
603              done.countDown();
603        } finally {
604              try { p.shutdown(); } catch (SecurityException ok) { return; }
605 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
606 +            assertTrue(p.isTerminated());
607 +            assertFalse(p.isTerminating());
608          }
606        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
607        assertTrue(p.isTerminated());
608        assertFalse(p.isTerminating());
609      }
610  
611      /**
# Line 616 | Line 616 | public class ThreadPoolExecutorSubclassT
616              new CustomTPE(1, 1,
617                            LONG_DELAY_MS, MILLISECONDS,
618                            new ArrayBlockingQueue<Runnable>(10));
619 <        final CountDownLatch threadStarted = new CountDownLatch(1);
620 <        final CountDownLatch done = new CountDownLatch(1);
621 <        try {
619 >        try (PoolCleaner cleaner = cleaner(p)) {
620 >            final CountDownLatch threadStarted = new CountDownLatch(1);
621 >            final CountDownLatch done = new CountDownLatch(1);
622              assertFalse(p.isTerminating());
623              p.execute(new CheckedRunnable() {
624                  public void realRun() throws InterruptedException {
# Line 629 | Line 629 | public class ThreadPoolExecutorSubclassT
629              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
630              assertFalse(p.isTerminating());
631              done.countDown();
632        } finally {
632              try { p.shutdown(); } catch (SecurityException ok) { return; }
633 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
634 +            assertTrue(p.isTerminated());
635 +            assertFalse(p.isTerminating());
636          }
635        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
636        assertTrue(p.isTerminated());
637        assertFalse(p.isTerminating());
637      }
638  
639      /**
# Line 646 | Line 645 | public class ThreadPoolExecutorSubclassT
645              new CustomTPE(1, 1,
646                            LONG_DELAY_MS, MILLISECONDS,
647                            q);
648 <        final CountDownLatch threadStarted = new CountDownLatch(1);
649 <        final CountDownLatch done = new CountDownLatch(1);
650 <        try {
648 >        try (PoolCleaner cleaner = cleaner(p)) {
649 >            final CountDownLatch threadStarted = new CountDownLatch(1);
650 >            final CountDownLatch done = new CountDownLatch(1);
651              FutureTask[] tasks = new FutureTask[5];
652              for (int i = 0; i < tasks.length; i++) {
653                  Callable task = new CheckedCallable<Boolean>() {
# Line 666 | Line 665 | public class ThreadPoolExecutorSubclassT
665              assertFalse(q.contains(tasks[0]));
666              assertTrue(q.contains(tasks[tasks.length - 1]));
667              assertEquals(tasks.length - 1, q.size());
669        } finally {
668              done.countDown();
671            joinPool(p);
669          }
670      }
671  
# Line 681 | Line 678 | public class ThreadPoolExecutorSubclassT
678              new CustomTPE(1, 1,
679                            LONG_DELAY_MS, MILLISECONDS,
680                            q);
681 <        Runnable[] tasks = new Runnable[6];
682 <        final CountDownLatch threadStarted = new CountDownLatch(1);
683 <        final CountDownLatch done = new CountDownLatch(1);
684 <        try {
681 >        try (PoolCleaner cleaner = cleaner(p)) {
682 >            Runnable[] tasks = new Runnable[6];
683 >            final CountDownLatch threadStarted = new CountDownLatch(1);
684 >            final CountDownLatch done = new CountDownLatch(1);
685              for (int i = 0; i < tasks.length; i++) {
686                  tasks[i] = new CheckedRunnable() {
687 <                        public void realRun() throws InterruptedException {
688 <                            threadStarted.countDown();
689 <                            done.await();
690 <                        }};
687 >                    public void realRun() throws InterruptedException {
688 >                        threadStarted.countDown();
689 >                        done.await();
690 >                    }};
691                  p.execute(tasks[i]);
692              }
693              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
# Line 703 | Line 700 | public class ThreadPoolExecutorSubclassT
700              assertTrue(q.contains(tasks[3]));
701              assertTrue(p.remove(tasks[3]));
702              assertFalse(q.contains(tasks[3]));
706        } finally {
703              done.countDown();
708            joinPool(p);
704          }
705      }
706  
# Line 720 | Line 715 | public class ThreadPoolExecutorSubclassT
715              new CustomTPE(1, 1,
716                            LONG_DELAY_MS, MILLISECONDS,
717                            q);
718 <        FutureTask[] tasks = new FutureTask[5];
719 <        try {
718 >        try (PoolCleaner cleaner = cleaner(p)) {
719 >            FutureTask[] tasks = new FutureTask[5];
720              for (int i = 0; i < tasks.length; i++) {
721                  Callable task = new CheckedCallable<Boolean>() {
722                      public Boolean realCall() throws InterruptedException {
# Line 745 | Line 740 | public class ThreadPoolExecutorSubclassT
740              p.purge();         // Nothing to do
741              assertEquals(tasks.length - 3, q.size());
742              assertEquals(tasks.length - 2, p.getTaskCount());
748        } finally {
743              done.countDown();
750            joinPool(p);
744          }
745      }
746  
# Line 1131 | Line 1124 | public class ThreadPoolExecutorSubclassT
1124       * execute throws RejectedExecutionException if saturated.
1125       */
1126      public void testSaturatedExecute() {
1127 <        ThreadPoolExecutor p =
1127 >        final ThreadPoolExecutor p =
1128              new CustomTPE(1, 1,
1129                            LONG_DELAY_MS, MILLISECONDS,
1130                            new ArrayBlockingQueue<Runnable>(1));
1131 <        final CountDownLatch done = new CountDownLatch(1);
1132 <        try {
1131 >        try (PoolCleaner cleaner = cleaner(p)) {
1132 >            final CountDownLatch done = new CountDownLatch(1);
1133              Runnable task = new CheckedRunnable() {
1134                  public void realRun() throws InterruptedException {
1135                      done.await();
# Line 1150 | Line 1143 | public class ThreadPoolExecutorSubclassT
1143                  } catch (RejectedExecutionException success) {}
1144                  assertTrue(p.getTaskCount() <= 2);
1145              }
1153        } finally {
1146              done.countDown();
1155            joinPool(p);
1147          }
1148      }
1149  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines