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.83 by jsr166, Mon Oct 5 20:45:41 2015 UTC vs.
Revision 1.90 by jsr166, Tue Oct 6 05:22:25 2015 UTC

# Line 260 | Line 260 | public class ThreadPoolExecutorSubclassT
260                  public void realRun() throws InterruptedException {
261                      threadStarted.countDown();
262                      assertEquals(1, p.getActiveCount());
263 <                    done.await();
263 >                    await(done);
264                  }});
265 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
265 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
266              assertEquals(1, p.getActiveCount());
267              done.countDown();
268          }
# Line 476 | Line 476 | public class ThreadPoolExecutorSubclassT
476       */
477      public void testGetLargestPoolSize() throws InterruptedException {
478          final int THREADS = 3;
479 +        final CountDownLatch done = new CountDownLatch(1);
480          final ThreadPoolExecutor p =
481              new CustomTPE(THREADS, THREADS,
482                            LONG_DELAY_MS, MILLISECONDS,
483                            new ArrayBlockingQueue<Runnable>(10));
484 <        try (PoolCleaner cleaner = cleaner(p)) {
484 <            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
485 <            final CountDownLatch done = new CountDownLatch(1);
484 >        try (PoolCleaner cleaner = cleaner(p, done)) {
485              assertEquals(0, p.getLargestPoolSize());
486 +            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
487              for (int i = 0; i < THREADS; i++)
488                  p.execute(new CheckedRunnable() {
489                      public void realRun() throws InterruptedException {
490                          threadsStarted.countDown();
491 <                        done.await();
491 >                        await(done);
492                          assertEquals(THREADS, p.getLargestPoolSize());
493                      }});
494 <            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
494 >            await(threadsStarted);
495              assertEquals(THREADS, p.getLargestPoolSize());
496            done.countDown();   // release pool
496          }
497          assertEquals(THREADS, p.getLargestPoolSize());
498      }
# Line 521 | Line 520 | public class ThreadPoolExecutorSubclassT
520       * become active
521       */
522      public void testGetPoolSize() throws InterruptedException {
523 +        final CountDownLatch done = new CountDownLatch(1);
524          final ThreadPoolExecutor p =
525              new CustomTPE(1, 1,
526                            LONG_DELAY_MS, MILLISECONDS,
527                            new ArrayBlockingQueue<Runnable>(10));
528 <        try (PoolCleaner cleaner = cleaner(p)) {
529 <            final CountDownLatch threadStarted = new CountDownLatch(1);
530 <            final CountDownLatch done = new CountDownLatch(1);
528 >        try (PoolCleaner cleaner = cleaner(p, done)) {
529              assertEquals(0, p.getPoolSize());
530 +            final CountDownLatch threadStarted = new CountDownLatch(1);
531              p.execute(new CheckedRunnable() {
532                  public void realRun() throws InterruptedException {
533                      threadStarted.countDown();
534                      assertEquals(1, p.getPoolSize());
535 <                    done.await();
535 >                    await(done);
536                  }});
537 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
537 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
538              assertEquals(1, p.getPoolSize());
540            done.countDown();   // release pool
539          }
540      }
541  
# Line 545 | Line 543 | public class ThreadPoolExecutorSubclassT
543       * getTaskCount increases, but doesn't overestimate, when tasks submitted
544       */
545      public void testGetTaskCount() throws InterruptedException {
546 +        final int TASKS = 3;
547 +        final CountDownLatch done = new CountDownLatch(1);
548          final ThreadPoolExecutor p =
549              new CustomTPE(1, 1,
550                            LONG_DELAY_MS, MILLISECONDS,
551                            new ArrayBlockingQueue<Runnable>(10));
552 <        try (PoolCleaner cleaner = cleaner(p)) {
552 >        try (PoolCleaner cleaner = cleaner(p, done)) {
553              final CountDownLatch threadStarted = new CountDownLatch(1);
554            final CountDownLatch done = new CountDownLatch(1);
554              assertEquals(0, p.getTaskCount());
555 +            assertEquals(0, p.getCompletedTaskCount());
556              p.execute(new CheckedRunnable() {
557                  public void realRun() throws InterruptedException {
558                      threadStarted.countDown();
559 <                    assertEquals(1, p.getTaskCount());
560 <                    done.await();
559 >                    await(done);
560                  }});
561 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
561 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
562              assertEquals(1, p.getTaskCount());
563 <            done.countDown();
563 >            assertEquals(0, p.getCompletedTaskCount());
564 >            for (int i = 0; i < TASKS; i++) {
565 >                assertEquals(1 + i, p.getTaskCount());
566 >                p.execute(new CheckedRunnable() {
567 >                    public void realRun() throws InterruptedException {
568 >                        threadStarted.countDown();
569 >                        assertEquals(1 + TASKS, p.getTaskCount());
570 >                        await(done);
571 >                    }});
572 >            }
573 >            assertEquals(1 + TASKS, p.getTaskCount());
574 >            assertEquals(0, p.getCompletedTaskCount());
575          }
576 +        assertEquals(1 + TASKS, p.getTaskCount());
577 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
578      }
579  
580      /**
# Line 596 | Line 608 | public class ThreadPoolExecutorSubclassT
608                  public void realRun() throws InterruptedException {
609                      assertFalse(p.isTerminating());
610                      threadStarted.countDown();
611 <                    done.await();
611 >                    await(done);
612                  }});
613 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
613 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
614              assertFalse(p.isTerminating());
615              done.countDown();
616              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 624 | Line 636 | public class ThreadPoolExecutorSubclassT
636                  public void realRun() throws InterruptedException {
637                      assertFalse(p.isTerminating());
638                      threadStarted.countDown();
639 <                    done.await();
639 >                    await(done);
640                  }});
641 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
641 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
642              assertFalse(p.isTerminating());
643              done.countDown();
644              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 654 | Line 666 | public class ThreadPoolExecutorSubclassT
666                      public Boolean realCall() throws InterruptedException {
667                          threadStarted.countDown();
668                          assertSame(q, p.getQueue());
669 <                        done.await();
669 >                        await(done);
670                          return Boolean.TRUE;
671                      }};
672                  tasks[i] = new FutureTask(task);
673                  p.execute(tasks[i]);
674              }
675 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
675 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
676              assertSame(q, p.getQueue());
677              assertFalse(q.contains(tasks[0]));
678              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 686 | Line 698 | public class ThreadPoolExecutorSubclassT
698                  tasks[i] = new CheckedRunnable() {
699                      public void realRun() throws InterruptedException {
700                          threadStarted.countDown();
701 <                        done.await();
701 >                        await(done);
702                      }};
703                  p.execute(tasks[i]);
704              }
705 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
705 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
706              assertFalse(p.remove(tasks[0]));
707              assertTrue(q.contains(tasks[4]));
708              assertTrue(q.contains(tasks[3]));
# Line 715 | Line 727 | public class ThreadPoolExecutorSubclassT
727              new CustomTPE(1, 1,
728                            LONG_DELAY_MS, MILLISECONDS,
729                            q);
730 <        try (PoolCleaner cleaner = cleaner(p)) {
730 >        try (PoolCleaner cleaner = cleaner(p, done)) {
731              FutureTask[] tasks = new FutureTask[5];
732              for (int i = 0; i < tasks.length; i++) {
733                  Callable task = new CheckedCallable<Boolean>() {
734                      public Boolean realCall() throws InterruptedException {
735                          threadStarted.countDown();
736 <                        done.await();
736 >                        await(done);
737                          return Boolean.TRUE;
738                      }};
739                  tasks[i] = new FutureTask(task);
740                  p.execute(tasks[i]);
741              }
742 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
742 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
743              assertEquals(tasks.length, p.getTaskCount());
744              assertEquals(tasks.length - 1, q.size());
745              assertEquals(1L, p.getActiveCount());
# Line 740 | Line 752 | public class ThreadPoolExecutorSubclassT
752              p.purge();         // Nothing to do
753              assertEquals(tasks.length - 3, q.size());
754              assertEquals(tasks.length - 2, p.getTaskCount());
743            done.countDown();
755          }
756      }
757  
# Line 766 | Line 777 | public class ThreadPoolExecutorSubclassT
777          }};
778          for (int i = 0; i < count; i++)
779              p.execute(waiter);
780 <        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
780 >        await(threadsStarted);
781          assertEquals(poolSize, p.getActiveCount());
782          assertEquals(0, p.getCompletedTaskCount());
783          final List<Runnable> queuedTasks;
# Line 1133 | Line 1144 | public class ThreadPoolExecutorSubclassT
1144              final CountDownLatch done = new CountDownLatch(1);
1145              Runnable task = new CheckedRunnable() {
1146                  public void realRun() throws InterruptedException {
1147 <                    done.await();
1147 >                    await(done);
1148                  }};
1149              for (int i = 0; i < 2; ++i)
1150                  p.execute(task);
# Line 1161 | Line 1172 | public class ThreadPoolExecutorSubclassT
1172              final CountDownLatch done = new CountDownLatch(1);
1173              Runnable blocker = new CheckedRunnable() {
1174                  public void realRun() throws InterruptedException {
1175 <                    done.await();
1175 >                    await(done);
1176                  }};
1177              p.execute(blocker);
1178              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
# Line 1829 | Line 1840 | public class ThreadPoolExecutorSubclassT
1840              List<Callable<String>> l = new ArrayList<Callable<String>>();
1841              l.add(new NPETask());
1842              List<Future<String>> futures =
1843 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1843 >                e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
1844              assertEquals(1, futures.size());
1845              try {
1846                  futures.get(0).get();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines