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 { |
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 { |