use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testForkTimedGet.
/**
* timed get of a forked task returns when task completes
*/
public void testForkTimedGet() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FibAction f = new FibAction(8);
assertSame(f, f.fork());
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
assertEquals(21, f.result);
checkCompletedNormally(f);
}
};
checkInvoke(a);
}
use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testInvokeAll2.
/**
* invokeAll(t1, t2) invokes all task arguments
*/
public void testInvokeAll2() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction f = new FibAction(8);
FibAction g = new FibAction(9);
invokeAll(f, g);
checkCompletedNormally(f);
assertEquals(21, f.result);
checkCompletedNormally(g);
assertEquals(34, g.result);
}
};
checkInvoke(a);
}
use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testForkGet.
/**
* get of a forked task returns when task completes
*/
public void testForkGet() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FibAction f = new FibAction(8);
assertSame(f, f.fork());
assertNull(f.get());
assertEquals(21, f.result);
checkCompletedNormally(f);
}
};
checkInvoke(a);
}
use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testInvokeAll1.
/**
* invokeAll(tasks) with 1 argument invokes task
*/
public void testInvokeAll1() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction f = new FibAction(8);
invokeAll(f);
checkCompletedNormally(f);
assertEquals(21, f.result);
}
};
checkInvoke(a);
}
use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testJoinIgnoresInterrupts.
/**
* join/quietlyJoin of a forked task succeeds in the presence of interrupts
*/
public void testJoinIgnoresInterrupts() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction f = new FibAction(8);
final Thread currentThread = Thread.currentThread();
// test join()
assertSame(f, f.fork());
currentThread.interrupt();
assertNull(f.join());
Thread.interrupted();
assertEquals(21, f.result);
checkCompletedNormally(f);
f = new FibAction(8);
f.cancel(true);
assertSame(f, f.fork());
currentThread.interrupt();
try {
f.join();
shouldThrow();
} catch (CancellationException success) {
Thread.interrupted();
checkCancelled(f);
}
f = new FibAction(8);
f.completeExceptionally(new FJException());
assertSame(f, f.fork());
currentThread.interrupt();
try {
f.join();
shouldThrow();
} catch (FJException success) {
Thread.interrupted();
checkCompletedAbnormally(f, success);
}
// test quietlyJoin()
f = new FibAction(8);
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
assertEquals(21, f.result);
checkCompletedNormally(f);
f = new FibAction(8);
f.cancel(true);
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
checkCancelled(f);
f = new FibAction(8);
f.completeExceptionally(new FJException());
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
checkCompletedAbnormally(f, f.getException());
}
};
checkInvoke(a);
a.reinitialize();
checkInvoke(a);
}
Aggregations