3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
|
*/ |
6 |
+ |
|
7 |
|
import junit.framework.*; |
8 |
|
import java.util.concurrent.*; |
9 |
|
import java.util.*; |
10 |
|
|
10 |
– |
|
11 |
|
public class RecursiveActionTest extends JSR166TestCase { |
12 |
|
|
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
+ |
|
17 |
|
public static Test suite() { |
18 |
< |
return new TestSuite(RecursiveActionTest.class); |
18 |
> |
return new TestSuite(RecursiveActionTest.class); |
19 |
> |
} |
20 |
> |
|
21 |
> |
private static ForkJoinPool mainPool() { |
22 |
> |
return new ForkJoinPool(); |
23 |
> |
} |
24 |
> |
|
25 |
> |
private static ForkJoinPool singletonPool() { |
26 |
> |
return new ForkJoinPool(1); |
27 |
|
} |
28 |
|
|
29 |
< |
static final ForkJoinPool mainPool = new ForkJoinPool(); |
30 |
< |
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
31 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
32 |
< |
static { |
33 |
< |
asyncSingletonPool.setAsyncMode(true); |
29 |
> |
private static ForkJoinPool asyncSingletonPool() { |
30 |
> |
return new ForkJoinPool(1, |
31 |
> |
ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
32 |
> |
null, true); |
33 |
> |
} |
34 |
> |
|
35 |
> |
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
36 |
> |
try { |
37 |
> |
assertTrue(pool.invoke(a) == null); |
38 |
> |
} finally { |
39 |
> |
joinPool(pool); |
40 |
> |
} |
41 |
|
} |
42 |
|
|
43 |
|
static final class FJException extends RuntimeException { |
84 |
|
* invoke returns when task completes normally. |
85 |
|
* isCompletedAbnormally and isCancelled return false for normally |
86 |
|
* completed tasks. getRawResult of a RecursiveAction returns null; |
71 |
– |
* |
87 |
|
*/ |
88 |
|
public void testInvoke() { |
89 |
|
RecursiveAction a = new RecursiveAction() { |
90 |
< |
public void compute() { |
91 |
< |
FibAction f = new FibAction(8); |
92 |
< |
f.invoke(); |
93 |
< |
threadAssertTrue(f.result == 21); |
94 |
< |
threadAssertTrue(f.isDone()); |
95 |
< |
threadAssertFalse(f.isCancelled()); |
96 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
97 |
< |
threadAssertTrue(f.getRawResult() == null); |
98 |
< |
} |
99 |
< |
}; |
85 |
< |
mainPool.invoke(a); |
90 |
> |
public void compute() { |
91 |
> |
FibAction f = new FibAction(8); |
92 |
> |
f.invoke(); |
93 |
> |
threadAssertTrue(f.result == 21); |
94 |
> |
threadAssertTrue(f.isDone()); |
95 |
> |
threadAssertFalse(f.isCancelled()); |
96 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
97 |
> |
threadAssertTrue(f.getRawResult() == null); |
98 |
> |
}}; |
99 |
> |
testInvokeOnPool(mainPool(), a); |
100 |
|
} |
101 |
|
|
102 |
|
/** |
106 |
|
*/ |
107 |
|
public void testQuietlyInvoke() { |
108 |
|
RecursiveAction a = new RecursiveAction() { |
109 |
< |
public void compute() { |
110 |
< |
FibAction f = new FibAction(8); |
111 |
< |
f.quietlyInvoke(); |
112 |
< |
threadAssertTrue(f.result == 21); |
113 |
< |
threadAssertTrue(f.isDone()); |
114 |
< |
threadAssertFalse(f.isCancelled()); |
115 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
116 |
< |
threadAssertTrue(f.getRawResult() == null); |
117 |
< |
} |
118 |
< |
}; |
105 |
< |
mainPool.invoke(a); |
109 |
> |
public void compute() { |
110 |
> |
FibAction f = new FibAction(8); |
111 |
> |
f.quietlyInvoke(); |
112 |
> |
threadAssertTrue(f.result == 21); |
113 |
> |
threadAssertTrue(f.isDone()); |
114 |
> |
threadAssertFalse(f.isCancelled()); |
115 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
116 |
> |
threadAssertTrue(f.getRawResult() == null); |
117 |
> |
}}; |
118 |
> |
testInvokeOnPool(mainPool(), a); |
119 |
|
} |
120 |
|
|
121 |
|
/** |
123 |
|
*/ |
124 |
|
public void testForkJoin() { |
125 |
|
RecursiveAction a = new RecursiveAction() { |
126 |
< |
public void compute() { |
127 |
< |
FibAction f = new FibAction(8); |
128 |
< |
f.fork(); |
129 |
< |
f.join(); |
130 |
< |
threadAssertTrue(f.result == 21); |
131 |
< |
threadAssertTrue(f.isDone()); |
132 |
< |
threadAssertTrue(f.getRawResult() == null); |
133 |
< |
} |
134 |
< |
}; |
122 |
< |
mainPool.invoke(a); |
126 |
> |
public void compute() { |
127 |
> |
FibAction f = new FibAction(8); |
128 |
> |
f.fork(); |
129 |
> |
f.join(); |
130 |
> |
threadAssertTrue(f.result == 21); |
131 |
> |
threadAssertTrue(f.isDone()); |
132 |
> |
threadAssertTrue(f.getRawResult() == null); |
133 |
> |
}}; |
134 |
> |
testInvokeOnPool(mainPool(), a); |
135 |
|
} |
136 |
|
|
137 |
|
/** |
139 |
|
*/ |
140 |
|
public void testForkGet() { |
141 |
|
RecursiveAction a = new RecursiveAction() { |
142 |
< |
public void compute() { |
143 |
< |
try { |
144 |
< |
FibAction f = new FibAction(8); |
145 |
< |
f.fork(); |
146 |
< |
f.get(); |
147 |
< |
threadAssertTrue(f.result == 21); |
148 |
< |
threadAssertTrue(f.isDone()); |
149 |
< |
} catch (Exception ex) { |
150 |
< |
unexpectedException(ex); |
139 |
< |
} |
142 |
> |
public void compute() { |
143 |
> |
try { |
144 |
> |
FibAction f = new FibAction(8); |
145 |
> |
f.fork(); |
146 |
> |
f.get(); |
147 |
> |
threadAssertTrue(f.result == 21); |
148 |
> |
threadAssertTrue(f.isDone()); |
149 |
> |
} catch (Exception ex) { |
150 |
> |
unexpectedException(ex); |
151 |
|
} |
152 |
< |
}; |
153 |
< |
mainPool.invoke(a); |
152 |
> |
}}; |
153 |
> |
testInvokeOnPool(mainPool(), a); |
154 |
|
} |
155 |
|
|
156 |
|
/** |
158 |
|
*/ |
159 |
|
public void testForkTimedGet() { |
160 |
|
RecursiveAction a = new RecursiveAction() { |
161 |
< |
public void compute() { |
162 |
< |
try { |
163 |
< |
FibAction f = new FibAction(8); |
164 |
< |
f.fork(); |
165 |
< |
f.get(5L, TimeUnit.SECONDS); |
166 |
< |
threadAssertTrue(f.result == 21); |
167 |
< |
threadAssertTrue(f.isDone()); |
168 |
< |
} catch (Exception ex) { |
169 |
< |
unexpectedException(ex); |
159 |
< |
} |
161 |
> |
public void compute() { |
162 |
> |
try { |
163 |
> |
FibAction f = new FibAction(8); |
164 |
> |
f.fork(); |
165 |
> |
f.get(5L, TimeUnit.SECONDS); |
166 |
> |
threadAssertTrue(f.result == 21); |
167 |
> |
threadAssertTrue(f.isDone()); |
168 |
> |
} catch (Exception ex) { |
169 |
> |
unexpectedException(ex); |
170 |
|
} |
171 |
< |
}; |
172 |
< |
mainPool.invoke(a); |
171 |
> |
}}; |
172 |
> |
testInvokeOnPool(mainPool(), a); |
173 |
|
} |
174 |
|
|
175 |
|
/** |
177 |
|
*/ |
178 |
|
public void testForkTimedGetNPE() { |
179 |
|
RecursiveAction a = new RecursiveAction() { |
180 |
< |
public void compute() { |
181 |
< |
try { |
172 |
< |
FibAction f = new FibAction(8); |
173 |
< |
f.fork(); |
174 |
< |
f.get(5L, null); |
175 |
< |
shouldThrow(); |
176 |
< |
} catch (NullPointerException success) { |
177 |
< |
} catch (Exception ex) { |
178 |
< |
unexpectedException(ex); |
179 |
< |
} |
180 |
< |
} |
181 |
< |
}; |
182 |
< |
mainPool.invoke(a); |
183 |
< |
} |
184 |
< |
|
185 |
< |
/** |
186 |
< |
* helpJoin of a forked task returns when task completes |
187 |
< |
*/ |
188 |
< |
public void testForkHelpJoin() { |
189 |
< |
RecursiveAction a = new RecursiveAction() { |
190 |
< |
public void compute() { |
180 |
> |
public void compute() { |
181 |
> |
try { |
182 |
|
FibAction f = new FibAction(8); |
183 |
|
f.fork(); |
184 |
< |
f.helpJoin(); |
185 |
< |
threadAssertTrue(f.result == 21); |
186 |
< |
threadAssertTrue(f.isDone()); |
184 |
> |
f.get(5L, null); |
185 |
> |
shouldThrow(); |
186 |
> |
} catch (NullPointerException success) { |
187 |
> |
} catch (Exception ex) { |
188 |
> |
unexpectedException(ex); |
189 |
|
} |
190 |
< |
}; |
191 |
< |
mainPool.invoke(a); |
190 |
> |
}}; |
191 |
> |
testInvokeOnPool(mainPool(), a); |
192 |
|
} |
193 |
|
|
194 |
|
/** |
196 |
|
*/ |
197 |
|
public void testForkQuietlyJoin() { |
198 |
|
RecursiveAction a = new RecursiveAction() { |
199 |
< |
public void compute() { |
200 |
< |
FibAction f = new FibAction(8); |
201 |
< |
f.fork(); |
202 |
< |
f.quietlyJoin(); |
203 |
< |
threadAssertTrue(f.result == 21); |
204 |
< |
threadAssertTrue(f.isDone()); |
205 |
< |
} |
206 |
< |
}; |
214 |
< |
mainPool.invoke(a); |
215 |
< |
} |
216 |
< |
|
217 |
< |
|
218 |
< |
/** |
219 |
< |
* quietlyHelpJoin of a forked task returns when task completes |
220 |
< |
*/ |
221 |
< |
public void testForkQuietlyHelpJoin() { |
222 |
< |
RecursiveAction a = new RecursiveAction() { |
223 |
< |
public void compute() { |
224 |
< |
FibAction f = new FibAction(8); |
225 |
< |
f.fork(); |
226 |
< |
f.quietlyHelpJoin(); |
227 |
< |
threadAssertTrue(f.result == 21); |
228 |
< |
threadAssertTrue(f.isDone()); |
229 |
< |
} |
230 |
< |
}; |
231 |
< |
mainPool.invoke(a); |
199 |
> |
public void compute() { |
200 |
> |
FibAction f = new FibAction(8); |
201 |
> |
f.fork(); |
202 |
> |
f.quietlyJoin(); |
203 |
> |
threadAssertTrue(f.result == 21); |
204 |
> |
threadAssertTrue(f.isDone()); |
205 |
> |
}}; |
206 |
> |
testInvokeOnPool(mainPool(), a); |
207 |
|
} |
208 |
|
|
209 |
|
|
213 |
|
*/ |
214 |
|
public void testForkHelpQuiesce() { |
215 |
|
RecursiveAction a = new RecursiveAction() { |
216 |
< |
public void compute() { |
217 |
< |
FibAction f = new FibAction(8); |
218 |
< |
f.fork(); |
219 |
< |
f.helpQuiesce(); |
220 |
< |
threadAssertTrue(f.result == 21); |
221 |
< |
threadAssertTrue(f.isDone()); |
222 |
< |
threadAssertTrue(getQueuedTaskCount() == 0); |
223 |
< |
} |
224 |
< |
}; |
250 |
< |
mainPool.invoke(a); |
216 |
> |
public void compute() { |
217 |
> |
FibAction f = new FibAction(8); |
218 |
> |
f.fork(); |
219 |
> |
f.helpQuiesce(); |
220 |
> |
threadAssertTrue(f.result == 21); |
221 |
> |
threadAssertTrue(f.isDone()); |
222 |
> |
threadAssertTrue(getQueuedTaskCount() == 0); |
223 |
> |
}}; |
224 |
> |
testInvokeOnPool(mainPool(), a); |
225 |
|
} |
226 |
|
|
227 |
|
|
230 |
|
*/ |
231 |
|
public void testAbnormalInvoke() { |
232 |
|
RecursiveAction a = new RecursiveAction() { |
233 |
< |
public void compute() { |
234 |
< |
try { |
235 |
< |
FailingFibAction f = new FailingFibAction(8); |
236 |
< |
f.invoke(); |
237 |
< |
shouldThrow(); |
238 |
< |
} catch (FJException success) { |
265 |
< |
} |
233 |
> |
public void compute() { |
234 |
> |
try { |
235 |
> |
FailingFibAction f = new FailingFibAction(8); |
236 |
> |
f.invoke(); |
237 |
> |
shouldThrow(); |
238 |
> |
} catch (FJException success) { |
239 |
|
} |
240 |
< |
}; |
241 |
< |
mainPool.invoke(a); |
240 |
> |
}}; |
241 |
> |
testInvokeOnPool(mainPool(), a); |
242 |
|
} |
243 |
|
|
244 |
|
/** |
246 |
|
*/ |
247 |
|
public void testAbnormalQuietlyInvoke() { |
248 |
|
RecursiveAction a = new RecursiveAction() { |
249 |
< |
public void compute() { |
250 |
< |
FailingFibAction f = new FailingFibAction(8); |
251 |
< |
f.quietlyInvoke(); |
252 |
< |
threadAssertTrue(f.isDone()); |
253 |
< |
} |
254 |
< |
}; |
282 |
< |
mainPool.invoke(a); |
249 |
> |
public void compute() { |
250 |
> |
FailingFibAction f = new FailingFibAction(8); |
251 |
> |
f.quietlyInvoke(); |
252 |
> |
threadAssertTrue(f.isDone()); |
253 |
> |
}}; |
254 |
> |
testInvokeOnPool(mainPool(), a); |
255 |
|
} |
256 |
|
|
257 |
|
/** |
259 |
|
*/ |
260 |
|
public void testAbnormalForkJoin() { |
261 |
|
RecursiveAction a = new RecursiveAction() { |
262 |
< |
public void compute() { |
263 |
< |
try { |
264 |
< |
FailingFibAction f = new FailingFibAction(8); |
265 |
< |
f.fork(); |
266 |
< |
f.join(); |
267 |
< |
shouldThrow(); |
268 |
< |
} catch (FJException success) { |
297 |
< |
} |
262 |
> |
public void compute() { |
263 |
> |
try { |
264 |
> |
FailingFibAction f = new FailingFibAction(8); |
265 |
> |
f.fork(); |
266 |
> |
f.join(); |
267 |
> |
shouldThrow(); |
268 |
> |
} catch (FJException success) { |
269 |
|
} |
270 |
< |
}; |
271 |
< |
mainPool.invoke(a); |
270 |
> |
}}; |
271 |
> |
testInvokeOnPool(mainPool(), a); |
272 |
|
} |
273 |
|
|
274 |
|
/** |
276 |
|
*/ |
277 |
|
public void testAbnormalForkGet() { |
278 |
|
RecursiveAction a = new RecursiveAction() { |
279 |
< |
public void compute() { |
280 |
< |
try { |
281 |
< |
FailingFibAction f = new FailingFibAction(8); |
282 |
< |
f.fork(); |
283 |
< |
f.get(); |
284 |
< |
shouldThrow(); |
285 |
< |
} catch (ExecutionException success) { |
286 |
< |
} catch (Exception ex) { |
287 |
< |
unexpectedException(ex); |
317 |
< |
} |
279 |
> |
public void compute() { |
280 |
> |
try { |
281 |
> |
FailingFibAction f = new FailingFibAction(8); |
282 |
> |
f.fork(); |
283 |
> |
f.get(); |
284 |
> |
shouldThrow(); |
285 |
> |
} catch (ExecutionException success) { |
286 |
> |
} catch (Exception ex) { |
287 |
> |
unexpectedException(ex); |
288 |
|
} |
289 |
< |
}; |
290 |
< |
mainPool.invoke(a); |
289 |
> |
}}; |
290 |
> |
testInvokeOnPool(mainPool(), a); |
291 |
|
} |
292 |
|
|
293 |
|
/** |
295 |
|
*/ |
296 |
|
public void testAbnormalForkTimedGet() { |
297 |
|
RecursiveAction a = new RecursiveAction() { |
298 |
< |
public void compute() { |
299 |
< |
try { |
330 |
< |
FailingFibAction f = new FailingFibAction(8); |
331 |
< |
f.fork(); |
332 |
< |
f.get(5L, TimeUnit.SECONDS); |
333 |
< |
shouldThrow(); |
334 |
< |
} catch (ExecutionException success) { |
335 |
< |
} catch (Exception ex) { |
336 |
< |
unexpectedException(ex); |
337 |
< |
} |
338 |
< |
} |
339 |
< |
}; |
340 |
< |
mainPool.invoke(a); |
341 |
< |
} |
342 |
< |
|
343 |
< |
/** |
344 |
< |
* join of a forked task throws exception when task completes abnormally |
345 |
< |
*/ |
346 |
< |
public void testAbnormalForkHelpJoin() { |
347 |
< |
RecursiveAction a = new RecursiveAction() { |
348 |
< |
public void compute() { |
349 |
< |
try { |
350 |
< |
FailingFibAction f = new FailingFibAction(8); |
351 |
< |
f.fork(); |
352 |
< |
f.helpJoin(); |
353 |
< |
shouldThrow(); |
354 |
< |
} catch (FJException success) { |
355 |
< |
} |
356 |
< |
} |
357 |
< |
}; |
358 |
< |
mainPool.invoke(a); |
359 |
< |
} |
360 |
< |
|
361 |
< |
/** |
362 |
< |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
363 |
< |
* getException of failed task returns its exception. |
364 |
< |
* isCompletedAbnormally of a failed task returns true. |
365 |
< |
* isCancelled of a failed uncancelled task returns false |
366 |
< |
*/ |
367 |
< |
public void testAbnormalForkQuietlyHelpJoin() { |
368 |
< |
RecursiveAction a = new RecursiveAction() { |
369 |
< |
public void compute() { |
298 |
> |
public void compute() { |
299 |
> |
try { |
300 |
|
FailingFibAction f = new FailingFibAction(8); |
301 |
|
f.fork(); |
302 |
< |
f.quietlyHelpJoin(); |
303 |
< |
threadAssertTrue(f.isDone()); |
304 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
305 |
< |
threadAssertFalse(f.isCancelled()); |
306 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
302 |
> |
f.get(5L, TimeUnit.SECONDS); |
303 |
> |
shouldThrow(); |
304 |
> |
} catch (ExecutionException success) { |
305 |
> |
} catch (Exception ex) { |
306 |
> |
unexpectedException(ex); |
307 |
|
} |
308 |
< |
}; |
309 |
< |
mainPool.invoke(a); |
308 |
> |
}}; |
309 |
> |
testInvokeOnPool(mainPool(), a); |
310 |
|
} |
311 |
|
|
312 |
|
/** |
314 |
|
*/ |
315 |
|
public void testAbnormalForkQuietlyJoin() { |
316 |
|
RecursiveAction a = new RecursiveAction() { |
317 |
< |
public void compute() { |
318 |
< |
FailingFibAction f = new FailingFibAction(8); |
319 |
< |
f.fork(); |
320 |
< |
f.quietlyJoin(); |
321 |
< |
threadAssertTrue(f.isDone()); |
322 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
323 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
324 |
< |
} |
325 |
< |
}; |
396 |
< |
mainPool.invoke(a); |
317 |
> |
public void compute() { |
318 |
> |
FailingFibAction f = new FailingFibAction(8); |
319 |
> |
f.fork(); |
320 |
> |
f.quietlyJoin(); |
321 |
> |
threadAssertTrue(f.isDone()); |
322 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
323 |
> |
threadAssertTrue(f.getException() instanceof FJException); |
324 |
> |
}}; |
325 |
> |
testInvokeOnPool(mainPool(), a); |
326 |
|
} |
327 |
|
|
328 |
|
/** |
330 |
|
*/ |
331 |
|
public void testCancelledInvoke() { |
332 |
|
RecursiveAction a = new RecursiveAction() { |
333 |
< |
public void compute() { |
334 |
< |
try { |
335 |
< |
FibAction f = new FibAction(8); |
336 |
< |
f.cancel(true); |
337 |
< |
f.invoke(); |
338 |
< |
shouldThrow(); |
339 |
< |
} catch (CancellationException success) { |
411 |
< |
} |
333 |
> |
public void compute() { |
334 |
> |
try { |
335 |
> |
FibAction f = new FibAction(8); |
336 |
> |
f.cancel(true); |
337 |
> |
f.invoke(); |
338 |
> |
shouldThrow(); |
339 |
> |
} catch (CancellationException success) { |
340 |
|
} |
341 |
< |
}; |
342 |
< |
mainPool.invoke(a); |
341 |
> |
}}; |
342 |
> |
testInvokeOnPool(mainPool(), a); |
343 |
|
} |
344 |
|
|
345 |
|
/** |
347 |
|
*/ |
348 |
|
public void testCancelledForkJoin() { |
349 |
|
RecursiveAction a = new RecursiveAction() { |
350 |
< |
public void compute() { |
351 |
< |
try { |
352 |
< |
FibAction f = new FibAction(8); |
353 |
< |
f.cancel(true); |
354 |
< |
f.fork(); |
355 |
< |
f.join(); |
356 |
< |
shouldThrow(); |
357 |
< |
} catch (CancellationException success) { |
430 |
< |
} |
350 |
> |
public void compute() { |
351 |
> |
try { |
352 |
> |
FibAction f = new FibAction(8); |
353 |
> |
f.cancel(true); |
354 |
> |
f.fork(); |
355 |
> |
f.join(); |
356 |
> |
shouldThrow(); |
357 |
> |
} catch (CancellationException success) { |
358 |
|
} |
359 |
< |
}; |
360 |
< |
mainPool.invoke(a); |
359 |
> |
}}; |
360 |
> |
testInvokeOnPool(mainPool(), a); |
361 |
|
} |
362 |
|
|
363 |
|
/** |
365 |
|
*/ |
366 |
|
public void testCancelledForkGet() { |
367 |
|
RecursiveAction a = new RecursiveAction() { |
368 |
< |
public void compute() { |
369 |
< |
try { |
370 |
< |
FibAction f = new FibAction(8); |
371 |
< |
f.cancel(true); |
372 |
< |
f.fork(); |
373 |
< |
f.get(); |
374 |
< |
shouldThrow(); |
375 |
< |
} catch (CancellationException success) { |
376 |
< |
} catch (Exception ex) { |
377 |
< |
unexpectedException(ex); |
451 |
< |
} |
368 |
> |
public void compute() { |
369 |
> |
try { |
370 |
> |
FibAction f = new FibAction(8); |
371 |
> |
f.cancel(true); |
372 |
> |
f.fork(); |
373 |
> |
f.get(); |
374 |
> |
shouldThrow(); |
375 |
> |
} catch (CancellationException success) { |
376 |
> |
} catch (Exception ex) { |
377 |
> |
unexpectedException(ex); |
378 |
|
} |
379 |
< |
}; |
380 |
< |
mainPool.invoke(a); |
379 |
> |
}}; |
380 |
> |
testInvokeOnPool(mainPool(), a); |
381 |
|
} |
382 |
|
|
383 |
|
/** |
385 |
|
*/ |
386 |
|
public void testCancelledForkTimedGet() { |
387 |
|
RecursiveAction a = new RecursiveAction() { |
388 |
< |
public void compute() { |
389 |
< |
try { |
464 |
< |
FibAction f = new FibAction(8); |
465 |
< |
f.cancel(true); |
466 |
< |
f.fork(); |
467 |
< |
f.get(5L, TimeUnit.SECONDS); |
468 |
< |
shouldThrow(); |
469 |
< |
} catch (CancellationException success) { |
470 |
< |
} catch (Exception ex) { |
471 |
< |
unexpectedException(ex); |
472 |
< |
} |
473 |
< |
} |
474 |
< |
}; |
475 |
< |
mainPool.invoke(a); |
476 |
< |
} |
477 |
< |
|
478 |
< |
/** |
479 |
< |
* join of a forked task throws exception when task cancelled |
480 |
< |
*/ |
481 |
< |
public void testCancelledForkHelpJoin() { |
482 |
< |
RecursiveAction a = new RecursiveAction() { |
483 |
< |
public void compute() { |
484 |
< |
try { |
485 |
< |
FibAction f = new FibAction(8); |
486 |
< |
f.cancel(true); |
487 |
< |
f.fork(); |
488 |
< |
f.helpJoin(); |
489 |
< |
shouldThrow(); |
490 |
< |
} catch (CancellationException success) { |
491 |
< |
} |
492 |
< |
} |
493 |
< |
}; |
494 |
< |
mainPool.invoke(a); |
495 |
< |
} |
496 |
< |
|
497 |
< |
/** |
498 |
< |
* quietlyHelpJoin of a forked task returns when task cancelled. |
499 |
< |
* getException of cancelled task returns its exception. |
500 |
< |
* isCompletedAbnormally of a cancelled task returns true. |
501 |
< |
* isCancelled of a cancelled task returns true |
502 |
< |
*/ |
503 |
< |
public void testCancelledForkQuietlyHelpJoin() { |
504 |
< |
RecursiveAction a = new RecursiveAction() { |
505 |
< |
public void compute() { |
388 |
> |
public void compute() { |
389 |
> |
try { |
390 |
|
FibAction f = new FibAction(8); |
391 |
|
f.cancel(true); |
392 |
|
f.fork(); |
393 |
< |
f.quietlyHelpJoin(); |
394 |
< |
threadAssertTrue(f.isDone()); |
395 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
396 |
< |
threadAssertTrue(f.isCancelled()); |
397 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
393 |
> |
f.get(5L, TimeUnit.SECONDS); |
394 |
> |
shouldThrow(); |
395 |
> |
} catch (CancellationException success) { |
396 |
> |
} catch (Exception ex) { |
397 |
> |
unexpectedException(ex); |
398 |
|
} |
399 |
< |
}; |
400 |
< |
mainPool.invoke(a); |
399 |
> |
}}; |
400 |
> |
testInvokeOnPool(mainPool(), a); |
401 |
|
} |
402 |
|
|
403 |
|
/** |
405 |
|
*/ |
406 |
|
public void testCancelledForkQuietlyJoin() { |
407 |
|
RecursiveAction a = new RecursiveAction() { |
408 |
< |
public void compute() { |
409 |
< |
FibAction f = new FibAction(8); |
410 |
< |
f.cancel(true); |
411 |
< |
f.fork(); |
412 |
< |
f.quietlyJoin(); |
413 |
< |
threadAssertTrue(f.isDone()); |
414 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
415 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
416 |
< |
} |
417 |
< |
}; |
534 |
< |
mainPool.invoke(a); |
408 |
> |
public void compute() { |
409 |
> |
FibAction f = new FibAction(8); |
410 |
> |
f.cancel(true); |
411 |
> |
f.fork(); |
412 |
> |
f.quietlyJoin(); |
413 |
> |
threadAssertTrue(f.isDone()); |
414 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
415 |
> |
threadAssertTrue(f.getException() instanceof CancellationException); |
416 |
> |
}}; |
417 |
> |
testInvokeOnPool(mainPool(), a); |
418 |
|
} |
419 |
|
|
420 |
|
/** |
421 |
|
* getPool of executing task returns its pool |
422 |
|
*/ |
423 |
|
public void testGetPool() { |
424 |
+ |
final ForkJoinPool mainPool = mainPool(); |
425 |
|
RecursiveAction a = new RecursiveAction() { |
426 |
< |
public void compute() { |
427 |
< |
threadAssertTrue(getPool() == mainPool); |
428 |
< |
} |
429 |
< |
}; |
546 |
< |
mainPool.invoke(a); |
426 |
> |
public void compute() { |
427 |
> |
threadAssertTrue(getPool() == mainPool); |
428 |
> |
}}; |
429 |
> |
testInvokeOnPool(mainPool, a); |
430 |
|
} |
431 |
|
|
432 |
|
/** |
434 |
|
*/ |
435 |
|
public void testGetPool2() { |
436 |
|
RecursiveAction a = new RecursiveAction() { |
437 |
< |
public void compute() { |
438 |
< |
threadAssertTrue(getPool() == null); |
439 |
< |
} |
557 |
< |
}; |
437 |
> |
public void compute() { |
438 |
> |
threadAssertTrue(getPool() == null); |
439 |
> |
}}; |
440 |
|
a.invoke(); |
441 |
|
} |
442 |
|
|
445 |
|
*/ |
446 |
|
public void testInForkJoinPool() { |
447 |
|
RecursiveAction a = new RecursiveAction() { |
448 |
< |
public void compute() { |
449 |
< |
threadAssertTrue(inForkJoinPool()); |
450 |
< |
} |
451 |
< |
}; |
570 |
< |
mainPool.invoke(a); |
448 |
> |
public void compute() { |
449 |
> |
threadAssertTrue(inForkJoinPool()); |
450 |
> |
}}; |
451 |
> |
testInvokeOnPool(mainPool(), a); |
452 |
|
} |
453 |
|
|
454 |
|
/** |
456 |
|
*/ |
457 |
|
public void testInForkJoinPool2() { |
458 |
|
RecursiveAction a = new RecursiveAction() { |
459 |
< |
public void compute() { |
460 |
< |
threadAssertTrue(!inForkJoinPool()); |
461 |
< |
} |
581 |
< |
}; |
459 |
> |
public void compute() { |
460 |
> |
threadAssertTrue(!inForkJoinPool()); |
461 |
> |
}}; |
462 |
|
a.invoke(); |
463 |
|
} |
464 |
|
|
466 |
|
* getPool of current thread in pool returns its pool |
467 |
|
*/ |
468 |
|
public void testWorkerGetPool() { |
469 |
+ |
final ForkJoinPool mainPool = mainPool(); |
470 |
|
RecursiveAction a = new RecursiveAction() { |
471 |
< |
public void compute() { |
472 |
< |
ForkJoinWorkerThread w = |
473 |
< |
(ForkJoinWorkerThread)(Thread.currentThread()); |
474 |
< |
threadAssertTrue(w.getPool() == mainPool); |
475 |
< |
} |
476 |
< |
}; |
596 |
< |
mainPool.invoke(a); |
471 |
> |
public void compute() { |
472 |
> |
ForkJoinWorkerThread w = |
473 |
> |
(ForkJoinWorkerThread) Thread.currentThread(); |
474 |
> |
threadAssertTrue(w.getPool() == mainPool); |
475 |
> |
}}; |
476 |
> |
testInvokeOnPool(mainPool, a); |
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
|
* getPoolIndex of current thread in pool returns 0 <= value < poolSize |
601 |
– |
* |
481 |
|
*/ |
482 |
|
public void testWorkerGetPoolIndex() { |
483 |
+ |
final ForkJoinPool mainPool = mainPool(); |
484 |
|
RecursiveAction a = new RecursiveAction() { |
485 |
< |
public void compute() { |
486 |
< |
ForkJoinWorkerThread w = |
487 |
< |
(ForkJoinWorkerThread)(Thread.currentThread()); |
488 |
< |
int idx = w.getPoolIndex(); |
489 |
< |
threadAssertTrue(idx >= 0); |
490 |
< |
threadAssertTrue(idx < mainPool.getPoolSize()); |
491 |
< |
} |
492 |
< |
}; |
613 |
< |
mainPool.invoke(a); |
485 |
> |
public void compute() { |
486 |
> |
ForkJoinWorkerThread w = |
487 |
> |
(ForkJoinWorkerThread)(Thread.currentThread()); |
488 |
> |
int idx = w.getPoolIndex(); |
489 |
> |
threadAssertTrue(idx >= 0); |
490 |
> |
threadAssertTrue(idx < mainPool.getPoolSize()); |
491 |
> |
}}; |
492 |
> |
testInvokeOnPool(mainPool, a); |
493 |
|
} |
494 |
|
|
495 |
|
|
498 |
|
*/ |
499 |
|
public void testSetRawResult() { |
500 |
|
RecursiveAction a = new RecursiveAction() { |
501 |
< |
public void compute() { |
502 |
< |
setRawResult(null); |
503 |
< |
} |
625 |
< |
}; |
501 |
> |
public void compute() { |
502 |
> |
setRawResult(null); |
503 |
> |
}}; |
504 |
|
a.invoke(); |
505 |
|
} |
506 |
|
|
509 |
|
*/ |
510 |
|
public void testReinitialize() { |
511 |
|
RecursiveAction a = new RecursiveAction() { |
512 |
< |
public void compute() { |
513 |
< |
FibAction f = new FibAction(8); |
514 |
< |
f.invoke(); |
515 |
< |
threadAssertTrue(f.result == 21); |
516 |
< |
threadAssertTrue(f.isDone()); |
517 |
< |
threadAssertFalse(f.isCancelled()); |
518 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
519 |
< |
f.reinitialize(); |
520 |
< |
f.invoke(); |
521 |
< |
threadAssertTrue(f.result == 21); |
522 |
< |
} |
523 |
< |
}; |
646 |
< |
mainPool.invoke(a); |
512 |
> |
public void compute() { |
513 |
> |
FibAction f = new FibAction(8); |
514 |
> |
f.invoke(); |
515 |
> |
threadAssertTrue(f.result == 21); |
516 |
> |
threadAssertTrue(f.isDone()); |
517 |
> |
threadAssertFalse(f.isCancelled()); |
518 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
519 |
> |
f.reinitialize(); |
520 |
> |
f.invoke(); |
521 |
> |
threadAssertTrue(f.result == 21); |
522 |
> |
}}; |
523 |
> |
testInvokeOnPool(mainPool(), a); |
524 |
|
} |
525 |
|
|
526 |
|
/** |
528 |
|
*/ |
529 |
|
public void testCompleteExceptionally() { |
530 |
|
RecursiveAction a = new RecursiveAction() { |
531 |
< |
public void compute() { |
532 |
< |
try { |
533 |
< |
FibAction f = new FibAction(8); |
534 |
< |
f.completeExceptionally(new FJException()); |
535 |
< |
f.invoke(); |
536 |
< |
shouldThrow(); |
537 |
< |
} catch (FJException success) { |
661 |
< |
} |
531 |
> |
public void compute() { |
532 |
> |
try { |
533 |
> |
FibAction f = new FibAction(8); |
534 |
> |
f.completeExceptionally(new FJException()); |
535 |
> |
f.invoke(); |
536 |
> |
shouldThrow(); |
537 |
> |
} catch (FJException success) { |
538 |
|
} |
539 |
< |
}; |
540 |
< |
mainPool.invoke(a); |
539 |
> |
}}; |
540 |
> |
testInvokeOnPool(mainPool(), a); |
541 |
|
} |
542 |
|
|
543 |
|
/** |
545 |
|
*/ |
546 |
|
public void testComplete() { |
547 |
|
RecursiveAction a = new RecursiveAction() { |
548 |
< |
public void compute() { |
549 |
< |
FibAction f = new FibAction(8); |
550 |
< |
f.complete(null); |
551 |
< |
f.invoke(); |
552 |
< |
threadAssertTrue(f.isDone()); |
553 |
< |
threadAssertTrue(f.result == 0); |
554 |
< |
} |
555 |
< |
}; |
680 |
< |
mainPool.invoke(a); |
548 |
> |
public void compute() { |
549 |
> |
FibAction f = new FibAction(8); |
550 |
> |
f.complete(null); |
551 |
> |
f.invoke(); |
552 |
> |
threadAssertTrue(f.isDone()); |
553 |
> |
threadAssertTrue(f.result == 0); |
554 |
> |
}}; |
555 |
> |
testInvokeOnPool(mainPool(), a); |
556 |
|
} |
557 |
|
|
558 |
|
/** |
560 |
|
*/ |
561 |
|
public void testInvokeAll2() { |
562 |
|
RecursiveAction a = new RecursiveAction() { |
563 |
< |
public void compute() { |
564 |
< |
FibAction f = new FibAction(8); |
565 |
< |
FibAction g = new FibAction(9); |
566 |
< |
invokeAll(f, g); |
567 |
< |
threadAssertTrue(f.isDone()); |
568 |
< |
threadAssertTrue(f.result == 21); |
569 |
< |
threadAssertTrue(g.isDone()); |
570 |
< |
threadAssertTrue(g.result == 34); |
571 |
< |
} |
572 |
< |
}; |
698 |
< |
mainPool.invoke(a); |
563 |
> |
public void compute() { |
564 |
> |
FibAction f = new FibAction(8); |
565 |
> |
FibAction g = new FibAction(9); |
566 |
> |
invokeAll(f, g); |
567 |
> |
threadAssertTrue(f.isDone()); |
568 |
> |
threadAssertTrue(f.result == 21); |
569 |
> |
threadAssertTrue(g.isDone()); |
570 |
> |
threadAssertTrue(g.result == 34); |
571 |
> |
}}; |
572 |
> |
testInvokeOnPool(mainPool(), a); |
573 |
|
} |
574 |
|
|
575 |
|
/** |
577 |
|
*/ |
578 |
|
public void testInvokeAll1() { |
579 |
|
RecursiveAction a = new RecursiveAction() { |
580 |
< |
public void compute() { |
581 |
< |
FibAction f = new FibAction(8); |
582 |
< |
invokeAll(f); |
583 |
< |
threadAssertTrue(f.isDone()); |
584 |
< |
threadAssertTrue(f.result == 21); |
585 |
< |
} |
586 |
< |
}; |
713 |
< |
mainPool.invoke(a); |
580 |
> |
public void compute() { |
581 |
> |
FibAction f = new FibAction(8); |
582 |
> |
invokeAll(f); |
583 |
> |
threadAssertTrue(f.isDone()); |
584 |
> |
threadAssertTrue(f.result == 21); |
585 |
> |
}}; |
586 |
> |
testInvokeOnPool(mainPool(), a); |
587 |
|
} |
588 |
|
|
589 |
|
/** |
591 |
|
*/ |
592 |
|
public void testInvokeAll3() { |
593 |
|
RecursiveAction a = new RecursiveAction() { |
594 |
< |
public void compute() { |
595 |
< |
FibAction f = new FibAction(8); |
596 |
< |
FibAction g = new FibAction(9); |
597 |
< |
FibAction h = new FibAction(7); |
598 |
< |
invokeAll(f, g, h); |
599 |
< |
threadAssertTrue(f.isDone()); |
600 |
< |
threadAssertTrue(f.result == 21); |
601 |
< |
threadAssertTrue(g.isDone()); |
602 |
< |
threadAssertTrue(g.result == 34); |
603 |
< |
threadAssertTrue(h.isDone()); |
604 |
< |
threadAssertTrue(h.result == 13); |
605 |
< |
} |
606 |
< |
}; |
734 |
< |
mainPool.invoke(a); |
594 |
> |
public void compute() { |
595 |
> |
FibAction f = new FibAction(8); |
596 |
> |
FibAction g = new FibAction(9); |
597 |
> |
FibAction h = new FibAction(7); |
598 |
> |
invokeAll(f, g, h); |
599 |
> |
threadAssertTrue(f.isDone()); |
600 |
> |
threadAssertTrue(f.result == 21); |
601 |
> |
threadAssertTrue(g.isDone()); |
602 |
> |
threadAssertTrue(g.result == 34); |
603 |
> |
threadAssertTrue(h.isDone()); |
604 |
> |
threadAssertTrue(h.result == 13); |
605 |
> |
}}; |
606 |
> |
testInvokeOnPool(mainPool(), a); |
607 |
|
} |
608 |
|
|
609 |
|
/** |
611 |
|
*/ |
612 |
|
public void testInvokeAllCollection() { |
613 |
|
RecursiveAction a = new RecursiveAction() { |
614 |
< |
public void compute() { |
615 |
< |
FibAction f = new FibAction(8); |
616 |
< |
FibAction g = new FibAction(9); |
617 |
< |
FibAction h = new FibAction(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.result == 21); |
625 |
< |
threadAssertTrue(g.isDone()); |
626 |
< |
threadAssertTrue(g.result == 34); |
627 |
< |
threadAssertTrue(h.isDone()); |
628 |
< |
threadAssertTrue(h.result == 13); |
629 |
< |
} |
630 |
< |
}; |
759 |
< |
mainPool.invoke(a); |
614 |
> |
public void compute() { |
615 |
> |
FibAction f = new FibAction(8); |
616 |
> |
FibAction g = new FibAction(9); |
617 |
> |
FibAction h = new FibAction(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.result == 21); |
625 |
> |
threadAssertTrue(g.isDone()); |
626 |
> |
threadAssertTrue(g.result == 34); |
627 |
> |
threadAssertTrue(h.isDone()); |
628 |
> |
threadAssertTrue(h.result == 13); |
629 |
> |
}}; |
630 |
> |
testInvokeOnPool(mainPool(), a); |
631 |
|
} |
632 |
|
|
633 |
|
|
636 |
|
*/ |
637 |
|
public void testInvokeAllNPE() { |
638 |
|
RecursiveAction a = new RecursiveAction() { |
639 |
< |
public void compute() { |
640 |
< |
try { |
641 |
< |
FibAction f = new FibAction(8); |
642 |
< |
FibAction g = new FibAction(9); |
643 |
< |
FibAction h = null; |
644 |
< |
invokeAll(f, g, h); |
645 |
< |
shouldThrow(); |
646 |
< |
} catch (NullPointerException success) { |
776 |
< |
} |
639 |
> |
public void compute() { |
640 |
> |
try { |
641 |
> |
FibAction f = new FibAction(8); |
642 |
> |
FibAction g = new FibAction(9); |
643 |
> |
FibAction h = null; |
644 |
> |
invokeAll(f, g, h); |
645 |
> |
shouldThrow(); |
646 |
> |
} catch (NullPointerException success) { |
647 |
|
} |
648 |
< |
}; |
649 |
< |
mainPool.invoke(a); |
648 |
> |
}}; |
649 |
> |
testInvokeOnPool(mainPool(), a); |
650 |
|
} |
651 |
|
|
652 |
|
/** |
654 |
|
*/ |
655 |
|
public void testAbnormalInvokeAll2() { |
656 |
|
RecursiveAction a = new RecursiveAction() { |
657 |
< |
public void compute() { |
658 |
< |
try { |
659 |
< |
FibAction f = new FibAction(8); |
660 |
< |
FailingFibAction g = new FailingFibAction(9); |
661 |
< |
invokeAll(f, g); |
662 |
< |
shouldThrow(); |
663 |
< |
} catch (FJException success) { |
794 |
< |
} |
657 |
> |
public void compute() { |
658 |
> |
try { |
659 |
> |
FibAction f = new FibAction(8); |
660 |
> |
FailingFibAction g = new FailingFibAction(9); |
661 |
> |
invokeAll(f, g); |
662 |
> |
shouldThrow(); |
663 |
> |
} catch (FJException success) { |
664 |
|
} |
665 |
< |
}; |
666 |
< |
mainPool.invoke(a); |
665 |
> |
}}; |
666 |
> |
testInvokeOnPool(mainPool(), a); |
667 |
|
} |
668 |
|
|
669 |
|
/** |
671 |
|
*/ |
672 |
|
public void testAbnormalInvokeAll1() { |
673 |
|
RecursiveAction a = new RecursiveAction() { |
674 |
< |
public void compute() { |
675 |
< |
try { |
676 |
< |
FailingFibAction g = new FailingFibAction(9); |
677 |
< |
invokeAll(g); |
678 |
< |
shouldThrow(); |
679 |
< |
} catch (FJException success) { |
811 |
< |
} |
674 |
> |
public void compute() { |
675 |
> |
try { |
676 |
> |
FailingFibAction g = new FailingFibAction(9); |
677 |
> |
invokeAll(g); |
678 |
> |
shouldThrow(); |
679 |
> |
} catch (FJException success) { |
680 |
|
} |
681 |
< |
}; |
682 |
< |
mainPool.invoke(a); |
681 |
> |
}}; |
682 |
> |
testInvokeOnPool(mainPool(), a); |
683 |
|
} |
684 |
|
|
685 |
|
/** |
687 |
|
*/ |
688 |
|
public void testAbnormalInvokeAll3() { |
689 |
|
RecursiveAction a = new RecursiveAction() { |
690 |
< |
public void compute() { |
691 |
< |
try { |
692 |
< |
FibAction f = new FibAction(8); |
693 |
< |
FailingFibAction g = new FailingFibAction(9); |
694 |
< |
FibAction h = new FibAction(7); |
695 |
< |
invokeAll(f, g, h); |
696 |
< |
shouldThrow(); |
697 |
< |
} catch (FJException success) { |
830 |
< |
} |
690 |
> |
public void compute() { |
691 |
> |
try { |
692 |
> |
FibAction f = new FibAction(8); |
693 |
> |
FailingFibAction g = new FailingFibAction(9); |
694 |
> |
FibAction h = new FibAction(7); |
695 |
> |
invokeAll(f, g, h); |
696 |
> |
shouldThrow(); |
697 |
> |
} catch (FJException success) { |
698 |
|
} |
699 |
< |
}; |
700 |
< |
mainPool.invoke(a); |
699 |
> |
}}; |
700 |
> |
testInvokeOnPool(mainPool(), a); |
701 |
|
} |
702 |
|
|
703 |
|
/** |
705 |
|
*/ |
706 |
|
public void testAbnormalInvokeAllCollection() { |
707 |
|
RecursiveAction a = new RecursiveAction() { |
708 |
< |
public void compute() { |
709 |
< |
try { |
710 |
< |
FailingFibAction f = new FailingFibAction(8); |
711 |
< |
FibAction g = new FibAction(9); |
712 |
< |
FibAction h = new FibAction(7); |
713 |
< |
HashSet set = new HashSet(); |
714 |
< |
set.add(f); |
715 |
< |
set.add(g); |
716 |
< |
set.add(h); |
717 |
< |
invokeAll(set); |
718 |
< |
shouldThrow(); |
719 |
< |
} catch (FJException success) { |
853 |
< |
} |
708 |
> |
public void compute() { |
709 |
> |
try { |
710 |
> |
FailingFibAction f = new FailingFibAction(8); |
711 |
> |
FibAction g = new FibAction(9); |
712 |
> |
FibAction h = new FibAction(7); |
713 |
> |
HashSet set = new HashSet(); |
714 |
> |
set.add(f); |
715 |
> |
set.add(g); |
716 |
> |
set.add(h); |
717 |
> |
invokeAll(set); |
718 |
> |
shouldThrow(); |
719 |
> |
} catch (FJException success) { |
720 |
|
} |
721 |
< |
}; |
722 |
< |
mainPool.invoke(a); |
721 |
> |
}}; |
722 |
> |
testInvokeOnPool(mainPool(), a); |
723 |
|
} |
724 |
|
|
725 |
|
/** |
728 |
|
*/ |
729 |
|
public void testTryUnfork() { |
730 |
|
RecursiveAction a = new RecursiveAction() { |
731 |
< |
public void compute() { |
732 |
< |
FibAction g = new FibAction(9); |
733 |
< |
g.fork(); |
734 |
< |
FibAction f = new FibAction(8); |
735 |
< |
f.fork(); |
736 |
< |
threadAssertTrue(f.tryUnfork()); |
737 |
< |
helpQuiesce(); |
738 |
< |
threadAssertFalse(f.isDone()); |
739 |
< |
threadAssertTrue(g.isDone()); |
740 |
< |
} |
741 |
< |
}; |
876 |
< |
singletonPool.invoke(a); |
731 |
> |
public void compute() { |
732 |
> |
FibAction g = new FibAction(9); |
733 |
> |
g.fork(); |
734 |
> |
FibAction f = new FibAction(8); |
735 |
> |
f.fork(); |
736 |
> |
threadAssertTrue(f.tryUnfork()); |
737 |
> |
helpQuiesce(); |
738 |
> |
threadAssertFalse(f.isDone()); |
739 |
> |
threadAssertTrue(g.isDone()); |
740 |
> |
}}; |
741 |
> |
testInvokeOnPool(singletonPool(), a); |
742 |
|
} |
743 |
|
|
744 |
|
/** |
747 |
|
*/ |
748 |
|
public void testGetSurplusQueuedTaskCount() { |
749 |
|
RecursiveAction a = new RecursiveAction() { |
750 |
< |
public void compute() { |
751 |
< |
FibAction h = new FibAction(7); |
752 |
< |
h.fork(); |
753 |
< |
FibAction g = new FibAction(9); |
754 |
< |
g.fork(); |
755 |
< |
FibAction f = new FibAction(8); |
756 |
< |
f.fork(); |
757 |
< |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
758 |
< |
helpQuiesce(); |
759 |
< |
} |
760 |
< |
}; |
896 |
< |
singletonPool.invoke(a); |
750 |
> |
public void compute() { |
751 |
> |
FibAction h = new FibAction(7); |
752 |
> |
h.fork(); |
753 |
> |
FibAction g = new FibAction(9); |
754 |
> |
g.fork(); |
755 |
> |
FibAction f = new FibAction(8); |
756 |
> |
f.fork(); |
757 |
> |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
758 |
> |
helpQuiesce(); |
759 |
> |
}}; |
760 |
> |
testInvokeOnPool(singletonPool(), a); |
761 |
|
} |
762 |
|
|
763 |
|
/** |
765 |
|
*/ |
766 |
|
public void testPeekNextLocalTask() { |
767 |
|
RecursiveAction a = new RecursiveAction() { |
768 |
< |
public void compute() { |
769 |
< |
FibAction g = new FibAction(9); |
770 |
< |
g.fork(); |
771 |
< |
FibAction f = new FibAction(8); |
772 |
< |
f.fork(); |
773 |
< |
threadAssertTrue(peekNextLocalTask() == f); |
774 |
< |
f.join(); |
775 |
< |
threadAssertTrue(f.isDone()); |
776 |
< |
helpQuiesce(); |
777 |
< |
} |
778 |
< |
}; |
915 |
< |
singletonPool.invoke(a); |
768 |
> |
public void compute() { |
769 |
> |
FibAction g = new FibAction(9); |
770 |
> |
g.fork(); |
771 |
> |
FibAction f = new FibAction(8); |
772 |
> |
f.fork(); |
773 |
> |
threadAssertTrue(peekNextLocalTask() == f); |
774 |
> |
f.join(); |
775 |
> |
threadAssertTrue(f.isDone()); |
776 |
> |
helpQuiesce(); |
777 |
> |
}}; |
778 |
> |
testInvokeOnPool(singletonPool(), a); |
779 |
|
} |
780 |
|
|
781 |
|
/** |
784 |
|
*/ |
785 |
|
public void testPollNextLocalTask() { |
786 |
|
RecursiveAction a = new RecursiveAction() { |
787 |
< |
public void compute() { |
788 |
< |
FibAction g = new FibAction(9); |
789 |
< |
g.fork(); |
790 |
< |
FibAction f = new FibAction(8); |
791 |
< |
f.fork(); |
792 |
< |
threadAssertTrue(pollNextLocalTask() == f); |
793 |
< |
helpQuiesce(); |
794 |
< |
threadAssertFalse(f.isDone()); |
795 |
< |
} |
796 |
< |
}; |
934 |
< |
singletonPool.invoke(a); |
787 |
> |
public void compute() { |
788 |
> |
FibAction g = new FibAction(9); |
789 |
> |
g.fork(); |
790 |
> |
FibAction f = new FibAction(8); |
791 |
> |
f.fork(); |
792 |
> |
threadAssertTrue(pollNextLocalTask() == f); |
793 |
> |
helpQuiesce(); |
794 |
> |
threadAssertFalse(f.isDone()); |
795 |
> |
}}; |
796 |
> |
testInvokeOnPool(singletonPool(), a); |
797 |
|
} |
798 |
|
|
799 |
|
/** |
802 |
|
*/ |
803 |
|
public void testPollTask() { |
804 |
|
RecursiveAction a = new RecursiveAction() { |
805 |
< |
public void compute() { |
806 |
< |
FibAction g = new FibAction(9); |
807 |
< |
g.fork(); |
808 |
< |
FibAction f = new FibAction(8); |
809 |
< |
f.fork(); |
810 |
< |
threadAssertTrue(pollTask() == f); |
811 |
< |
helpQuiesce(); |
812 |
< |
threadAssertFalse(f.isDone()); |
813 |
< |
threadAssertTrue(g.isDone()); |
814 |
< |
} |
815 |
< |
}; |
954 |
< |
singletonPool.invoke(a); |
805 |
> |
public void compute() { |
806 |
> |
FibAction g = new FibAction(9); |
807 |
> |
g.fork(); |
808 |
> |
FibAction f = new FibAction(8); |
809 |
> |
f.fork(); |
810 |
> |
threadAssertTrue(pollTask() == f); |
811 |
> |
helpQuiesce(); |
812 |
> |
threadAssertFalse(f.isDone()); |
813 |
> |
threadAssertTrue(g.isDone()); |
814 |
> |
}}; |
815 |
> |
testInvokeOnPool(singletonPool(), a); |
816 |
|
} |
817 |
|
|
818 |
|
/** |
820 |
|
*/ |
821 |
|
public void testPeekNextLocalTaskAsync() { |
822 |
|
RecursiveAction a = new RecursiveAction() { |
823 |
< |
public void compute() { |
824 |
< |
FibAction g = new FibAction(9); |
825 |
< |
g.fork(); |
826 |
< |
FibAction f = new FibAction(8); |
827 |
< |
f.fork(); |
828 |
< |
threadAssertTrue(peekNextLocalTask() == g); |
829 |
< |
f.join(); |
830 |
< |
helpQuiesce(); |
831 |
< |
threadAssertTrue(f.isDone()); |
832 |
< |
} |
833 |
< |
}; |
973 |
< |
asyncSingletonPool.invoke(a); |
823 |
> |
public void compute() { |
824 |
> |
FibAction g = new FibAction(9); |
825 |
> |
g.fork(); |
826 |
> |
FibAction f = new FibAction(8); |
827 |
> |
f.fork(); |
828 |
> |
threadAssertTrue(peekNextLocalTask() == g); |
829 |
> |
f.join(); |
830 |
> |
helpQuiesce(); |
831 |
> |
threadAssertTrue(f.isDone()); |
832 |
> |
}}; |
833 |
> |
testInvokeOnPool(asyncSingletonPool(), a); |
834 |
|
} |
835 |
|
|
836 |
|
/** |
839 |
|
*/ |
840 |
|
public void testPollNextLocalTaskAsync() { |
841 |
|
RecursiveAction a = new RecursiveAction() { |
842 |
< |
public void compute() { |
843 |
< |
FibAction g = new FibAction(9); |
844 |
< |
g.fork(); |
845 |
< |
FibAction f = new FibAction(8); |
846 |
< |
f.fork(); |
847 |
< |
threadAssertTrue(pollNextLocalTask() == g); |
848 |
< |
helpQuiesce(); |
849 |
< |
threadAssertTrue(f.isDone()); |
850 |
< |
threadAssertFalse(g.isDone()); |
851 |
< |
} |
852 |
< |
}; |
993 |
< |
asyncSingletonPool.invoke(a); |
842 |
> |
public void compute() { |
843 |
> |
FibAction g = new FibAction(9); |
844 |
> |
g.fork(); |
845 |
> |
FibAction f = new FibAction(8); |
846 |
> |
f.fork(); |
847 |
> |
threadAssertTrue(pollNextLocalTask() == g); |
848 |
> |
helpQuiesce(); |
849 |
> |
threadAssertTrue(f.isDone()); |
850 |
> |
threadAssertFalse(g.isDone()); |
851 |
> |
}}; |
852 |
> |
testInvokeOnPool(asyncSingletonPool(), a); |
853 |
|
} |
854 |
|
|
855 |
|
/** |
858 |
|
*/ |
859 |
|
public void testPollTaskAsync() { |
860 |
|
RecursiveAction a = new RecursiveAction() { |
861 |
< |
public void compute() { |
862 |
< |
FibAction g = new FibAction(9); |
863 |
< |
g.fork(); |
864 |
< |
FibAction f = new FibAction(8); |
865 |
< |
f.fork(); |
866 |
< |
threadAssertTrue(pollTask() == g); |
867 |
< |
helpQuiesce(); |
868 |
< |
threadAssertTrue(f.isDone()); |
869 |
< |
threadAssertFalse(g.isDone()); |
870 |
< |
} |
871 |
< |
}; |
1013 |
< |
asyncSingletonPool.invoke(a); |
861 |
> |
public void compute() { |
862 |
> |
FibAction g = new FibAction(9); |
863 |
> |
g.fork(); |
864 |
> |
FibAction f = new FibAction(8); |
865 |
> |
f.fork(); |
866 |
> |
threadAssertTrue(pollTask() == g); |
867 |
> |
helpQuiesce(); |
868 |
> |
threadAssertTrue(f.isDone()); |
869 |
> |
threadAssertFalse(g.isDone()); |
870 |
> |
}}; |
871 |
> |
testInvokeOnPool(asyncSingletonPool(), a); |
872 |
|
} |
873 |
|
|
874 |
|
} |