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 |
– |
import junit.framework.*; |
7 |
– |
import java.util.concurrent.*; |
8 |
– |
import java.util.*; |
6 |
|
|
7 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
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; |
14 |
+ |
import java.util.concurrent.RecursiveTask; |
15 |
+ |
import java.util.concurrent.TimeoutException; |
16 |
+ |
|
17 |
+ |
import junit.framework.Test; |
18 |
+ |
import junit.framework.TestSuite; |
19 |
|
|
20 |
|
public class RecursiveTaskTest extends JSR166TestCase { |
21 |
|
|
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run (suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
public static Test suite() { |
26 |
< |
return new TestSuite(RecursiveTaskTest.class); |
26 |
> |
return new TestSuite(RecursiveTaskTest.class); |
27 |
> |
} |
28 |
> |
|
29 |
> |
private static ForkJoinPool mainPool() { |
30 |
> |
return new ForkJoinPool(); |
31 |
|
} |
32 |
|
|
33 |
< |
static final ForkJoinPool mainPool = new ForkJoinPool(); |
34 |
< |
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
22 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
23 |
< |
static { |
24 |
< |
asyncSingletonPool.setAsyncMode(true); |
33 |
> |
private static ForkJoinPool singletonPool() { |
34 |
> |
return new ForkJoinPool(1); |
35 |
|
} |
36 |
|
|
37 |
< |
static final class FJException extends RuntimeException { |
38 |
< |
FJException() { super(); } |
37 |
> |
private static ForkJoinPool asyncSingletonPool() { |
38 |
> |
return new ForkJoinPool(1, |
39 |
> |
ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
40 |
> |
null, true); |
41 |
> |
} |
42 |
> |
|
43 |
> |
private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) { |
44 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
45 |
> |
checkNotDone(a); |
46 |
> |
|
47 |
> |
T result = pool.invoke(a); |
48 |
> |
|
49 |
> |
checkCompletedNormally(a, result); |
50 |
> |
return result; |
51 |
> |
} |
52 |
|
} |
53 |
|
|
54 |
< |
// An invalid return value for Fib |
54 |
> |
void checkNotDone(RecursiveTask<?> a) { |
55 |
> |
assertFalse(a.isDone()); |
56 |
> |
assertFalse(a.isCompletedNormally()); |
57 |
> |
assertFalse(a.isCompletedAbnormally()); |
58 |
> |
assertFalse(a.isCancelled()); |
59 |
> |
assertNull(a.getException()); |
60 |
> |
assertNull(a.getRawResult()); |
61 |
> |
|
62 |
> |
if (! ForkJoinTask.inForkJoinPool()) { |
63 |
> |
Thread.currentThread().interrupt(); |
64 |
> |
try { |
65 |
> |
a.get(); |
66 |
> |
shouldThrow(); |
67 |
> |
} catch (InterruptedException success) { |
68 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
69 |
> |
|
70 |
> |
Thread.currentThread().interrupt(); |
71 |
> |
try { |
72 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
73 |
> |
shouldThrow(); |
74 |
> |
} catch (InterruptedException success) { |
75 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
76 |
> |
} |
77 |
> |
|
78 |
> |
try { |
79 |
> |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
80 |
> |
shouldThrow(); |
81 |
> |
} catch (TimeoutException success) { |
82 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
83 |
> |
} |
84 |
> |
|
85 |
> |
<T> void checkCompletedNormally(RecursiveTask<T> a, T expectedValue) { |
86 |
> |
assertTrue(a.isDone()); |
87 |
> |
assertFalse(a.isCancelled()); |
88 |
> |
assertTrue(a.isCompletedNormally()); |
89 |
> |
assertFalse(a.isCompletedAbnormally()); |
90 |
> |
assertNull(a.getException()); |
91 |
> |
assertSame(expectedValue, a.getRawResult()); |
92 |
> |
assertSame(expectedValue, a.join()); |
93 |
> |
assertFalse(a.cancel(false)); |
94 |
> |
assertFalse(a.cancel(true)); |
95 |
> |
|
96 |
> |
T v1 = null, v2 = null; |
97 |
> |
try { |
98 |
> |
v1 = a.get(); |
99 |
> |
v2 = a.get(randomTimeout(), randomTimeUnit()); |
100 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
101 |
> |
assertSame(expectedValue, v1); |
102 |
> |
assertSame(expectedValue, v2); |
103 |
> |
} |
104 |
> |
|
105 |
> |
/** |
106 |
> |
* Waits for the task to complete, and checks that when it does, |
107 |
> |
* it will have an Integer result equals to the given int. |
108 |
> |
*/ |
109 |
> |
void checkCompletesNormally(RecursiveTask<Integer> a, int expectedValue) { |
110 |
> |
Integer r = a.join(); |
111 |
> |
assertEquals(expectedValue, (int) r); |
112 |
> |
checkCompletedNormally(a, r); |
113 |
> |
} |
114 |
> |
|
115 |
> |
/** |
116 |
> |
* Like checkCompletesNormally, but verifies that the task has |
117 |
> |
* already completed. |
118 |
> |
*/ |
119 |
> |
void checkCompletedNormally(RecursiveTask<Integer> a, int expectedValue) { |
120 |
> |
Integer r = a.getRawResult(); |
121 |
> |
assertEquals(expectedValue, (int) r); |
122 |
> |
checkCompletedNormally(a, r); |
123 |
> |
} |
124 |
> |
|
125 |
> |
void checkCancelled(RecursiveTask<?> a) { |
126 |
> |
assertTrue(a.isDone()); |
127 |
> |
assertTrue(a.isCancelled()); |
128 |
> |
assertFalse(a.isCompletedNormally()); |
129 |
> |
assertTrue(a.isCompletedAbnormally()); |
130 |
> |
assertTrue(a.getException() instanceof CancellationException); |
131 |
> |
assertNull(a.getRawResult()); |
132 |
> |
|
133 |
> |
try { |
134 |
> |
a.join(); |
135 |
> |
shouldThrow(); |
136 |
> |
} catch (CancellationException success) { |
137 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
138 |
> |
|
139 |
> |
try { |
140 |
> |
a.get(); |
141 |
> |
shouldThrow(); |
142 |
> |
} catch (CancellationException success) { |
143 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
144 |
> |
|
145 |
> |
try { |
146 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
147 |
> |
shouldThrow(); |
148 |
> |
} catch (CancellationException success) { |
149 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
150 |
> |
} |
151 |
> |
|
152 |
> |
void checkCompletedAbnormally(RecursiveTask<?> a, Throwable t) { |
153 |
> |
assertTrue(a.isDone()); |
154 |
> |
assertFalse(a.isCancelled()); |
155 |
> |
assertFalse(a.isCompletedNormally()); |
156 |
> |
assertTrue(a.isCompletedAbnormally()); |
157 |
> |
assertSame(t.getClass(), a.getException().getClass()); |
158 |
> |
assertNull(a.getRawResult()); |
159 |
> |
assertFalse(a.cancel(false)); |
160 |
> |
assertFalse(a.cancel(true)); |
161 |
> |
|
162 |
> |
try { |
163 |
> |
a.join(); |
164 |
> |
shouldThrow(); |
165 |
> |
} catch (Throwable expected) { |
166 |
> |
assertSame(t.getClass(), expected.getClass()); |
167 |
> |
} |
168 |
> |
|
169 |
> |
try { |
170 |
> |
a.get(); |
171 |
> |
shouldThrow(); |
172 |
> |
} catch (ExecutionException success) { |
173 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
174 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
175 |
> |
|
176 |
> |
try { |
177 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
178 |
> |
shouldThrow(); |
179 |
> |
} catch (ExecutionException success) { |
180 |
> |
assertSame(t.getClass(), success.getCause().getClass()); |
181 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
182 |
> |
} |
183 |
> |
|
184 |
> |
public static final class FJException extends RuntimeException { |
185 |
> |
public FJException() { super(); } |
186 |
> |
} |
187 |
> |
|
188 |
> |
/** An invalid return value for Fib. */ |
189 |
|
static final Integer NoResult = Integer.valueOf(-17); |
190 |
|
|
191 |
< |
// A simple recursive task for testing |
192 |
< |
static final class FibTask extends RecursiveTask<Integer> { |
191 |
> |
/** A simple recursive task for testing. */ |
192 |
> |
final class FibTask extends CheckedRecursiveTask<Integer> { |
193 |
|
final int number; |
194 |
|
FibTask(int n) { number = n; } |
195 |
< |
public Integer compute() { |
195 |
> |
public Integer realCompute() { |
196 |
|
int n = number; |
197 |
|
if (n <= 1) |
198 |
|
return n; |
199 |
|
FibTask f1 = new FibTask(n - 1); |
200 |
|
f1.fork(); |
201 |
< |
return (new FibTask(n - 2)).compute() + f1.join(); |
201 |
> |
return new FibTask(n - 2).compute() + f1.join(); |
202 |
> |
} |
203 |
> |
|
204 |
> |
public void publicSetRawResult(Integer result) { |
205 |
> |
setRawResult(result); |
206 |
|
} |
207 |
|
} |
208 |
|
|
209 |
< |
// A recursive action failing in base case |
210 |
< |
static final class FailingFibTask extends RecursiveTask<Integer> { |
209 |
> |
/** A recursive action failing in base case. */ |
210 |
> |
final class FailingFibTask extends RecursiveTask<Integer> { |
211 |
|
final int number; |
212 |
|
int result; |
213 |
|
FailingFibTask(int n) { number = n; } |
217 |
|
throw new FJException(); |
218 |
|
FailingFibTask f1 = new FailingFibTask(n - 1); |
219 |
|
f1.fork(); |
220 |
< |
return (new FibTask(n - 2)).compute() + f1.join(); |
220 |
> |
return new FibTask(n - 2).compute() + f1.join(); |
221 |
|
} |
222 |
|
} |
223 |
|
|
226 |
|
* isCompletedAbnormally and isCancelled return false for normally |
227 |
|
* completed tasks. getRawResult of a completed non-null task |
228 |
|
* returns value; |
68 |
– |
* |
229 |
|
*/ |
230 |
|
public void testInvoke() { |
231 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
232 |
< |
public Integer compute() { |
231 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
232 |
> |
public Integer realCompute() { |
233 |
|
FibTask f = new FibTask(8); |
234 |
|
Integer r = f.invoke(); |
235 |
< |
threadAssertTrue(r == 21); |
236 |
< |
threadAssertTrue(f.isDone()); |
77 |
< |
threadAssertFalse(f.isCancelled()); |
78 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
79 |
< |
threadAssertTrue(f.getRawResult() == 21); |
235 |
> |
assertEquals(21, (int) r); |
236 |
> |
checkCompletedNormally(f, r); |
237 |
|
return r; |
238 |
< |
} |
239 |
< |
}; |
83 |
< |
assertTrue(mainPool.invoke(a) == 21); |
238 |
> |
}}; |
239 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
240 |
|
} |
241 |
|
|
242 |
|
/** |
245 |
|
* completed tasks |
246 |
|
*/ |
247 |
|
public void testQuietlyInvoke() { |
248 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
249 |
< |
public Integer compute() { |
248 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
249 |
> |
public Integer realCompute() { |
250 |
|
FibTask f = new FibTask(8); |
251 |
|
f.quietlyInvoke(); |
252 |
< |
Integer r = f.getRawResult(); |
253 |
< |
threadAssertTrue(r == 21); |
254 |
< |
threadAssertTrue(f.isDone()); |
255 |
< |
threadAssertFalse(f.isCancelled()); |
100 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
101 |
< |
return r; |
102 |
< |
} |
103 |
< |
}; |
104 |
< |
assertTrue(mainPool.invoke(a) == 21); |
252 |
> |
checkCompletedNormally(f, 21); |
253 |
> |
return NoResult; |
254 |
> |
}}; |
255 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
256 |
|
} |
257 |
|
|
258 |
|
/** |
259 |
|
* join of a forked task returns when task completes |
260 |
|
*/ |
261 |
|
public void testForkJoin() { |
262 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
263 |
< |
public Integer compute() { |
262 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
263 |
> |
public Integer realCompute() { |
264 |
|
FibTask f = new FibTask(8); |
265 |
< |
f.fork(); |
265 |
> |
assertSame(f, f.fork()); |
266 |
|
Integer r = f.join(); |
267 |
< |
threadAssertTrue(r == 21); |
268 |
< |
threadAssertTrue(f.isDone()); |
267 |
> |
assertEquals(21, (int) r); |
268 |
> |
checkCompletedNormally(f, r); |
269 |
|
return r; |
270 |
< |
} |
271 |
< |
}; |
121 |
< |
assertTrue(mainPool.invoke(a) == 21); |
270 |
> |
}}; |
271 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
272 |
|
} |
273 |
|
|
274 |
|
/** |
275 |
|
* get of a forked task returns when task completes |
276 |
|
*/ |
277 |
|
public void testForkGet() { |
278 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
279 |
< |
public Integer compute() { |
280 |
< |
try { |
281 |
< |
FibTask f = new FibTask(8); |
282 |
< |
f.fork(); |
283 |
< |
Integer r = f.get(); |
284 |
< |
threadAssertTrue(r == 21); |
285 |
< |
threadAssertTrue(f.isDone()); |
286 |
< |
return r; |
287 |
< |
} catch (Exception ex) { |
138 |
< |
unexpectedException(ex); |
139 |
< |
} |
140 |
< |
return NoResult; |
141 |
< |
} |
142 |
< |
}; |
143 |
< |
assertTrue(mainPool.invoke(a) == 21); |
278 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
279 |
> |
public Integer realCompute() throws Exception { |
280 |
> |
FibTask f = new FibTask(8); |
281 |
> |
assertSame(f, f.fork()); |
282 |
> |
Integer r = f.get(); |
283 |
> |
assertEquals(21, (int) r); |
284 |
> |
checkCompletedNormally(f, r); |
285 |
> |
return r; |
286 |
> |
}}; |
287 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
288 |
|
} |
289 |
|
|
290 |
|
/** |
291 |
|
* timed get of a forked task returns when task completes |
292 |
|
*/ |
293 |
|
public void testForkTimedGet() { |
294 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
295 |
< |
public Integer compute() { |
152 |
< |
try { |
153 |
< |
FibTask f = new FibTask(8); |
154 |
< |
f.fork(); |
155 |
< |
Integer r = f.get(5L, TimeUnit.SECONDS); |
156 |
< |
threadAssertTrue(r == 21); |
157 |
< |
threadAssertTrue(f.isDone()); |
158 |
< |
return r; |
159 |
< |
} catch (Exception ex) { |
160 |
< |
unexpectedException(ex); |
161 |
< |
} |
162 |
< |
return NoResult; |
163 |
< |
} |
164 |
< |
}; |
165 |
< |
assertTrue(mainPool.invoke(a) == 21); |
166 |
< |
} |
167 |
< |
|
168 |
< |
/** |
169 |
< |
* helpJoin of a forked task returns when task completes |
170 |
< |
*/ |
171 |
< |
public void testForkHelpJoin() { |
172 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
173 |
< |
public Integer compute() { |
294 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
295 |
> |
public Integer realCompute() throws Exception { |
296 |
|
FibTask f = new FibTask(8); |
297 |
< |
f.fork(); |
298 |
< |
Integer r = f.helpJoin(); |
299 |
< |
threadAssertTrue(r == 21); |
300 |
< |
threadAssertTrue(f.isDone()); |
297 |
> |
assertSame(f, f.fork()); |
298 |
> |
Integer r = f.get(LONG_DELAY_MS, MILLISECONDS); |
299 |
> |
assertEquals(21, (int) r); |
300 |
> |
checkCompletedNormally(f, r); |
301 |
|
return r; |
302 |
< |
} |
303 |
< |
}; |
182 |
< |
assertTrue(mainPool.invoke(a) == 21); |
302 |
> |
}}; |
303 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
304 |
|
} |
305 |
|
|
306 |
|
/** |
307 |
|
* quietlyJoin of a forked task returns when task completes |
308 |
|
*/ |
309 |
|
public void testForkQuietlyJoin() { |
310 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
311 |
< |
public Integer compute() { |
310 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
311 |
> |
public Integer realCompute() { |
312 |
|
FibTask f = new FibTask(8); |
313 |
< |
f.fork(); |
313 |
> |
assertSame(f, f.fork()); |
314 |
|
f.quietlyJoin(); |
315 |
|
Integer r = f.getRawResult(); |
316 |
< |
threadAssertTrue(r == 21); |
317 |
< |
threadAssertTrue(f.isDone()); |
197 |
< |
return r; |
198 |
< |
} |
199 |
< |
}; |
200 |
< |
assertTrue(mainPool.invoke(a) == 21); |
201 |
< |
} |
202 |
< |
|
203 |
< |
|
204 |
< |
/** |
205 |
< |
* quietlyHelpJoin of a forked task returns when task completes |
206 |
< |
*/ |
207 |
< |
public void testForkQuietlyHelpJoin() { |
208 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
209 |
< |
public Integer compute() { |
210 |
< |
FibTask f = new FibTask(8); |
211 |
< |
f.fork(); |
212 |
< |
f.quietlyHelpJoin(); |
213 |
< |
Integer r = f.getRawResult(); |
214 |
< |
threadAssertTrue(r == 21); |
215 |
< |
threadAssertTrue(f.isDone()); |
316 |
> |
assertEquals(21, (int) r); |
317 |
> |
checkCompletedNormally(f, r); |
318 |
|
return r; |
319 |
< |
} |
320 |
< |
}; |
219 |
< |
assertTrue(mainPool.invoke(a) == 21); |
319 |
> |
}}; |
320 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
321 |
|
} |
322 |
|
|
222 |
– |
|
323 |
|
/** |
324 |
|
* helpQuiesce returns when tasks are complete. |
325 |
|
* getQueuedTaskCount returns 0 when quiescent |
326 |
|
*/ |
327 |
|
public void testForkHelpQuiesce() { |
328 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
329 |
< |
public Integer compute() { |
328 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
329 |
> |
public Integer realCompute() { |
330 |
|
FibTask f = new FibTask(8); |
331 |
< |
f.fork(); |
332 |
< |
f.helpQuiesce(); |
333 |
< |
Integer r = f.getRawResult(); |
334 |
< |
threadAssertTrue(r == 21); |
335 |
< |
threadAssertTrue(f.isDone()); |
336 |
< |
threadAssertTrue(getQueuedTaskCount() == 0); |
337 |
< |
return r; |
338 |
< |
} |
339 |
< |
}; |
240 |
< |
assertTrue(mainPool.invoke(a) == 21); |
331 |
> |
assertSame(f, f.fork()); |
332 |
> |
helpQuiesce(); |
333 |
> |
while (!f.isDone()) // wait out race |
334 |
> |
; |
335 |
> |
assertEquals(0, getQueuedTaskCount()); |
336 |
> |
checkCompletedNormally(f, 21); |
337 |
> |
return NoResult; |
338 |
> |
}}; |
339 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
340 |
|
} |
341 |
|
|
243 |
– |
|
342 |
|
/** |
343 |
|
* invoke task throws exception when task completes abnormally |
344 |
|
*/ |
345 |
|
public void testAbnormalInvoke() { |
346 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
347 |
< |
public Integer compute() { |
346 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
347 |
> |
public Integer realCompute() { |
348 |
> |
FailingFibTask f = new FailingFibTask(8); |
349 |
|
try { |
251 |
– |
FailingFibTask f = new FailingFibTask(8); |
350 |
|
f.invoke(); |
351 |
|
shouldThrow(); |
254 |
– |
return NoResult; |
352 |
|
} catch (FJException success) { |
353 |
+ |
checkCompletedAbnormally(f, success); |
354 |
|
} |
355 |
|
return NoResult; |
356 |
< |
} |
357 |
< |
}; |
260 |
< |
mainPool.invoke(a); |
356 |
> |
}}; |
357 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
358 |
|
} |
359 |
|
|
360 |
|
/** |
361 |
|
* quietlyInvoke task returns when task completes abnormally |
362 |
|
*/ |
363 |
|
public void testAbnormalQuietlyInvoke() { |
364 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
365 |
< |
public Integer compute() { |
364 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
365 |
> |
public Integer realCompute() { |
366 |
|
FailingFibTask f = new FailingFibTask(8); |
367 |
|
f.quietlyInvoke(); |
368 |
< |
threadAssertTrue(f.isDone()); |
368 |
> |
assertTrue(f.getException() instanceof FJException); |
369 |
> |
checkCompletedAbnormally(f, f.getException()); |
370 |
|
return NoResult; |
371 |
< |
} |
372 |
< |
}; |
275 |
< |
mainPool.invoke(a); |
371 |
> |
}}; |
372 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
373 |
|
} |
374 |
|
|
375 |
|
/** |
376 |
|
* join of a forked task throws exception when task completes abnormally |
377 |
|
*/ |
378 |
|
public void testAbnormalForkJoin() { |
379 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
380 |
< |
public Integer compute() { |
379 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
380 |
> |
public Integer realCompute() { |
381 |
> |
FailingFibTask f = new FailingFibTask(8); |
382 |
> |
assertSame(f, f.fork()); |
383 |
|
try { |
384 |
< |
FailingFibTask f = new FailingFibTask(8); |
286 |
< |
f.fork(); |
287 |
< |
Integer r = f.join(); |
384 |
> |
f.join(); |
385 |
|
shouldThrow(); |
289 |
– |
return r; |
386 |
|
} catch (FJException success) { |
387 |
+ |
checkCompletedAbnormally(f, success); |
388 |
|
} |
389 |
|
return NoResult; |
390 |
< |
} |
391 |
< |
}; |
295 |
< |
mainPool.invoke(a); |
390 |
> |
}}; |
391 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
392 |
|
} |
393 |
|
|
394 |
|
/** |
395 |
|
* get of a forked task throws exception when task completes abnormally |
396 |
|
*/ |
397 |
|
public void testAbnormalForkGet() { |
398 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
399 |
< |
public Integer compute() { |
398 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
399 |
> |
public Integer realCompute() throws Exception { |
400 |
> |
FailingFibTask f = new FailingFibTask(8); |
401 |
> |
assertSame(f, f.fork()); |
402 |
|
try { |
403 |
< |
FailingFibTask f = new FailingFibTask(8); |
306 |
< |
f.fork(); |
307 |
< |
Integer r = f.get(); |
403 |
> |
f.get(); |
404 |
|
shouldThrow(); |
309 |
– |
return r; |
405 |
|
} catch (ExecutionException success) { |
406 |
< |
} catch (Exception ex) { |
407 |
< |
unexpectedException(ex); |
406 |
> |
Throwable cause = success.getCause(); |
407 |
> |
assertTrue(cause instanceof FJException); |
408 |
> |
checkCompletedAbnormally(f, cause); |
409 |
|
} |
410 |
|
return NoResult; |
411 |
< |
} |
412 |
< |
}; |
317 |
< |
mainPool.invoke(a); |
411 |
> |
}}; |
412 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
413 |
|
} |
414 |
|
|
415 |
|
/** |
416 |
|
* timed get of a forked task throws exception when task completes abnormally |
417 |
|
*/ |
418 |
|
public void testAbnormalForkTimedGet() { |
419 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
420 |
< |
public Integer compute() { |
419 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
420 |
> |
public Integer realCompute() throws Exception { |
421 |
> |
FailingFibTask f = new FailingFibTask(8); |
422 |
> |
assertSame(f, f.fork()); |
423 |
|
try { |
424 |
< |
FailingFibTask f = new FailingFibTask(8); |
328 |
< |
f.fork(); |
329 |
< |
Integer r = f.get(5L, TimeUnit.SECONDS); |
424 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
425 |
|
shouldThrow(); |
331 |
– |
return r; |
426 |
|
} catch (ExecutionException success) { |
427 |
< |
} catch (Exception ex) { |
428 |
< |
unexpectedException(ex); |
429 |
< |
} |
336 |
< |
return NoResult; |
337 |
< |
} |
338 |
< |
}; |
339 |
< |
mainPool.invoke(a); |
340 |
< |
} |
341 |
< |
|
342 |
< |
/** |
343 |
< |
* join of a forked task throws exception when task completes abnormally |
344 |
< |
*/ |
345 |
< |
public void testAbnormalForkHelpJoin() { |
346 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
347 |
< |
public Integer compute() { |
348 |
< |
try { |
349 |
< |
FailingFibTask f = new FailingFibTask(8); |
350 |
< |
f.fork(); |
351 |
< |
Integer r = f.helpJoin(); |
352 |
< |
shouldThrow(); |
353 |
< |
return r; |
354 |
< |
} catch (FJException success) { |
427 |
> |
Throwable cause = success.getCause(); |
428 |
> |
assertTrue(cause instanceof FJException); |
429 |
> |
checkCompletedAbnormally(f, cause); |
430 |
|
} |
431 |
|
return NoResult; |
432 |
< |
} |
433 |
< |
}; |
359 |
< |
mainPool.invoke(a); |
360 |
< |
} |
361 |
< |
|
362 |
< |
/** |
363 |
< |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
364 |
< |
* getException of failed task returns its exception. |
365 |
< |
* isCompletedAbnormally of a failed task returns true. |
366 |
< |
* isCancelled of a failed uncancelled task returns false |
367 |
< |
*/ |
368 |
< |
public void testAbnormalForkQuietlyHelpJoin() { |
369 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
370 |
< |
public Integer compute() { |
371 |
< |
FailingFibTask f = new FailingFibTask(8); |
372 |
< |
f.fork(); |
373 |
< |
f.quietlyHelpJoin(); |
374 |
< |
threadAssertTrue(f.isDone()); |
375 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
376 |
< |
threadAssertFalse(f.isCancelled()); |
377 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
378 |
< |
return NoResult; |
379 |
< |
} |
380 |
< |
}; |
381 |
< |
mainPool.invoke(a); |
432 |
> |
}}; |
433 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
434 |
|
} |
435 |
|
|
436 |
|
/** |
437 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
438 |
|
*/ |
439 |
|
public void testAbnormalForkQuietlyJoin() { |
440 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
441 |
< |
public Integer compute() { |
440 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
441 |
> |
public Integer realCompute() { |
442 |
|
FailingFibTask f = new FailingFibTask(8); |
443 |
< |
f.fork(); |
443 |
> |
assertSame(f, f.fork()); |
444 |
|
f.quietlyJoin(); |
445 |
< |
threadAssertTrue(f.isDone()); |
446 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
395 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
445 |
> |
assertTrue(f.getException() instanceof FJException); |
446 |
> |
checkCompletedAbnormally(f, f.getException()); |
447 |
|
return NoResult; |
448 |
< |
} |
449 |
< |
}; |
399 |
< |
mainPool.invoke(a); |
448 |
> |
}}; |
449 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
450 |
|
} |
451 |
|
|
452 |
|
/** |
453 |
|
* invoke task throws exception when task cancelled |
454 |
|
*/ |
455 |
|
public void testCancelledInvoke() { |
456 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
457 |
< |
public Integer compute() { |
456 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
457 |
> |
public Integer realCompute() { |
458 |
> |
FibTask f = new FibTask(8); |
459 |
> |
assertTrue(f.cancel(true)); |
460 |
|
try { |
461 |
< |
FibTask f = new FibTask(8); |
410 |
< |
f.cancel(true); |
411 |
< |
Integer r = f.invoke(); |
461 |
> |
f.invoke(); |
462 |
|
shouldThrow(); |
413 |
– |
return r; |
463 |
|
} catch (CancellationException success) { |
464 |
+ |
checkCancelled(f); |
465 |
|
} |
466 |
|
return NoResult; |
467 |
< |
} |
468 |
< |
}; |
419 |
< |
mainPool.invoke(a); |
467 |
> |
}}; |
468 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
469 |
|
} |
470 |
|
|
471 |
|
/** |
472 |
|
* join of a forked task throws exception when task cancelled |
473 |
|
*/ |
474 |
|
public void testCancelledForkJoin() { |
475 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
476 |
< |
public Integer compute() { |
475 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
476 |
> |
public Integer realCompute() { |
477 |
> |
FibTask f = new FibTask(8); |
478 |
> |
assertTrue(f.cancel(true)); |
479 |
> |
assertSame(f, f.fork()); |
480 |
|
try { |
481 |
< |
FibTask f = new FibTask(8); |
430 |
< |
f.cancel(true); |
431 |
< |
f.fork(); |
432 |
< |
Integer r = f.join(); |
481 |
> |
f.join(); |
482 |
|
shouldThrow(); |
434 |
– |
return r; |
483 |
|
} catch (CancellationException success) { |
484 |
+ |
checkCancelled(f); |
485 |
|
} |
486 |
|
return NoResult; |
487 |
< |
} |
488 |
< |
}; |
440 |
< |
mainPool.invoke(a); |
487 |
> |
}}; |
488 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
489 |
|
} |
490 |
|
|
491 |
|
/** |
492 |
|
* get of a forked task throws exception when task cancelled |
493 |
|
*/ |
494 |
|
public void testCancelledForkGet() { |
495 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
496 |
< |
public Integer compute() { |
495 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
496 |
> |
public Integer realCompute() throws Exception { |
497 |
> |
FibTask f = new FibTask(8); |
498 |
> |
assertTrue(f.cancel(true)); |
499 |
> |
assertSame(f, f.fork()); |
500 |
|
try { |
501 |
< |
FibTask f = new FibTask(8); |
451 |
< |
f.cancel(true); |
452 |
< |
f.fork(); |
453 |
< |
Integer r = f.get(); |
501 |
> |
f.get(); |
502 |
|
shouldThrow(); |
455 |
– |
return r; |
503 |
|
} catch (CancellationException success) { |
504 |
< |
} catch (Exception ex) { |
458 |
< |
unexpectedException(ex); |
504 |
> |
checkCancelled(f); |
505 |
|
} |
506 |
|
return NoResult; |
507 |
< |
} |
508 |
< |
}; |
463 |
< |
mainPool.invoke(a); |
507 |
> |
}}; |
508 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
509 |
|
} |
510 |
|
|
511 |
|
/** |
512 |
|
* timed get of a forked task throws exception when task cancelled |
513 |
|
*/ |
514 |
|
public void testCancelledForkTimedGet() { |
515 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
516 |
< |
public Integer compute() { |
515 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
516 |
> |
public Integer realCompute() throws Exception { |
517 |
> |
FibTask f = new FibTask(8); |
518 |
> |
assertTrue(f.cancel(true)); |
519 |
> |
assertSame(f, f.fork()); |
520 |
|
try { |
521 |
< |
FibTask f = new FibTask(8); |
474 |
< |
f.cancel(true); |
475 |
< |
f.fork(); |
476 |
< |
Integer r = f.get(5L, TimeUnit.SECONDS); |
521 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
522 |
|
shouldThrow(); |
478 |
– |
return r; |
523 |
|
} catch (CancellationException success) { |
524 |
< |
} catch (Exception ex) { |
481 |
< |
unexpectedException(ex); |
524 |
> |
checkCancelled(f); |
525 |
|
} |
526 |
|
return NoResult; |
527 |
< |
} |
528 |
< |
}; |
486 |
< |
mainPool.invoke(a); |
487 |
< |
} |
488 |
< |
|
489 |
< |
/** |
490 |
< |
* join of a forked task throws exception when task cancelled |
491 |
< |
*/ |
492 |
< |
public void testCancelledForkHelpJoin() { |
493 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
494 |
< |
public Integer compute() { |
495 |
< |
try { |
496 |
< |
FibTask f = new FibTask(8); |
497 |
< |
f.cancel(true); |
498 |
< |
f.fork(); |
499 |
< |
Integer r = f.helpJoin(); |
500 |
< |
shouldThrow(); |
501 |
< |
return r; |
502 |
< |
} catch (CancellationException success) { |
503 |
< |
} |
504 |
< |
return NoResult; |
505 |
< |
} |
506 |
< |
}; |
507 |
< |
mainPool.invoke(a); |
508 |
< |
} |
509 |
< |
|
510 |
< |
/** |
511 |
< |
* quietlyHelpJoin of a forked task returns when task cancelled. |
512 |
< |
* getException of cancelled task returns its exception |
513 |
< |
* isCompletedAbnormally of a cancelled task returns true. |
514 |
< |
* isCancelled of a cancelled task returns true |
515 |
< |
*/ |
516 |
< |
public void testCancelledForkQuietlyHelpJoin() { |
517 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
518 |
< |
public Integer compute() { |
519 |
< |
FibTask f = new FibTask(8); |
520 |
< |
f.cancel(true); |
521 |
< |
f.fork(); |
522 |
< |
f.quietlyHelpJoin(); |
523 |
< |
threadAssertTrue(f.isDone()); |
524 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
525 |
< |
threadAssertTrue(f.isCancelled()); |
526 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
527 |
< |
return NoResult; |
528 |
< |
} |
529 |
< |
}; |
530 |
< |
mainPool.invoke(a); |
527 |
> |
}}; |
528 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
529 |
|
} |
530 |
|
|
531 |
|
/** |
532 |
|
* quietlyJoin of a forked task returns when task cancelled |
533 |
|
*/ |
534 |
|
public void testCancelledForkQuietlyJoin() { |
535 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
536 |
< |
public Integer compute() { |
535 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
536 |
> |
public Integer realCompute() { |
537 |
|
FibTask f = new FibTask(8); |
538 |
< |
f.cancel(true); |
539 |
< |
f.fork(); |
538 |
> |
assertTrue(f.cancel(true)); |
539 |
> |
assertSame(f, f.fork()); |
540 |
|
f.quietlyJoin(); |
541 |
< |
threadAssertTrue(f.isDone()); |
544 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
545 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
541 |
> |
checkCancelled(f); |
542 |
|
return NoResult; |
543 |
< |
} |
544 |
< |
}; |
549 |
< |
mainPool.invoke(a); |
543 |
> |
}}; |
544 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
545 |
|
} |
546 |
|
|
547 |
|
/** |
548 |
|
* getPool of executing task returns its pool |
549 |
|
*/ |
550 |
|
public void testGetPool() { |
551 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
552 |
< |
public Integer compute() { |
553 |
< |
threadAssertTrue(getPool() == mainPool); |
551 |
> |
final ForkJoinPool mainPool = mainPool(); |
552 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
553 |
> |
public Integer realCompute() { |
554 |
> |
assertSame(mainPool, getPool()); |
555 |
|
return NoResult; |
556 |
< |
} |
557 |
< |
}; |
562 |
< |
mainPool.invoke(a); |
556 |
> |
}}; |
557 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool, a)); |
558 |
|
} |
559 |
|
|
560 |
|
/** |
561 |
|
* getPool of non-FJ task returns null |
562 |
|
*/ |
563 |
|
public void testGetPool2() { |
564 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
565 |
< |
public Integer compute() { |
566 |
< |
threadAssertTrue(getPool() == null); |
564 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
565 |
> |
public Integer realCompute() { |
566 |
> |
assertNull(getPool()); |
567 |
|
return NoResult; |
568 |
< |
} |
569 |
< |
}; |
575 |
< |
a.invoke(); |
568 |
> |
}}; |
569 |
> |
assertSame(NoResult, a.invoke()); |
570 |
|
} |
571 |
|
|
572 |
|
/** |
573 |
|
* inForkJoinPool of executing task returns true |
574 |
|
*/ |
575 |
|
public void testInForkJoinPool() { |
576 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
577 |
< |
public Integer compute() { |
578 |
< |
threadAssertTrue(inForkJoinPool()); |
576 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
577 |
> |
public Integer realCompute() { |
578 |
> |
assertTrue(inForkJoinPool()); |
579 |
|
return NoResult; |
580 |
< |
} |
581 |
< |
}; |
588 |
< |
mainPool.invoke(a); |
580 |
> |
}}; |
581 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
582 |
|
} |
583 |
|
|
584 |
|
/** |
585 |
|
* inForkJoinPool of non-FJ task returns false |
586 |
|
*/ |
587 |
|
public void testInForkJoinPool2() { |
588 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
589 |
< |
public Integer compute() { |
590 |
< |
threadAssertTrue(!inForkJoinPool()); |
588 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
589 |
> |
public Integer realCompute() { |
590 |
> |
assertFalse(inForkJoinPool()); |
591 |
|
return NoResult; |
592 |
< |
} |
593 |
< |
}; |
601 |
< |
a.invoke(); |
592 |
> |
}}; |
593 |
> |
assertSame(NoResult, a.invoke()); |
594 |
|
} |
595 |
|
|
596 |
|
/** |
597 |
< |
* setRawResult(null) succeeds |
597 |
> |
* The value set by setRawResult is returned by getRawResult |
598 |
|
*/ |
599 |
|
public void testSetRawResult() { |
600 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
601 |
< |
public Integer compute() { |
600 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
601 |
> |
public Integer realCompute() { |
602 |
|
setRawResult(NoResult); |
603 |
+ |
assertSame(NoResult, getRawResult()); |
604 |
|
return NoResult; |
605 |
|
} |
606 |
|
}; |
607 |
< |
assertEquals(a.invoke(), NoResult); |
607 |
> |
assertSame(NoResult, a.invoke()); |
608 |
|
} |
609 |
|
|
610 |
|
/** |
611 |
< |
* A reinitialized task may be re-invoked |
611 |
> |
* A reinitialized normally completed task may be re-invoked |
612 |
|
*/ |
613 |
|
public void testReinitialize() { |
614 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
615 |
< |
public Integer compute() { |
614 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
615 |
> |
public Integer realCompute() { |
616 |
|
FibTask f = new FibTask(8); |
617 |
< |
Integer r = f.invoke(); |
618 |
< |
threadAssertTrue(r == 21); |
619 |
< |
threadAssertTrue(f.isDone()); |
620 |
< |
threadAssertFalse(f.isCancelled()); |
621 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
622 |
< |
f.reinitialize(); |
623 |
< |
r = f.invoke(); |
624 |
< |
threadAssertTrue(r == 21); |
617 |
> |
checkNotDone(f); |
618 |
> |
|
619 |
> |
for (int i = 0; i < 3; i++) { |
620 |
> |
Integer r = f.invoke(); |
621 |
> |
assertEquals(21, (int) r); |
622 |
> |
checkCompletedNormally(f, r); |
623 |
> |
f.reinitialize(); |
624 |
> |
f.publicSetRawResult(null); |
625 |
> |
checkNotDone(f); |
626 |
> |
} |
627 |
|
return NoResult; |
628 |
< |
} |
629 |
< |
}; |
630 |
< |
mainPool.invoke(a); |
628 |
> |
}}; |
629 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
630 |
> |
} |
631 |
> |
|
632 |
> |
/** |
633 |
> |
* A reinitialized abnormally completed task may be re-invoked |
634 |
> |
*/ |
635 |
> |
public void testReinitializeAbnormal() { |
636 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
637 |
> |
public Integer realCompute() { |
638 |
> |
FailingFibTask f = new FailingFibTask(8); |
639 |
> |
checkNotDone(f); |
640 |
> |
|
641 |
> |
for (int i = 0; i < 3; i++) { |
642 |
> |
try { |
643 |
> |
f.invoke(); |
644 |
> |
shouldThrow(); |
645 |
> |
} catch (FJException success) { |
646 |
> |
checkCompletedAbnormally(f, success); |
647 |
> |
} |
648 |
> |
f.reinitialize(); |
649 |
> |
checkNotDone(f); |
650 |
> |
} |
651 |
> |
return NoResult; |
652 |
> |
}}; |
653 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
654 |
|
} |
655 |
|
|
656 |
|
/** |
657 |
|
* invoke task throws exception after invoking completeExceptionally |
658 |
|
*/ |
659 |
|
public void testCompleteExceptionally() { |
660 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
661 |
< |
public Integer compute() { |
660 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
661 |
> |
public Integer realCompute() { |
662 |
> |
FibTask f = new FibTask(8); |
663 |
> |
f.completeExceptionally(new FJException()); |
664 |
|
try { |
665 |
< |
FibTask f = new FibTask(8); |
646 |
< |
f.completeExceptionally(new FJException()); |
647 |
< |
Integer r = f.invoke(); |
665 |
> |
f.invoke(); |
666 |
|
shouldThrow(); |
649 |
– |
return r; |
667 |
|
} catch (FJException success) { |
668 |
+ |
checkCompletedAbnormally(f, success); |
669 |
|
} |
670 |
|
return NoResult; |
671 |
< |
} |
672 |
< |
}; |
655 |
< |
mainPool.invoke(a); |
671 |
> |
}}; |
672 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
673 |
|
} |
674 |
|
|
675 |
|
/** |
676 |
|
* invoke task suppresses execution invoking complete |
677 |
|
*/ |
678 |
|
public void testComplete() { |
679 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
680 |
< |
public Integer compute() { |
679 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
680 |
> |
public Integer realCompute() { |
681 |
|
FibTask f = new FibTask(8); |
682 |
|
f.complete(NoResult); |
683 |
|
Integer r = f.invoke(); |
684 |
< |
threadAssertTrue(f.isDone()); |
685 |
< |
threadAssertTrue(r == NoResult); |
684 |
> |
assertSame(NoResult, r); |
685 |
> |
checkCompletedNormally(f, NoResult); |
686 |
|
return r; |
687 |
< |
} |
688 |
< |
}; |
672 |
< |
mainPool.invoke(a); |
687 |
> |
}}; |
688 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
689 |
|
} |
690 |
|
|
691 |
|
/** |
692 |
|
* invokeAll(t1, t2) invokes all task arguments |
693 |
|
*/ |
694 |
|
public void testInvokeAll2() { |
695 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
696 |
< |
public Integer compute() { |
695 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
696 |
> |
public Integer realCompute() { |
697 |
|
FibTask f = new FibTask(8); |
698 |
|
FibTask g = new FibTask(9); |
699 |
|
invokeAll(f, g); |
700 |
< |
threadAssertTrue(f.isDone()); |
701 |
< |
threadAssertTrue(f.join() == 21); |
686 |
< |
threadAssertTrue(g.isDone()); |
687 |
< |
threadAssertTrue(g.join() == 34); |
700 |
> |
checkCompletedNormally(f, 21); |
701 |
> |
checkCompletedNormally(g, 34); |
702 |
|
return NoResult; |
703 |
< |
} |
704 |
< |
}; |
691 |
< |
mainPool.invoke(a); |
703 |
> |
}}; |
704 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
705 |
|
} |
706 |
|
|
707 |
|
/** |
708 |
|
* invokeAll(tasks) with 1 argument invokes task |
709 |
|
*/ |
710 |
|
public void testInvokeAll1() { |
711 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
712 |
< |
public Integer compute() { |
711 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
712 |
> |
public Integer realCompute() { |
713 |
|
FibTask f = new FibTask(8); |
714 |
|
invokeAll(f); |
715 |
< |
threadAssertTrue(f.isDone()); |
703 |
< |
threadAssertTrue(f.join() == 21); |
715 |
> |
checkCompletedNormally(f, 21); |
716 |
|
return NoResult; |
717 |
< |
} |
718 |
< |
}; |
707 |
< |
mainPool.invoke(a); |
717 |
> |
}}; |
718 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
719 |
|
} |
720 |
|
|
721 |
|
/** |
722 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
723 |
|
*/ |
724 |
|
public void testInvokeAll3() { |
725 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
726 |
< |
public Integer compute() { |
725 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
726 |
> |
public Integer realCompute() { |
727 |
|
FibTask f = new FibTask(8); |
728 |
|
FibTask g = new FibTask(9); |
729 |
|
FibTask h = new FibTask(7); |
730 |
|
invokeAll(f, g, h); |
731 |
< |
threadAssertTrue(f.isDone()); |
732 |
< |
threadAssertTrue(f.join() == 21); |
733 |
< |
threadAssertTrue(g.isDone()); |
734 |
< |
threadAssertTrue(g.join() == 34); |
735 |
< |
threadAssertTrue(h.isDone()); |
736 |
< |
threadAssertTrue(h.join() == 13); |
731 |
> |
assertTrue(f.isDone()); |
732 |
> |
assertTrue(g.isDone()); |
733 |
> |
assertTrue(h.isDone()); |
734 |
> |
checkCompletedNormally(f, 21); |
735 |
> |
checkCompletedNormally(g, 34); |
736 |
> |
checkCompletedNormally(h, 13); |
737 |
|
return NoResult; |
738 |
< |
} |
739 |
< |
}; |
729 |
< |
mainPool.invoke(a); |
738 |
> |
}}; |
739 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
740 |
|
} |
741 |
|
|
742 |
|
/** |
743 |
|
* invokeAll(collection) invokes all tasks in the collection |
744 |
|
*/ |
745 |
|
public void testInvokeAllCollection() { |
746 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
747 |
< |
public Integer compute() { |
746 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
747 |
> |
public Integer realCompute() { |
748 |
|
FibTask f = new FibTask(8); |
749 |
|
FibTask g = new FibTask(9); |
750 |
|
FibTask h = new FibTask(7); |
751 |
< |
HashSet set = new HashSet(); |
751 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
752 |
|
set.add(f); |
753 |
|
set.add(g); |
754 |
|
set.add(h); |
755 |
|
invokeAll(set); |
756 |
< |
threadAssertTrue(f.isDone()); |
757 |
< |
threadAssertTrue(f.join() == 21); |
758 |
< |
threadAssertTrue(g.isDone()); |
759 |
< |
threadAssertTrue(g.join() == 34); |
760 |
< |
threadAssertTrue(h.isDone()); |
761 |
< |
threadAssertTrue(h.join() == 13); |
756 |
> |
assertTrue(f.isDone()); |
757 |
> |
assertTrue(g.isDone()); |
758 |
> |
assertTrue(h.isDone()); |
759 |
> |
checkCompletedNormally(f, 21); |
760 |
> |
checkCompletedNormally(g, 34); |
761 |
> |
checkCompletedNormally(h, 13); |
762 |
|
return NoResult; |
763 |
< |
} |
764 |
< |
}; |
755 |
< |
mainPool.invoke(a); |
763 |
> |
}}; |
764 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
765 |
|
} |
766 |
|
|
767 |
+ |
/** |
768 |
+ |
* invokeAll(tasks) with any null task throws NPE |
769 |
+ |
*/ |
770 |
+ |
public void testInvokeAllNPE() { |
771 |
+ |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
772 |
+ |
public Integer realCompute() { |
773 |
+ |
FibTask f = new FibTask(8); |
774 |
+ |
FibTask g = new FibTask(9); |
775 |
+ |
FibTask h = null; |
776 |
+ |
try { |
777 |
+ |
invokeAll(f, g, h); |
778 |
+ |
shouldThrow(); |
779 |
+ |
} catch (NullPointerException success) {} |
780 |
+ |
return NoResult; |
781 |
+ |
}}; |
782 |
+ |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
783 |
+ |
} |
784 |
|
|
785 |
|
/** |
786 |
|
* invokeAll(t1, t2) throw exception if any task does |
787 |
|
*/ |
788 |
|
public void testAbnormalInvokeAll2() { |
789 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
790 |
< |
public Integer compute() { |
789 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
790 |
> |
public Integer realCompute() { |
791 |
> |
FibTask f = new FibTask(8); |
792 |
> |
FailingFibTask g = new FailingFibTask(9); |
793 |
|
try { |
766 |
– |
FibTask f = new FibTask(8); |
767 |
– |
FailingFibTask g = new FailingFibTask(9); |
794 |
|
invokeAll(f, g); |
795 |
|
shouldThrow(); |
770 |
– |
return NoResult; |
796 |
|
} catch (FJException success) { |
797 |
+ |
checkCompletedAbnormally(g, success); |
798 |
|
} |
799 |
|
return NoResult; |
800 |
< |
} |
801 |
< |
}; |
776 |
< |
mainPool.invoke(a); |
800 |
> |
}}; |
801 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
802 |
|
} |
803 |
|
|
804 |
|
/** |
805 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
806 |
|
*/ |
807 |
|
public void testAbnormalInvokeAll1() { |
808 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
809 |
< |
public Integer compute() { |
808 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
809 |
> |
public Integer realCompute() { |
810 |
> |
FailingFibTask g = new FailingFibTask(9); |
811 |
|
try { |
786 |
– |
FailingFibTask g = new FailingFibTask(9); |
812 |
|
invokeAll(g); |
813 |
|
shouldThrow(); |
789 |
– |
return NoResult; |
814 |
|
} catch (FJException success) { |
815 |
+ |
checkCompletedAbnormally(g, success); |
816 |
|
} |
817 |
|
return NoResult; |
818 |
< |
} |
819 |
< |
}; |
795 |
< |
mainPool.invoke(a); |
818 |
> |
}}; |
819 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
820 |
|
} |
821 |
|
|
822 |
|
/** |
823 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
824 |
|
*/ |
825 |
|
public void testAbnormalInvokeAll3() { |
826 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
827 |
< |
public Integer compute() { |
826 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
827 |
> |
public Integer realCompute() { |
828 |
> |
FibTask f = new FibTask(8); |
829 |
> |
FailingFibTask g = new FailingFibTask(9); |
830 |
> |
FibTask h = new FibTask(7); |
831 |
|
try { |
805 |
– |
FibTask f = new FibTask(8); |
806 |
– |
FailingFibTask g = new FailingFibTask(9); |
807 |
– |
FibTask h = new FibTask(7); |
832 |
|
invokeAll(f, g, h); |
833 |
|
shouldThrow(); |
810 |
– |
return NoResult; |
834 |
|
} catch (FJException success) { |
835 |
+ |
checkCompletedAbnormally(g, success); |
836 |
|
} |
837 |
|
return NoResult; |
838 |
< |
} |
839 |
< |
}; |
816 |
< |
mainPool.invoke(a); |
838 |
> |
}}; |
839 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
840 |
|
} |
841 |
|
|
842 |
|
/** |
843 |
|
* invokeAll(collection) throws exception if any task does |
844 |
|
*/ |
845 |
|
public void testAbnormalInvokeAllCollection() { |
846 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
847 |
< |
public Integer compute() { |
846 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
847 |
> |
public Integer realCompute() { |
848 |
> |
FailingFibTask f = new FailingFibTask(8); |
849 |
> |
FibTask g = new FibTask(9); |
850 |
> |
FibTask h = new FibTask(7); |
851 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
852 |
> |
set.add(f); |
853 |
> |
set.add(g); |
854 |
> |
set.add(h); |
855 |
|
try { |
826 |
– |
FailingFibTask f = new FailingFibTask(8); |
827 |
– |
FibTask g = new FibTask(9); |
828 |
– |
FibTask h = new FibTask(7); |
829 |
– |
HashSet set = new HashSet(); |
830 |
– |
set.add(f); |
831 |
– |
set.add(g); |
832 |
– |
set.add(h); |
856 |
|
invokeAll(set); |
857 |
|
shouldThrow(); |
835 |
– |
return NoResult; |
858 |
|
} catch (FJException success) { |
859 |
+ |
checkCompletedAbnormally(f, success); |
860 |
|
} |
861 |
|
return NoResult; |
862 |
< |
} |
863 |
< |
}; |
841 |
< |
mainPool.invoke(a); |
862 |
> |
}}; |
863 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
864 |
|
} |
865 |
|
|
866 |
|
/** |
868 |
|
* and suppresses execution |
869 |
|
*/ |
870 |
|
public void testTryUnfork() { |
871 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
872 |
< |
public Integer compute() { |
871 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
872 |
> |
public Integer realCompute() { |
873 |
|
FibTask g = new FibTask(9); |
874 |
< |
g.fork(); |
874 |
> |
assertSame(g, g.fork()); |
875 |
|
FibTask f = new FibTask(8); |
876 |
< |
f.fork(); |
877 |
< |
threadAssertTrue(f.tryUnfork()); |
876 |
> |
assertSame(f, f.fork()); |
877 |
> |
assertTrue(f.tryUnfork()); |
878 |
|
helpQuiesce(); |
879 |
< |
threadAssertFalse(f.isDone()); |
880 |
< |
threadAssertTrue(g.isDone()); |
879 |
> |
checkNotDone(f); |
880 |
> |
checkCompletedNormally(g, 34); |
881 |
|
return NoResult; |
882 |
< |
} |
883 |
< |
}; |
862 |
< |
singletonPool.invoke(a); |
882 |
> |
}}; |
883 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
884 |
|
} |
885 |
|
|
886 |
|
/** |
888 |
|
* there are more tasks than threads |
889 |
|
*/ |
890 |
|
public void testGetSurplusQueuedTaskCount() { |
891 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
892 |
< |
public Integer compute() { |
891 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
892 |
> |
public Integer realCompute() { |
893 |
|
FibTask h = new FibTask(7); |
894 |
< |
h.fork(); |
894 |
> |
assertSame(h, h.fork()); |
895 |
|
FibTask g = new FibTask(9); |
896 |
< |
g.fork(); |
896 |
> |
assertSame(g, g.fork()); |
897 |
|
FibTask f = new FibTask(8); |
898 |
< |
f.fork(); |
899 |
< |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
898 |
> |
assertSame(f, f.fork()); |
899 |
> |
assertTrue(getSurplusQueuedTaskCount() > 0); |
900 |
|
helpQuiesce(); |
901 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
902 |
+ |
checkCompletedNormally(f, 21); |
903 |
+ |
checkCompletedNormally(g, 34); |
904 |
+ |
checkCompletedNormally(h, 13); |
905 |
|
return NoResult; |
906 |
< |
} |
907 |
< |
}; |
883 |
< |
singletonPool.invoke(a); |
906 |
> |
}}; |
907 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
908 |
|
} |
909 |
|
|
910 |
|
/** |
911 |
|
* peekNextLocalTask returns most recent unexecuted task. |
912 |
|
*/ |
913 |
|
public void testPeekNextLocalTask() { |
914 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
915 |
< |
public Integer compute() { |
914 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
915 |
> |
public Integer realCompute() { |
916 |
|
FibTask g = new FibTask(9); |
917 |
< |
g.fork(); |
917 |
> |
assertSame(g, g.fork()); |
918 |
|
FibTask f = new FibTask(8); |
919 |
< |
f.fork(); |
920 |
< |
threadAssertTrue(peekNextLocalTask() == f); |
921 |
< |
f.join(); |
898 |
< |
threadAssertTrue(f.isDone()); |
919 |
> |
assertSame(f, f.fork()); |
920 |
> |
assertSame(f, peekNextLocalTask()); |
921 |
> |
checkCompletesNormally(f, 21); |
922 |
|
helpQuiesce(); |
923 |
+ |
checkCompletedNormally(g, 34); |
924 |
|
return NoResult; |
925 |
< |
} |
926 |
< |
}; |
903 |
< |
singletonPool.invoke(a); |
925 |
> |
}}; |
926 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
927 |
|
} |
928 |
|
|
929 |
|
/** |
931 |
|
* without executing it |
932 |
|
*/ |
933 |
|
public void testPollNextLocalTask() { |
934 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
935 |
< |
public Integer compute() { |
934 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
935 |
> |
public Integer realCompute() { |
936 |
|
FibTask g = new FibTask(9); |
937 |
< |
g.fork(); |
937 |
> |
assertSame(g, g.fork()); |
938 |
|
FibTask f = new FibTask(8); |
939 |
< |
f.fork(); |
940 |
< |
threadAssertTrue(pollNextLocalTask() == f); |
939 |
> |
assertSame(f, f.fork()); |
940 |
> |
assertSame(f, pollNextLocalTask()); |
941 |
|
helpQuiesce(); |
942 |
< |
threadAssertFalse(f.isDone()); |
942 |
> |
checkNotDone(f); |
943 |
> |
checkCompletedNormally(g, 34); |
944 |
|
return NoResult; |
945 |
< |
} |
946 |
< |
}; |
923 |
< |
singletonPool.invoke(a); |
945 |
> |
}}; |
946 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
947 |
|
} |
948 |
|
|
949 |
|
/** |
950 |
< |
* pollTask returns an unexecuted task |
928 |
< |
* without executing it |
950 |
> |
* pollTask returns an unexecuted task without executing it |
951 |
|
*/ |
952 |
|
public void testPollTask() { |
953 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
954 |
< |
public Integer compute() { |
953 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
954 |
> |
public Integer realCompute() { |
955 |
|
FibTask g = new FibTask(9); |
956 |
< |
g.fork(); |
956 |
> |
assertSame(g, g.fork()); |
957 |
|
FibTask f = new FibTask(8); |
958 |
< |
f.fork(); |
959 |
< |
threadAssertTrue(pollTask() == f); |
958 |
> |
assertSame(f, f.fork()); |
959 |
> |
assertSame(f, pollTask()); |
960 |
|
helpQuiesce(); |
961 |
< |
threadAssertFalse(f.isDone()); |
962 |
< |
threadAssertTrue(g.isDone()); |
961 |
> |
checkNotDone(f); |
962 |
> |
checkCompletedNormally(g, 34); |
963 |
|
return NoResult; |
964 |
< |
} |
965 |
< |
}; |
944 |
< |
singletonPool.invoke(a); |
964 |
> |
}}; |
965 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
966 |
|
} |
967 |
|
|
968 |
|
/** |
969 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
970 |
|
*/ |
971 |
|
public void testPeekNextLocalTaskAsync() { |
972 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
973 |
< |
public Integer compute() { |
972 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
973 |
> |
public Integer realCompute() { |
974 |
|
FibTask g = new FibTask(9); |
975 |
< |
g.fork(); |
975 |
> |
assertSame(g, g.fork()); |
976 |
|
FibTask f = new FibTask(8); |
977 |
< |
f.fork(); |
978 |
< |
threadAssertTrue(peekNextLocalTask() == g); |
979 |
< |
f.join(); |
977 |
> |
assertSame(f, f.fork()); |
978 |
> |
assertSame(g, peekNextLocalTask()); |
979 |
> |
assertEquals(21, (int) f.join()); |
980 |
|
helpQuiesce(); |
981 |
< |
threadAssertTrue(f.isDone()); |
981 |
> |
checkCompletedNormally(f, 21); |
982 |
> |
checkCompletedNormally(g, 34); |
983 |
|
return NoResult; |
984 |
< |
} |
985 |
< |
}; |
964 |
< |
asyncSingletonPool.invoke(a); |
984 |
> |
}}; |
985 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
986 |
|
} |
987 |
|
|
988 |
|
/** |
989 |
< |
* pollNextLocalTask returns least recent unexecuted task |
990 |
< |
* without executing it, in async mode |
989 |
> |
* pollNextLocalTask returns least recent unexecuted task without |
990 |
> |
* executing it, in async mode |
991 |
|
*/ |
992 |
|
public void testPollNextLocalTaskAsync() { |
993 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
994 |
< |
public Integer compute() { |
993 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
994 |
> |
public Integer realCompute() { |
995 |
|
FibTask g = new FibTask(9); |
996 |
< |
g.fork(); |
996 |
> |
assertSame(g, g.fork()); |
997 |
|
FibTask f = new FibTask(8); |
998 |
< |
f.fork(); |
999 |
< |
threadAssertTrue(pollNextLocalTask() == g); |
998 |
> |
assertSame(f, f.fork()); |
999 |
> |
assertSame(g, pollNextLocalTask()); |
1000 |
|
helpQuiesce(); |
1001 |
< |
threadAssertTrue(f.isDone()); |
1002 |
< |
threadAssertFalse(g.isDone()); |
1001 |
> |
checkCompletedNormally(f, 21); |
1002 |
> |
checkNotDone(g); |
1003 |
|
return NoResult; |
1004 |
< |
} |
1005 |
< |
}; |
985 |
< |
asyncSingletonPool.invoke(a); |
1004 |
> |
}}; |
1005 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
1006 |
|
} |
1007 |
|
|
1008 |
|
/** |
1009 |
< |
* pollTask returns an unexecuted task |
1010 |
< |
* without executing it, in async mode |
1009 |
> |
* pollTask returns an unexecuted task without executing it, in |
1010 |
> |
* async mode |
1011 |
|
*/ |
1012 |
|
public void testPollTaskAsync() { |
1013 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
1014 |
< |
public Integer compute() { |
1013 |
> |
RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() { |
1014 |
> |
public Integer realCompute() { |
1015 |
|
FibTask g = new FibTask(9); |
1016 |
< |
g.fork(); |
1016 |
> |
assertSame(g, g.fork()); |
1017 |
|
FibTask f = new FibTask(8); |
1018 |
< |
f.fork(); |
1019 |
< |
threadAssertTrue(pollTask() == g); |
1018 |
> |
assertSame(f, f.fork()); |
1019 |
> |
assertSame(g, pollTask()); |
1020 |
|
helpQuiesce(); |
1021 |
< |
threadAssertTrue(f.isDone()); |
1022 |
< |
threadAssertFalse(g.isDone()); |
1021 |
> |
checkCompletedNormally(f, 21); |
1022 |
> |
checkNotDone(g); |
1023 |
|
return NoResult; |
1024 |
< |
} |
1025 |
< |
}; |
1006 |
< |
asyncSingletonPool.invoke(a); |
1024 |
> |
}}; |
1025 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
1026 |
|
} |
1027 |
|
|
1028 |
|
} |