3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
+ |
|
7 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
+ |
import static java.util.concurrent.TimeUnit.SECONDS; |
9 |
+ |
|
10 |
+ |
import java.util.HashSet; |
11 |
|
import java.util.concurrent.ExecutionException; |
7 |
– |
import java.util.concurrent.CancellationException; |
12 |
|
import java.util.concurrent.ForkJoinPool; |
13 |
|
import java.util.concurrent.ForkJoinTask; |
10 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
14 |
|
import java.util.concurrent.RecursiveAction; |
12 |
– |
import java.util.concurrent.TimeUnit; |
15 |
|
import java.util.concurrent.TimeoutException; |
16 |
< |
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
17 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
18 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
17 |
< |
import java.util.HashSet; |
18 |
< |
import junit.framework.*; |
16 |
> |
|
17 |
> |
import junit.framework.Test; |
18 |
> |
import junit.framework.TestSuite; |
19 |
|
|
20 |
|
public class ForkJoinTask8Test extends JSR166TestCase { |
21 |
|
|
32 |
|
static final short INITIAL_STATE = -1; |
33 |
|
static final short COMPLETE_STATE = 0; |
34 |
|
static final short EXCEPTION_STATE = 1; |
35 |
– |
|
35 |
|
|
36 |
|
public static void main(String[] args) { |
37 |
|
junit.textui.TestRunner.run(suite()); |
180 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
181 |
|
} |
182 |
|
|
184 |
– |
|
183 |
|
public static final class FJException extends RuntimeException { |
184 |
|
FJException() { super(); } |
185 |
|
} |
204 |
|
} |
205 |
|
|
206 |
|
protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) { |
207 |
< |
if (this.getForkJoinTaskTag() != COMPLETE_STATE || |
208 |
< |
x.getForkJoinTaskTag() != COMPLETE_STATE || |
207 |
> |
if (this.getForkJoinTaskTag() != COMPLETE_STATE || |
208 |
> |
x.getForkJoinTaskTag() != COMPLETE_STATE || |
209 |
|
y.getForkJoinTaskTag() != COMPLETE_STATE) { |
210 |
|
completeThisExceptionally(new FJException()); |
211 |
|
} |
239 |
|
a.sibling = null; |
240 |
|
a.parent = null; |
241 |
|
a.completeThis(); |
242 |
< |
if (p == null || |
242 |
> |
if (p == null || |
243 |
|
p.compareAndSetForkJoinTaskTag(INITIAL_STATE, COMPLETE_STATE)) |
244 |
|
break; |
245 |
|
try { |
277 |
|
super.reinitialize(); |
278 |
|
} |
279 |
|
|
282 |
– |
|
280 |
|
} |
281 |
|
|
282 |
|
static final class AsyncFib extends BinaryAsyncAction { |
301 |
|
} |
302 |
|
f.complete(); |
303 |
|
} |
304 |
< |
catch(Throwable ex) { |
304 |
> |
catch (Throwable ex) { |
305 |
|
compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE); |
306 |
|
} |
307 |
|
return false; |
570 |
|
testInvokeOnPool(mainPool(), a); |
571 |
|
} |
572 |
|
|
576 |
– |
|
573 |
|
/** |
574 |
|
* getPool of executing task returns its pool |
575 |
|
*/ |
721 |
|
} |
722 |
|
|
723 |
|
/** |
724 |
< |
* invokeAll(tasks) with any null task throws NPE |
724 |
> |
* invokeAll(tasks) with any null task throws NullPointerException |
725 |
|
*/ |
726 |
< |
public void testInvokeAllNPE() { |
726 |
> |
public void testInvokeAllNullTask() { |
727 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
728 |
|
protected void realCompute() { |
729 |
|
AsyncFib f = new AsyncFib(8); |
730 |
|
AsyncFib g = new AsyncFib(9); |
731 |
< |
AsyncFib h = null; |
732 |
< |
try { |
733 |
< |
invokeAll(f, g, h); |
734 |
< |
shouldThrow(); |
735 |
< |
} catch (NullPointerException success) {} |
731 |
> |
AsyncFib nul = null; |
732 |
> |
Runnable[] throwingActions = { |
733 |
> |
() -> invokeAll(nul), |
734 |
> |
() -> invokeAll(nul, nul), |
735 |
> |
() -> invokeAll(f, g, nul), |
736 |
> |
() -> invokeAll(f, nul, g), |
737 |
> |
() -> invokeAll(nul, f, g), |
738 |
> |
}; |
739 |
> |
assertThrows(NullPointerException.class, throwingActions); |
740 |
|
}}; |
741 |
|
testInvokeOnPool(mainPool(), a); |
742 |
|
} |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
< |
* invokeAll(collection) throws exception if any task does |
799 |
> |
* invokeAll(collection) throws exception if any task does |
800 |
|
*/ |
801 |
|
public void testAbnormalInvokeAllCollection() { |
802 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1302 |
|
} |
1303 |
|
|
1304 |
|
/** |
1305 |
< |
* invokeAll(tasks) with any null task throws NPE |
1305 |
> |
* invokeAll(tasks) with any null task throws NullPointerException |
1306 |
|
*/ |
1307 |
< |
public void testInvokeAllNPESingleton() { |
1307 |
> |
public void testInvokeAllNullTaskSingleton() { |
1308 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1309 |
|
protected void realCompute() { |
1310 |
|
AsyncFib f = new AsyncFib(8); |
1311 |
|
AsyncFib g = new AsyncFib(9); |
1312 |
< |
AsyncFib h = null; |
1313 |
< |
try { |
1314 |
< |
invokeAll(f, g, h); |
1315 |
< |
shouldThrow(); |
1316 |
< |
} catch (NullPointerException success) {} |
1312 |
> |
AsyncFib nul = null; |
1313 |
> |
Runnable[] throwingActions = { |
1314 |
> |
() -> invokeAll(nul), |
1315 |
> |
() -> invokeAll(nul, nul), |
1316 |
> |
() -> invokeAll(f, g, nul), |
1317 |
> |
() -> invokeAll(f, nul, g), |
1318 |
> |
() -> invokeAll(nul, f, g), |
1319 |
> |
}; |
1320 |
> |
assertThrows(NullPointerException.class, throwingActions); |
1321 |
|
}}; |
1322 |
|
testInvokeOnPool(singletonPool(), a); |
1323 |
|
} |
1377 |
|
} |
1378 |
|
|
1379 |
|
/** |
1380 |
< |
* invokeAll(collection) throws exception if any task does |
1380 |
> |
* invokeAll(collection) throws exception if any task does |
1381 |
|
*/ |
1382 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1383 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1399 |
|
testInvokeOnPool(singletonPool(), a); |
1400 |
|
} |
1401 |
|
|
1398 |
– |
|
1402 |
|
/** |
1403 |
|
* ForkJoinTask.quietlyComplete returns when task completes |
1404 |
|
* normally without setting a value. The most recent value |