16 |
|
import java.util.concurrent.Future; |
17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
+ |
import java.util.concurrent.CompletionStage; |
20 |
|
import java.util.concurrent.TimeoutException; |
21 |
|
import java.util.concurrent.atomic.AtomicInteger; |
22 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
103 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
104 |
|
} |
105 |
|
|
106 |
+ |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
107 |
+ |
CFException ex) { |
108 |
+ |
try { |
109 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
110 |
+ |
shouldThrow(); |
111 |
+ |
} catch (ExecutionException success) { |
112 |
+ |
assertSame(ex, success.getCause()); |
113 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
114 |
+ |
try { |
115 |
+ |
f.join(); |
116 |
+ |
shouldThrow(); |
117 |
+ |
} catch (CompletionException success) { |
118 |
+ |
assertSame(ex, success.getCause()); |
119 |
+ |
} |
120 |
+ |
try { |
121 |
+ |
f.getNow(null); |
122 |
+ |
shouldThrow(); |
123 |
+ |
} catch (CompletionException success) { |
124 |
+ |
assertSame(ex, success.getCause()); |
125 |
+ |
} |
126 |
+ |
try { |
127 |
+ |
f.get(); |
128 |
+ |
shouldThrow(); |
129 |
+ |
} catch (ExecutionException success) { |
130 |
+ |
assertSame(ex, success.getCause()); |
131 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
132 |
+ |
assertTrue(f.isDone()); |
133 |
+ |
assertFalse(f.isCancelled()); |
134 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
135 |
+ |
} |
136 |
+ |
|
137 |
|
void checkCancelled(CompletableFuture<?> f) { |
138 |
|
try { |
139 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
291 |
|
assertEquals(g.getNumberOfDependents(), 0); |
292 |
|
} |
293 |
|
|
262 |
– |
|
294 |
|
/** |
295 |
|
* toString indicates current completion state |
296 |
|
*/ |
318 |
|
|
319 |
|
// Choose non-commutative actions for better coverage |
320 |
|
|
321 |
+ |
// A non-commutative function that handles and produces null values as well. |
322 |
+ |
static Integer subtract(Integer x, Integer y) { |
323 |
+ |
return (x == null && y == null) ? null : |
324 |
+ |
((x == null) ? 42 : x.intValue()) |
325 |
+ |
- ((y == null) ? 99 : y.intValue()); |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
// A function that handles and produces null values as well. |
329 |
+ |
static Integer inc(Integer x) { |
330 |
+ |
return (x == null) ? null : x + 1; |
331 |
+ |
} |
332 |
+ |
|
333 |
|
static final Supplier<Integer> supplyOne = |
334 |
|
() -> Integer.valueOf(1); |
335 |
|
static final Function<Integer, Integer> inc = |
336 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
337 |
|
static final BiFunction<Integer, Integer, Integer> subtract = |
338 |
< |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); |
338 |
> |
(Integer x, Integer y) -> subtract(x, y); |
339 |
|
static final class IncAction implements Consumer<Integer> { |
340 |
< |
int value; |
341 |
< |
public void accept(Integer x) { value = x.intValue() + 1; } |
340 |
> |
int invocationCount = 0; |
341 |
> |
Integer value; |
342 |
> |
public boolean ran() { return invocationCount == 1; } |
343 |
> |
public void accept(Integer x) { |
344 |
> |
invocationCount++; |
345 |
> |
value = inc(x); |
346 |
> |
} |
347 |
> |
} |
348 |
> |
static final class IncFunction implements Function<Integer,Integer> { |
349 |
> |
int invocationCount = 0; |
350 |
> |
Integer value; |
351 |
> |
public boolean ran() { return invocationCount == 1; } |
352 |
> |
public Integer apply(Integer x) { |
353 |
> |
invocationCount++; |
354 |
> |
return value = inc(x); |
355 |
> |
} |
356 |
|
} |
357 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
358 |
< |
int value; |
358 |
> |
int invocationCount = 0; |
359 |
> |
Integer value; |
360 |
> |
// Check this action was invoked exactly once when result is computed. |
361 |
> |
public boolean ran() { return invocationCount == 1; } |
362 |
|
public void accept(Integer x, Integer y) { |
363 |
< |
value = x.intValue() - y.intValue(); |
363 |
> |
invocationCount++; |
364 |
> |
value = subtract(x, y); |
365 |
> |
} |
366 |
> |
} |
367 |
> |
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
368 |
> |
int invocationCount = 0; |
369 |
> |
Integer value; |
370 |
> |
// Check this action was invoked exactly once when result is computed. |
371 |
> |
public boolean ran() { return invocationCount == 1; } |
372 |
> |
public Integer apply(Integer x, Integer y) { |
373 |
> |
invocationCount++; |
374 |
> |
return value = subtract(x, y); |
375 |
|
} |
376 |
|
} |
377 |
|
static final class Noop implements Runnable { |
445 |
|
} |
446 |
|
} |
447 |
|
|
448 |
+ |
/** |
449 |
+ |
* Permits the testing of parallel code for the 3 different |
450 |
+ |
* execution modes without repeating all the testing code. |
451 |
+ |
*/ |
452 |
+ |
enum ExecutionMode { |
453 |
+ |
DEFAULT { |
454 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
455 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
456 |
+ |
return f.runAfterBoth(g, a); |
457 |
+ |
} |
458 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
459 |
+ |
(CompletableFuture<T> f, |
460 |
+ |
CompletionStage<? extends U> g, |
461 |
+ |
BiConsumer<? super T,? super U> a) { |
462 |
+ |
return f.thenAcceptBoth(g, a); |
463 |
+ |
} |
464 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
465 |
+ |
(CompletableFuture<T> f, |
466 |
+ |
CompletionStage<? extends U> g, |
467 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
468 |
+ |
return f.thenCombine(g, a); |
469 |
+ |
} |
470 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
471 |
+ |
(CompletableFuture<T> f, |
472 |
+ |
CompletionStage<? extends T> g, |
473 |
+ |
Function<? super T,U> a) { |
474 |
+ |
return f.applyToEither(g, a); |
475 |
+ |
} |
476 |
+ |
public <T> CompletableFuture<Void> acceptEither |
477 |
+ |
(CompletableFuture<T> f, |
478 |
+ |
CompletionStage<? extends T> g, |
479 |
+ |
Consumer<? super T> a) { |
480 |
+ |
return f.acceptEither(g, a); |
481 |
+ |
} |
482 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
483 |
+ |
(CompletableFuture<T> f, |
484 |
+ |
CompletionStage<?> g, |
485 |
+ |
java.lang.Runnable a) { |
486 |
+ |
return f.runAfterEither(g, a); |
487 |
+ |
} |
488 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
489 |
+ |
(CompletableFuture<T> f, |
490 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
491 |
+ |
return f.thenCompose(a); |
492 |
+ |
} |
493 |
+ |
public <T> CompletableFuture<T> whenComplete |
494 |
+ |
(CompletableFuture<T> f, |
495 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
496 |
+ |
return f.whenComplete(a); |
497 |
+ |
} |
498 |
+ |
}, |
499 |
+ |
|
500 |
+ |
// /** Experimental way to do more testing */ |
501 |
+ |
// REVERSE_DEFAULT { |
502 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
503 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
504 |
+ |
// return g.runAfterBoth(f, a); |
505 |
+ |
// } |
506 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
507 |
+ |
// (CompletableFuture<T> f, |
508 |
+ |
// CompletionStage<? extends U> g, |
509 |
+ |
// BiConsumer<? super T,? super U> a) { |
510 |
+ |
// return DEFAULT.thenAcceptBoth(f, g, a); |
511 |
+ |
// } |
512 |
+ |
// }, |
513 |
+ |
|
514 |
+ |
DEFAULT_ASYNC { |
515 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
516 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
517 |
+ |
return f.runAfterBothAsync(g, a); |
518 |
+ |
} |
519 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
520 |
+ |
(CompletableFuture<T> f, |
521 |
+ |
CompletionStage<? extends U> g, |
522 |
+ |
BiConsumer<? super T,? super U> a) { |
523 |
+ |
return f.thenAcceptBothAsync(g, a); |
524 |
+ |
} |
525 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
526 |
+ |
(CompletableFuture<T> f, |
527 |
+ |
CompletionStage<? extends U> g, |
528 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
529 |
+ |
return f.thenCombineAsync(g, a); |
530 |
+ |
} |
531 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
532 |
+ |
(CompletableFuture<T> f, |
533 |
+ |
CompletionStage<? extends T> g, |
534 |
+ |
Function<? super T,U> a) { |
535 |
+ |
return f.applyToEitherAsync(g, a); |
536 |
+ |
} |
537 |
+ |
public <T> CompletableFuture<Void> acceptEither |
538 |
+ |
(CompletableFuture<T> f, |
539 |
+ |
CompletionStage<? extends T> g, |
540 |
+ |
Consumer<? super T> a) { |
541 |
+ |
return f.acceptEitherAsync(g, a); |
542 |
+ |
} |
543 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
544 |
+ |
(CompletableFuture<T> f, |
545 |
+ |
CompletionStage<?> g, |
546 |
+ |
java.lang.Runnable a) { |
547 |
+ |
return f.runAfterEitherAsync(g, a); |
548 |
+ |
} |
549 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
550 |
+ |
(CompletableFuture<T> f, |
551 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
552 |
+ |
return f.thenComposeAsync(a); |
553 |
+ |
} |
554 |
+ |
public <T> CompletableFuture<T> whenComplete |
555 |
+ |
(CompletableFuture<T> f, |
556 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
557 |
+ |
return f.whenCompleteAsync(a); |
558 |
+ |
} |
559 |
+ |
}, |
560 |
+ |
|
561 |
+ |
// REVERSE_DEFAULT_ASYNC { |
562 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
563 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
564 |
+ |
// return f.runAfterBothAsync(g, a); |
565 |
+ |
// } |
566 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
567 |
+ |
// (CompletableFuture<T> f, |
568 |
+ |
// CompletionStage<? extends U> g, |
569 |
+ |
// BiConsumer<? super T,? super U> a) { |
570 |
+ |
// return DEFAULT_ASYNC.thenAcceptBoth(f, g, a); |
571 |
+ |
// } |
572 |
+ |
// }, |
573 |
+ |
|
574 |
+ |
EXECUTOR { |
575 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
576 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
577 |
+ |
return f.runAfterBothAsync(g, a, new ThreadExecutor()); |
578 |
+ |
} |
579 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
580 |
+ |
(CompletableFuture<T> f, |
581 |
+ |
CompletionStage<? extends U> g, |
582 |
+ |
BiConsumer<? super T,? super U> a) { |
583 |
+ |
return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); |
584 |
+ |
} |
585 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
586 |
+ |
(CompletableFuture<T> f, |
587 |
+ |
CompletionStage<? extends U> g, |
588 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
589 |
+ |
return f.thenCombineAsync(g, a, new ThreadExecutor()); |
590 |
+ |
} |
591 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
592 |
+ |
(CompletableFuture<T> f, |
593 |
+ |
CompletionStage<? extends T> g, |
594 |
+ |
Function<? super T,U> a) { |
595 |
+ |
return f.applyToEitherAsync(g, a, new ThreadExecutor()); |
596 |
+ |
} |
597 |
+ |
public <T> CompletableFuture<Void> acceptEither |
598 |
+ |
(CompletableFuture<T> f, |
599 |
+ |
CompletionStage<? extends T> g, |
600 |
+ |
Consumer<? super T> a) { |
601 |
+ |
return f.acceptEitherAsync(g, a, new ThreadExecutor()); |
602 |
+ |
} |
603 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
604 |
+ |
(CompletableFuture<T> f, |
605 |
+ |
CompletionStage<?> g, |
606 |
+ |
java.lang.Runnable a) { |
607 |
+ |
return f.runAfterEitherAsync(g, a, new ThreadExecutor()); |
608 |
+ |
} |
609 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
610 |
+ |
(CompletableFuture<T> f, |
611 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
612 |
+ |
return f.thenComposeAsync(a, new ThreadExecutor()); |
613 |
+ |
} |
614 |
+ |
public <T> CompletableFuture<T> whenComplete |
615 |
+ |
(CompletableFuture<T> f, |
616 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
617 |
+ |
return f.whenCompleteAsync(a, new ThreadExecutor()); |
618 |
+ |
} |
619 |
+ |
}; |
620 |
+ |
|
621 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
622 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a); |
623 |
+ |
public abstract <T,U> CompletableFuture<Void> thenAcceptBoth |
624 |
+ |
(CompletableFuture<T> f, |
625 |
+ |
CompletionStage<? extends U> g, |
626 |
+ |
BiConsumer<? super T,? super U> a); |
627 |
+ |
public abstract <T,U,V> CompletableFuture<V> thenCombine |
628 |
+ |
(CompletableFuture<T> f, |
629 |
+ |
CompletionStage<? extends U> g, |
630 |
+ |
BiFunction<? super T,? super U,? extends V> a); |
631 |
+ |
public abstract <T,U> CompletableFuture<U> applyToEither |
632 |
+ |
(CompletableFuture<T> f, |
633 |
+ |
CompletionStage<? extends T> g, |
634 |
+ |
Function<? super T,U> a); |
635 |
+ |
public abstract <T> CompletableFuture<Void> acceptEither |
636 |
+ |
(CompletableFuture<T> f, |
637 |
+ |
CompletionStage<? extends T> g, |
638 |
+ |
Consumer<? super T> a); |
639 |
+ |
public abstract <T> CompletableFuture<Void> runAfterEither |
640 |
+ |
(CompletableFuture<T> f, |
641 |
+ |
CompletionStage<?> g, |
642 |
+ |
java.lang.Runnable a); |
643 |
+ |
public abstract <T,U> CompletableFuture<U> thenCompose |
644 |
+ |
(CompletableFuture<T> f, |
645 |
+ |
Function<? super T,? extends CompletionStage<U>> a); |
646 |
+ |
public abstract <T> CompletableFuture<T> whenComplete |
647 |
+ |
(CompletableFuture<T> f, |
648 |
+ |
BiConsumer<? super T,? super Throwable> a); |
649 |
+ |
|
650 |
+ |
|
651 |
+ |
} |
652 |
|
|
653 |
|
/** |
654 |
|
* exceptionally action completes with function value on source |
655 |
< |
* exception; otherwise with source value |
655 |
> |
* exception; otherwise with source value |
656 |
|
*/ |
657 |
|
public void testExceptionally() { |
658 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
900 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
901 |
|
f.complete(one); |
902 |
|
checkCompletedNormally(g, null); |
903 |
< |
assertEquals(r.value, 2); |
903 |
> |
assertEquals(r.value, (Integer) 2); |
904 |
|
} |
905 |
|
|
906 |
|
/** |
938 |
|
checkCompletedWithWrappedCancellationException(g); |
939 |
|
} |
940 |
|
|
666 |
– |
|
941 |
|
/** |
942 |
|
* thenCombine result completes normally after normal completion |
943 |
|
* of sources |
944 |
|
*/ |
945 |
< |
public void testThenCombine() { |
946 |
< |
CompletableFuture<Integer> f, g, h; |
945 |
> |
public void testThenCombine_normalCompletion1() { |
946 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
947 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
948 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
949 |
> |
|
950 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
951 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
952 |
> |
final SubtractFunction r = new SubtractFunction(); |
953 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
954 |
> |
|
955 |
> |
f.complete(v1); |
956 |
> |
checkIncomplete(h); |
957 |
> |
assertFalse(r.ran()); |
958 |
> |
g.complete(v2); |
959 |
> |
|
960 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
961 |
> |
checkCompletedNormally(f, v1); |
962 |
> |
checkCompletedNormally(g, v2); |
963 |
> |
} |
964 |
> |
} |
965 |
|
|
966 |
< |
f = new CompletableFuture<>(); |
967 |
< |
g = new CompletableFuture<>(); |
968 |
< |
h = f.thenCombine(g, subtract); |
969 |
< |
f.complete(3); |
970 |
< |
checkIncomplete(h); |
971 |
< |
g.complete(1); |
972 |
< |
checkCompletedNormally(h, 2); |
966 |
> |
public void testThenCombine_normalCompletion2() { |
967 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
968 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
969 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
970 |
> |
|
971 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
972 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
973 |
> |
final SubtractFunction r = new SubtractFunction(); |
974 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
975 |
> |
|
976 |
> |
g.complete(v2); |
977 |
> |
checkIncomplete(h); |
978 |
> |
assertFalse(r.ran()); |
979 |
> |
f.complete(v1); |
980 |
> |
|
981 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
982 |
> |
checkCompletedNormally(f, v1); |
983 |
> |
checkCompletedNormally(g, v2); |
984 |
> |
} |
985 |
> |
} |
986 |
|
|
987 |
< |
f = new CompletableFuture<>(); |
988 |
< |
g = new CompletableFuture<>(); |
989 |
< |
h = f.thenCombine(g, subtract); |
990 |
< |
g.complete(1); |
991 |
< |
checkIncomplete(h); |
992 |
< |
f.complete(3); |
993 |
< |
checkCompletedNormally(h, 2); |
987 |
> |
public void testThenCombine_normalCompletion3() { |
988 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
989 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
990 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
991 |
> |
|
992 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
993 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
994 |
> |
final SubtractFunction r = new SubtractFunction(); |
995 |
> |
|
996 |
> |
g.complete(v2); |
997 |
> |
f.complete(v1); |
998 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
999 |
> |
|
1000 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1001 |
> |
checkCompletedNormally(f, v1); |
1002 |
> |
checkCompletedNormally(g, v2); |
1003 |
> |
} |
1004 |
> |
} |
1005 |
|
|
1006 |
< |
f = new CompletableFuture<>(); |
1007 |
< |
g = new CompletableFuture<>(); |
1008 |
< |
g.complete(1); |
1009 |
< |
f.complete(3); |
1010 |
< |
h = f.thenCombine(g, subtract); |
1011 |
< |
checkCompletedNormally(h, 2); |
1006 |
> |
public void testThenCombine_normalCompletion4() { |
1007 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1008 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1009 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1010 |
> |
|
1011 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1012 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1013 |
> |
final SubtractFunction r = new SubtractFunction(); |
1014 |
> |
|
1015 |
> |
f.complete(v1); |
1016 |
> |
g.complete(v2); |
1017 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1018 |
> |
|
1019 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1020 |
> |
checkCompletedNormally(f, v1); |
1021 |
> |
checkCompletedNormally(g, v2); |
1022 |
> |
} |
1023 |
|
} |
1024 |
|
|
1025 |
|
/** |
1026 |
|
* thenCombine result completes exceptionally after exceptional |
1027 |
|
* completion of either source |
1028 |
|
*/ |
1029 |
< |
public void testThenCombine2() { |
1030 |
< |
CompletableFuture<Integer> f, g, h; |
1031 |
< |
|
1032 |
< |
f = new CompletableFuture<>(); |
1033 |
< |
g = new CompletableFuture<>(); |
1034 |
< |
h = f.thenCombine(g, subtract); |
1035 |
< |
f.completeExceptionally(new CFException()); |
1036 |
< |
checkIncomplete(h); |
1037 |
< |
g.complete(1); |
1038 |
< |
checkCompletedWithWrappedCFException(h); |
1029 |
> |
public void testThenCombine_exceptionalCompletion1() { |
1030 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1031 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1032 |
> |
|
1033 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1034 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1035 |
> |
final SubtractFunction r = new SubtractFunction(); |
1036 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1037 |
> |
final CFException ex = new CFException(); |
1038 |
> |
|
1039 |
> |
f.completeExceptionally(ex); |
1040 |
> |
checkIncomplete(h); |
1041 |
> |
g.complete(v1); |
1042 |
> |
|
1043 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1044 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1045 |
> |
assertFalse(r.ran()); |
1046 |
> |
checkCompletedNormally(g, v1); |
1047 |
> |
} |
1048 |
> |
} |
1049 |
|
|
1050 |
< |
f = new CompletableFuture<>(); |
1051 |
< |
g = new CompletableFuture<>(); |
1052 |
< |
h = f.thenCombine(g, subtract); |
1053 |
< |
g.completeExceptionally(new CFException()); |
1054 |
< |
checkIncomplete(h); |
1055 |
< |
f.complete(3); |
1056 |
< |
checkCompletedWithWrappedCFException(h); |
1050 |
> |
public void testThenCombine_exceptionalCompletion2() { |
1051 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1052 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1053 |
> |
|
1054 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1055 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1056 |
> |
final SubtractFunction r = new SubtractFunction(); |
1057 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1058 |
> |
final CFException ex = new CFException(); |
1059 |
> |
|
1060 |
> |
g.completeExceptionally(ex); |
1061 |
> |
checkIncomplete(h); |
1062 |
> |
f.complete(v1); |
1063 |
> |
|
1064 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1065 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1066 |
> |
assertFalse(r.ran()); |
1067 |
> |
checkCompletedNormally(f, v1); |
1068 |
> |
} |
1069 |
> |
} |
1070 |
|
|
1071 |
< |
f = new CompletableFuture<>(); |
1072 |
< |
g = new CompletableFuture<>(); |
1073 |
< |
f.complete(3); |
1074 |
< |
g.completeExceptionally(new CFException()); |
1075 |
< |
h = f.thenCombine(g, subtract); |
1076 |
< |
checkCompletedWithWrappedCFException(h); |
1071 |
> |
public void testThenCombine_exceptionalCompletion3() { |
1072 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1073 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1074 |
> |
|
1075 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1076 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1077 |
> |
final SubtractFunction r = new SubtractFunction(); |
1078 |
> |
final CFException ex = new CFException(); |
1079 |
> |
|
1080 |
> |
g.completeExceptionally(ex); |
1081 |
> |
f.complete(v1); |
1082 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1083 |
> |
|
1084 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1085 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1086 |
> |
assertFalse(r.ran()); |
1087 |
> |
checkCompletedNormally(f, v1); |
1088 |
> |
} |
1089 |
> |
} |
1090 |
|
|
1091 |
< |
f = new CompletableFuture<>(); |
1092 |
< |
g = new CompletableFuture<>(); |
1093 |
< |
f.completeExceptionally(new CFException()); |
1094 |
< |
g.complete(3); |
1095 |
< |
h = f.thenCombine(g, subtract); |
1096 |
< |
checkCompletedWithWrappedCFException(h); |
1091 |
> |
public void testThenCombine_exceptionalCompletion4() { |
1092 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1093 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1094 |
> |
|
1095 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1096 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1097 |
> |
final SubtractFunction r = new SubtractFunction(); |
1098 |
> |
final CFException ex = new CFException(); |
1099 |
> |
|
1100 |
> |
f.completeExceptionally(ex); |
1101 |
> |
g.complete(v1); |
1102 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1103 |
> |
|
1104 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1105 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1106 |
> |
assertFalse(r.ran()); |
1107 |
> |
checkCompletedNormally(g, v1); |
1108 |
> |
} |
1109 |
|
} |
1110 |
|
|
1111 |
|
/** |
1112 |
|
* thenCombine result completes exceptionally if action does |
1113 |
|
*/ |
1114 |
< |
public void testThenCombine3() { |
1115 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1116 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1117 |
< |
FailingBiFunction r = new FailingBiFunction(); |
1118 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
1119 |
< |
f.complete(one); |
1120 |
< |
checkIncomplete(g); |
1121 |
< |
assertFalse(r.ran); |
1122 |
< |
f2.complete(two); |
1123 |
< |
checkCompletedWithWrappedCFException(g); |
1124 |
< |
assertTrue(r.ran); |
1114 |
> |
public void testThenCombine_actionFailed1() { |
1115 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1116 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1117 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1118 |
> |
|
1119 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1120 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1121 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1122 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1123 |
> |
|
1124 |
> |
f.complete(v1); |
1125 |
> |
checkIncomplete(h); |
1126 |
> |
g.complete(v2); |
1127 |
> |
|
1128 |
> |
checkCompletedWithWrappedCFException(h); |
1129 |
> |
checkCompletedNormally(f, v1); |
1130 |
> |
checkCompletedNormally(g, v2); |
1131 |
> |
} |
1132 |
> |
} |
1133 |
> |
|
1134 |
> |
public void testThenCombine_actionFailed2() { |
1135 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1136 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1137 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1138 |
> |
|
1139 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1140 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1141 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1142 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1143 |
> |
|
1144 |
> |
g.complete(v2); |
1145 |
> |
checkIncomplete(h); |
1146 |
> |
f.complete(v1); |
1147 |
> |
|
1148 |
> |
checkCompletedWithWrappedCFException(h); |
1149 |
> |
checkCompletedNormally(f, v1); |
1150 |
> |
checkCompletedNormally(g, v2); |
1151 |
> |
} |
1152 |
|
} |
1153 |
|
|
1154 |
|
/** |
1155 |
|
* thenCombine result completes exceptionally if either source cancelled |
1156 |
|
*/ |
1157 |
< |
public void testThenCombine4() { |
1158 |
< |
CompletableFuture<Integer> f, g, h; |
1157 |
> |
public void testThenCombine_sourceCancelled1() { |
1158 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1159 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1160 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1161 |
> |
|
1162 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1163 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1164 |
> |
final SubtractFunction r = new SubtractFunction(); |
1165 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1166 |
|
|
1167 |
< |
f = new CompletableFuture<>(); |
759 |
< |
g = new CompletableFuture<>(); |
760 |
< |
h = f.thenCombine(g, subtract); |
761 |
< |
assertTrue(f.cancel(true)); |
1167 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1168 |
|
checkIncomplete(h); |
1169 |
< |
g.complete(1); |
1169 |
> |
g.complete(v1); |
1170 |
> |
|
1171 |
|
checkCompletedWithWrappedCancellationException(h); |
1172 |
+ |
checkCancelled(f); |
1173 |
+ |
assertFalse(r.ran()); |
1174 |
+ |
checkCompletedNormally(g, v1); |
1175 |
+ |
} |
1176 |
+ |
} |
1177 |
|
|
1178 |
< |
f = new CompletableFuture<>(); |
1179 |
< |
g = new CompletableFuture<>(); |
1180 |
< |
h = f.thenCombine(g, subtract); |
1181 |
< |
assertTrue(g.cancel(true)); |
1178 |
> |
public void testThenCombine_sourceCancelled2() { |
1179 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1180 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1181 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1182 |
> |
|
1183 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1184 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1185 |
> |
final SubtractFunction r = new SubtractFunction(); |
1186 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1187 |
> |
|
1188 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1189 |
|
checkIncomplete(h); |
1190 |
< |
f.complete(3); |
1190 |
> |
f.complete(v1); |
1191 |
> |
|
1192 |
|
checkCompletedWithWrappedCancellationException(h); |
1193 |
+ |
checkCancelled(g); |
1194 |
+ |
assertFalse(r.ran()); |
1195 |
+ |
checkCompletedNormally(f, v1); |
1196 |
+ |
} |
1197 |
+ |
} |
1198 |
+ |
|
1199 |
+ |
public void testThenCombine_sourceCancelled3() { |
1200 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1201 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1202 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1203 |
+ |
|
1204 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1206 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1207 |
+ |
|
1208 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1209 |
+ |
f.complete(v1); |
1210 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1211 |
+ |
|
1212 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1213 |
+ |
checkCancelled(g); |
1214 |
+ |
assertFalse(r.ran()); |
1215 |
+ |
checkCompletedNormally(f, v1); |
1216 |
+ |
} |
1217 |
+ |
} |
1218 |
+ |
|
1219 |
+ |
public void testThenCombine_sourceCancelled4() { |
1220 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1221 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1222 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1223 |
+ |
|
1224 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1225 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1226 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1227 |
+ |
|
1228 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1229 |
+ |
g.complete(v1); |
1230 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1231 |
|
|
774 |
– |
f = new CompletableFuture<>(); |
775 |
– |
g = new CompletableFuture<>(); |
776 |
– |
assertTrue(f.cancel(true)); |
777 |
– |
assertTrue(g.cancel(true)); |
778 |
– |
h = f.thenCombine(g, subtract); |
1232 |
|
checkCompletedWithWrappedCancellationException(h); |
1233 |
+ |
checkCancelled(f); |
1234 |
+ |
assertFalse(r.ran()); |
1235 |
+ |
checkCompletedNormally(g, v1); |
1236 |
+ |
} |
1237 |
|
} |
1238 |
|
|
1239 |
|
/** |
1240 |
|
* thenAcceptBoth result completes normally after normal |
1241 |
|
* completion of sources |
1242 |
|
*/ |
1243 |
< |
public void testThenAcceptBoth() { |
1244 |
< |
CompletableFuture<Integer> f, g; |
1245 |
< |
CompletableFuture<Void> h; |
1246 |
< |
SubtractAction r; |
1243 |
> |
public void testThenAcceptBoth_normalCompletion1() { |
1244 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1245 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1246 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1247 |
> |
|
1248 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1249 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1250 |
> |
final SubtractAction r = new SubtractAction(); |
1251 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1252 |
|
|
1253 |
< |
f = new CompletableFuture<>(); |
792 |
< |
g = new CompletableFuture<>(); |
793 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
794 |
< |
f.complete(3); |
1253 |
> |
f.complete(v1); |
1254 |
|
checkIncomplete(h); |
1255 |
< |
g.complete(1); |
1255 |
> |
assertFalse(r.ran()); |
1256 |
> |
g.complete(v2); |
1257 |
> |
|
1258 |
|
checkCompletedNormally(h, null); |
1259 |
< |
assertEquals(r.value, 2); |
1259 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1260 |
> |
checkCompletedNormally(f, v1); |
1261 |
> |
checkCompletedNormally(g, v2); |
1262 |
> |
} |
1263 |
> |
} |
1264 |
|
|
1265 |
< |
f = new CompletableFuture<>(); |
1266 |
< |
g = new CompletableFuture<>(); |
1267 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1268 |
< |
g.complete(1); |
1265 |
> |
public void testThenAcceptBoth_normalCompletion2() { |
1266 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1267 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1268 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1269 |
> |
|
1270 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1271 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1272 |
> |
final SubtractAction r = new SubtractAction(); |
1273 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1274 |
> |
|
1275 |
> |
g.complete(v2); |
1276 |
|
checkIncomplete(h); |
1277 |
< |
f.complete(3); |
1277 |
> |
assertFalse(r.ran()); |
1278 |
> |
f.complete(v1); |
1279 |
> |
|
1280 |
|
checkCompletedNormally(h, null); |
1281 |
< |
assertEquals(r.value, 2); |
1281 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1282 |
> |
checkCompletedNormally(f, v1); |
1283 |
> |
checkCompletedNormally(g, v2); |
1284 |
> |
} |
1285 |
> |
} |
1286 |
> |
|
1287 |
> |
public void testThenAcceptBoth_normalCompletion3() { |
1288 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1289 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1290 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1291 |
> |
|
1292 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1293 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1294 |
> |
final SubtractAction r = new SubtractAction(); |
1295 |
> |
|
1296 |
> |
g.complete(v2); |
1297 |
> |
f.complete(v1); |
1298 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1299 |
|
|
809 |
– |
f = new CompletableFuture<>(); |
810 |
– |
g = new CompletableFuture<>(); |
811 |
– |
g.complete(1); |
812 |
– |
f.complete(3); |
813 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1300 |
|
checkCompletedNormally(h, null); |
1301 |
< |
assertEquals(r.value, 2); |
1301 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1302 |
> |
checkCompletedNormally(f, v1); |
1303 |
> |
checkCompletedNormally(g, v2); |
1304 |
> |
} |
1305 |
> |
} |
1306 |
> |
|
1307 |
> |
public void testThenAcceptBoth_normalCompletion4() { |
1308 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1309 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1310 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1311 |
> |
|
1312 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1313 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1314 |
> |
final SubtractAction r = new SubtractAction(); |
1315 |
> |
|
1316 |
> |
f.complete(v1); |
1317 |
> |
g.complete(v2); |
1318 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1319 |
> |
|
1320 |
> |
checkCompletedNormally(h, null); |
1321 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1322 |
> |
checkCompletedNormally(f, v1); |
1323 |
> |
checkCompletedNormally(g, v2); |
1324 |
> |
} |
1325 |
|
} |
1326 |
|
|
1327 |
|
/** |
1328 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1329 |
|
* completion of either source |
1330 |
|
*/ |
1331 |
< |
public void testThenAcceptBoth2() { |
1332 |
< |
CompletableFuture<Integer> f, g; |
1333 |
< |
CompletableFuture<Void> h; |
1334 |
< |
SubtractAction r; |
1335 |
< |
|
1336 |
< |
f = new CompletableFuture<>(); |
1337 |
< |
g = new CompletableFuture<>(); |
1338 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1339 |
< |
f.completeExceptionally(new CFException()); |
1340 |
< |
checkIncomplete(h); |
1341 |
< |
g.complete(1); |
1342 |
< |
checkCompletedWithWrappedCFException(h); |
1331 |
> |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1332 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1333 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1334 |
> |
|
1335 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1336 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1337 |
> |
final SubtractAction r = new SubtractAction(); |
1338 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1339 |
> |
final CFException ex = new CFException(); |
1340 |
> |
|
1341 |
> |
f.completeExceptionally(ex); |
1342 |
> |
checkIncomplete(h); |
1343 |
> |
g.complete(v1); |
1344 |
> |
|
1345 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1346 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1347 |
> |
assertFalse(r.ran()); |
1348 |
> |
checkCompletedNormally(g, v1); |
1349 |
> |
} |
1350 |
> |
} |
1351 |
|
|
1352 |
< |
f = new CompletableFuture<>(); |
1353 |
< |
g = new CompletableFuture<>(); |
1354 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1355 |
< |
g.completeExceptionally(new CFException()); |
1356 |
< |
checkIncomplete(h); |
1357 |
< |
f.complete(3); |
1358 |
< |
checkCompletedWithWrappedCFException(h); |
1352 |
> |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1353 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1354 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1355 |
> |
|
1356 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1357 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1358 |
> |
final SubtractAction r = new SubtractAction(); |
1359 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1360 |
> |
final CFException ex = new CFException(); |
1361 |
> |
|
1362 |
> |
g.completeExceptionally(ex); |
1363 |
> |
checkIncomplete(h); |
1364 |
> |
f.complete(v1); |
1365 |
> |
|
1366 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1367 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1368 |
> |
assertFalse(r.ran()); |
1369 |
> |
checkCompletedNormally(f, v1); |
1370 |
> |
} |
1371 |
> |
} |
1372 |
|
|
1373 |
< |
f = new CompletableFuture<>(); |
1374 |
< |
g = new CompletableFuture<>(); |
1375 |
< |
f.complete(3); |
1376 |
< |
g.completeExceptionally(new CFException()); |
1377 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1378 |
< |
checkCompletedWithWrappedCFException(h); |
1373 |
> |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1374 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1375 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1376 |
> |
|
1377 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1378 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1379 |
> |
final SubtractAction r = new SubtractAction(); |
1380 |
> |
final CFException ex = new CFException(); |
1381 |
> |
|
1382 |
> |
g.completeExceptionally(ex); |
1383 |
> |
f.complete(v1); |
1384 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1385 |
> |
|
1386 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1387 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1388 |
> |
assertFalse(r.ran()); |
1389 |
> |
checkCompletedNormally(f, v1); |
1390 |
> |
} |
1391 |
> |
} |
1392 |
|
|
1393 |
< |
f = new CompletableFuture<>(); |
1394 |
< |
g = new CompletableFuture<>(); |
1395 |
< |
f.completeExceptionally(new CFException()); |
1396 |
< |
g.complete(3); |
1397 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1398 |
< |
checkCompletedWithWrappedCFException(h); |
1393 |
> |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1394 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1395 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1396 |
> |
|
1397 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1398 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1399 |
> |
final SubtractAction r = new SubtractAction(); |
1400 |
> |
final CFException ex = new CFException(); |
1401 |
> |
|
1402 |
> |
f.completeExceptionally(ex); |
1403 |
> |
g.complete(v1); |
1404 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1405 |
> |
|
1406 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1407 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1408 |
> |
assertFalse(r.ran()); |
1409 |
> |
checkCompletedNormally(g, v1); |
1410 |
> |
} |
1411 |
|
} |
1412 |
|
|
1413 |
|
/** |
1414 |
|
* thenAcceptBoth result completes exceptionally if action does |
1415 |
|
*/ |
1416 |
< |
public void testThenAcceptBoth3() { |
1417 |
< |
CompletableFuture<Integer> f, g; |
1418 |
< |
CompletableFuture<Void> h; |
1419 |
< |
FailingBiConsumer r; |
1416 |
> |
public void testThenAcceptBoth_actionFailed1() { |
1417 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1419 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1420 |
|
|
1421 |
< |
f = new CompletableFuture<>(); |
1422 |
< |
g = new CompletableFuture<>(); |
1423 |
< |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1424 |
< |
f.complete(3); |
1421 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1423 |
> |
final FailingBiConsumer r = new FailingBiConsumer(); |
1424 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1425 |
> |
|
1426 |
> |
f.complete(v1); |
1427 |
|
checkIncomplete(h); |
1428 |
< |
g.complete(1); |
1428 |
> |
g.complete(v2); |
1429 |
> |
|
1430 |
|
checkCompletedWithWrappedCFException(h); |
1431 |
+ |
checkCompletedNormally(f, v1); |
1432 |
+ |
checkCompletedNormally(g, v2); |
1433 |
+ |
} |
1434 |
+ |
} |
1435 |
+ |
|
1436 |
+ |
public void testThenAcceptBoth_actionFailed2() { |
1437 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1438 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1439 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1440 |
+ |
|
1441 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1442 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1443 |
+ |
final FailingBiConsumer r = new FailingBiConsumer(); |
1444 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1445 |
+ |
|
1446 |
+ |
g.complete(v2); |
1447 |
+ |
checkIncomplete(h); |
1448 |
+ |
f.complete(v1); |
1449 |
|
|
874 |
– |
f = new CompletableFuture<>(); |
875 |
– |
g = new CompletableFuture<>(); |
876 |
– |
f.complete(3); |
877 |
– |
g.complete(1); |
878 |
– |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1450 |
|
checkCompletedWithWrappedCFException(h); |
1451 |
+ |
checkCompletedNormally(f, v1); |
1452 |
+ |
checkCompletedNormally(g, v2); |
1453 |
+ |
} |
1454 |
|
} |
1455 |
|
|
1456 |
|
/** |
1457 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1458 |
|
*/ |
1459 |
< |
public void testThenAcceptBoth4() { |
1460 |
< |
CompletableFuture<Integer> f, g; |
1461 |
< |
CompletableFuture<Void> h; |
1462 |
< |
SubtractAction r; |
1459 |
> |
public void testThenAcceptBoth_sourceCancelled1() { |
1460 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1461 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1462 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1463 |
> |
|
1464 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1465 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1466 |
> |
final SubtractAction r = new SubtractAction(); |
1467 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1468 |
|
|
1469 |
< |
f = new CompletableFuture<>(); |
891 |
< |
g = new CompletableFuture<>(); |
892 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
893 |
< |
assertTrue(f.cancel(true)); |
1469 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1470 |
|
checkIncomplete(h); |
1471 |
< |
g.complete(1); |
1471 |
> |
g.complete(v1); |
1472 |
> |
|
1473 |
|
checkCompletedWithWrappedCancellationException(h); |
1474 |
+ |
checkCancelled(f); |
1475 |
+ |
assertFalse(r.ran()); |
1476 |
+ |
checkCompletedNormally(g, v1); |
1477 |
+ |
} |
1478 |
+ |
} |
1479 |
|
|
1480 |
< |
f = new CompletableFuture<>(); |
1481 |
< |
g = new CompletableFuture<>(); |
1482 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1483 |
< |
assertTrue(g.cancel(true)); |
1480 |
> |
public void testThenAcceptBoth_sourceCancelled2() { |
1481 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1482 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1483 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1484 |
> |
|
1485 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1486 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1487 |
> |
final SubtractAction r = new SubtractAction(); |
1488 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1489 |
> |
|
1490 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1491 |
|
checkIncomplete(h); |
1492 |
< |
f.complete(3); |
904 |
< |
checkCompletedWithWrappedCancellationException(h); |
1492 |
> |
f.complete(v1); |
1493 |
|
|
906 |
– |
f = new CompletableFuture<>(); |
907 |
– |
g = new CompletableFuture<>(); |
908 |
– |
f.complete(3); |
909 |
– |
assertTrue(g.cancel(true)); |
910 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1494 |
|
checkCompletedWithWrappedCancellationException(h); |
1495 |
+ |
checkCancelled(g); |
1496 |
+ |
assertFalse(r.ran()); |
1497 |
+ |
checkCompletedNormally(f, v1); |
1498 |
+ |
} |
1499 |
+ |
} |
1500 |
+ |
|
1501 |
+ |
public void testThenAcceptBoth_sourceCancelled3() { |
1502 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1503 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1504 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1505 |
+ |
|
1506 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1507 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1508 |
+ |
final SubtractAction r = new SubtractAction(); |
1509 |
+ |
|
1510 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1511 |
+ |
f.complete(v1); |
1512 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1513 |
+ |
|
1514 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1515 |
+ |
checkCancelled(g); |
1516 |
+ |
assertFalse(r.ran()); |
1517 |
+ |
checkCompletedNormally(f, v1); |
1518 |
+ |
} |
1519 |
+ |
} |
1520 |
+ |
|
1521 |
+ |
public void testThenAcceptBoth_sourceCancelled4() { |
1522 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1523 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1524 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1525 |
+ |
|
1526 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1527 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1528 |
+ |
final SubtractAction r = new SubtractAction(); |
1529 |
+ |
|
1530 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1531 |
+ |
g.complete(v1); |
1532 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1533 |
|
|
913 |
– |
f = new CompletableFuture<>(); |
914 |
– |
g = new CompletableFuture<>(); |
915 |
– |
assertTrue(f.cancel(true)); |
916 |
– |
g.complete(3); |
917 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1534 |
|
checkCompletedWithWrappedCancellationException(h); |
1535 |
+ |
checkCancelled(f); |
1536 |
+ |
assertFalse(r.ran()); |
1537 |
+ |
checkCompletedNormally(g, v1); |
1538 |
+ |
} |
1539 |
|
} |
1540 |
|
|
1541 |
|
/** |
1542 |
|
* runAfterBoth result completes normally after normal |
1543 |
|
* completion of sources |
1544 |
|
*/ |
1545 |
< |
public void testRunAfterBoth() { |
1546 |
< |
CompletableFuture<Integer> f, g; |
1547 |
< |
CompletableFuture<Void> h; |
1548 |
< |
Noop r; |
1545 |
> |
public void testRunAfterBoth_normalCompletion1() { |
1546 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1547 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1548 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1549 |
> |
|
1550 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1551 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1552 |
> |
final Noop r = new Noop(); |
1553 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1554 |
|
|
1555 |
< |
f = new CompletableFuture<>(); |
931 |
< |
g = new CompletableFuture<>(); |
932 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
933 |
< |
f.complete(3); |
1555 |
> |
f.complete(v1); |
1556 |
|
checkIncomplete(h); |
1557 |
< |
g.complete(1); |
1557 |
> |
assertFalse(r.ran); |
1558 |
> |
g.complete(v2); |
1559 |
> |
|
1560 |
|
checkCompletedNormally(h, null); |
1561 |
|
assertTrue(r.ran); |
1562 |
+ |
checkCompletedNormally(f, v1); |
1563 |
+ |
checkCompletedNormally(g, v2); |
1564 |
+ |
} |
1565 |
+ |
} |
1566 |
|
|
1567 |
< |
f = new CompletableFuture<>(); |
1568 |
< |
g = new CompletableFuture<>(); |
1569 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1570 |
< |
g.complete(1); |
1567 |
> |
public void testRunAfterBoth_normalCompletion2() { |
1568 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1569 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1570 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1571 |
> |
|
1572 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1573 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1574 |
> |
final Noop r = new Noop(); |
1575 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1576 |
> |
|
1577 |
> |
g.complete(v2); |
1578 |
|
checkIncomplete(h); |
1579 |
< |
f.complete(3); |
1579 |
> |
assertFalse(r.ran); |
1580 |
> |
f.complete(v1); |
1581 |
> |
|
1582 |
|
checkCompletedNormally(h, null); |
1583 |
|
assertTrue(r.ran); |
1584 |
+ |
checkCompletedNormally(f, v1); |
1585 |
+ |
checkCompletedNormally(g, v2); |
1586 |
+ |
} |
1587 |
+ |
} |
1588 |
+ |
|
1589 |
+ |
public void testRunAfterBoth_normalCompletion3() { |
1590 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1591 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1592 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1593 |
+ |
|
1594 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1595 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1596 |
+ |
final Noop r = new Noop(); |
1597 |
+ |
|
1598 |
+ |
g.complete(v2); |
1599 |
+ |
f.complete(v1); |
1600 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1601 |
+ |
|
1602 |
+ |
checkCompletedNormally(h, null); |
1603 |
+ |
assertTrue(r.ran); |
1604 |
+ |
checkCompletedNormally(f, v1); |
1605 |
+ |
checkCompletedNormally(g, v2); |
1606 |
+ |
} |
1607 |
+ |
} |
1608 |
+ |
|
1609 |
+ |
public void testRunAfterBoth_normalCompletion4() { |
1610 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1611 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1612 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1613 |
+ |
|
1614 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1615 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1616 |
+ |
final Noop r = new Noop(); |
1617 |
+ |
|
1618 |
+ |
f.complete(v1); |
1619 |
+ |
g.complete(v2); |
1620 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1621 |
|
|
948 |
– |
f = new CompletableFuture<>(); |
949 |
– |
g = new CompletableFuture<>(); |
950 |
– |
g.complete(1); |
951 |
– |
f.complete(3); |
952 |
– |
h = f.runAfterBoth(g, r = new Noop()); |
1622 |
|
checkCompletedNormally(h, null); |
1623 |
|
assertTrue(r.ran); |
1624 |
+ |
checkCompletedNormally(f, v1); |
1625 |
+ |
checkCompletedNormally(g, v2); |
1626 |
+ |
} |
1627 |
|
} |
1628 |
|
|
1629 |
|
/** |
1630 |
|
* runAfterBoth result completes exceptionally after exceptional |
1631 |
|
* completion of either source |
1632 |
|
*/ |
1633 |
< |
public void testRunAfterBoth2() { |
1634 |
< |
CompletableFuture<Integer> f, g; |
1635 |
< |
CompletableFuture<Void> h; |
1636 |
< |
Noop r; |
1633 |
> |
public void testRunAfterBoth_exceptionalCompletion1() { |
1634 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1635 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1636 |
> |
|
1637 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1638 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1639 |
> |
final Noop r = new Noop(); |
1640 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1641 |
> |
final CFException ex = new CFException(); |
1642 |
|
|
1643 |
< |
f = new CompletableFuture<>(); |
967 |
< |
g = new CompletableFuture<>(); |
968 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
969 |
< |
f.completeExceptionally(new CFException()); |
1643 |
> |
f.completeExceptionally(ex); |
1644 |
|
checkIncomplete(h); |
1645 |
< |
g.complete(1); |
1646 |
< |
checkCompletedWithWrappedCFException(h); |
1645 |
> |
g.complete(v1); |
1646 |
> |
|
1647 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1648 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1649 |
|
assertFalse(r.ran); |
1650 |
+ |
checkCompletedNormally(g, v1); |
1651 |
+ |
} |
1652 |
+ |
} |
1653 |
|
|
1654 |
< |
f = new CompletableFuture<>(); |
1655 |
< |
g = new CompletableFuture<>(); |
1656 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1657 |
< |
g.completeExceptionally(new CFException()); |
1654 |
> |
public void testRunAfterBoth_exceptionalCompletion2() { |
1655 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1656 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1657 |
> |
|
1658 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1659 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1660 |
> |
final Noop r = new Noop(); |
1661 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1662 |
> |
final CFException ex = new CFException(); |
1663 |
> |
|
1664 |
> |
g.completeExceptionally(ex); |
1665 |
|
checkIncomplete(h); |
1666 |
< |
f.complete(3); |
1667 |
< |
checkCompletedWithWrappedCFException(h); |
1666 |
> |
f.complete(v1); |
1667 |
> |
|
1668 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1669 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1670 |
|
assertFalse(r.ran); |
1671 |
+ |
checkCompletedNormally(f, v1); |
1672 |
+ |
} |
1673 |
+ |
} |
1674 |
|
|
1675 |
< |
f = new CompletableFuture<>(); |
1676 |
< |
g = new CompletableFuture<>(); |
1677 |
< |
g.completeExceptionally(new CFException()); |
1678 |
< |
f.complete(3); |
1679 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1680 |
< |
checkCompletedWithWrappedCFException(h); |
1675 |
> |
public void testRunAfterBoth_exceptionalCompletion3() { |
1676 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1677 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1678 |
> |
|
1679 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1680 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1681 |
> |
final Noop r = new Noop(); |
1682 |
> |
final CFException ex = new CFException(); |
1683 |
> |
|
1684 |
> |
g.completeExceptionally(ex); |
1685 |
> |
f.complete(v1); |
1686 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1687 |
> |
|
1688 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1689 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1690 |
|
assertFalse(r.ran); |
1691 |
+ |
checkCompletedNormally(f, v1); |
1692 |
+ |
} |
1693 |
+ |
} |
1694 |
|
|
1695 |
< |
f = new CompletableFuture<>(); |
1696 |
< |
g = new CompletableFuture<>(); |
1697 |
< |
f.completeExceptionally(new CFException()); |
1698 |
< |
g.complete(1); |
1699 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1700 |
< |
checkCompletedWithWrappedCFException(h); |
1695 |
> |
public void testRunAfterBoth_exceptionalCompletion4() { |
1696 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1697 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1698 |
> |
|
1699 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1700 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1701 |
> |
final Noop r = new Noop(); |
1702 |
> |
final CFException ex = new CFException(); |
1703 |
> |
|
1704 |
> |
f.completeExceptionally(ex); |
1705 |
> |
g.complete(v1); |
1706 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1707 |
> |
|
1708 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1709 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1710 |
|
assertFalse(r.ran); |
1711 |
+ |
checkCompletedNormally(g, v1); |
1712 |
+ |
} |
1713 |
|
} |
1714 |
|
|
1715 |
|
/** |
1716 |
|
* runAfterBoth result completes exceptionally if action does |
1717 |
|
*/ |
1718 |
< |
public void testRunAfterBoth3() { |
1719 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1720 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1721 |
< |
FailingNoop r = new FailingNoop(); |
1722 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1723 |
< |
f.complete(one); |
1724 |
< |
checkIncomplete(g); |
1725 |
< |
f2.complete(two); |
1726 |
< |
checkCompletedWithWrappedCFException(g); |
1718 |
> |
public void testRunAfterBoth_actionFailed1() { |
1719 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1720 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1721 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1722 |
> |
|
1723 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1724 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1725 |
> |
final FailingNoop r = new FailingNoop(); |
1726 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1727 |
> |
|
1728 |
> |
f.complete(v1); |
1729 |
> |
checkIncomplete(h); |
1730 |
> |
g.complete(v2); |
1731 |
> |
|
1732 |
> |
checkCompletedWithWrappedCFException(h); |
1733 |
> |
checkCompletedNormally(f, v1); |
1734 |
> |
checkCompletedNormally(g, v2); |
1735 |
> |
} |
1736 |
> |
} |
1737 |
> |
|
1738 |
> |
public void testRunAfterBoth_actionFailed2() { |
1739 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1740 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1741 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1742 |
> |
|
1743 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1744 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1745 |
> |
final FailingNoop r = new FailingNoop(); |
1746 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1747 |
> |
|
1748 |
> |
g.complete(v2); |
1749 |
> |
checkIncomplete(h); |
1750 |
> |
f.complete(v1); |
1751 |
> |
|
1752 |
> |
checkCompletedWithWrappedCFException(h); |
1753 |
> |
checkCompletedNormally(f, v1); |
1754 |
> |
checkCompletedNormally(g, v2); |
1755 |
> |
} |
1756 |
|
} |
1757 |
|
|
1758 |
|
/** |
1759 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1760 |
|
*/ |
1761 |
< |
public void testRunAfterBoth4() { |
1762 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1763 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1764 |
< |
Noop r = new Noop(); |
1765 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1766 |
< |
assertTrue(f.cancel(true)); |
1767 |
< |
f2.complete(two); |
1768 |
< |
checkCompletedWithWrappedCancellationException(g); |
1769 |
< |
f = new CompletableFuture<>(); |
1770 |
< |
f2 = new CompletableFuture<>(); |
1771 |
< |
r = new Noop(); |
1772 |
< |
g = f.runAfterBoth(f2, r); |
1773 |
< |
f.complete(one); |
1774 |
< |
assertTrue(f2.cancel(true)); |
1775 |
< |
checkCompletedWithWrappedCancellationException(g); |
1761 |
> |
public void testRunAfterBoth_sourceCancelled1() { |
1762 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1763 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1764 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1765 |
> |
|
1766 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1767 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1768 |
> |
final Noop r = new Noop(); |
1769 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1770 |
> |
|
1771 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1772 |
> |
checkIncomplete(h); |
1773 |
> |
g.complete(v1); |
1774 |
> |
|
1775 |
> |
checkCompletedWithWrappedCancellationException(h); |
1776 |
> |
checkCancelled(f); |
1777 |
> |
assertFalse(r.ran); |
1778 |
> |
checkCompletedNormally(g, v1); |
1779 |
> |
} |
1780 |
> |
} |
1781 |
> |
|
1782 |
> |
public void testRunAfterBoth_sourceCancelled2() { |
1783 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1784 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1785 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1786 |
> |
|
1787 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1788 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1789 |
> |
final Noop r = new Noop(); |
1790 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1791 |
> |
|
1792 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1793 |
> |
checkIncomplete(h); |
1794 |
> |
f.complete(v1); |
1795 |
> |
|
1796 |
> |
checkCompletedWithWrappedCancellationException(h); |
1797 |
> |
checkCancelled(g); |
1798 |
> |
assertFalse(r.ran); |
1799 |
> |
checkCompletedNormally(f, v1); |
1800 |
> |
} |
1801 |
> |
} |
1802 |
> |
|
1803 |
> |
public void testRunAfterBoth_sourceCancelled3() { |
1804 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1805 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1806 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1807 |
> |
|
1808 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1809 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1810 |
> |
final Noop r = new Noop(); |
1811 |
> |
|
1812 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1813 |
> |
f.complete(v1); |
1814 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1815 |
> |
|
1816 |
> |
checkCompletedWithWrappedCancellationException(h); |
1817 |
> |
checkCancelled(g); |
1818 |
> |
assertFalse(r.ran); |
1819 |
> |
checkCompletedNormally(f, v1); |
1820 |
> |
} |
1821 |
> |
} |
1822 |
> |
|
1823 |
> |
public void testRunAfterBoth_sourceCancelled4() { |
1824 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1825 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1826 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1827 |
> |
|
1828 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1829 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1830 |
> |
final Noop r = new Noop(); |
1831 |
> |
|
1832 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1833 |
> |
g.complete(v1); |
1834 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1835 |
> |
|
1836 |
> |
checkCompletedWithWrappedCancellationException(h); |
1837 |
> |
checkCancelled(f); |
1838 |
> |
assertFalse(r.ran); |
1839 |
> |
checkCompletedNormally(g, v1); |
1840 |
> |
} |
1841 |
|
} |
1842 |
|
|
1843 |
|
/** |
1919 |
|
checkCompletedNormally(g, null); |
1920 |
|
f2.complete(one); |
1921 |
|
checkCompletedNormally(g, null); |
1922 |
< |
assertEquals(r.value, 2); |
1922 |
> |
assertEquals(r.value, (Integer) 2); |
1923 |
|
|
1924 |
|
r = new IncAction(); |
1925 |
|
f = new CompletableFuture<>(); |
1927 |
|
f2 = new CompletableFuture<>(); |
1928 |
|
g = f.acceptEither(f2, r); |
1929 |
|
checkCompletedNormally(g, null); |
1930 |
< |
assertEquals(r.value, 2); |
1930 |
> |
assertEquals(r.value, (Integer) 2); |
1931 |
|
} |
1932 |
|
|
1933 |
|
/** |
1979 |
|
checkCompletedWithWrappedCancellationException(g); |
1980 |
|
} |
1981 |
|
|
1174 |
– |
|
1982 |
|
/** |
1983 |
|
* runAfterEither result completes normally after normal completion |
1984 |
|
* of either source |
2127 |
|
checkCompletedWithWrappedCancellationException(g); |
2128 |
|
} |
2129 |
|
|
1323 |
– |
|
2130 |
|
// asyncs |
2131 |
|
|
2132 |
|
/** |
2159 |
|
try { |
2160 |
|
g.join(); |
2161 |
|
shouldThrow(); |
2162 |
< |
} catch (Exception ok) { |
1357 |
< |
} |
2162 |
> |
} catch (CompletionException success) {} |
2163 |
|
checkCompletedWithWrappedCFException(g); |
2164 |
|
} |
2165 |
|
|
2237 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2238 |
|
f.complete(one); |
2239 |
|
checkCompletedNormally(g, null); |
2240 |
< |
assertEquals(r.value, 2); |
2240 |
> |
assertEquals(r.value, (Integer) 2); |
2241 |
|
} |
2242 |
|
|
2243 |
|
/** |
2275 |
|
} |
2276 |
|
|
2277 |
|
/** |
1473 |
– |
* thenCombineAsync result completes normally after normal |
1474 |
– |
* completion of sources |
1475 |
– |
*/ |
1476 |
– |
public void testThenCombineAsync() { |
1477 |
– |
CompletableFuture<Integer> f, g, h; |
1478 |
– |
|
1479 |
– |
f = new CompletableFuture<>(); |
1480 |
– |
g = new CompletableFuture<>(); |
1481 |
– |
h = f.thenCombineAsync(g, subtract); |
1482 |
– |
f.complete(3); |
1483 |
– |
checkIncomplete(h); |
1484 |
– |
g.complete(1); |
1485 |
– |
checkCompletedNormally(h, 2); |
1486 |
– |
|
1487 |
– |
f = new CompletableFuture<>(); |
1488 |
– |
g = new CompletableFuture<>(); |
1489 |
– |
h = f.thenCombineAsync(g, subtract); |
1490 |
– |
g.complete(1); |
1491 |
– |
checkIncomplete(h); |
1492 |
– |
f.complete(3); |
1493 |
– |
checkCompletedNormally(h, 2); |
1494 |
– |
|
1495 |
– |
f = new CompletableFuture<>(); |
1496 |
– |
g = new CompletableFuture<>(); |
1497 |
– |
g.complete(1); |
1498 |
– |
f.complete(3); |
1499 |
– |
h = f.thenCombineAsync(g, subtract); |
1500 |
– |
checkCompletedNormally(h, 2); |
1501 |
– |
} |
1502 |
– |
|
1503 |
– |
/** |
1504 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
1505 |
– |
* completion of either source |
1506 |
– |
*/ |
1507 |
– |
public void testThenCombineAsync2() { |
1508 |
– |
CompletableFuture<Integer> f, g, h; |
1509 |
– |
|
1510 |
– |
f = new CompletableFuture<>(); |
1511 |
– |
g = new CompletableFuture<>(); |
1512 |
– |
h = f.thenCombineAsync(g, subtract); |
1513 |
– |
f.completeExceptionally(new CFException()); |
1514 |
– |
checkIncomplete(h); |
1515 |
– |
g.complete(1); |
1516 |
– |
checkCompletedWithWrappedCFException(h); |
1517 |
– |
|
1518 |
– |
f = new CompletableFuture<>(); |
1519 |
– |
g = new CompletableFuture<>(); |
1520 |
– |
h = f.thenCombineAsync(g, subtract); |
1521 |
– |
g.completeExceptionally(new CFException()); |
1522 |
– |
checkIncomplete(h); |
1523 |
– |
f.complete(3); |
1524 |
– |
checkCompletedWithWrappedCFException(h); |
1525 |
– |
|
1526 |
– |
f = new CompletableFuture<>(); |
1527 |
– |
g = new CompletableFuture<>(); |
1528 |
– |
g.completeExceptionally(new CFException()); |
1529 |
– |
f.complete(3); |
1530 |
– |
h = f.thenCombineAsync(g, subtract); |
1531 |
– |
checkCompletedWithWrappedCFException(h); |
1532 |
– |
} |
1533 |
– |
|
1534 |
– |
/** |
1535 |
– |
* thenCombineAsync result completes exceptionally if action does |
1536 |
– |
*/ |
1537 |
– |
public void testThenCombineAsync3() { |
1538 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1539 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1540 |
– |
FailingBiFunction r = new FailingBiFunction(); |
1541 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1542 |
– |
f.complete(one); |
1543 |
– |
checkIncomplete(g); |
1544 |
– |
assertFalse(r.ran); |
1545 |
– |
f2.complete(two); |
1546 |
– |
checkCompletedWithWrappedCFException(g); |
1547 |
– |
assertTrue(r.ran); |
1548 |
– |
} |
1549 |
– |
|
1550 |
– |
/** |
1551 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
1552 |
– |
*/ |
1553 |
– |
public void testThenCombineAsync4() { |
1554 |
– |
CompletableFuture<Integer> f, g, h; |
1555 |
– |
|
1556 |
– |
f = new CompletableFuture<>(); |
1557 |
– |
g = new CompletableFuture<>(); |
1558 |
– |
h = f.thenCombineAsync(g, subtract); |
1559 |
– |
assertTrue(f.cancel(true)); |
1560 |
– |
checkIncomplete(h); |
1561 |
– |
g.complete(1); |
1562 |
– |
checkCompletedWithWrappedCancellationException(h); |
1563 |
– |
|
1564 |
– |
f = new CompletableFuture<>(); |
1565 |
– |
g = new CompletableFuture<>(); |
1566 |
– |
h = f.thenCombineAsync(g, subtract); |
1567 |
– |
assertTrue(g.cancel(true)); |
1568 |
– |
checkIncomplete(h); |
1569 |
– |
f.complete(3); |
1570 |
– |
checkCompletedWithWrappedCancellationException(h); |
1571 |
– |
|
1572 |
– |
f = new CompletableFuture<>(); |
1573 |
– |
g = new CompletableFuture<>(); |
1574 |
– |
g.complete(3); |
1575 |
– |
assertTrue(f.cancel(true)); |
1576 |
– |
h = f.thenCombineAsync(g, subtract); |
1577 |
– |
checkCompletedWithWrappedCancellationException(h); |
1578 |
– |
|
1579 |
– |
f = new CompletableFuture<>(); |
1580 |
– |
g = new CompletableFuture<>(); |
1581 |
– |
f.complete(3); |
1582 |
– |
assertTrue(g.cancel(true)); |
1583 |
– |
h = f.thenCombineAsync(g, subtract); |
1584 |
– |
checkCompletedWithWrappedCancellationException(h); |
1585 |
– |
} |
1586 |
– |
|
1587 |
– |
/** |
1588 |
– |
* thenAcceptBothAsync result completes normally after normal |
1589 |
– |
* completion of sources |
1590 |
– |
*/ |
1591 |
– |
public void testThenAcceptBothAsync() { |
1592 |
– |
CompletableFuture<Integer> f, g; |
1593 |
– |
CompletableFuture<Void> h; |
1594 |
– |
SubtractAction r; |
1595 |
– |
|
1596 |
– |
f = new CompletableFuture<>(); |
1597 |
– |
g = new CompletableFuture<>(); |
1598 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1599 |
– |
f.complete(3); |
1600 |
– |
checkIncomplete(h); |
1601 |
– |
g.complete(1); |
1602 |
– |
checkCompletedNormally(h, null); |
1603 |
– |
assertEquals(r.value, 2); |
1604 |
– |
|
1605 |
– |
f = new CompletableFuture<>(); |
1606 |
– |
g = new CompletableFuture<>(); |
1607 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1608 |
– |
g.complete(1); |
1609 |
– |
checkIncomplete(h); |
1610 |
– |
f.complete(3); |
1611 |
– |
checkCompletedNormally(h, null); |
1612 |
– |
assertEquals(r.value, 2); |
1613 |
– |
|
1614 |
– |
f = new CompletableFuture<>(); |
1615 |
– |
g = new CompletableFuture<>(); |
1616 |
– |
g.complete(1); |
1617 |
– |
f.complete(3); |
1618 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1619 |
– |
checkCompletedNormally(h, null); |
1620 |
– |
assertEquals(r.value, 2); |
1621 |
– |
} |
1622 |
– |
|
1623 |
– |
/** |
1624 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
1625 |
– |
* completion of source |
1626 |
– |
*/ |
1627 |
– |
public void testThenAcceptBothAsync2() { |
1628 |
– |
CompletableFuture<Integer> f, g; |
1629 |
– |
CompletableFuture<Void> h; |
1630 |
– |
SubtractAction r; |
1631 |
– |
|
1632 |
– |
f = new CompletableFuture<>(); |
1633 |
– |
g = new CompletableFuture<>(); |
1634 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1635 |
– |
f.completeExceptionally(new CFException()); |
1636 |
– |
checkIncomplete(h); |
1637 |
– |
g.complete(1); |
1638 |
– |
checkCompletedWithWrappedCFException(h); |
1639 |
– |
|
1640 |
– |
f = new CompletableFuture<>(); |
1641 |
– |
g = new CompletableFuture<>(); |
1642 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1643 |
– |
g.completeExceptionally(new CFException()); |
1644 |
– |
checkIncomplete(h); |
1645 |
– |
f.complete(3); |
1646 |
– |
checkCompletedWithWrappedCFException(h); |
1647 |
– |
|
1648 |
– |
f = new CompletableFuture<>(); |
1649 |
– |
g = new CompletableFuture<>(); |
1650 |
– |
f.complete(3); |
1651 |
– |
g.completeExceptionally(new CFException()); |
1652 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1653 |
– |
checkCompletedWithWrappedCFException(h); |
1654 |
– |
|
1655 |
– |
f = new CompletableFuture<>(); |
1656 |
– |
g = new CompletableFuture<>(); |
1657 |
– |
f.completeExceptionally(new CFException()); |
1658 |
– |
g.complete(3); |
1659 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1660 |
– |
checkCompletedWithWrappedCFException(h); |
1661 |
– |
} |
1662 |
– |
|
1663 |
– |
/** |
1664 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
1665 |
– |
*/ |
1666 |
– |
public void testThenAcceptBothAsync3() { |
1667 |
– |
CompletableFuture<Integer> f, g; |
1668 |
– |
CompletableFuture<Void> h; |
1669 |
– |
FailingBiConsumer r; |
1670 |
– |
|
1671 |
– |
f = new CompletableFuture<>(); |
1672 |
– |
g = new CompletableFuture<>(); |
1673 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1674 |
– |
f.complete(3); |
1675 |
– |
checkIncomplete(h); |
1676 |
– |
g.complete(1); |
1677 |
– |
checkCompletedWithWrappedCFException(h); |
1678 |
– |
|
1679 |
– |
f = new CompletableFuture<>(); |
1680 |
– |
g = new CompletableFuture<>(); |
1681 |
– |
f.complete(3); |
1682 |
– |
g.complete(1); |
1683 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1684 |
– |
checkCompletedWithWrappedCFException(h); |
1685 |
– |
} |
1686 |
– |
|
1687 |
– |
/** |
1688 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1689 |
– |
*/ |
1690 |
– |
public void testThenAcceptBothAsync4() { |
1691 |
– |
CompletableFuture<Integer> f, g; |
1692 |
– |
CompletableFuture<Void> h; |
1693 |
– |
SubtractAction r; |
1694 |
– |
|
1695 |
– |
f = new CompletableFuture<>(); |
1696 |
– |
g = new CompletableFuture<>(); |
1697 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1698 |
– |
assertTrue(f.cancel(true)); |
1699 |
– |
checkIncomplete(h); |
1700 |
– |
g.complete(1); |
1701 |
– |
checkCompletedWithWrappedCancellationException(h); |
1702 |
– |
|
1703 |
– |
f = new CompletableFuture<>(); |
1704 |
– |
g = new CompletableFuture<>(); |
1705 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1706 |
– |
assertTrue(g.cancel(true)); |
1707 |
– |
checkIncomplete(h); |
1708 |
– |
f.complete(3); |
1709 |
– |
checkCompletedWithWrappedCancellationException(h); |
1710 |
– |
|
1711 |
– |
f = new CompletableFuture<>(); |
1712 |
– |
g = new CompletableFuture<>(); |
1713 |
– |
f.complete(3); |
1714 |
– |
assertTrue(g.cancel(true)); |
1715 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1716 |
– |
checkCompletedWithWrappedCancellationException(h); |
1717 |
– |
|
1718 |
– |
f = new CompletableFuture<>(); |
1719 |
– |
g = new CompletableFuture<>(); |
1720 |
– |
assertTrue(f.cancel(true)); |
1721 |
– |
g.complete(3); |
1722 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1723 |
– |
checkCompletedWithWrappedCancellationException(h); |
1724 |
– |
} |
1725 |
– |
|
1726 |
– |
/** |
1727 |
– |
* runAfterBothAsync result completes normally after normal |
1728 |
– |
* completion of sources |
1729 |
– |
*/ |
1730 |
– |
public void testRunAfterBothAsync() { |
1731 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1732 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1733 |
– |
Noop r = new Noop(); |
1734 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1735 |
– |
f.complete(one); |
1736 |
– |
checkIncomplete(g); |
1737 |
– |
f2.complete(two); |
1738 |
– |
checkCompletedNormally(g, null); |
1739 |
– |
assertTrue(r.ran); |
1740 |
– |
} |
1741 |
– |
|
1742 |
– |
/** |
1743 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
1744 |
– |
* completion of source |
1745 |
– |
*/ |
1746 |
– |
public void testRunAfterBothAsync2() { |
1747 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1748 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1749 |
– |
Noop r = new Noop(); |
1750 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1751 |
– |
f.completeExceptionally(new CFException()); |
1752 |
– |
f2.complete(two); |
1753 |
– |
checkCompletedWithWrappedCFException(g); |
1754 |
– |
|
1755 |
– |
r = new Noop(); |
1756 |
– |
f = new CompletableFuture<>(); |
1757 |
– |
f2 = new CompletableFuture<>(); |
1758 |
– |
g = f.runAfterBothAsync(f2, r); |
1759 |
– |
f.complete(one); |
1760 |
– |
f2.completeExceptionally(new CFException()); |
1761 |
– |
checkCompletedWithWrappedCFException(g); |
1762 |
– |
} |
1763 |
– |
|
1764 |
– |
/** |
1765 |
– |
* runAfterBothAsync result completes exceptionally if action does |
1766 |
– |
*/ |
1767 |
– |
public void testRunAfterBothAsync3() { |
1768 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1769 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1770 |
– |
FailingNoop r = new FailingNoop(); |
1771 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1772 |
– |
f.complete(one); |
1773 |
– |
checkIncomplete(g); |
1774 |
– |
f2.complete(two); |
1775 |
– |
checkCompletedWithWrappedCFException(g); |
1776 |
– |
} |
1777 |
– |
|
1778 |
– |
/** |
1779 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
1780 |
– |
*/ |
1781 |
– |
public void testRunAfterBothAsync4() { |
1782 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1783 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1784 |
– |
Noop r = new Noop(); |
1785 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1786 |
– |
assertTrue(f.cancel(true)); |
1787 |
– |
f2.complete(two); |
1788 |
– |
checkCompletedWithWrappedCancellationException(g); |
1789 |
– |
|
1790 |
– |
r = new Noop(); |
1791 |
– |
f = new CompletableFuture<>(); |
1792 |
– |
f2 = new CompletableFuture<>(); |
1793 |
– |
g = f.runAfterBothAsync(f2, r); |
1794 |
– |
f.complete(one); |
1795 |
– |
assertTrue(f2.cancel(true)); |
1796 |
– |
checkCompletedWithWrappedCancellationException(g); |
1797 |
– |
} |
1798 |
– |
|
1799 |
– |
/** |
2278 |
|
* applyToEitherAsync result completes normally after normal |
2279 |
|
* completion of sources |
2280 |
|
*/ |
2351 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2352 |
|
f.complete(one); |
2353 |
|
checkCompletedNormally(g, null); |
2354 |
< |
assertEquals(r.value, 2); |
2354 |
> |
assertEquals(r.value, (Integer) 2); |
2355 |
|
|
2356 |
|
r = new IncAction(); |
2357 |
|
f = new CompletableFuture<>(); |
2359 |
|
f2 = new CompletableFuture<>(); |
2360 |
|
g = f.acceptEitherAsync(f2, r); |
2361 |
|
checkCompletedNormally(g, null); |
2362 |
< |
assertEquals(r.value, 2); |
2362 |
> |
assertEquals(r.value, (Integer) 2); |
2363 |
|
} |
2364 |
|
|
2365 |
|
/** |
2566 |
|
checkCompletedWithWrappedCancellationException(g); |
2567 |
|
} |
2568 |
|
|
2091 |
– |
|
2569 |
|
// async with explicit executors |
2570 |
|
|
2571 |
|
/** |
2598 |
|
try { |
2599 |
|
g.join(); |
2600 |
|
shouldThrow(); |
2601 |
< |
} catch (Exception ok) { |
2125 |
< |
} |
2601 |
> |
} catch (CompletionException success) {} |
2602 |
|
checkCompletedWithWrappedCFException(g); |
2603 |
|
} |
2604 |
|
|
2676 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2677 |
|
f.complete(one); |
2678 |
|
checkCompletedNormally(g, null); |
2679 |
< |
assertEquals(r.value, 2); |
2679 |
> |
assertEquals(r.value, (Integer) 2); |
2680 |
|
} |
2681 |
|
|
2682 |
|
/** |
2714 |
|
} |
2715 |
|
|
2716 |
|
/** |
2241 |
– |
* thenCombineAsync result completes normally after normal |
2242 |
– |
* completion of sources |
2243 |
– |
*/ |
2244 |
– |
public void testThenCombineAsyncE() { |
2245 |
– |
CompletableFuture<Integer> f, g, h; |
2246 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2247 |
– |
int count = 0; |
2248 |
– |
|
2249 |
– |
f = new CompletableFuture<>(); |
2250 |
– |
g = new CompletableFuture<>(); |
2251 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2252 |
– |
f.complete(3); |
2253 |
– |
checkIncomplete(h); |
2254 |
– |
g.complete(1); |
2255 |
– |
checkCompletedNormally(h, 2); |
2256 |
– |
assertEquals(++count, e.count.get()); |
2257 |
– |
|
2258 |
– |
f = new CompletableFuture<>(); |
2259 |
– |
g = new CompletableFuture<>(); |
2260 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2261 |
– |
g.complete(1); |
2262 |
– |
checkIncomplete(h); |
2263 |
– |
f.complete(3); |
2264 |
– |
checkCompletedNormally(h, 2); |
2265 |
– |
assertEquals(++count, e.count.get()); |
2266 |
– |
|
2267 |
– |
f = new CompletableFuture<>(); |
2268 |
– |
g = new CompletableFuture<>(); |
2269 |
– |
g.complete(1); |
2270 |
– |
f.complete(3); |
2271 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2272 |
– |
checkCompletedNormally(h, 2); |
2273 |
– |
assertEquals(++count, e.count.get()); |
2274 |
– |
} |
2275 |
– |
|
2276 |
– |
/** |
2277 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
2278 |
– |
* completion of either source |
2279 |
– |
*/ |
2280 |
– |
public void testThenCombineAsync2E() { |
2281 |
– |
CompletableFuture<Integer> f, g, h; |
2282 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2283 |
– |
int count = 0; |
2284 |
– |
|
2285 |
– |
f = new CompletableFuture<>(); |
2286 |
– |
g = new CompletableFuture<>(); |
2287 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2288 |
– |
f.completeExceptionally(new CFException()); |
2289 |
– |
checkIncomplete(h); |
2290 |
– |
g.complete(1); |
2291 |
– |
checkCompletedWithWrappedCFException(h); |
2292 |
– |
|
2293 |
– |
f = new CompletableFuture<>(); |
2294 |
– |
g = new CompletableFuture<>(); |
2295 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2296 |
– |
g.completeExceptionally(new CFException()); |
2297 |
– |
checkIncomplete(h); |
2298 |
– |
f.complete(3); |
2299 |
– |
checkCompletedWithWrappedCFException(h); |
2300 |
– |
|
2301 |
– |
f = new CompletableFuture<>(); |
2302 |
– |
g = new CompletableFuture<>(); |
2303 |
– |
g.completeExceptionally(new CFException()); |
2304 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2305 |
– |
checkIncomplete(h); |
2306 |
– |
f.complete(3); |
2307 |
– |
checkCompletedWithWrappedCFException(h); |
2308 |
– |
|
2309 |
– |
assertEquals(0, e.count.get()); |
2310 |
– |
} |
2311 |
– |
|
2312 |
– |
/** |
2313 |
– |
* thenCombineAsync result completes exceptionally if action does |
2314 |
– |
*/ |
2315 |
– |
public void testThenCombineAsync3E() { |
2316 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2317 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2318 |
– |
FailingBiFunction r = new FailingBiFunction(); |
2319 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2320 |
– |
f.complete(one); |
2321 |
– |
checkIncomplete(g); |
2322 |
– |
assertFalse(r.ran); |
2323 |
– |
f2.complete(two); |
2324 |
– |
checkCompletedWithWrappedCFException(g); |
2325 |
– |
assertTrue(r.ran); |
2326 |
– |
} |
2327 |
– |
|
2328 |
– |
/** |
2329 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
2330 |
– |
*/ |
2331 |
– |
public void testThenCombineAsync4E() { |
2332 |
– |
CompletableFuture<Integer> f, g, h; |
2333 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2334 |
– |
|
2335 |
– |
f = new CompletableFuture<>(); |
2336 |
– |
g = new CompletableFuture<>(); |
2337 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2338 |
– |
assertTrue(f.cancel(true)); |
2339 |
– |
checkIncomplete(h); |
2340 |
– |
g.complete(1); |
2341 |
– |
checkCompletedWithWrappedCancellationException(h); |
2342 |
– |
|
2343 |
– |
f = new CompletableFuture<>(); |
2344 |
– |
g = new CompletableFuture<>(); |
2345 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2346 |
– |
assertTrue(g.cancel(true)); |
2347 |
– |
checkIncomplete(h); |
2348 |
– |
f.complete(3); |
2349 |
– |
checkCompletedWithWrappedCancellationException(h); |
2350 |
– |
|
2351 |
– |
f = new CompletableFuture<>(); |
2352 |
– |
g = new CompletableFuture<>(); |
2353 |
– |
assertTrue(g.cancel(true)); |
2354 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2355 |
– |
checkIncomplete(h); |
2356 |
– |
f.complete(3); |
2357 |
– |
checkCompletedWithWrappedCancellationException(h); |
2358 |
– |
|
2359 |
– |
f = new CompletableFuture<>(); |
2360 |
– |
g = new CompletableFuture<>(); |
2361 |
– |
assertTrue(f.cancel(true)); |
2362 |
– |
assertTrue(g.cancel(true)); |
2363 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2364 |
– |
checkCompletedWithWrappedCancellationException(h); |
2365 |
– |
|
2366 |
– |
assertEquals(0, e.count.get()); |
2367 |
– |
} |
2368 |
– |
|
2369 |
– |
/** |
2370 |
– |
* thenAcceptBothAsync result completes normally after normal |
2371 |
– |
* completion of sources |
2372 |
– |
*/ |
2373 |
– |
public void testThenAcceptBothAsyncE() { |
2374 |
– |
CompletableFuture<Integer> f, g; |
2375 |
– |
CompletableFuture<Void> h; |
2376 |
– |
SubtractAction r; |
2377 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2378 |
– |
|
2379 |
– |
f = new CompletableFuture<>(); |
2380 |
– |
g = new CompletableFuture<>(); |
2381 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2382 |
– |
f.complete(3); |
2383 |
– |
checkIncomplete(h); |
2384 |
– |
g.complete(1); |
2385 |
– |
checkCompletedNormally(h, null); |
2386 |
– |
assertEquals(r.value, 2); |
2387 |
– |
|
2388 |
– |
f = new CompletableFuture<>(); |
2389 |
– |
g = new CompletableFuture<>(); |
2390 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2391 |
– |
g.complete(1); |
2392 |
– |
checkIncomplete(h); |
2393 |
– |
f.complete(3); |
2394 |
– |
checkCompletedNormally(h, null); |
2395 |
– |
assertEquals(r.value, 2); |
2396 |
– |
|
2397 |
– |
f = new CompletableFuture<>(); |
2398 |
– |
g = new CompletableFuture<>(); |
2399 |
– |
g.complete(1); |
2400 |
– |
f.complete(3); |
2401 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2402 |
– |
checkCompletedNormally(h, null); |
2403 |
– |
assertEquals(r.value, 2); |
2404 |
– |
|
2405 |
– |
assertEquals(3, e.count.get()); |
2406 |
– |
} |
2407 |
– |
|
2408 |
– |
/** |
2409 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
2410 |
– |
* completion of source |
2411 |
– |
*/ |
2412 |
– |
public void testThenAcceptBothAsync2E() { |
2413 |
– |
CompletableFuture<Integer> f, g; |
2414 |
– |
CompletableFuture<Void> h; |
2415 |
– |
SubtractAction r; |
2416 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2417 |
– |
|
2418 |
– |
f = new CompletableFuture<>(); |
2419 |
– |
g = new CompletableFuture<>(); |
2420 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2421 |
– |
f.completeExceptionally(new CFException()); |
2422 |
– |
checkIncomplete(h); |
2423 |
– |
g.complete(1); |
2424 |
– |
checkCompletedWithWrappedCFException(h); |
2425 |
– |
|
2426 |
– |
f = new CompletableFuture<>(); |
2427 |
– |
g = new CompletableFuture<>(); |
2428 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2429 |
– |
g.completeExceptionally(new CFException()); |
2430 |
– |
checkIncomplete(h); |
2431 |
– |
f.complete(3); |
2432 |
– |
checkCompletedWithWrappedCFException(h); |
2433 |
– |
|
2434 |
– |
f = new CompletableFuture<>(); |
2435 |
– |
g = new CompletableFuture<>(); |
2436 |
– |
f.complete(3); |
2437 |
– |
g.completeExceptionally(new CFException()); |
2438 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2439 |
– |
checkCompletedWithWrappedCFException(h); |
2440 |
– |
|
2441 |
– |
f = new CompletableFuture<>(); |
2442 |
– |
g = new CompletableFuture<>(); |
2443 |
– |
f.completeExceptionally(new CFException()); |
2444 |
– |
g.complete(3); |
2445 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2446 |
– |
checkCompletedWithWrappedCFException(h); |
2447 |
– |
|
2448 |
– |
assertEquals(0, e.count.get()); |
2449 |
– |
} |
2450 |
– |
|
2451 |
– |
/** |
2452 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
2453 |
– |
*/ |
2454 |
– |
public void testThenAcceptBothAsync3E() { |
2455 |
– |
CompletableFuture<Integer> f, g; |
2456 |
– |
CompletableFuture<Void> h; |
2457 |
– |
FailingBiConsumer r; |
2458 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2459 |
– |
|
2460 |
– |
f = new CompletableFuture<>(); |
2461 |
– |
g = new CompletableFuture<>(); |
2462 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2463 |
– |
f.complete(3); |
2464 |
– |
checkIncomplete(h); |
2465 |
– |
g.complete(1); |
2466 |
– |
checkCompletedWithWrappedCFException(h); |
2467 |
– |
|
2468 |
– |
f = new CompletableFuture<>(); |
2469 |
– |
g = new CompletableFuture<>(); |
2470 |
– |
f.complete(3); |
2471 |
– |
g.complete(1); |
2472 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2473 |
– |
checkCompletedWithWrappedCFException(h); |
2474 |
– |
|
2475 |
– |
assertEquals(2, e.count.get()); |
2476 |
– |
} |
2477 |
– |
|
2478 |
– |
/** |
2479 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2480 |
– |
*/ |
2481 |
– |
public void testThenAcceptBothAsync4E() { |
2482 |
– |
CompletableFuture<Integer> f, g; |
2483 |
– |
CompletableFuture<Void> h; |
2484 |
– |
SubtractAction r; |
2485 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2486 |
– |
|
2487 |
– |
f = new CompletableFuture<>(); |
2488 |
– |
g = new CompletableFuture<>(); |
2489 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2490 |
– |
assertTrue(f.cancel(true)); |
2491 |
– |
checkIncomplete(h); |
2492 |
– |
g.complete(1); |
2493 |
– |
checkCompletedWithWrappedCancellationException(h); |
2494 |
– |
|
2495 |
– |
f = new CompletableFuture<>(); |
2496 |
– |
g = new CompletableFuture<>(); |
2497 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2498 |
– |
assertTrue(g.cancel(true)); |
2499 |
– |
checkIncomplete(h); |
2500 |
– |
f.complete(3); |
2501 |
– |
checkCompletedWithWrappedCancellationException(h); |
2502 |
– |
|
2503 |
– |
f = new CompletableFuture<>(); |
2504 |
– |
g = new CompletableFuture<>(); |
2505 |
– |
f.complete(3); |
2506 |
– |
assertTrue(g.cancel(true)); |
2507 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2508 |
– |
checkCompletedWithWrappedCancellationException(h); |
2509 |
– |
|
2510 |
– |
f = new CompletableFuture<>(); |
2511 |
– |
g = new CompletableFuture<>(); |
2512 |
– |
assertTrue(f.cancel(true)); |
2513 |
– |
g.complete(3); |
2514 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2515 |
– |
checkCompletedWithWrappedCancellationException(h); |
2516 |
– |
|
2517 |
– |
assertEquals(0, e.count.get()); |
2518 |
– |
} |
2519 |
– |
|
2520 |
– |
/** |
2521 |
– |
* runAfterBothAsync result completes normally after normal |
2522 |
– |
* completion of sources |
2523 |
– |
*/ |
2524 |
– |
public void testRunAfterBothAsyncE() { |
2525 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2526 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2527 |
– |
Noop r = new Noop(); |
2528 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2529 |
– |
f.complete(one); |
2530 |
– |
checkIncomplete(g); |
2531 |
– |
f2.complete(two); |
2532 |
– |
checkCompletedNormally(g, null); |
2533 |
– |
assertTrue(r.ran); |
2534 |
– |
} |
2535 |
– |
|
2536 |
– |
/** |
2537 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
2538 |
– |
* completion of source |
2539 |
– |
*/ |
2540 |
– |
public void testRunAfterBothAsync2E() { |
2541 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2542 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2543 |
– |
Noop r = new Noop(); |
2544 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2545 |
– |
f.completeExceptionally(new CFException()); |
2546 |
– |
f2.complete(two); |
2547 |
– |
checkCompletedWithWrappedCFException(g); |
2548 |
– |
|
2549 |
– |
r = new Noop(); |
2550 |
– |
f = new CompletableFuture<>(); |
2551 |
– |
f2 = new CompletableFuture<>(); |
2552 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2553 |
– |
f.complete(one); |
2554 |
– |
f2.completeExceptionally(new CFException()); |
2555 |
– |
checkCompletedWithWrappedCFException(g); |
2556 |
– |
} |
2557 |
– |
|
2558 |
– |
/** |
2559 |
– |
* runAfterBothAsync result completes exceptionally if action does |
2560 |
– |
*/ |
2561 |
– |
public void testRunAfterBothAsync3E() { |
2562 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2563 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2564 |
– |
FailingNoop r = new FailingNoop(); |
2565 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2566 |
– |
f.complete(one); |
2567 |
– |
checkIncomplete(g); |
2568 |
– |
f2.complete(two); |
2569 |
– |
checkCompletedWithWrappedCFException(g); |
2570 |
– |
} |
2571 |
– |
|
2572 |
– |
/** |
2573 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
2574 |
– |
*/ |
2575 |
– |
public void testRunAfterBothAsync4E() { |
2576 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2577 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2578 |
– |
Noop r = new Noop(); |
2579 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2580 |
– |
assertTrue(f.cancel(true)); |
2581 |
– |
f2.complete(two); |
2582 |
– |
checkCompletedWithWrappedCancellationException(g); |
2583 |
– |
|
2584 |
– |
r = new Noop(); |
2585 |
– |
f = new CompletableFuture<>(); |
2586 |
– |
f2 = new CompletableFuture<>(); |
2587 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2588 |
– |
f.complete(one); |
2589 |
– |
assertTrue(f2.cancel(true)); |
2590 |
– |
checkCompletedWithWrappedCancellationException(g); |
2591 |
– |
} |
2592 |
– |
|
2593 |
– |
/** |
2717 |
|
* applyToEitherAsync result completes normally after normal |
2718 |
|
* completion of sources |
2719 |
|
*/ |
2790 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2791 |
|
f.complete(one); |
2792 |
|
checkCompletedNormally(g, null); |
2793 |
< |
assertEquals(r.value, 2); |
2793 |
> |
assertEquals(r.value, (Integer) 2); |
2794 |
|
|
2795 |
|
r = new IncAction(); |
2796 |
|
f = new CompletableFuture<>(); |
2798 |
|
f2 = new CompletableFuture<>(); |
2799 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2800 |
|
checkCompletedNormally(g, null); |
2801 |
< |
assertEquals(r.value, 2); |
2801 |
> |
assertEquals(r.value, (Integer) 2); |
2802 |
|
} |
2803 |
|
|
2804 |
|
/** |
3062 |
|
ThreadExecutor exec = new ThreadExecutor(); |
3063 |
|
|
3064 |
|
Runnable[] throwingActions = { |
3065 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
3066 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
3067 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
3068 |
< |
|
3069 |
< |
() -> { CompletableFuture.runAsync(null); }, |
3070 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
3071 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
3072 |
< |
|
3073 |
< |
() -> { f.completeExceptionally(null); }, |
3074 |
< |
|
3075 |
< |
() -> { f.thenApply(null); }, |
3076 |
< |
() -> { f.thenApplyAsync(null); }, |
3077 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
3078 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
3079 |
< |
|
3080 |
< |
() -> { f.thenAccept(null); }, |
3081 |
< |
() -> { f.thenAcceptAsync(null); }, |
3082 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
3083 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
3084 |
< |
|
3085 |
< |
() -> { f.thenRun(null); }, |
3086 |
< |
() -> { f.thenRunAsync(null); }, |
3087 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
3088 |
< |
() -> { f.thenRunAsync(null, exec); }, |
3089 |
< |
|
3090 |
< |
() -> { f.thenCombine(g, null); }, |
3091 |
< |
() -> { f.thenCombineAsync(g, null); }, |
3092 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
3093 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
3094 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
3095 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
3096 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
3097 |
< |
|
3098 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
3099 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
3100 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
3101 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
3102 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
3103 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
3104 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
3105 |
< |
|
3106 |
< |
() -> { f.runAfterBoth(g, null); }, |
3107 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
3108 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
3109 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
3110 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
3111 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
3112 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
3113 |
< |
|
3114 |
< |
() -> { f.applyToEither(g, null); }, |
3115 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
3116 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
3117 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
3118 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
3119 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
3120 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
3121 |
< |
|
3122 |
< |
() -> { f.acceptEither(g, null); }, |
3123 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
3124 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
3125 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
3126 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
3127 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
3128 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
3129 |
< |
|
3130 |
< |
() -> { f.runAfterEither(g, null); }, |
3131 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3132 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3133 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3134 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3135 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3136 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3137 |
< |
|
3138 |
< |
() -> { f.thenCompose(null); }, |
3139 |
< |
() -> { f.thenComposeAsync(null); }, |
3140 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3141 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3142 |
< |
|
3143 |
< |
() -> { f.exceptionally(null); }, |
3144 |
< |
|
3145 |
< |
() -> { f.handle(null); }, |
3146 |
< |
|
3147 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3148 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3149 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3150 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3151 |
< |
|
3152 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3153 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3154 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3155 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
3065 |
> |
() -> CompletableFuture.supplyAsync(null), |
3066 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
3067 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
3068 |
> |
|
3069 |
> |
() -> CompletableFuture.runAsync(null), |
3070 |
> |
() -> CompletableFuture.runAsync(null, exec), |
3071 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
3072 |
> |
|
3073 |
> |
() -> f.completeExceptionally(null), |
3074 |
> |
|
3075 |
> |
() -> f.thenApply(null), |
3076 |
> |
() -> f.thenApplyAsync(null), |
3077 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
3078 |
> |
() -> f.thenApplyAsync(null, exec), |
3079 |
> |
|
3080 |
> |
() -> f.thenAccept(null), |
3081 |
> |
() -> f.thenAcceptAsync(null), |
3082 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
3083 |
> |
() -> f.thenAcceptAsync(null, exec), |
3084 |
> |
|
3085 |
> |
() -> f.thenRun(null), |
3086 |
> |
() -> f.thenRunAsync(null), |
3087 |
> |
() -> f.thenRunAsync(() -> {} , null), |
3088 |
> |
() -> f.thenRunAsync(null, exec), |
3089 |
> |
|
3090 |
> |
() -> f.thenCombine(g, null), |
3091 |
> |
() -> f.thenCombineAsync(g, null), |
3092 |
> |
() -> f.thenCombineAsync(g, null, exec), |
3093 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
3094 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
3095 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
3096 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
3097 |
> |
|
3098 |
> |
() -> f.thenAcceptBoth(g, null), |
3099 |
> |
() -> f.thenAcceptBothAsync(g, null), |
3100 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
3101 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
3102 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
3103 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
3104 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
3105 |
> |
|
3106 |
> |
() -> f.runAfterBoth(g, null), |
3107 |
> |
() -> f.runAfterBothAsync(g, null), |
3108 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
3109 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
3110 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
3111 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
3112 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
3113 |
> |
|
3114 |
> |
() -> f.applyToEither(g, null), |
3115 |
> |
() -> f.applyToEitherAsync(g, null), |
3116 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
3117 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
3118 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
3119 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
3120 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
3121 |
> |
|
3122 |
> |
() -> f.acceptEither(g, null), |
3123 |
> |
() -> f.acceptEitherAsync(g, null), |
3124 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
3125 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3126 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3127 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3128 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3129 |
> |
|
3130 |
> |
() -> f.runAfterEither(g, null), |
3131 |
> |
() -> f.runAfterEitherAsync(g, null), |
3132 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3133 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3134 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3135 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3136 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3137 |
> |
|
3138 |
> |
() -> f.thenCompose(null), |
3139 |
> |
() -> f.thenComposeAsync(null), |
3140 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3141 |
> |
() -> f.thenComposeAsync(null, exec), |
3142 |
> |
|
3143 |
> |
() -> f.exceptionally(null), |
3144 |
> |
|
3145 |
> |
() -> f.handle(null), |
3146 |
> |
|
3147 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3148 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3149 |
> |
() -> CompletableFuture.allOf(f, null), |
3150 |
> |
() -> CompletableFuture.allOf(null, f), |
3151 |
> |
|
3152 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3153 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3154 |
> |
() -> CompletableFuture.anyOf(f, null), |
3155 |
> |
() -> CompletableFuture.anyOf(null, f), |
3156 |
> |
|
3157 |
> |
() -> f.obtrudeException(null), |
3158 |
|
}; |
3159 |
|
|
3160 |
|
assertThrows(NullPointerException.class, throwingActions); |
3306 |
|
checkCompletedWithWrappedCFException(g); |
3307 |
|
} |
3308 |
|
|
3184 |
– |
|
3309 |
|
/** |
3310 |
< |
* handleAsync action action completes normally with function |
3311 |
< |
* value on either normal or exceptional completion of source |
3310 |
> |
* handleAsync action completes normally with function value on |
3311 |
> |
* either normal or exceptional completion of source |
3312 |
|
*/ |
3313 |
|
public void testHandleAsync() { |
3314 |
|
CompletableFuture<Integer> f, g; |