551 |
|
public CompletableFuture<Integer> apply(Integer x) { |
552 |
|
invoked(); |
553 |
|
value = x; |
554 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
555 |
< |
assertTrue(f.complete(inc(x))); |
556 |
< |
return f; |
554 |
> |
return CompletableFuture.completedFuture(inc(x)); |
555 |
|
} |
556 |
|
} |
557 |
|
|
572 |
|
ExceptionalCompletableFutureFunction(ExecutionMode m) { super(m); } |
573 |
|
public CompletionStage<Integer> apply(Throwable x) { |
574 |
|
invoked(); |
575 |
< |
CompletableFuture<Integer> d = new CompletableFuture<Integer>(); |
578 |
< |
d.complete(value); |
579 |
< |
return d; |
575 |
> |
return CompletableFuture.completedFuture(value); |
576 |
|
} |
577 |
|
} |
578 |
|
|
926 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
927 |
|
for (Integer v1 : new Integer[] { 1, null }) |
928 |
|
{ |
933 |
– |
final AtomicInteger a = new AtomicInteger(0); |
929 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
930 |
|
if (!createIncomplete) assertTrue(f.complete(v1)); |
931 |
|
final CompletableFuture<Integer> g = m.exceptionally |
932 |
|
(f, (Throwable t) -> { |
938 |
– |
a.getAndIncrement(); |
933 |
|
threadFail("should not be called"); |
934 |
|
return null; // unreached |
935 |
|
}); |
937 |
|
|
938 |
|
checkCompletedNormally(g, v1); |
939 |
|
checkCompletedNormally(f, v1); |
946 |
– |
assertEquals(0, a.get()); |
940 |
|
}} |
941 |
|
|
942 |
|
/** |
3167 |
|
final CompletableFuture<Integer> g = m.exceptionallyCompose(f, r); |
3168 |
|
if (createIncomplete) assertTrue(f.complete(v1)); |
3169 |
|
|
3170 |
+ |
if (!createIncomplete && testImplementationDetails) |
3171 |
+ |
assertSame(f, g); |
3172 |
|
checkCompletedNormally(f, v1); |
3173 |
|
checkCompletedNormally(g, v1); |
3174 |
|
r.assertNotInvoked(); |
4779 |
|
} |
4780 |
|
|
4781 |
|
/** |
4782 |
+ |
* default-implemented exceptionallyAsync action is not invoked when |
4783 |
+ |
* source completes normally, and source result is propagated |
4784 |
+ |
*/ |
4785 |
+ |
public void testDefaultExceptionallyAsync_normalCompletion() { |
4786 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4787 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
4788 |
+ |
{ |
4789 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
4790 |
+ |
final DelegatedCompletionStage<Integer> d = |
4791 |
+ |
new DelegatedCompletionStage<Integer>(f); |
4792 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
4793 |
+ |
final CompletionStage<Integer> g = d.exceptionallyAsync |
4794 |
+ |
((Throwable t) -> { |
4795 |
+ |
threadFail("should not be called"); |
4796 |
+ |
return null; // unreached |
4797 |
+ |
}); |
4798 |
+ |
if (createIncomplete) assertTrue(f.complete(v1)); |
4799 |
+ |
|
4800 |
+ |
checkCompletedNormally(g.toCompletableFuture(), v1); |
4801 |
+ |
}} |
4802 |
+ |
|
4803 |
+ |
/** |
4804 |
|
* default-implemented exceptionallyAsync action completes with |
4805 |
|
* function value on source exception |
4806 |
|
*/ |
4807 |
< |
public void testDefaulExceptionallyAsync_exceptionalCompletion() { |
4807 |
> |
public void testDefaultExceptionallyAsync_exceptionalCompletion() { |
4808 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
4809 |
|
for (Integer v1 : new Integer[] { 1, null }) |
4810 |
|
{ |
4831 |
|
* throws an exception, it completes exceptionally with that |
4832 |
|
* exception |
4833 |
|
*/ |
4834 |
< |
public void testDefaulExceptionallyAsync_exceptionalCompletionActionFailed() { |
4834 |
> |
public void testDefaultExceptionallyAsync_exceptionalCompletionActionFailed() { |
4835 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
4836 |
|
{ |
4837 |
|
final AtomicInteger a = new AtomicInteger(0); |
5004 |
|
final DelegatedCompletionStage<Integer> d = |
5005 |
|
new DelegatedCompletionStage<Integer>(f); |
5006 |
|
if (!createIncomplete) assertTrue(f.complete(v1)); |
5007 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5007 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5008 |
|
if (createIncomplete) assertTrue(f.complete(v1)); |
5009 |
|
|
5010 |
|
checkCompletedNormally(f, v1); |
5026 |
|
final DelegatedCompletionStage<Integer> d = |
5027 |
|
new DelegatedCompletionStage<Integer>(f); |
5028 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
5029 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5029 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5030 |
|
if (createIncomplete) f.completeExceptionally(ex); |
5031 |
|
|
5032 |
|
checkCompletedExceptionally(f, ex); |
5049 |
|
final DelegatedCompletionStage<Integer> d = |
5050 |
|
new DelegatedCompletionStage<Integer>(f); |
5051 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
5052 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5052 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5053 |
|
if (createIncomplete) f.completeExceptionally(ex); |
5054 |
|
|
5055 |
|
checkCompletedExceptionally(f, ex); |