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.82 by jsr166, Sun Oct 4 07:23:20 2015 UTC vs.
Revision 1.86 by jsr166, Mon Oct 5 22:09:02 2015 UTC

# Line 262 | Line 262 | public class ThreadPoolExecutorSubclassT
262                      assertEquals(1, p.getActiveCount());
263                      done.await();
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 491 | Line 491 | public class ThreadPoolExecutorSubclassT
491                          done.await();
492                          assertEquals(THREADS, p.getLargestPoolSize());
493                      }});
494 <            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
494 >            assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
495              assertEquals(THREADS, p.getLargestPoolSize());
496              done.countDown();   // release pool
497          }
# Line 535 | Line 535 | public class ThreadPoolExecutorSubclassT
535                      assertEquals(1, p.getPoolSize());
536                      done.await();
537                  }});
538 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
538 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
539              assertEquals(1, p.getPoolSize());
540              done.countDown();   // release pool
541          }
# Line 545 | Line 545 | public class ThreadPoolExecutorSubclassT
545       * getTaskCount increases, but doesn't overestimate, when tasks submitted
546       */
547      public void testGetTaskCount() throws InterruptedException {
548 +        final int TASKS = 3;
549 +        final CountDownLatch done = new CountDownLatch(1);
550          final ThreadPoolExecutor p =
551              new CustomTPE(1, 1,
552                            LONG_DELAY_MS, MILLISECONDS,
553                            new ArrayBlockingQueue<Runnable>(10));
554 <        try (PoolCleaner cleaner = cleaner(p)) {
554 >        try (PoolCleaner cleaner = cleaner(p, done)) {
555              final CountDownLatch threadStarted = new CountDownLatch(1);
554            final CountDownLatch done = new CountDownLatch(1);
556              assertEquals(0, p.getTaskCount());
557 +            assertEquals(0, p.getCompletedTaskCount());
558              p.execute(new CheckedRunnable() {
559                  public void realRun() throws InterruptedException {
560                      threadStarted.countDown();
559                    assertEquals(1, p.getTaskCount());
561                      done.await();
562                  }});
563 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
563 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
564              assertEquals(1, p.getTaskCount());
565 <            done.countDown();
565 >            assertEquals(0, p.getCompletedTaskCount());
566 >            for (int i = 0; i < TASKS; i++) {
567 >                assertEquals(1 + i, p.getTaskCount());
568 >                p.execute(new CheckedRunnable() {
569 >                    public void realRun() throws InterruptedException {
570 >                        threadStarted.countDown();
571 >                        assertEquals(1 + TASKS, p.getTaskCount());
572 >                        done.await();
573 >                    }});
574 >            }
575 >            assertEquals(1 + TASKS, p.getTaskCount());
576 >            assertEquals(0, p.getCompletedTaskCount());
577          }
578 +        assertEquals(1 + TASKS, p.getTaskCount());
579 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
580      }
581  
582      /**
# Line 598 | Line 612 | public class ThreadPoolExecutorSubclassT
612                      threadStarted.countDown();
613                      done.await();
614                  }});
615 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
615 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
616              assertFalse(p.isTerminating());
617              done.countDown();
618              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 626 | Line 640 | public class ThreadPoolExecutorSubclassT
640                      threadStarted.countDown();
641                      done.await();
642                  }});
643 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
643 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
644              assertFalse(p.isTerminating());
645              done.countDown();
646              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 660 | Line 674 | public class ThreadPoolExecutorSubclassT
674                  tasks[i] = new FutureTask(task);
675                  p.execute(tasks[i]);
676              }
677 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
677 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
678              assertSame(q, p.getQueue());
679              assertFalse(q.contains(tasks[0]));
680              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 690 | Line 704 | public class ThreadPoolExecutorSubclassT
704                      }};
705                  p.execute(tasks[i]);
706              }
707 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
707 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
708              assertFalse(p.remove(tasks[0]));
709              assertTrue(q.contains(tasks[4]));
710              assertTrue(q.contains(tasks[3]));
# Line 715 | Line 729 | public class ThreadPoolExecutorSubclassT
729              new CustomTPE(1, 1,
730                            LONG_DELAY_MS, MILLISECONDS,
731                            q);
732 <        try (PoolCleaner cleaner = cleaner(p)) {
732 >        try (PoolCleaner cleaner = cleaner(p, done)) {
733              FutureTask[] tasks = new FutureTask[5];
734              for (int i = 0; i < tasks.length; i++) {
735                  Callable task = new CheckedCallable<Boolean>() {
# Line 727 | Line 741 | public class ThreadPoolExecutorSubclassT
741                  tasks[i] = new FutureTask(task);
742                  p.execute(tasks[i]);
743              }
744 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
744 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
745              assertEquals(tasks.length, p.getTaskCount());
746              assertEquals(tasks.length - 1, q.size());
747              assertEquals(1L, p.getActiveCount());
# Line 740 | Line 754 | public class ThreadPoolExecutorSubclassT
754              p.purge();         // Nothing to do
755              assertEquals(tasks.length - 3, q.size());
756              assertEquals(tasks.length - 2, p.getTaskCount());
743            done.countDown();
757          }
758      }
759  
# Line 756 | Line 769 | public class ThreadPoolExecutorSubclassT
769              new CustomTPE(poolSize, poolSize,
770                            LONG_DELAY_MS, MILLISECONDS,
771                            new ArrayBlockingQueue<Runnable>(10));
772 <        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
772 >        final CountDownLatch threadsStarted = new CountDownLatch(poolSize);
773          Runnable waiter = new CheckedRunnable() { public void realRun() {
774              threadsStarted.countDown();
775              try {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines