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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.98 by jsr166, Sun Oct 4 07:23:20 2015 UTC vs.
Revision 1.102 by jsr166, Mon Oct 5 22:09:02 2015 UTC

# Line 115 | Line 115 | public class ThreadPoolExecutorTest exte
115                      assertEquals(1, p.getActiveCount());
116                      done.await();
117                  }});
118 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
118 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
119              assertEquals(1, p.getActiveCount());
120              done.countDown();
121          }
# Line 344 | Line 344 | public class ThreadPoolExecutorTest exte
344                          done.await();
345                          assertEquals(THREADS, p.getLargestPoolSize());
346                      }});
347 <            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
347 >            assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
348              assertEquals(THREADS, p.getLargestPoolSize());
349              done.countDown();   // release pool
350          }
# Line 388 | Line 388 | public class ThreadPoolExecutorTest exte
388                      assertEquals(1, p.getPoolSize());
389                      done.await();
390                  }});
391 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
391 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
392              assertEquals(1, p.getPoolSize());
393              done.countDown();   // release pool
394          }
# Line 398 | Line 398 | public class ThreadPoolExecutorTest exte
398       * getTaskCount increases, but doesn't overestimate, when tasks submitted
399       */
400      public void testGetTaskCount() throws InterruptedException {
401 +        final int TASKS = 3;
402 +        final CountDownLatch done = new CountDownLatch(1);
403          final ThreadPoolExecutor p =
404              new ThreadPoolExecutor(1, 1,
405                                     LONG_DELAY_MS, MILLISECONDS,
406                                     new ArrayBlockingQueue<Runnable>(10));
407 <        try (PoolCleaner cleaner = cleaner(p)) {
407 >        try (PoolCleaner cleaner = cleaner(p, done)) {
408              final CountDownLatch threadStarted = new CountDownLatch(1);
407            final CountDownLatch done = new CountDownLatch(1);
409              assertEquals(0, p.getTaskCount());
410 +            assertEquals(0, p.getCompletedTaskCount());
411              p.execute(new CheckedRunnable() {
412                  public void realRun() throws InterruptedException {
413                      threadStarted.countDown();
412                    assertEquals(1, p.getTaskCount());
414                      done.await();
415                  }});
416 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
416 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
417              assertEquals(1, p.getTaskCount());
418 <            done.countDown();
418 >            assertEquals(0, p.getCompletedTaskCount());
419 >            for (int i = 0; i < TASKS; i++) {
420 >                assertEquals(1 + i, p.getTaskCount());
421 >                p.execute(new CheckedRunnable() {
422 >                    public void realRun() throws InterruptedException {
423 >                        threadStarted.countDown();
424 >                        assertEquals(1 + TASKS, p.getTaskCount());
425 >                        done.await();
426 >                    }});
427 >            }
428 >            assertEquals(1 + TASKS, p.getTaskCount());
429 >            assertEquals(0, p.getCompletedTaskCount());
430          }
431 +        assertEquals(1 + TASKS, p.getTaskCount());
432 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
433      }
434  
435      /**
# Line 483 | Line 497 | public class ThreadPoolExecutorTest exte
497                      threadStarted.countDown();
498                      done.await();
499                  }});
500 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
500 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
501              assertFalse(p.isTerminating());
502              done.countDown();
503              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 511 | Line 525 | public class ThreadPoolExecutorTest exte
525                      threadStarted.countDown();
526                      done.await();
527                  }});
528 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
528 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
529              assertFalse(p.isTerminating());
530              done.countDown();
531              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 545 | Line 559 | public class ThreadPoolExecutorTest exte
559                  tasks[i] = new FutureTask(task);
560                  p.execute(tasks[i]);
561              }
562 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
562 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
563              assertSame(q, p.getQueue());
564              assertFalse(q.contains(tasks[0]));
565              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 575 | Line 589 | public class ThreadPoolExecutorTest exte
589                      }};
590                  p.execute(tasks[i]);
591              }
592 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
592 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
593              assertFalse(p.remove(tasks[0]));
594              assertTrue(q.contains(tasks[4]));
595              assertTrue(q.contains(tasks[3]));
# Line 600 | Line 614 | public class ThreadPoolExecutorTest exte
614              new ThreadPoolExecutor(1, 1,
615                                     LONG_DELAY_MS, MILLISECONDS,
616                                     q);
617 <        try (PoolCleaner cleaner = cleaner(p)) {
617 >        try (PoolCleaner cleaner = cleaner(p, done)) {
618              FutureTask[] tasks = new FutureTask[5];
619              for (int i = 0; i < tasks.length; i++) {
620                  Callable task = new CheckedCallable<Boolean>() {
# Line 612 | Line 626 | public class ThreadPoolExecutorTest exte
626                  tasks[i] = new FutureTask(task);
627                  p.execute(tasks[i]);
628              }
629 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
629 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
630              assertEquals(tasks.length, p.getTaskCount());
631              assertEquals(tasks.length - 1, q.size());
632              assertEquals(1L, p.getActiveCount());
# Line 625 | Line 639 | public class ThreadPoolExecutorTest exte
639              p.purge();         // Nothing to do
640              assertEquals(tasks.length - 3, q.size());
641              assertEquals(tasks.length - 2, p.getTaskCount());
628            done.countDown();
642          }
643      }
644  
# Line 641 | Line 654 | public class ThreadPoolExecutorTest exte
654              new ThreadPoolExecutor(poolSize, poolSize,
655                                     LONG_DELAY_MS, MILLISECONDS,
656                                     new ArrayBlockingQueue<Runnable>(10));
657 <        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
657 >        final CountDownLatch threadsStarted = new CountDownLatch(poolSize);
658          Runnable waiter = new CheckedRunnable() { public void realRun() {
659              threadsStarted.countDown();
660              try {
# Line 1032 | Line 1045 | public class ThreadPoolExecutorTest exte
1045                      p.submit(task).get();
1046                  }});
1047  
1048 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
1048 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
1049              t.interrupt();
1050              awaitTermination(t, MEDIUM_DELAY_MS);
1051              done.countDown();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines