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.46 by jsr166, Sun May 29 13:55:36 2011 UTC vs.
Revision 1.49 by jsr166, Wed Sep 25 07:39:17 2013 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 + import junit.framework.*;
10   import java.util.concurrent.*;
11   import static java.util.concurrent.TimeUnit.MILLISECONDS;
12 < import java.util.concurrent.atomic.*;
12 < import junit.framework.*;
12 > import static java.util.concurrent.TimeUnit.NANOSECONDS;
13   import java.util.*;
14  
15   public class ThreadPoolExecutorTest extends JSR166TestCase {
# Line 402 | Line 402 | public class ThreadPoolExecutorTest exte
402      }
403  
404      /**
405 +     * awaitTermination on a non-shutdown pool times out
406 +     */
407 +    public void testAwaitTermination_timesOut() throws InterruptedException {
408 +        final ThreadPoolExecutor p =
409 +            new ThreadPoolExecutor(1, 1,
410 +                                   LONG_DELAY_MS, MILLISECONDS,
411 +                                   new ArrayBlockingQueue<Runnable>(10));
412 +        assertFalse(p.isTerminated());
413 +        assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
414 +        assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
415 +        assertFalse(p.awaitTermination(-1L, NANOSECONDS));
416 +        assertFalse(p.awaitTermination(-1L, MILLISECONDS));
417 +        assertFalse(p.awaitTermination(0L, NANOSECONDS));
418 +        assertFalse(p.awaitTermination(0L, MILLISECONDS));
419 +        long timeoutNanos = 999999L;
420 +        long startTime = System.nanoTime();
421 +        assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
422 +        assertTrue(System.nanoTime() - startTime >= timeoutNanos);
423 +        assertFalse(p.isTerminated());
424 +        startTime = System.nanoTime();
425 +        long timeoutMillis = timeoutMillis();
426 +        assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
427 +        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
428 +        assertFalse(p.isTerminated());
429 +        p.shutdown();
430 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
431 +        assertTrue(p.isTerminated());
432 +    }
433 +
434 +    /**
435       * isTerminated is false before termination, true after
436       */
437      public void testIsTerminated() throws InterruptedException {
# Line 1345 | Line 1375 | public class ThreadPoolExecutorTest exte
1375          ExtendedTPE p = new ExtendedTPE();
1376          try {
1377              final CountDownLatch done = new CountDownLatch(1);
1378 <            final CheckedRunnable task = new CheckedRunnable() {
1378 >            p.execute(new CheckedRunnable() {
1379                  public void realRun() {
1380                      done.countDown();
1381 <                }};
1352 <            p.execute(task);
1381 >                }});
1382              await(p.afterCalled);
1383              assertEquals(0, done.getCount());
1384              assertTrue(p.afterCalled());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines