11 |
|
public class RecursiveTaskTest extends JSR166TestCase { |
12 |
|
|
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
< |
return new TestSuite(RecursiveTaskTest.class); |
17 |
> |
return new TestSuite(RecursiveTaskTest.class); |
18 |
|
} |
19 |
|
|
20 |
|
static final ForkJoinPool mainPool = new ForkJoinPool(); |
21 |
|
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
22 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
23 |
< |
static { |
24 |
< |
asyncSingletonPool.setAsyncMode(true); |
25 |
< |
} |
22 |
> |
static final ForkJoinPool asyncSingletonPool = |
23 |
> |
new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
24 |
> |
null, true); |
25 |
|
|
26 |
|
static final class FJException extends RuntimeException { |
27 |
|
FJException() { super(); } |
68 |
|
*/ |
69 |
|
public void testInvoke() { |
70 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
71 |
< |
public Integer compute() { |
72 |
< |
FibTask f = new FibTask(8); |
73 |
< |
Integer r = f.invoke(); |
74 |
< |
threadAssertTrue(r == 21); |
75 |
< |
threadAssertTrue(f.isDone()); |
76 |
< |
threadAssertFalse(f.isCancelled()); |
77 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
78 |
< |
threadAssertTrue(f.getRawResult() == 21); |
79 |
< |
return r; |
80 |
< |
} |
81 |
< |
}; |
71 |
> |
public Integer compute() { |
72 |
> |
FibTask f = new FibTask(8); |
73 |
> |
Integer r = f.invoke(); |
74 |
> |
threadAssertTrue(r == 21); |
75 |
> |
threadAssertTrue(f.isDone()); |
76 |
> |
threadAssertFalse(f.isCancelled()); |
77 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
78 |
> |
threadAssertTrue(f.getRawResult() == 21); |
79 |
> |
return r; |
80 |
> |
} |
81 |
> |
}; |
82 |
|
assertTrue(mainPool.invoke(a) == 21); |
83 |
|
} |
84 |
|
|
89 |
|
*/ |
90 |
|
public void testQuietlyInvoke() { |
91 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
92 |
< |
public Integer compute() { |
93 |
< |
FibTask f = new FibTask(8); |
94 |
< |
f.quietlyInvoke(); |
95 |
< |
Integer r = f.getRawResult(); |
96 |
< |
threadAssertTrue(r == 21); |
97 |
< |
threadAssertTrue(f.isDone()); |
98 |
< |
threadAssertFalse(f.isCancelled()); |
99 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
100 |
< |
return r; |
101 |
< |
} |
102 |
< |
}; |
92 |
> |
public Integer compute() { |
93 |
> |
FibTask f = new FibTask(8); |
94 |
> |
f.quietlyInvoke(); |
95 |
> |
Integer r = f.getRawResult(); |
96 |
> |
threadAssertTrue(r == 21); |
97 |
> |
threadAssertTrue(f.isDone()); |
98 |
> |
threadAssertFalse(f.isCancelled()); |
99 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
100 |
> |
return r; |
101 |
> |
} |
102 |
> |
}; |
103 |
|
assertTrue(mainPool.invoke(a) == 21); |
104 |
|
} |
105 |
|
|
108 |
|
*/ |
109 |
|
public void testForkJoin() { |
110 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
111 |
< |
public Integer compute() { |
112 |
< |
FibTask f = new FibTask(8); |
113 |
< |
f.fork(); |
114 |
< |
Integer r = f.join(); |
115 |
< |
threadAssertTrue(r == 21); |
116 |
< |
threadAssertTrue(f.isDone()); |
117 |
< |
return r; |
118 |
< |
} |
119 |
< |
}; |
111 |
> |
public Integer compute() { |
112 |
> |
FibTask f = new FibTask(8); |
113 |
> |
f.fork(); |
114 |
> |
Integer r = f.join(); |
115 |
> |
threadAssertTrue(r == 21); |
116 |
> |
threadAssertTrue(f.isDone()); |
117 |
> |
return r; |
118 |
> |
} |
119 |
> |
}; |
120 |
|
assertTrue(mainPool.invoke(a) == 21); |
121 |
|
} |
122 |
|
|
125 |
|
*/ |
126 |
|
public void testForkGet() { |
127 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
128 |
< |
public Integer compute() { |
129 |
< |
try { |
131 |
< |
FibTask f = new FibTask(8); |
132 |
< |
f.fork(); |
133 |
< |
Integer r = f.get(); |
134 |
< |
threadAssertTrue(r == 21); |
135 |
< |
threadAssertTrue(f.isDone()); |
136 |
< |
return r; |
137 |
< |
} catch (Exception ex) { |
138 |
< |
unexpectedException(); |
139 |
< |
} |
140 |
< |
return NoResult; |
141 |
< |
} |
142 |
< |
}; |
143 |
< |
assertTrue(mainPool.invoke(a) == 21); |
144 |
< |
} |
145 |
< |
|
146 |
< |
/** |
147 |
< |
* timed get of a forked task returns when task completes |
148 |
< |
*/ |
149 |
< |
public void testForkTimedGet() { |
150 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
151 |
< |
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(); |
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() { |
128 |
> |
public Integer compute() { |
129 |
> |
try { |
130 |
|
FibTask f = new FibTask(8); |
131 |
|
f.fork(); |
132 |
< |
Integer r = f.helpJoin(); |
132 |
> |
Integer r = f.get(); |
133 |
|
threadAssertTrue(r == 21); |
134 |
|
threadAssertTrue(f.isDone()); |
135 |
|
return r; |
136 |
+ |
} catch (Exception ex) { |
137 |
+ |
unexpectedException(ex); |
138 |
|
} |
139 |
< |
}; |
139 |
> |
return NoResult; |
140 |
> |
} |
141 |
> |
}; |
142 |
|
assertTrue(mainPool.invoke(a) == 21); |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
< |
* quietlyJoin of a forked task returns when task completes |
146 |
> |
* timed get of a forked task returns when task completes |
147 |
|
*/ |
148 |
< |
public void testForkQuietlyJoin() { |
148 |
> |
public void testForkTimedGet() { |
149 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
150 |
< |
public Integer compute() { |
150 |
> |
public Integer compute() { |
151 |
> |
try { |
152 |
|
FibTask f = new FibTask(8); |
153 |
|
f.fork(); |
154 |
< |
f.quietlyJoin(); |
194 |
< |
Integer r = f.getRawResult(); |
154 |
> |
Integer r = f.get(5L, TimeUnit.SECONDS); |
155 |
|
threadAssertTrue(r == 21); |
156 |
|
threadAssertTrue(f.isDone()); |
157 |
|
return r; |
158 |
+ |
} catch (Exception ex) { |
159 |
+ |
unexpectedException(ex); |
160 |
|
} |
161 |
< |
}; |
161 |
> |
return NoResult; |
162 |
> |
} |
163 |
> |
}; |
164 |
|
assertTrue(mainPool.invoke(a) == 21); |
165 |
|
} |
166 |
|
|
203 |
– |
|
167 |
|
/** |
168 |
< |
* quietlyHelpJoin of a forked task returns when task completes |
168 |
> |
* quietlyJoin of a forked task returns when task completes |
169 |
|
*/ |
170 |
< |
public void testForkQuietlyHelpJoin() { |
170 |
> |
public void testForkQuietlyJoin() { |
171 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
172 |
< |
public Integer compute() { |
173 |
< |
FibTask f = new FibTask(8); |
174 |
< |
f.fork(); |
175 |
< |
f.quietlyHelpJoin(); |
176 |
< |
Integer r = f.getRawResult(); |
177 |
< |
threadAssertTrue(r == 21); |
178 |
< |
threadAssertTrue(f.isDone()); |
179 |
< |
return r; |
180 |
< |
} |
181 |
< |
}; |
172 |
> |
public Integer compute() { |
173 |
> |
FibTask f = new FibTask(8); |
174 |
> |
f.fork(); |
175 |
> |
f.quietlyJoin(); |
176 |
> |
Integer r = f.getRawResult(); |
177 |
> |
threadAssertTrue(r == 21); |
178 |
> |
threadAssertTrue(f.isDone()); |
179 |
> |
return r; |
180 |
> |
} |
181 |
> |
}; |
182 |
|
assertTrue(mainPool.invoke(a) == 21); |
183 |
|
} |
184 |
|
|
189 |
|
*/ |
190 |
|
public void testForkHelpQuiesce() { |
191 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
192 |
< |
public Integer compute() { |
193 |
< |
FibTask f = new FibTask(8); |
194 |
< |
f.fork(); |
195 |
< |
f.helpQuiesce(); |
196 |
< |
Integer r = f.getRawResult(); |
197 |
< |
threadAssertTrue(r == 21); |
198 |
< |
threadAssertTrue(f.isDone()); |
199 |
< |
threadAssertTrue(getQueuedTaskCount() == 0); |
200 |
< |
return r; |
201 |
< |
} |
202 |
< |
}; |
192 |
> |
public Integer compute() { |
193 |
> |
FibTask f = new FibTask(8); |
194 |
> |
f.fork(); |
195 |
> |
f.helpQuiesce(); |
196 |
> |
Integer r = f.getRawResult(); |
197 |
> |
threadAssertTrue(r == 21); |
198 |
> |
threadAssertTrue(f.isDone()); |
199 |
> |
threadAssertTrue(getQueuedTaskCount() == 0); |
200 |
> |
return r; |
201 |
> |
} |
202 |
> |
}; |
203 |
|
assertTrue(mainPool.invoke(a) == 21); |
204 |
|
} |
205 |
|
|
209 |
|
*/ |
210 |
|
public void testAbnormalInvoke() { |
211 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
212 |
< |
public Integer compute() { |
213 |
< |
try { |
214 |
< |
FailingFibTask f = new FailingFibTask(8); |
215 |
< |
f.invoke(); |
216 |
< |
shouldThrow(); |
254 |
< |
return NoResult; |
255 |
< |
} catch (FJException success) { |
256 |
< |
} |
212 |
> |
public Integer compute() { |
213 |
> |
try { |
214 |
> |
FailingFibTask f = new FailingFibTask(8); |
215 |
> |
f.invoke(); |
216 |
> |
shouldThrow(); |
217 |
|
return NoResult; |
218 |
+ |
} catch (FJException success) { |
219 |
|
} |
220 |
< |
}; |
220 |
> |
return NoResult; |
221 |
> |
} |
222 |
> |
}; |
223 |
|
mainPool.invoke(a); |
224 |
|
} |
225 |
|
|
226 |
|
/** |
227 |
< |
* quietelyInvoke task returns when task completes abnormally |
227 |
> |
* quietlyInvoke task returns when task completes abnormally |
228 |
|
*/ |
229 |
|
public void testAbnormalQuietlyInvoke() { |
230 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
231 |
< |
public Integer compute() { |
232 |
< |
FailingFibTask f = new FailingFibTask(8); |
233 |
< |
f.quietlyInvoke(); |
234 |
< |
threadAssertTrue(f.isDone()); |
235 |
< |
return NoResult; |
236 |
< |
} |
237 |
< |
}; |
231 |
> |
public Integer compute() { |
232 |
> |
FailingFibTask f = new FailingFibTask(8); |
233 |
> |
f.quietlyInvoke(); |
234 |
> |
threadAssertTrue(f.isDone()); |
235 |
> |
return NoResult; |
236 |
> |
} |
237 |
> |
}; |
238 |
|
mainPool.invoke(a); |
239 |
|
} |
240 |
|
|
243 |
|
*/ |
244 |
|
public void testAbnormalForkJoin() { |
245 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
246 |
< |
public Integer compute() { |
247 |
< |
try { |
248 |
< |
FailingFibTask f = new FailingFibTask(8); |
249 |
< |
f.fork(); |
250 |
< |
Integer r = f.join(); |
251 |
< |
shouldThrow(); |
252 |
< |
return r; |
253 |
< |
} catch (FJException success) { |
291 |
< |
} |
292 |
< |
return NoResult; |
246 |
> |
public Integer compute() { |
247 |
> |
try { |
248 |
> |
FailingFibTask f = new FailingFibTask(8); |
249 |
> |
f.fork(); |
250 |
> |
Integer r = f.join(); |
251 |
> |
shouldThrow(); |
252 |
> |
return r; |
253 |
> |
} catch (FJException success) { |
254 |
|
} |
255 |
< |
}; |
255 |
> |
return NoResult; |
256 |
> |
} |
257 |
> |
}; |
258 |
|
mainPool.invoke(a); |
259 |
|
} |
260 |
|
|
263 |
|
*/ |
264 |
|
public void testAbnormalForkGet() { |
265 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
266 |
< |
public Integer compute() { |
267 |
< |
try { |
268 |
< |
FailingFibTask f = new FailingFibTask(8); |
269 |
< |
f.fork(); |
270 |
< |
Integer r = f.get(); |
271 |
< |
shouldThrow(); |
272 |
< |
return r; |
273 |
< |
} catch (Exception success) { |
274 |
< |
} |
275 |
< |
return NoResult; |
266 |
> |
public Integer compute() { |
267 |
> |
try { |
268 |
> |
FailingFibTask f = new FailingFibTask(8); |
269 |
> |
f.fork(); |
270 |
> |
Integer r = f.get(); |
271 |
> |
shouldThrow(); |
272 |
> |
return r; |
273 |
> |
} catch (ExecutionException success) { |
274 |
> |
} catch (Exception ex) { |
275 |
> |
unexpectedException(ex); |
276 |
|
} |
277 |
< |
}; |
277 |
> |
return NoResult; |
278 |
> |
} |
279 |
> |
}; |
280 |
|
mainPool.invoke(a); |
281 |
|
} |
282 |
|
|
285 |
|
*/ |
286 |
|
public void testAbnormalForkTimedGet() { |
287 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
288 |
< |
public Integer compute() { |
289 |
< |
try { |
325 |
< |
FailingFibTask f = new FailingFibTask(8); |
326 |
< |
f.fork(); |
327 |
< |
Integer r = f.get(5L, TimeUnit.SECONDS); |
328 |
< |
shouldThrow(); |
329 |
< |
return r; |
330 |
< |
} catch (Exception success) { |
331 |
< |
} |
332 |
< |
return NoResult; |
333 |
< |
} |
334 |
< |
}; |
335 |
< |
mainPool.invoke(a); |
336 |
< |
} |
337 |
< |
|
338 |
< |
/** |
339 |
< |
* join of a forked task throws exception when task completes abnormally |
340 |
< |
*/ |
341 |
< |
public void testAbnormalForkHelpJoin() { |
342 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
343 |
< |
public Integer compute() { |
344 |
< |
try { |
345 |
< |
FailingFibTask f = new FailingFibTask(8); |
346 |
< |
f.fork(); |
347 |
< |
Integer r = f.helpJoin(); |
348 |
< |
shouldThrow(); |
349 |
< |
return r; |
350 |
< |
} catch (FJException success) { |
351 |
< |
} |
352 |
< |
return NoResult; |
353 |
< |
} |
354 |
< |
}; |
355 |
< |
mainPool.invoke(a); |
356 |
< |
} |
357 |
< |
|
358 |
< |
/** |
359 |
< |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
360 |
< |
* getException of failed task returns its exception. |
361 |
< |
* isCompletedAbnormally of a failed task returns true. |
362 |
< |
* isCancelled of a failed uncancelled task returns false |
363 |
< |
*/ |
364 |
< |
public void testAbnormalForkQuietlyHelpJoin() { |
365 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
366 |
< |
public Integer compute() { |
288 |
> |
public Integer compute() { |
289 |
> |
try { |
290 |
|
FailingFibTask f = new FailingFibTask(8); |
291 |
|
f.fork(); |
292 |
< |
f.quietlyHelpJoin(); |
293 |
< |
threadAssertTrue(f.isDone()); |
294 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
295 |
< |
threadAssertFalse(f.isCancelled()); |
296 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
297 |
< |
return NoResult; |
292 |
> |
Integer r = f.get(5L, TimeUnit.SECONDS); |
293 |
> |
shouldThrow(); |
294 |
> |
return r; |
295 |
> |
} catch (ExecutionException success) { |
296 |
> |
} catch (Exception ex) { |
297 |
> |
unexpectedException(ex); |
298 |
|
} |
299 |
< |
}; |
299 |
> |
return NoResult; |
300 |
> |
} |
301 |
> |
}; |
302 |
|
mainPool.invoke(a); |
303 |
|
} |
304 |
|
|
307 |
|
*/ |
308 |
|
public void testAbnormalForkQuietlyJoin() { |
309 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
310 |
< |
public Integer compute() { |
311 |
< |
FailingFibTask f = new FailingFibTask(8); |
312 |
< |
f.fork(); |
313 |
< |
f.quietlyJoin(); |
314 |
< |
threadAssertTrue(f.isDone()); |
315 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
316 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
317 |
< |
return NoResult; |
318 |
< |
} |
319 |
< |
}; |
310 |
> |
public Integer compute() { |
311 |
> |
FailingFibTask f = new FailingFibTask(8); |
312 |
> |
f.fork(); |
313 |
> |
f.quietlyJoin(); |
314 |
> |
threadAssertTrue(f.isDone()); |
315 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
316 |
> |
threadAssertTrue(f.getException() instanceof FJException); |
317 |
> |
return NoResult; |
318 |
> |
} |
319 |
> |
}; |
320 |
|
mainPool.invoke(a); |
321 |
|
} |
322 |
|
|
325 |
|
*/ |
326 |
|
public void testCancelledInvoke() { |
327 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
328 |
< |
public Integer compute() { |
329 |
< |
try { |
330 |
< |
FibTask f = new FibTask(8); |
331 |
< |
f.cancel(true); |
332 |
< |
Integer r = f.invoke(); |
333 |
< |
shouldThrow(); |
334 |
< |
return r; |
335 |
< |
} catch (CancellationException success) { |
411 |
< |
} |
412 |
< |
return NoResult; |
328 |
> |
public Integer compute() { |
329 |
> |
try { |
330 |
> |
FibTask f = new FibTask(8); |
331 |
> |
f.cancel(true); |
332 |
> |
Integer r = f.invoke(); |
333 |
> |
shouldThrow(); |
334 |
> |
return r; |
335 |
> |
} catch (CancellationException success) { |
336 |
|
} |
337 |
< |
}; |
337 |
> |
return NoResult; |
338 |
> |
} |
339 |
> |
}; |
340 |
|
mainPool.invoke(a); |
341 |
|
} |
342 |
|
|
345 |
|
*/ |
346 |
|
public void testCancelledForkJoin() { |
347 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
348 |
< |
public Integer compute() { |
349 |
< |
try { |
350 |
< |
FibTask f = new FibTask(8); |
351 |
< |
f.cancel(true); |
352 |
< |
f.fork(); |
353 |
< |
Integer r = f.join(); |
354 |
< |
shouldThrow(); |
355 |
< |
return r; |
356 |
< |
} catch (CancellationException success) { |
432 |
< |
} |
433 |
< |
return NoResult; |
348 |
> |
public Integer compute() { |
349 |
> |
try { |
350 |
> |
FibTask f = new FibTask(8); |
351 |
> |
f.cancel(true); |
352 |
> |
f.fork(); |
353 |
> |
Integer r = f.join(); |
354 |
> |
shouldThrow(); |
355 |
> |
return r; |
356 |
> |
} catch (CancellationException success) { |
357 |
|
} |
358 |
< |
}; |
358 |
> |
return NoResult; |
359 |
> |
} |
360 |
> |
}; |
361 |
|
mainPool.invoke(a); |
362 |
|
} |
363 |
|
|
366 |
|
*/ |
367 |
|
public void testCancelledForkGet() { |
368 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
369 |
< |
public Integer compute() { |
370 |
< |
try { |
371 |
< |
FibTask f = new FibTask(8); |
372 |
< |
f.cancel(true); |
373 |
< |
f.fork(); |
374 |
< |
Integer r = f.get(); |
375 |
< |
shouldThrow(); |
376 |
< |
return r; |
377 |
< |
} catch (Exception success) { |
378 |
< |
} |
379 |
< |
return NoResult; |
369 |
> |
public Integer compute() { |
370 |
> |
try { |
371 |
> |
FibTask f = new FibTask(8); |
372 |
> |
f.cancel(true); |
373 |
> |
f.fork(); |
374 |
> |
Integer r = f.get(); |
375 |
> |
shouldThrow(); |
376 |
> |
return r; |
377 |
> |
} catch (CancellationException success) { |
378 |
> |
} catch (Exception ex) { |
379 |
> |
unexpectedException(ex); |
380 |
|
} |
381 |
< |
}; |
381 |
> |
return NoResult; |
382 |
> |
} |
383 |
> |
}; |
384 |
|
mainPool.invoke(a); |
385 |
|
} |
386 |
|
|
389 |
|
*/ |
390 |
|
public void testCancelledForkTimedGet() { |
391 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
392 |
< |
public Integer compute() { |
393 |
< |
try { |
467 |
< |
FibTask f = new FibTask(8); |
468 |
< |
f.cancel(true); |
469 |
< |
f.fork(); |
470 |
< |
Integer r = f.get(5L, TimeUnit.SECONDS); |
471 |
< |
shouldThrow(); |
472 |
< |
return r; |
473 |
< |
} catch (Exception success) { |
474 |
< |
} |
475 |
< |
return NoResult; |
476 |
< |
} |
477 |
< |
}; |
478 |
< |
mainPool.invoke(a); |
479 |
< |
} |
480 |
< |
|
481 |
< |
/** |
482 |
< |
* join of a forked task throws exception when task cancelled |
483 |
< |
*/ |
484 |
< |
public void testCancelledForkHelpJoin() { |
485 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
486 |
< |
public Integer compute() { |
487 |
< |
try { |
488 |
< |
FibTask f = new FibTask(8); |
489 |
< |
f.cancel(true); |
490 |
< |
f.fork(); |
491 |
< |
Integer r = f.helpJoin(); |
492 |
< |
shouldThrow(); |
493 |
< |
return r; |
494 |
< |
} catch (CancellationException success) { |
495 |
< |
} |
496 |
< |
return NoResult; |
497 |
< |
} |
498 |
< |
}; |
499 |
< |
mainPool.invoke(a); |
500 |
< |
} |
501 |
< |
|
502 |
< |
/** |
503 |
< |
* quietlyHelpJoin of a forked task returns when task cancelled. |
504 |
< |
* getException of cancelled task returns its exception |
505 |
< |
* isCompletedAbnormally of a cancelled task returns true. |
506 |
< |
* isCancelled of a cancelled task returns true |
507 |
< |
*/ |
508 |
< |
public void testCancelledForkQuietlyHelpJoin() { |
509 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
510 |
< |
public Integer compute() { |
392 |
> |
public Integer compute() { |
393 |
> |
try { |
394 |
|
FibTask f = new FibTask(8); |
395 |
|
f.cancel(true); |
396 |
|
f.fork(); |
397 |
< |
f.quietlyHelpJoin(); |
398 |
< |
threadAssertTrue(f.isDone()); |
399 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
400 |
< |
threadAssertTrue(f.isCancelled()); |
401 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
402 |
< |
return NoResult; |
397 |
> |
Integer r = f.get(5L, TimeUnit.SECONDS); |
398 |
> |
shouldThrow(); |
399 |
> |
return r; |
400 |
> |
} catch (CancellationException success) { |
401 |
> |
} catch (Exception ex) { |
402 |
> |
unexpectedException(ex); |
403 |
|
} |
404 |
< |
}; |
404 |
> |
return NoResult; |
405 |
> |
} |
406 |
> |
}; |
407 |
|
mainPool.invoke(a); |
408 |
|
} |
409 |
|
|
412 |
|
*/ |
413 |
|
public void testCancelledForkQuietlyJoin() { |
414 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
415 |
< |
public Integer compute() { |
416 |
< |
FibTask f = new FibTask(8); |
417 |
< |
f.cancel(true); |
418 |
< |
f.fork(); |
419 |
< |
f.quietlyJoin(); |
420 |
< |
threadAssertTrue(f.isDone()); |
421 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
422 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
423 |
< |
return NoResult; |
424 |
< |
} |
425 |
< |
}; |
415 |
> |
public Integer compute() { |
416 |
> |
FibTask f = new FibTask(8); |
417 |
> |
f.cancel(true); |
418 |
> |
f.fork(); |
419 |
> |
f.quietlyJoin(); |
420 |
> |
threadAssertTrue(f.isDone()); |
421 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
422 |
> |
threadAssertTrue(f.getException() instanceof CancellationException); |
423 |
> |
return NoResult; |
424 |
> |
} |
425 |
> |
}; |
426 |
|
mainPool.invoke(a); |
427 |
|
} |
428 |
|
|
431 |
|
*/ |
432 |
|
public void testGetPool() { |
433 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
434 |
< |
public Integer compute() { |
435 |
< |
threadAssertTrue(getPool() == mainPool); |
436 |
< |
return NoResult; |
437 |
< |
} |
438 |
< |
}; |
434 |
> |
public Integer compute() { |
435 |
> |
threadAssertTrue(getPool() == mainPool); |
436 |
> |
return NoResult; |
437 |
> |
} |
438 |
> |
}; |
439 |
|
mainPool.invoke(a); |
440 |
|
} |
441 |
|
|
457 |
|
*/ |
458 |
|
public void testInForkJoinPool() { |
459 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
460 |
< |
public Integer compute() { |
461 |
< |
threadAssertTrue(inForkJoinPool()); |
462 |
< |
return NoResult; |
463 |
< |
} |
464 |
< |
}; |
460 |
> |
public Integer compute() { |
461 |
> |
threadAssertTrue(inForkJoinPool()); |
462 |
> |
return NoResult; |
463 |
> |
} |
464 |
> |
}; |
465 |
|
mainPool.invoke(a); |
466 |
|
} |
467 |
|
|
470 |
|
*/ |
471 |
|
public void testInForkJoinPool2() { |
472 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
473 |
< |
public Integer compute() { |
474 |
< |
threadAssertTrue(!inForkJoinPool()); |
475 |
< |
return NoResult; |
476 |
< |
} |
477 |
< |
}; |
473 |
> |
public Integer compute() { |
474 |
> |
threadAssertTrue(!inForkJoinPool()); |
475 |
> |
return NoResult; |
476 |
> |
} |
477 |
> |
}; |
478 |
|
a.invoke(); |
479 |
|
} |
480 |
|
|
483 |
|
*/ |
484 |
|
public void testSetRawResult() { |
485 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
486 |
< |
public Integer compute() { |
487 |
< |
setRawResult(NoResult); |
488 |
< |
return NoResult; |
489 |
< |
} |
490 |
< |
}; |
486 |
> |
public Integer compute() { |
487 |
> |
setRawResult(NoResult); |
488 |
> |
return NoResult; |
489 |
> |
} |
490 |
> |
}; |
491 |
|
assertEquals(a.invoke(), NoResult); |
492 |
|
} |
493 |
|
|
496 |
|
*/ |
497 |
|
public void testReinitialize() { |
498 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
499 |
< |
public Integer compute() { |
500 |
< |
FibTask f = new FibTask(8); |
501 |
< |
Integer r = f.invoke(); |
502 |
< |
threadAssertTrue(r == 21); |
503 |
< |
threadAssertTrue(f.isDone()); |
504 |
< |
threadAssertFalse(f.isCancelled()); |
505 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
506 |
< |
f.reinitialize(); |
507 |
< |
r = f.invoke(); |
508 |
< |
threadAssertTrue(r == 21); |
509 |
< |
return NoResult; |
510 |
< |
} |
511 |
< |
}; |
499 |
> |
public Integer compute() { |
500 |
> |
FibTask f = new FibTask(8); |
501 |
> |
Integer r = f.invoke(); |
502 |
> |
threadAssertTrue(r == 21); |
503 |
> |
threadAssertTrue(f.isDone()); |
504 |
> |
threadAssertFalse(f.isCancelled()); |
505 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
506 |
> |
f.reinitialize(); |
507 |
> |
r = f.invoke(); |
508 |
> |
threadAssertTrue(r == 21); |
509 |
> |
return NoResult; |
510 |
> |
} |
511 |
> |
}; |
512 |
|
mainPool.invoke(a); |
513 |
|
} |
514 |
|
|
517 |
|
*/ |
518 |
|
public void testCompleteExceptionally() { |
519 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
520 |
< |
public Integer compute() { |
521 |
< |
try { |
522 |
< |
FibTask f = new FibTask(8); |
523 |
< |
f.completeExceptionally(new FJException()); |
524 |
< |
Integer r = f.invoke(); |
525 |
< |
shouldThrow(); |
526 |
< |
return r; |
527 |
< |
} catch (FJException success) { |
643 |
< |
} |
644 |
< |
return NoResult; |
520 |
> |
public Integer compute() { |
521 |
> |
try { |
522 |
> |
FibTask f = new FibTask(8); |
523 |
> |
f.completeExceptionally(new FJException()); |
524 |
> |
Integer r = f.invoke(); |
525 |
> |
shouldThrow(); |
526 |
> |
return r; |
527 |
> |
} catch (FJException success) { |
528 |
|
} |
529 |
< |
}; |
529 |
> |
return NoResult; |
530 |
> |
} |
531 |
> |
}; |
532 |
|
mainPool.invoke(a); |
533 |
|
} |
534 |
|
|
537 |
|
*/ |
538 |
|
public void testComplete() { |
539 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
540 |
< |
public Integer compute() { |
541 |
< |
FibTask f = new FibTask(8); |
542 |
< |
f.complete(NoResult); |
543 |
< |
Integer r = f.invoke(); |
544 |
< |
threadAssertTrue(f.isDone()); |
545 |
< |
threadAssertTrue(r == NoResult); |
546 |
< |
return r; |
547 |
< |
} |
548 |
< |
}; |
540 |
> |
public Integer compute() { |
541 |
> |
FibTask f = new FibTask(8); |
542 |
> |
f.complete(NoResult); |
543 |
> |
Integer r = f.invoke(); |
544 |
> |
threadAssertTrue(f.isDone()); |
545 |
> |
threadAssertTrue(r == NoResult); |
546 |
> |
return r; |
547 |
> |
} |
548 |
> |
}; |
549 |
|
mainPool.invoke(a); |
550 |
|
} |
551 |
|
|
554 |
|
*/ |
555 |
|
public void testInvokeAll2() { |
556 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
557 |
< |
public Integer compute() { |
558 |
< |
FibTask f = new FibTask(8); |
559 |
< |
FibTask g = new FibTask(9); |
560 |
< |
invokeAll(f, g); |
561 |
< |
threadAssertTrue(f.isDone()); |
562 |
< |
threadAssertTrue(f.join() == 21); |
563 |
< |
threadAssertTrue(g.isDone()); |
564 |
< |
threadAssertTrue(g.join() == 34); |
565 |
< |
return NoResult; |
566 |
< |
} |
567 |
< |
}; |
557 |
> |
public Integer compute() { |
558 |
> |
FibTask f = new FibTask(8); |
559 |
> |
FibTask g = new FibTask(9); |
560 |
> |
invokeAll(f, g); |
561 |
> |
threadAssertTrue(f.isDone()); |
562 |
> |
threadAssertTrue(f.join() == 21); |
563 |
> |
threadAssertTrue(g.isDone()); |
564 |
> |
threadAssertTrue(g.join() == 34); |
565 |
> |
return NoResult; |
566 |
> |
} |
567 |
> |
}; |
568 |
|
mainPool.invoke(a); |
569 |
|
} |
570 |
|
|
573 |
|
*/ |
574 |
|
public void testInvokeAll1() { |
575 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
576 |
< |
public Integer compute() { |
577 |
< |
FibTask f = new FibTask(8); |
578 |
< |
invokeAll(f); |
579 |
< |
threadAssertTrue(f.isDone()); |
580 |
< |
threadAssertTrue(f.join() == 21); |
581 |
< |
return NoResult; |
582 |
< |
} |
583 |
< |
}; |
576 |
> |
public Integer compute() { |
577 |
> |
FibTask f = new FibTask(8); |
578 |
> |
invokeAll(f); |
579 |
> |
threadAssertTrue(f.isDone()); |
580 |
> |
threadAssertTrue(f.join() == 21); |
581 |
> |
return NoResult; |
582 |
> |
} |
583 |
> |
}; |
584 |
|
mainPool.invoke(a); |
585 |
|
} |
586 |
|
|
589 |
|
*/ |
590 |
|
public void testInvokeAll3() { |
591 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
592 |
< |
public Integer compute() { |
593 |
< |
FibTask f = new FibTask(8); |
594 |
< |
FibTask g = new FibTask(9); |
595 |
< |
FibTask h = new FibTask(7); |
596 |
< |
invokeAll(f, g, h); |
597 |
< |
threadAssertTrue(f.isDone()); |
598 |
< |
threadAssertTrue(f.join() == 21); |
599 |
< |
threadAssertTrue(g.isDone()); |
600 |
< |
threadAssertTrue(g.join() == 34); |
601 |
< |
threadAssertTrue(h.isDone()); |
602 |
< |
threadAssertTrue(h.join() == 13); |
603 |
< |
return NoResult; |
604 |
< |
} |
605 |
< |
}; |
592 |
> |
public Integer compute() { |
593 |
> |
FibTask f = new FibTask(8); |
594 |
> |
FibTask g = new FibTask(9); |
595 |
> |
FibTask h = new FibTask(7); |
596 |
> |
invokeAll(f, g, h); |
597 |
> |
threadAssertTrue(f.isDone()); |
598 |
> |
threadAssertTrue(f.join() == 21); |
599 |
> |
threadAssertTrue(g.isDone()); |
600 |
> |
threadAssertTrue(g.join() == 34); |
601 |
> |
threadAssertTrue(h.isDone()); |
602 |
> |
threadAssertTrue(h.join() == 13); |
603 |
> |
return NoResult; |
604 |
> |
} |
605 |
> |
}; |
606 |
|
mainPool.invoke(a); |
607 |
|
} |
608 |
|
|
611 |
|
*/ |
612 |
|
public void testInvokeAllCollection() { |
613 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
614 |
< |
public Integer compute() { |
615 |
< |
FibTask f = new FibTask(8); |
616 |
< |
FibTask g = new FibTask(9); |
617 |
< |
FibTask h = new FibTask(7); |
618 |
< |
HashSet set = new HashSet(); |
619 |
< |
set.add(f); |
620 |
< |
set.add(g); |
621 |
< |
set.add(h); |
622 |
< |
invokeAll(set); |
623 |
< |
threadAssertTrue(f.isDone()); |
624 |
< |
threadAssertTrue(f.join() == 21); |
625 |
< |
threadAssertTrue(g.isDone()); |
626 |
< |
threadAssertTrue(g.join() == 34); |
627 |
< |
threadAssertTrue(h.isDone()); |
628 |
< |
threadAssertTrue(h.join() == 13); |
629 |
< |
return NoResult; |
630 |
< |
} |
631 |
< |
}; |
614 |
> |
public Integer compute() { |
615 |
> |
FibTask f = new FibTask(8); |
616 |
> |
FibTask g = new FibTask(9); |
617 |
> |
FibTask h = new FibTask(7); |
618 |
> |
HashSet set = new HashSet(); |
619 |
> |
set.add(f); |
620 |
> |
set.add(g); |
621 |
> |
set.add(h); |
622 |
> |
invokeAll(set); |
623 |
> |
threadAssertTrue(f.isDone()); |
624 |
> |
threadAssertTrue(f.join() == 21); |
625 |
> |
threadAssertTrue(g.isDone()); |
626 |
> |
threadAssertTrue(g.join() == 34); |
627 |
> |
threadAssertTrue(h.isDone()); |
628 |
> |
threadAssertTrue(h.join() == 13); |
629 |
> |
return NoResult; |
630 |
> |
} |
631 |
> |
}; |
632 |
|
mainPool.invoke(a); |
633 |
|
} |
634 |
|
|
638 |
|
*/ |
639 |
|
public void testAbnormalInvokeAll2() { |
640 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
641 |
< |
public Integer compute() { |
642 |
< |
try { |
643 |
< |
FibTask f = new FibTask(8); |
644 |
< |
FailingFibTask g = new FailingFibTask(9); |
645 |
< |
invokeAll(f, g); |
646 |
< |
shouldThrow(); |
762 |
< |
return NoResult; |
763 |
< |
} catch (FJException success) { |
764 |
< |
} |
641 |
> |
public Integer compute() { |
642 |
> |
try { |
643 |
> |
FibTask f = new FibTask(8); |
644 |
> |
FailingFibTask g = new FailingFibTask(9); |
645 |
> |
invokeAll(f, g); |
646 |
> |
shouldThrow(); |
647 |
|
return NoResult; |
648 |
+ |
} catch (FJException success) { |
649 |
|
} |
650 |
< |
}; |
650 |
> |
return NoResult; |
651 |
> |
} |
652 |
> |
}; |
653 |
|
mainPool.invoke(a); |
654 |
|
} |
655 |
|
|
658 |
|
*/ |
659 |
|
public void testAbnormalInvokeAll1() { |
660 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
661 |
< |
public Integer compute() { |
662 |
< |
try { |
663 |
< |
FailingFibTask g = new FailingFibTask(9); |
664 |
< |
invokeAll(g); |
665 |
< |
shouldThrow(); |
781 |
< |
return NoResult; |
782 |
< |
} catch (FJException success) { |
783 |
< |
} |
661 |
> |
public Integer compute() { |
662 |
> |
try { |
663 |
> |
FailingFibTask g = new FailingFibTask(9); |
664 |
> |
invokeAll(g); |
665 |
> |
shouldThrow(); |
666 |
|
return NoResult; |
667 |
+ |
} catch (FJException success) { |
668 |
|
} |
669 |
< |
}; |
669 |
> |
return NoResult; |
670 |
> |
} |
671 |
> |
}; |
672 |
|
mainPool.invoke(a); |
673 |
|
} |
674 |
|
|
677 |
|
*/ |
678 |
|
public void testAbnormalInvokeAll3() { |
679 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
680 |
< |
public Integer compute() { |
681 |
< |
try { |
682 |
< |
FibTask f = new FibTask(8); |
683 |
< |
FailingFibTask g = new FailingFibTask(9); |
684 |
< |
FibTask h = new FibTask(7); |
685 |
< |
invokeAll(f, g, h); |
686 |
< |
shouldThrow(); |
802 |
< |
return NoResult; |
803 |
< |
} catch (FJException success) { |
804 |
< |
} |
680 |
> |
public Integer compute() { |
681 |
> |
try { |
682 |
> |
FibTask f = new FibTask(8); |
683 |
> |
FailingFibTask g = new FailingFibTask(9); |
684 |
> |
FibTask h = new FibTask(7); |
685 |
> |
invokeAll(f, g, h); |
686 |
> |
shouldThrow(); |
687 |
|
return NoResult; |
688 |
+ |
} catch (FJException success) { |
689 |
|
} |
690 |
< |
}; |
690 |
> |
return NoResult; |
691 |
> |
} |
692 |
> |
}; |
693 |
|
mainPool.invoke(a); |
694 |
|
} |
695 |
|
|
698 |
|
*/ |
699 |
|
public void testAbnormalInvokeAllCollection() { |
700 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
701 |
< |
public Integer compute() { |
702 |
< |
try { |
703 |
< |
FailingFibTask f = new FailingFibTask(8); |
704 |
< |
FibTask g = new FibTask(9); |
705 |
< |
FibTask h = new FibTask(7); |
706 |
< |
HashSet set = new HashSet(); |
707 |
< |
set.add(f); |
708 |
< |
set.add(g); |
709 |
< |
set.add(h); |
710 |
< |
invokeAll(set); |
711 |
< |
shouldThrow(); |
827 |
< |
return NoResult; |
828 |
< |
} catch (FJException success) { |
829 |
< |
} |
701 |
> |
public Integer compute() { |
702 |
> |
try { |
703 |
> |
FailingFibTask f = new FailingFibTask(8); |
704 |
> |
FibTask g = new FibTask(9); |
705 |
> |
FibTask h = new FibTask(7); |
706 |
> |
HashSet set = new HashSet(); |
707 |
> |
set.add(f); |
708 |
> |
set.add(g); |
709 |
> |
set.add(h); |
710 |
> |
invokeAll(set); |
711 |
> |
shouldThrow(); |
712 |
|
return NoResult; |
713 |
+ |
} catch (FJException success) { |
714 |
|
} |
715 |
< |
}; |
715 |
> |
return NoResult; |
716 |
> |
} |
717 |
> |
}; |
718 |
|
mainPool.invoke(a); |
719 |
|
} |
720 |
|
|
724 |
|
*/ |
725 |
|
public void testTryUnfork() { |
726 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
727 |
< |
public Integer compute() { |
728 |
< |
FibTask g = new FibTask(9); |
729 |
< |
g.fork(); |
730 |
< |
FibTask f = new FibTask(8); |
731 |
< |
f.fork(); |
732 |
< |
threadAssertTrue(f.tryUnfork()); |
733 |
< |
helpQuiesce(); |
734 |
< |
threadAssertFalse(f.isDone()); |
735 |
< |
threadAssertTrue(g.isDone()); |
736 |
< |
return NoResult; |
737 |
< |
} |
738 |
< |
}; |
727 |
> |
public Integer compute() { |
728 |
> |
FibTask g = new FibTask(9); |
729 |
> |
g.fork(); |
730 |
> |
FibTask f = new FibTask(8); |
731 |
> |
f.fork(); |
732 |
> |
threadAssertTrue(f.tryUnfork()); |
733 |
> |
helpQuiesce(); |
734 |
> |
threadAssertFalse(f.isDone()); |
735 |
> |
threadAssertTrue(g.isDone()); |
736 |
> |
return NoResult; |
737 |
> |
} |
738 |
> |
}; |
739 |
|
singletonPool.invoke(a); |
740 |
|
} |
741 |
|
|
745 |
|
*/ |
746 |
|
public void testGetSurplusQueuedTaskCount() { |
747 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
748 |
< |
public Integer compute() { |
749 |
< |
FibTask h = new FibTask(7); |
750 |
< |
h.fork(); |
751 |
< |
FibTask g = new FibTask(9); |
752 |
< |
g.fork(); |
753 |
< |
FibTask f = new FibTask(8); |
754 |
< |
f.fork(); |
755 |
< |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
756 |
< |
helpQuiesce(); |
757 |
< |
return NoResult; |
758 |
< |
} |
759 |
< |
}; |
748 |
> |
public Integer compute() { |
749 |
> |
FibTask h = new FibTask(7); |
750 |
> |
h.fork(); |
751 |
> |
FibTask g = new FibTask(9); |
752 |
> |
g.fork(); |
753 |
> |
FibTask f = new FibTask(8); |
754 |
> |
f.fork(); |
755 |
> |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
756 |
> |
helpQuiesce(); |
757 |
> |
return NoResult; |
758 |
> |
} |
759 |
> |
}; |
760 |
|
singletonPool.invoke(a); |
761 |
|
} |
762 |
|
|
765 |
|
*/ |
766 |
|
public void testPeekNextLocalTask() { |
767 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
768 |
< |
public Integer compute() { |
769 |
< |
FibTask g = new FibTask(9); |
770 |
< |
g.fork(); |
771 |
< |
FibTask f = new FibTask(8); |
772 |
< |
f.fork(); |
773 |
< |
threadAssertTrue(peekNextLocalTask() == f); |
774 |
< |
f.join(); |
775 |
< |
threadAssertTrue(f.isDone()); |
776 |
< |
helpQuiesce(); |
777 |
< |
return NoResult; |
778 |
< |
} |
779 |
< |
}; |
768 |
> |
public Integer compute() { |
769 |
> |
FibTask g = new FibTask(9); |
770 |
> |
g.fork(); |
771 |
> |
FibTask f = new FibTask(8); |
772 |
> |
f.fork(); |
773 |
> |
threadAssertTrue(peekNextLocalTask() == f); |
774 |
> |
f.join(); |
775 |
> |
threadAssertTrue(f.isDone()); |
776 |
> |
helpQuiesce(); |
777 |
> |
return NoResult; |
778 |
> |
} |
779 |
> |
}; |
780 |
|
singletonPool.invoke(a); |
781 |
|
} |
782 |
|
|
786 |
|
*/ |
787 |
|
public void testPollNextLocalTask() { |
788 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
789 |
< |
public Integer compute() { |
790 |
< |
FibTask g = new FibTask(9); |
791 |
< |
g.fork(); |
792 |
< |
FibTask f = new FibTask(8); |
793 |
< |
f.fork(); |
794 |
< |
threadAssertTrue(pollNextLocalTask() == f); |
795 |
< |
helpQuiesce(); |
796 |
< |
threadAssertFalse(f.isDone()); |
797 |
< |
return NoResult; |
798 |
< |
} |
799 |
< |
}; |
789 |
> |
public Integer compute() { |
790 |
> |
FibTask g = new FibTask(9); |
791 |
> |
g.fork(); |
792 |
> |
FibTask f = new FibTask(8); |
793 |
> |
f.fork(); |
794 |
> |
threadAssertTrue(pollNextLocalTask() == f); |
795 |
> |
helpQuiesce(); |
796 |
> |
threadAssertFalse(f.isDone()); |
797 |
> |
return NoResult; |
798 |
> |
} |
799 |
> |
}; |
800 |
|
singletonPool.invoke(a); |
801 |
|
} |
802 |
|
|
806 |
|
*/ |
807 |
|
public void testPollTask() { |
808 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
809 |
< |
public Integer compute() { |
810 |
< |
FibTask g = new FibTask(9); |
811 |
< |
g.fork(); |
812 |
< |
FibTask f = new FibTask(8); |
813 |
< |
f.fork(); |
814 |
< |
threadAssertTrue(pollTask() == f); |
815 |
< |
helpQuiesce(); |
816 |
< |
threadAssertFalse(f.isDone()); |
817 |
< |
threadAssertTrue(g.isDone()); |
818 |
< |
return NoResult; |
819 |
< |
} |
820 |
< |
}; |
809 |
> |
public Integer compute() { |
810 |
> |
FibTask g = new FibTask(9); |
811 |
> |
g.fork(); |
812 |
> |
FibTask f = new FibTask(8); |
813 |
> |
f.fork(); |
814 |
> |
threadAssertTrue(pollTask() == f); |
815 |
> |
helpQuiesce(); |
816 |
> |
threadAssertFalse(f.isDone()); |
817 |
> |
threadAssertTrue(g.isDone()); |
818 |
> |
return NoResult; |
819 |
> |
} |
820 |
> |
}; |
821 |
|
singletonPool.invoke(a); |
822 |
|
} |
823 |
|
|
826 |
|
*/ |
827 |
|
public void testPeekNextLocalTaskAsync() { |
828 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
829 |
< |
public Integer compute() { |
830 |
< |
FibTask g = new FibTask(9); |
831 |
< |
g.fork(); |
832 |
< |
FibTask f = new FibTask(8); |
833 |
< |
f.fork(); |
834 |
< |
threadAssertTrue(peekNextLocalTask() == g); |
835 |
< |
f.join(); |
836 |
< |
helpQuiesce(); |
837 |
< |
threadAssertTrue(f.isDone()); |
838 |
< |
return NoResult; |
839 |
< |
} |
840 |
< |
}; |
829 |
> |
public Integer compute() { |
830 |
> |
FibTask g = new FibTask(9); |
831 |
> |
g.fork(); |
832 |
> |
FibTask f = new FibTask(8); |
833 |
> |
f.fork(); |
834 |
> |
threadAssertTrue(peekNextLocalTask() == g); |
835 |
> |
f.join(); |
836 |
> |
helpQuiesce(); |
837 |
> |
threadAssertTrue(f.isDone()); |
838 |
> |
return NoResult; |
839 |
> |
} |
840 |
> |
}; |
841 |
|
asyncSingletonPool.invoke(a); |
842 |
|
} |
843 |
|
|
847 |
|
*/ |
848 |
|
public void testPollNextLocalTaskAsync() { |
849 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
850 |
< |
public Integer compute() { |
851 |
< |
FibTask g = new FibTask(9); |
852 |
< |
g.fork(); |
853 |
< |
FibTask f = new FibTask(8); |
854 |
< |
f.fork(); |
855 |
< |
threadAssertTrue(pollNextLocalTask() == g); |
856 |
< |
helpQuiesce(); |
857 |
< |
threadAssertTrue(f.isDone()); |
858 |
< |
threadAssertFalse(g.isDone()); |
859 |
< |
return NoResult; |
860 |
< |
} |
861 |
< |
}; |
850 |
> |
public Integer compute() { |
851 |
> |
FibTask g = new FibTask(9); |
852 |
> |
g.fork(); |
853 |
> |
FibTask f = new FibTask(8); |
854 |
> |
f.fork(); |
855 |
> |
threadAssertTrue(pollNextLocalTask() == g); |
856 |
> |
helpQuiesce(); |
857 |
> |
threadAssertTrue(f.isDone()); |
858 |
> |
threadAssertFalse(g.isDone()); |
859 |
> |
return NoResult; |
860 |
> |
} |
861 |
> |
}; |
862 |
|
asyncSingletonPool.invoke(a); |
863 |
|
} |
864 |
|
|
868 |
|
*/ |
869 |
|
public void testPollTaskAsync() { |
870 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
871 |
< |
public Integer compute() { |
872 |
< |
FibTask g = new FibTask(9); |
873 |
< |
g.fork(); |
874 |
< |
FibTask f = new FibTask(8); |
875 |
< |
f.fork(); |
876 |
< |
threadAssertTrue(pollTask() == g); |
877 |
< |
helpQuiesce(); |
878 |
< |
threadAssertTrue(f.isDone()); |
879 |
< |
threadAssertFalse(g.isDone()); |
880 |
< |
return NoResult; |
881 |
< |
} |
882 |
< |
}; |
871 |
> |
public Integer compute() { |
872 |
> |
FibTask g = new FibTask(9); |
873 |
> |
g.fork(); |
874 |
> |
FibTask f = new FibTask(8); |
875 |
> |
f.fork(); |
876 |
> |
threadAssertTrue(pollTask() == g); |
877 |
> |
helpQuiesce(); |
878 |
> |
threadAssertTrue(f.isDone()); |
879 |
> |
threadAssertFalse(g.isDone()); |
880 |
> |
return NoResult; |
881 |
> |
} |
882 |
> |
}; |
883 |
|
asyncSingletonPool.invoke(a); |
884 |
|
} |
885 |
|
|