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.*; |
7 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
8 |
> |
|
9 |
> |
import java.util.HashSet; |
10 |
|
import java.util.concurrent.CancellationException; |
11 |
|
import java.util.concurrent.ExecutionException; |
12 |
|
import java.util.concurrent.ForkJoinPool; |
13 |
|
import java.util.concurrent.ForkJoinTask; |
12 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
14 |
|
import java.util.concurrent.RecursiveTask; |
14 |
– |
import java.util.concurrent.TimeUnit; |
15 |
|
import java.util.concurrent.TimeoutException; |
16 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
17 |
< |
import java.util.HashSet; |
16 |
> |
|
17 |
> |
import junit.framework.Test; |
18 |
> |
import junit.framework.TestSuite; |
19 |
|
|
20 |
|
public class RecursiveTaskTest extends JSR166TestCase { |
21 |
|
|
154 |
|
assertFalse(a.isCancelled()); |
155 |
|
assertFalse(a.isCompletedNormally()); |
156 |
|
assertTrue(a.isCompletedAbnormally()); |
157 |
< |
assertSame(t, a.getException()); |
157 |
> |
assertSame(t.getClass(), a.getException().getClass()); |
158 |
|
assertNull(a.getRawResult()); |
159 |
|
assertFalse(a.cancel(false)); |
160 |
|
assertFalse(a.cancel(true)); |
163 |
|
a.join(); |
164 |
|
shouldThrow(); |
165 |
|
} catch (Throwable expected) { |
166 |
< |
assertSame(t, expected); |
166 |
> |
assertSame(t.getClass(), expected.getClass()); |
167 |
|
} |
168 |
|
|
169 |
|
try { |
170 |
|
a.get(); |
171 |
|
shouldThrow(); |
172 |
|
} catch (ExecutionException success) { |
173 |
< |
assertSame(t, success.getCause()); |
173 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
174 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
175 |
|
|
176 |
|
try { |
177 |
|
a.get(5L, SECONDS); |
178 |
|
shouldThrow(); |
179 |
|
} catch (ExecutionException success) { |
180 |
< |
assertSame(t, success.getCause()); |
180 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
181 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
182 |
|
} |
183 |
|
|
184 |
< |
static final class FJException extends RuntimeException { |
185 |
< |
FJException() { super(); } |
184 |
> |
public static final class FJException extends RuntimeException { |
185 |
> |
public FJException() { super(); } |
186 |
|
} |
187 |
|
|
188 |
|
// An invalid return value for Fib |
320 |
|
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
321 |
|
} |
322 |
|
|
322 |
– |
|
323 |
|
/** |
324 |
|
* helpQuiesce returns when tasks are complete. |
325 |
|
* getQueuedTaskCount returns 0 when quiescent |
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; |
337 |
|
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
338 |
|
} |
339 |
|
|
340 |
– |
|
340 |
|
/** |
341 |
|
* invoke task throws exception when task completes abnormally |
342 |
|
*/ |
762 |
|
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
763 |
|
} |
764 |
|
|
766 |
– |
|
765 |
|
/** |
766 |
|
* invokeAll(tasks) with any null task throws NPE |
767 |
|
*/ |