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