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.ForkJoinTask; |
12 |
|
import java.util.concurrent.ForkJoinWorkerThread; |
13 |
|
import java.util.concurrent.RecursiveTask; |
14 |
|
import java.util.concurrent.TimeUnit; |
60 |
|
assertNull(a.getException()); |
61 |
|
assertNull(a.getRawResult()); |
62 |
|
|
63 |
< |
if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) { |
63 |
> |
if (! ForkJoinTask.inForkJoinPool()) { |
64 |
|
Thread.currentThread().interrupt(); |
65 |
|
try { |
66 |
|
a.get(); |
91 |
|
assertNull(a.getException()); |
92 |
|
assertSame(expected, a.getRawResult()); |
93 |
|
assertSame(expected, a.join()); |
94 |
+ |
assertFalse(a.cancel(false)); |
95 |
+ |
assertFalse(a.cancel(true)); |
96 |
|
try { |
97 |
|
assertSame(expected, a.get()); |
98 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
153 |
|
assertFalse(a.isCancelled()); |
154 |
|
assertFalse(a.isCompletedNormally()); |
155 |
|
assertTrue(a.isCompletedAbnormally()); |
156 |
< |
assertSame(t, a.getException()); |
156 |
> |
assertSame(t.getClass(), a.getException().getClass()); |
157 |
|
assertNull(a.getRawResult()); |
158 |
+ |
assertFalse(a.cancel(false)); |
159 |
+ |
assertFalse(a.cancel(true)); |
160 |
|
|
161 |
|
try { |
162 |
|
a.join(); |
163 |
|
shouldThrow(); |
164 |
|
} catch (Throwable expected) { |
165 |
< |
assertSame(t, expected); |
165 |
> |
assertSame(t.getClass(), expected.getClass()); |
166 |
|
} |
167 |
|
|
168 |
|
try { |
169 |
|
a.get(); |
170 |
|
shouldThrow(); |
171 |
|
} catch (ExecutionException success) { |
172 |
< |
assertSame(t, success.getCause()); |
172 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
173 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
174 |
|
|
175 |
|
try { |
176 |
|
a.get(5L, SECONDS); |
177 |
|
shouldThrow(); |
178 |
|
} catch (ExecutionException success) { |
179 |
< |
assertSame(t, success.getCause()); |
179 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
180 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
181 |
|
} |
182 |
|
|
183 |
< |
static final class FJException extends RuntimeException { |
184 |
< |
FJException() { super(); } |
183 |
> |
public static final class FJException extends RuntimeException { |
184 |
> |
public FJException() { super(); } |
185 |
|
} |
186 |
|
|
187 |
|
// An invalid return value for Fib |
329 |
|
public Integer realCompute() { |
330 |
|
FibTask f = new FibTask(8); |
331 |
|
assertSame(f, f.fork()); |
332 |
< |
f.helpQuiesce(); |
332 |
> |
helpQuiesce(); |
333 |
|
assertEquals(0, getQueuedTaskCount()); |
334 |
|
checkCompletedNormally(f, 21); |
335 |
|
return NoResult; |
603 |
|
return NoResult; |
604 |
|
} |
605 |
|
}; |
606 |
< |
a.invoke(); |
606 |
> |
assertSame(NoResult, a.invoke()); |
607 |
|
} |
608 |
|
|
609 |
|
/** |