503 |
|
public void checkExecutionMode() { |
504 |
|
assertNull(ForkJoinTask.getPool()); |
505 |
|
} |
506 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
507 |
+ |
throw new UnsupportedOperationException(); |
508 |
+ |
} |
509 |
|
public <T> CompletableFuture<Void> thenRun |
510 |
|
(CompletableFuture<T> f, Runnable a) { |
511 |
|
return f.thenRun(a); |
574 |
|
assertSame(ForkJoinPool.commonPool(), |
575 |
|
ForkJoinTask.getPool()); |
576 |
|
} |
577 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
578 |
+ |
return CompletableFuture.runAsync(a); |
579 |
+ |
} |
580 |
|
public <T> CompletableFuture<Void> thenRun |
581 |
|
(CompletableFuture<T> f, Runnable a) { |
582 |
|
return f.thenRunAsync(a); |
644 |
|
public void checkExecutionMode() { |
645 |
|
assertTrue(ThreadExecutor.startedCurrentThread()); |
646 |
|
} |
647 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
648 |
+ |
return CompletableFuture.runAsync(a, new ThreadExecutor()); |
649 |
+ |
} |
650 |
|
public <T> CompletableFuture<Void> thenRun |
651 |
|
(CompletableFuture<T> f, Runnable a) { |
652 |
|
return f.thenRunAsync(a, new ThreadExecutor()); |
711 |
|
}; |
712 |
|
|
713 |
|
public abstract void checkExecutionMode(); |
714 |
+ |
public abstract CompletableFuture<Void> runAsync(Runnable a); |
715 |
|
public abstract <T> CompletableFuture<Void> thenRun |
716 |
|
(CompletableFuture<T> f, Runnable a); |
717 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
790 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
791 |
|
final CompletableFuture<Integer> g = f.exceptionally |
792 |
|
((Throwable t) -> { |
793 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
794 |
|
threadAssertSame(t, ex); |
795 |
|
a.getAndIncrement(); |
796 |
|
return v1; |
812 |
|
if (!createIncomplete) f.completeExceptionally(ex1); |
813 |
|
final CompletableFuture<Integer> g = f.exceptionally |
814 |
|
((Throwable t) -> { |
815 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
816 |
|
threadAssertSame(t, ex1); |
817 |
|
a.getAndIncrement(); |
818 |
|
throw ex2; |
838 |
|
final CompletableFuture<Integer> g = m.handle |
839 |
|
(f, |
840 |
|
(Integer x, Throwable t) -> { |
841 |
+ |
m.checkExecutionMode(); |
842 |
|
threadAssertSame(x, v1); |
843 |
|
threadAssertNull(t); |
844 |
|
a.getAndIncrement(); |
867 |
|
final CompletableFuture<Integer> g = m.handle |
868 |
|
(f, |
869 |
|
(Integer x, Throwable t) -> { |
870 |
+ |
m.checkExecutionMode(); |
871 |
|
threadAssertNull(x); |
872 |
|
threadAssertSame(t, ex); |
873 |
|
a.getAndIncrement(); |
896 |
|
final CompletableFuture<Integer> g = m.handle |
897 |
|
(f, |
898 |
|
(Integer x, Throwable t) -> { |
899 |
+ |
m.checkExecutionMode(); |
900 |
|
threadAssertNull(x); |
901 |
|
threadAssertTrue(t instanceof CancellationException); |
902 |
|
a.getAndIncrement(); |
924 |
|
final CompletableFuture<Integer> g = m.handle |
925 |
|
(f, |
926 |
|
(Integer x, Throwable t) -> { |
927 |
+ |
m.checkExecutionMode(); |
928 |
|
threadAssertNull(x); |
929 |
|
threadAssertSame(ex1, t); |
930 |
|
a.getAndIncrement(); |
949 |
|
final CompletableFuture<Integer> g = m.handle |
950 |
|
(f, |
951 |
|
(Integer x, Throwable t) -> { |
952 |
+ |
m.checkExecutionMode(); |
953 |
|
threadAssertSame(x, v1); |
954 |
|
threadAssertNull(t); |
955 |
|
a.getAndIncrement(); |
965 |
|
/** |
966 |
|
* runAsync completes after running Runnable |
967 |
|
*/ |
968 |
< |
public void testRunAsync() { |
969 |
< |
Noop r = new Noop(ExecutionMode.ASYNC); |
970 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
968 |
> |
public void testRunAsync_normalCompletion() { |
969 |
> |
ExecutionMode[] executionModes = { |
970 |
> |
ExecutionMode.ASYNC, |
971 |
> |
ExecutionMode.EXECUTOR, |
972 |
> |
}; |
973 |
> |
for (ExecutionMode m : executionModes) |
974 |
> |
{ |
975 |
> |
final Noop r = new Noop(m); |
976 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
977 |
|
assertNull(f.join()); |
955 |
– |
assertEquals(1, r.invocationCount); |
978 |
|
checkCompletedNormally(f, null); |
957 |
– |
} |
958 |
– |
|
959 |
– |
/** |
960 |
– |
* runAsync with executor completes after running Runnable |
961 |
– |
*/ |
962 |
– |
public void testRunAsync2() { |
963 |
– |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
964 |
– |
ThreadExecutor exec = new ThreadExecutor(); |
965 |
– |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
966 |
– |
assertNull(f.join()); |
979 |
|
assertEquals(1, r.invocationCount); |
980 |
< |
checkCompletedNormally(f, null); |
969 |
< |
assertEquals(1, exec.count.get()); |
970 |
< |
} |
980 |
> |
}} |
981 |
|
|
982 |
|
/** |
983 |
|
* failing runAsync completes exceptionally after running Runnable |
984 |
|
*/ |
985 |
< |
public void testRunAsync3() { |
986 |
< |
FailingRunnable r = new FailingRunnable(ExecutionMode.ASYNC); |
987 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
985 |
> |
public void testRunAsync_exceptionalCompletion() { |
986 |
> |
ExecutionMode[] executionModes = { |
987 |
> |
ExecutionMode.ASYNC, |
988 |
> |
ExecutionMode.EXECUTOR, |
989 |
> |
}; |
990 |
> |
for (ExecutionMode m : executionModes) |
991 |
> |
{ |
992 |
> |
final FailingRunnable r = new FailingRunnable(m); |
993 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
994 |
|
checkCompletedWithWrappedCFException(f); |
995 |
|
assertEquals(1, r.invocationCount); |
996 |
< |
} |
996 |
> |
}} |
997 |
|
|
998 |
|
/** |
999 |
|
* supplyAsync completes with result of supplier |