From 94569bdeecf80549f5540afdcbf49e0891fbc731 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sun, 11 Aug 2024 00:24:11 +0800 Subject: [PATCH] WIP --- .../io/foldright/cffu/CffuFactoryTest.java | 121 ++++++------------ .../test/java/io/foldright/cffu/CffuTest.java | 92 +++++++------ .../java/io/foldright/test_utils/TestUtils.kt | 12 ++ 3 files changed, 95 insertions(+), 130 deletions(-) diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java index 55939ab9..0e32a2ba 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -63,8 +63,8 @@ void test_mRun() throws Exception { cffuFactory.mRunAnySuccessAsync(runnable, runnable), cffuFactory.mRunAnyAsync(runnable, runnable), }; - assertTrue(System.currentTimeMillis() - tick < 50); + for (Cffu cf : cfs) { assertNull(cf.get()); } @@ -72,13 +72,9 @@ void test_mRun() throws Exception { @Test void test_mSupply() throws Exception { - final Supplier supplier = () -> { - snoreZzz(); - return n; - }; + final Supplier supplier = supplyLater(n); final long tick = System.currentTimeMillis(); - @SuppressWarnings("unchecked") Cffu>[] cfs = new Cffu[]{ cffuFactory.mSupplyFastFailAsync(supplier, supplier), @@ -90,14 +86,13 @@ void test_mSupply() throws Exception { cffuFactory.mSupplyAsync(supplier, supplier), cffuFactory.mSupplyAsync(executorService, supplier, supplier), }; - assertTrue(System.currentTimeMillis() - tick < 50); + for (Cffu> cf : cfs) { assertEquals(Arrays.asList(n, n), cf.get()); } final long tick1 = System.currentTimeMillis(); - @SuppressWarnings("unchecked") Cffu[] cfs1 = new Cffu[]{ cffuFactory.mSupplyAnySuccessAsync(supplier, supplier), @@ -105,8 +100,8 @@ void test_mSupply() throws Exception { cffuFactory.mSupplyAnyAsync(supplier, supplier), cffuFactory.mSupplyAnyAsync(executorService, supplier, supplier), }; - assertTrue(System.currentTimeMillis() - tick1 < 50); + for (Cffu cf : cfs1) { assertEquals(n, cf.get()); } @@ -119,27 +114,11 @@ void test_mSupply() throws Exception { @Test void test_tupleMSupplyAsync() throws Exception { - final Supplier supplier_n = () -> { - snoreZzz(); - return n; - }; - final Supplier supplier_s = () -> { - snoreZzz(); - return s; - }; - - final Supplier supplier_d = () -> { - snoreZzz(); - return d; - }; - final Supplier supplier_an = () -> { - snoreZzz(); - return anotherN; - }; - final Supplier supplier_nn = () -> { - snoreZzz(); - return n + n; - }; + final Supplier supplier_n = supplyLater(n); + final Supplier supplier_s = supplyLater(s); + final Supplier supplier_d = supplyLater(d); + final Supplier supplier_an = supplyLater(anotherN); + final Supplier supplier_nnn = supplyLater(nnn); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s).get()); @@ -147,8 +126,8 @@ void test_tupleMSupplyAsync() throws Exception { assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyFastFailAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAllSuccessAsync(supplier_n, supplier_s).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAllSuccessAsync(executorService, supplier_n, supplier_s).get()); @@ -156,8 +135,8 @@ void test_tupleMSupplyAsync() throws Exception { assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAllSuccessAsync(executorService, supplier_n, supplier_s, supplier_d).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAllSuccessAsync(supplier_n, supplier_s, supplier_d, supplier_an).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAllSuccessAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAllSuccessAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAllSuccessAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyAllSuccessAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyAllSuccessAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s).get()); @@ -165,8 +144,8 @@ void test_tupleMSupplyAsync() throws Exception { assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d, supplier_an).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyAsync(executorService, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nnn).get()); } @Test @@ -190,7 +169,7 @@ void test_tupleMSupplyMostSuccessAsync() throws Exception { }; final Supplier supplier_nn = () -> { nap(); - return n + n; + return nnn; }; assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s).get()); assertEquals(Tuple2.of(n, s), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s).get()); @@ -201,8 +180,8 @@ void test_tupleMSupplyMostSuccessAsync() throws Exception { assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an).get()); assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.tupleMSupplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get()); } // endregion @@ -423,33 +402,21 @@ void test_anySuccessOf__trivial_case() throws Exception { assertEquals(n, cffuFactory.anySuccessOf( cffuFactory.newIncompleteCffu(), cffuFactory.newIncompleteCffu(), - cffuFactory.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), + cffuFactory.supplyAsync(supplyLater(anotherN)), cffuFactory.completedFuture(n) ).get()); // success then failed assertEquals(n, cffuFactory.anySuccessOf( cffuFactory.newIncompleteCffu(), cffuFactory.newIncompleteCffu(), - cffuFactory.supplyAsync(() -> { - snoreZzz(); - throw rte; - }), + cffuFactory.supplyAsync(supplyLater(rte)), cffuFactory.completedFuture(n) ).get()); // all success assertEquals(n, cffuFactory.anySuccessOf( - cffuFactory.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), - cffuFactory.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), + cffuFactory.supplyAsync(supplyLater(anotherN)), + cffuFactory.supplyAsync(supplyLater(anotherN)), cffuFactory.completedFuture(n) ).get()); @@ -459,33 +426,21 @@ void test_anySuccessOf__trivial_case() throws Exception { assertEquals(n, cffuFactory.anySuccessOf( incompleteCf(), incompleteCf(), - CompletableFuture.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), + CompletableFuture.supplyAsync(supplyLater(anotherN)), completedFuture(n) ).get()); // success then failed assertEquals(n, cffuFactory.anySuccessOf( incompleteCf(), incompleteCf(), - CompletableFuture.supplyAsync(() -> { - snoreZzz(); - throw rte; - }), + CompletableFuture.supplyAsync(supplyLater(rte)), completedFuture(n) ).get()); // all success assertEquals(n, cffuFactory.anySuccessOf( - CompletableFuture.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), - CompletableFuture.supplyAsync(() -> { - snoreZzz(); - return anotherN; - }), + CompletableFuture.supplyAsync(supplyLater(anotherN)), + CompletableFuture.supplyAsync(supplyLater(anotherN)), completedFuture(n) ).get()); @@ -519,12 +474,12 @@ void test_allTupleFastFailOf() throws Exception { completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allTupleFastFailOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allTupleFastFailOf( completedFuture(n), completedFuture(s), completedFuture(d), completedFuture(anotherN), - completedFuture(n + n) + completedFuture(nnn) ).get()); //////////////////////////////////////////////////////////////////////////////// @@ -547,12 +502,12 @@ void test_allTupleFastFailOf() throws Exception { cffuFactory.completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allTupleFastFailOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allTupleFastFailOf( cffuFactory.completedFuture(n), cffuFactory.completedFuture(s), cffuFactory.completedFuture(d), cffuFactory.completedFuture(anotherN), - cffuFactory.completedFuture(n + n) + cffuFactory.completedFuture(nnn) ).get()); } @@ -597,12 +552,12 @@ void test_allSuccessTupleOf() throws Exception { completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allSuccessTupleOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allSuccessTupleOf( completedFuture(n), completedFuture(s), completedFuture(d), completedFuture(anotherN), - completedFuture(n + n) + completedFuture(nnn) ).get()); //////////////////////////////////////////////////////////////////////////////// @@ -625,12 +580,12 @@ void test_allSuccessTupleOf() throws Exception { cffuFactory.completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allSuccessTupleOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allSuccessTupleOf( cffuFactory.completedFuture(n), cffuFactory.completedFuture(s), cffuFactory.completedFuture(d), cffuFactory.completedFuture(anotherN), - cffuFactory.completedFuture(n + n) + cffuFactory.completedFuture(nnn) ).get()); } @@ -688,12 +643,12 @@ void test_allTupleOf() throws Exception { completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allTupleOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allTupleOf( completedFuture(n), completedFuture(s), completedFuture(d), completedFuture(anotherN), - completedFuture(n + n) + completedFuture(nnn) ).get()); //////////////////////////////////////////////////////////////////////////////// @@ -716,12 +671,12 @@ void test_allTupleOf() throws Exception { cffuFactory.completedFuture(anotherN) ).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.allTupleOf( + assertEquals(Tuple5.of(n, s, d, anotherN, nnn), cffuFactory.allTupleOf( cffuFactory.completedFuture(n), cffuFactory.completedFuture(s), cffuFactory.completedFuture(d), cffuFactory.completedFuture(anotherN), - cffuFactory.completedFuture(n + n) + cffuFactory.completedFuture(nnn) ).get()); } diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java index 239650cc..41442d98 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -71,8 +71,8 @@ void test_thenMApply() throws Exception { completed.thenMApplyAsync(function_n, function_n), completed.thenMApplyAsync(executorService, function_n, function_n) }; - assertTrue(System.currentTimeMillis() - tick < 50); + for (Cffu> cf : cfs) { assertEquals(Arrays.asList(n, n), cf.get()); } @@ -86,8 +86,8 @@ void test_thenMApply() throws Exception { completed.thenMApplyAnyAsync(function_n, function_n), completed.thenMApplyAnyAsync(executorService, function_n, function_n), }; - assertTrue(System.currentTimeMillis() - tick1 < 50); + for (Cffu cf : cfs1) { assertEquals(n, cf.get()); } @@ -102,7 +102,6 @@ void test_thenMAccept() throws Exception { }; final long tick = System.currentTimeMillis(); - @SuppressWarnings("unchecked") Cffu>[] cfs = new Cffu[]{ completed.thenMAcceptAsync(consumer, consumer), @@ -114,8 +113,8 @@ void test_thenMAccept() throws Exception { completed.thenMAcceptAnyAsync(consumer, consumer), completed.thenMAcceptAnyAsync(executorService, consumer, consumer) }; - assertTrue(System.currentTimeMillis() - tick < 50); + for (Cffu> cf : cfs) { assertNull(cf.get()); } @@ -127,7 +126,6 @@ void test_thenMRun() throws Exception { final Runnable runnable = TestUtils::snoreZzz; final long tick = System.currentTimeMillis(); - @SuppressWarnings("unchecked") Cffu[] cfs = new Cffu[]{ completed.thenMRunAsync(runnable, runnable), @@ -139,8 +137,8 @@ void test_thenMRun() throws Exception { completed.thenMRunAnyAsync(runnable, runnable), completed.thenMRunAnyAsync(executorService, runnable, runnable), }; - assertTrue(System.currentTimeMillis() - tick < 50); + for (Cffu cf : cfs) { assertNull(cf.get()); } @@ -156,62 +154,62 @@ void test_thenTupleMApplyAsync() throws Exception { final Cffu completed = cffuFactory.completedFuture(n); final Function function_n = (x) -> { nap(); - return n; + return n + n; }; final Function function_s = (x) -> { nap(); - return s; + return s + n; }; final Function function_d = (x) -> { nap(); - return d; + return d + n; }; final Function function_an = (x) -> { nap(); - return anotherN; + return anotherN + n; }; - final Function function_nn = (x) -> { + final Function function_nnn = (x) -> { nap(); - return n + n; + return nnn + n; }; - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyFastFailAsync(function_n, function_s).get()); - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an, function_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an, function_nn).get()); - - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s).get()); - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d, function_an, function_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d, function_an, function_nn).get()); - - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s).get()); - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nn).get()); - - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAsync(function_n, function_s).get()); - assertEquals(Tuple2.of(n, s), completed.thenTupleMApplyAsync(executorService, function_n, function_s).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAsync(function_n, function_s, function_d).get()); - assertEquals(Tuple3.of(n, s, d), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple4.of(n, s, d, anotherN), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an, function_nn).get()); - assertEquals(Tuple5.of(n, s, d, anotherN, n + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an, function_nn).get()); + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s).get()); + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyFastFailAsync(function_n, function_s, function_d, function_an, function_nnn).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyFastFailAsync(executorService, function_n, function_s, function_d, function_an, function_nnn).get()); + + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s).get()); + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyAllSuccessAsync(function_n, function_s, function_d, function_an, function_nnn).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyAllSuccessAsync(executorService, function_n, function_s, function_d, function_an, function_nnn).get()); + + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s).get()); + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nnn).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyMostSuccessAsync(executorService, 100, TimeUnit.MILLISECONDS, function_n, function_s, function_d, function_an, function_nnn).get()); + + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyAsync(function_n, function_s).get()); + assertEquals(Tuple2.of(n + n, s + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyAsync(function_n, function_s, function_d).get()); + assertEquals(Tuple3.of(n + n, s + n, d + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple4.of(n + n, s + n, d + n, anotherN + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyAsync(function_n, function_s, function_d, function_an, function_nnn).get()); + assertEquals(Tuple5.of(n + n, s + n, d + n, anotherN + n, nnn + n), completed.thenTupleMApplyAsync(executorService, function_n, function_s, function_d, function_an, function_nnn).get()); } // endregion diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt index 763754d0..4cd6e39b 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt @@ -48,6 +48,18 @@ fun cancelledFuture(mayInterruptIfRunning: Boolean = false): CompletableFutu private val DEFAULT_EXECUTOR: Executor = Executor { /* do nothing */ } +@JvmOverloads +fun supplyLater(value: T, millis: Long = 100) = Supplier { + sleep(millis) + value +} + +@JvmOverloads +fun supplyLater(ex: Throwable, millis: Long = 100) = Supplier { + sleep(millis) + throw ex +} + // endregion //////////////////////////////////////////////////////////////////////////////// // region# Helper functions for API compatibility test