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.100 by jsr166, Mon Oct 5 21:42:49 2015 UTC vs.
Revision 1.103 by jsr166, Mon Oct 5 22:19:00 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 329 | Line 329 | public class ThreadPoolExecutorTest exte
329       */
330      public void testGetLargestPoolSize() throws InterruptedException {
331          final int THREADS = 3;
332 +        final CountDownLatch done = new CountDownLatch(1);
333          final ThreadPoolExecutor p =
334              new ThreadPoolExecutor(THREADS, THREADS,
335                                     LONG_DELAY_MS, MILLISECONDS,
336                                     new ArrayBlockingQueue<Runnable>(10));
337 <        try (PoolCleaner cleaner = cleaner(p)) {
337 <            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
338 <            final CountDownLatch done = new CountDownLatch(1);
337 >        try (PoolCleaner cleaner = cleaner(p, done)) {
338              assertEquals(0, p.getLargestPoolSize());
339 +            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
340              for (int i = 0; i < THREADS; i++)
341                  p.execute(new CheckedRunnable() {
342                      public void realRun() throws InterruptedException {
# 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
349          }
350          assertEquals(THREADS, p.getLargestPoolSize());
351      }
# Line 374 | Line 373 | public class ThreadPoolExecutorTest exte
373       * become active
374       */
375      public void testGetPoolSize() throws InterruptedException {
376 +        final CountDownLatch done = new CountDownLatch(1);
377          final ThreadPoolExecutor p =
378              new ThreadPoolExecutor(1, 1,
379                                     LONG_DELAY_MS, MILLISECONDS,
380                                     new ArrayBlockingQueue<Runnable>(10));
381 <        try (PoolCleaner cleaner = cleaner(p)) {
382 <            final CountDownLatch threadStarted = new CountDownLatch(1);
383 <            final CountDownLatch done = new CountDownLatch(1);
381 >        try (PoolCleaner cleaner = cleaner(p, done)) {
382              assertEquals(0, p.getPoolSize());
383 +            final CountDownLatch threadStarted = new CountDownLatch(1);
384              p.execute(new CheckedRunnable() {
385                  public void realRun() throws InterruptedException {
386                      threadStarted.countDown();
387                      assertEquals(1, p.getPoolSize());
388                      done.await();
389                  }});
390 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
390 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
391              assertEquals(1, p.getPoolSize());
393            done.countDown();   // release pool
392          }
393      }
394  
# Line 497 | Line 495 | public class ThreadPoolExecutorTest exte
495                      threadStarted.countDown();
496                      done.await();
497                  }});
498 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
498 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
499              assertFalse(p.isTerminating());
500              done.countDown();
501              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 525 | Line 523 | public class ThreadPoolExecutorTest exte
523                      threadStarted.countDown();
524                      done.await();
525                  }});
526 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
526 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
527              assertFalse(p.isTerminating());
528              done.countDown();
529              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 559 | Line 557 | public class ThreadPoolExecutorTest exte
557                  tasks[i] = new FutureTask(task);
558                  p.execute(tasks[i]);
559              }
560 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
560 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
561              assertSame(q, p.getQueue());
562              assertFalse(q.contains(tasks[0]));
563              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 589 | Line 587 | public class ThreadPoolExecutorTest exte
587                      }};
588                  p.execute(tasks[i]);
589              }
590 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
590 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
591              assertFalse(p.remove(tasks[0]));
592              assertTrue(q.contains(tasks[4]));
593              assertTrue(q.contains(tasks[3]));
# Line 614 | Line 612 | public class ThreadPoolExecutorTest exte
612              new ThreadPoolExecutor(1, 1,
613                                     LONG_DELAY_MS, MILLISECONDS,
614                                     q);
615 <        try (PoolCleaner cleaner = cleaner(p)) {
615 >        try (PoolCleaner cleaner = cleaner(p, done)) {
616              FutureTask[] tasks = new FutureTask[5];
617              for (int i = 0; i < tasks.length; i++) {
618                  Callable task = new CheckedCallable<Boolean>() {
# Line 626 | Line 624 | public class ThreadPoolExecutorTest exte
624                  tasks[i] = new FutureTask(task);
625                  p.execute(tasks[i]);
626              }
627 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
627 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
628              assertEquals(tasks.length, p.getTaskCount());
629              assertEquals(tasks.length - 1, q.size());
630              assertEquals(1L, p.getActiveCount());
# Line 639 | Line 637 | public class ThreadPoolExecutorTest exte
637              p.purge();         // Nothing to do
638              assertEquals(tasks.length - 3, q.size());
639              assertEquals(tasks.length - 2, p.getTaskCount());
642            done.countDown();
640          }
641      }
642  
# Line 1046 | Line 1043 | public class ThreadPoolExecutorTest exte
1043                      p.submit(task).get();
1044                  }});
1045  
1046 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
1046 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
1047              t.interrupt();
1048              awaitTermination(t, MEDIUM_DELAY_MS);
1049              done.countDown();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines