1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
8 |
|
import java.util.concurrent.CancellationException; |
9 |
|
import java.util.concurrent.ExecutionException; |
10 |
|
import java.util.concurrent.ForkJoinPool; |
11 |
< |
import java.util.concurrent.ForkJoinWorkerThread; |
11 |
> |
import java.util.concurrent.ForkJoinTask; |
12 |
|
import java.util.concurrent.RecursiveTask; |
13 |
– |
import java.util.concurrent.TimeUnit; |
13 |
|
import java.util.concurrent.TimeoutException; |
14 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
15 |
|
import java.util.HashSet; |
58 |
|
assertNull(a.getException()); |
59 |
|
assertNull(a.getRawResult()); |
60 |
|
|
61 |
< |
if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) { |
61 |
> |
if (! ForkJoinTask.inForkJoinPool()) { |
62 |
|
Thread.currentThread().interrupt(); |
63 |
|
try { |
64 |
|
a.get(); |
151 |
|
assertFalse(a.isCancelled()); |
152 |
|
assertFalse(a.isCompletedNormally()); |
153 |
|
assertTrue(a.isCompletedAbnormally()); |
154 |
< |
assertSame(t, a.getException()); |
154 |
> |
assertSame(t.getClass(), a.getException().getClass()); |
155 |
|
assertNull(a.getRawResult()); |
156 |
|
assertFalse(a.cancel(false)); |
157 |
|
assertFalse(a.cancel(true)); |
160 |
|
a.join(); |
161 |
|
shouldThrow(); |
162 |
|
} catch (Throwable expected) { |
163 |
< |
assertSame(t, expected); |
163 |
> |
assertSame(t.getClass(), expected.getClass()); |
164 |
|
} |
165 |
|
|
166 |
|
try { |
167 |
|
a.get(); |
168 |
|
shouldThrow(); |
169 |
|
} catch (ExecutionException success) { |
170 |
< |
assertSame(t, success.getCause()); |
170 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
171 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
172 |
|
|
173 |
|
try { |
174 |
|
a.get(5L, SECONDS); |
175 |
|
shouldThrow(); |
176 |
|
} catch (ExecutionException success) { |
177 |
< |
assertSame(t, success.getCause()); |
177 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
178 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
179 |
|
} |
180 |
|
|
181 |
< |
static final class FJException extends RuntimeException { |
182 |
< |
FJException() { super(); } |
181 |
> |
public static final class FJException extends RuntimeException { |
182 |
> |
public FJException() { super(); } |
183 |
|
} |
184 |
|
|
185 |
|
// An invalid return value for Fib |
317 |
|
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
318 |
|
} |
319 |
|
|
321 |
– |
|
320 |
|
/** |
321 |
|
* helpQuiesce returns when tasks are complete. |
322 |
|
* getQueuedTaskCount returns 0 when quiescent |
326 |
|
public Integer realCompute() { |
327 |
|
FibTask f = new FibTask(8); |
328 |
|
assertSame(f, f.fork()); |
329 |
< |
f.helpQuiesce(); |
329 |
> |
helpQuiesce(); |
330 |
|
assertEquals(0, getQueuedTaskCount()); |
331 |
|
checkCompletedNormally(f, 21); |
332 |
|
return NoResult; |
334 |
|
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
335 |
|
} |
336 |
|
|
339 |
– |
|
337 |
|
/** |
338 |
|
* invoke task throws exception when task completes abnormally |
339 |
|
*/ |
599 |
|
return NoResult; |
600 |
|
} |
601 |
|
}; |
602 |
< |
a.invoke(); |
602 |
> |
assertSame(NoResult, a.invoke()); |
603 |
|
} |
604 |
|
|
605 |
|
/** |
759 |
|
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
760 |
|
} |
761 |
|
|
765 |
– |
|
762 |
|
/** |
763 |
|
* invokeAll(tasks) with any null task throws NPE |
764 |
|
*/ |