25 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
26 |
|
import java.util.concurrent.locks.ReentrantLock; |
27 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
28 |
+ |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
29 |
|
import java.security.AccessControlException; |
30 |
|
import java.security.Policy; |
31 |
|
import java.security.PrivilegedAction; |
40 |
|
return new TestSuite(ForkJoinPoolTest.class); |
41 |
|
} |
42 |
|
|
43 |
< |
/** |
43 |
> |
/* |
44 |
|
* Testing coverage notes: |
45 |
|
* |
46 |
|
* 1. shutdown and related methods are tested via super.joinPool. |
108 |
|
static final class FibTask extends RecursiveTask<Integer> { |
109 |
|
final int number; |
110 |
|
FibTask(int n) { number = n; } |
111 |
< |
public Integer compute() { |
111 |
> |
protected Integer compute() { |
112 |
|
int n = number; |
113 |
|
if (n <= 1) |
114 |
|
return n; |
136 |
|
this.locker = locker; |
137 |
|
this.lock = lock; |
138 |
|
} |
139 |
< |
public Integer compute() { |
139 |
> |
protected Integer compute() { |
140 |
|
int n; |
141 |
|
LockingFibTask f1 = null; |
142 |
|
LockingFibTask f2 = null; |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
+ |
* awaitTermination on a non-shutdown pool times out |
231 |
+ |
*/ |
232 |
+ |
public void testAwaitTermination_timesOut() throws InterruptedException { |
233 |
+ |
ForkJoinPool p = new ForkJoinPool(1); |
234 |
+ |
assertFalse(p.isTerminated()); |
235 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS)); |
236 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
237 |
+ |
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
238 |
+ |
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
239 |
+ |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
240 |
+ |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
241 |
+ |
long timeoutNanos = 999999L; |
242 |
+ |
long startTime = System.nanoTime(); |
243 |
+ |
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
244 |
+ |
assertTrue(System.nanoTime() - startTime >= timeoutNanos); |
245 |
+ |
assertFalse(p.isTerminated()); |
246 |
+ |
startTime = System.nanoTime(); |
247 |
+ |
long timeoutMillis = timeoutMillis(); |
248 |
+ |
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS)); |
249 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
250 |
+ |
assertFalse(p.isTerminated()); |
251 |
+ |
p.shutdown(); |
252 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
253 |
+ |
assertTrue(p.isTerminated()); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
/** |
257 |
|
* setUncaughtExceptionHandler changes handler for uncaught exceptions. |
258 |
|
* |
259 |
|
* Additionally tests: Overriding ForkJoinWorkerThread.onStart |
419 |
|
ExecutorService e = new ForkJoinPool(1); |
420 |
|
try { |
421 |
|
final AtomicBoolean done = new AtomicBoolean(false); |
422 |
< |
CheckedRunnable task = new CheckedRunnable() { |
422 |
> |
Future<?> future = e.submit(new CheckedRunnable() { |
423 |
|
public void realRun() { |
424 |
|
done.set(true); |
425 |
< |
}}; |
398 |
< |
Future<?> future = e.submit(task); |
425 |
> |
}}); |
426 |
|
assertNull(future.get()); |
427 |
|
assertNull(future.get(0, MILLISECONDS)); |
428 |
|
assertTrue(done.get()); |