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 |
|
|
4780 |
|
} |
4781 |
|
|
4782 |
|
/** |
4783 |
+ |
* default-implemented exceptionallyAsync action is not invoked when |
4784 |
+ |
* source completes normally, and source result is propagated |
4785 |
+ |
*/ |
4786 |
+ |
public void testDefaultExceptionallyAsync_normalCompletion() { |
4787 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4788 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
4789 |
+ |
{ |
4790 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
4791 |
+ |
final DelegatedCompletionStage<Integer> d = |
4792 |
+ |
new DelegatedCompletionStage<Integer>(f); |
4793 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
4794 |
+ |
final CompletionStage<Integer> g = d.exceptionallyAsync |
4795 |
+ |
((Throwable t) -> { |
4796 |
+ |
threadFail("should not be called"); |
4797 |
+ |
return null; // unreached |
4798 |
+ |
}); |
4799 |
+ |
if (createIncomplete) assertTrue(f.complete(v1)); |
4800 |
+ |
|
4801 |
+ |
checkCompletedNormally(g.toCompletableFuture(), v1); |
4802 |
+ |
}} |
4803 |
+ |
|
4804 |
+ |
/** |
4805 |
|
* default-implemented exceptionallyAsync action completes with |
4806 |
|
* function value on source exception |
4807 |
|
*/ |
4808 |
< |
public void testDefaulExceptionallyAsync_exceptionalCompletion() { |
4808 |
> |
public void testDefaultExceptionallyAsync_exceptionalCompletion() { |
4809 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
4810 |
|
for (Integer v1 : new Integer[] { 1, null }) |
4811 |
|
{ |
4832 |
|
* throws an exception, it completes exceptionally with that |
4833 |
|
* exception |
4834 |
|
*/ |
4835 |
< |
public void testDefaulExceptionallyAsync_exceptionalCompletionActionFailed() { |
4835 |
> |
public void testDefaultExceptionallyAsync_exceptionalCompletionActionFailed() { |
4836 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
4837 |
|
{ |
4838 |
|
final AtomicInteger a = new AtomicInteger(0); |
5005 |
|
final DelegatedCompletionStage<Integer> d = |
5006 |
|
new DelegatedCompletionStage<Integer>(f); |
5007 |
|
if (!createIncomplete) assertTrue(f.complete(v1)); |
5008 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5008 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5009 |
|
if (createIncomplete) assertTrue(f.complete(v1)); |
5010 |
|
|
5011 |
|
checkCompletedNormally(f, v1); |
5027 |
|
final DelegatedCompletionStage<Integer> d = |
5028 |
|
new DelegatedCompletionStage<Integer>(f); |
5029 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
5030 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5030 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5031 |
|
if (createIncomplete) f.completeExceptionally(ex); |
5032 |
|
|
5033 |
|
checkCompletedExceptionally(f, ex); |
5050 |
|
final DelegatedCompletionStage<Integer> d = |
5051 |
|
new DelegatedCompletionStage<Integer>(f); |
5052 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
5053 |
< |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5053 |
> |
final CompletionStage<Integer> g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); |
5054 |
|
if (createIncomplete) f.completeExceptionally(ex); |
5055 |
|
|
5056 |
|
checkCompletedExceptionally(f, ex); |