Skip to content

Commit

Permalink
CffuFactory新增相关重载线程池参数方法及单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
huhaosumail committed Jun 25, 2024
1 parent 49cac79 commit 4dc50e0
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 4 deletions.
189 changes: 185 additions & 4 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyFastFailAsync(
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(supplier1, supplier2));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the fast-fail behavior.
*
* @return the new Cffu
* @see #allResultsOfFastFail(CompletionStage[])
*/
public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyFastFailAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2) {
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(executor,supplier1, supplier2));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -276,6 +291,21 @@ public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyFastFailAsync(
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(supplier1, supplier2, supplier3));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier, Supplier)} except for the fast-fail behavior.
*
* @return the new Cffu
* @see #allResultsOfFastFail(CompletionStage[])
*/
public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyFastFailAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2, Supplier<? extends T3> supplier3) {
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(executor,supplier1, supplier2, supplier3));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -292,6 +322,22 @@ public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyFastFailAsync(
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(supplier1, supplier2, supplier3, supplier4));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier, Supplier, Supplier)} except for the fast-fail behavior.
*
* @return the new Cffu
* @see #allResultsOfFastFail(CompletionStage[])
*/
public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyFastFailAsync(
Executor executor,Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4) {
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(executor,supplier1, supplier2, supplier3, supplier4));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -308,6 +354,23 @@ public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyFastFai
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(supplier1, supplier2, supplier3, supplier4, supplier5));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier, Supplier, Supplier, Supplier)} except for the fast-fail behavior.
*
* @return the new Cffu
* @see #allResultsOfFastFail(CompletionStage[])
*/
public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyFastFailAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2, Supplier<? extends T3> supplier3,
Supplier<? extends T4> supplier4, Supplier<? extends T5> supplier5) {
return create(CompletableFutureUtils.tupleMSupplyFastFailAsync(executor,supplier1, supplier2, supplier3, supplier4, supplier5));
}


/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -319,7 +382,22 @@ public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyFastFai
*/
public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyMostSuccessAsync(
long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(defaultExecutor, timeout, unit, supplier1, supplier2));
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(timeout, unit, supplier1, supplier2));
}


/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior.
*
* @return the new Cffu
*/
public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyMostSuccessAsync(Executor executor,
long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(executor,timeout, unit, supplier1, supplier2));
}

/**
Expand All @@ -335,7 +413,23 @@ public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyMostSuccessAsync(
long timeout, TimeUnit unit,
Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2, Supplier<? extends T3> supplier3) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
defaultExecutor, timeout, unit, supplier1, supplier2, supplier3));
timeout, unit, supplier1, supplier2, supplier3));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior.
*
* @return the new Cffu
*/
public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyMostSuccessAsync(
Executor executor,long timeout, TimeUnit unit,
Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2, Supplier<? extends T3> supplier3) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
executor, timeout, unit, supplier1, supplier2, supplier3));
}

/**
Expand All @@ -351,7 +445,23 @@ public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyMostSuccessAsyn
long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
defaultExecutor, timeout, unit, supplier1, supplier2, supplier3, supplier4));
timeout, unit, supplier1, supplier2, supplier3, supplier4));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior.
*
* @return the new Cffu
*/
public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyMostSuccessAsync(
Executor executor, long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
executor, timeout, unit, supplier1, supplier2, supplier3, supplier4));
}

/**
Expand All @@ -367,7 +477,23 @@ public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyMostSuc
long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4, Supplier<? extends T5> supplier5) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
defaultExecutor, timeout, unit, supplier1, supplier2, supplier3, supplier4, supplier5));
timeout, unit, supplier1, supplier2, supplier3, supplier4, supplier5));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
* <p>
* This method is the same as {@link #tupleMSupplyAsync(Supplier, Supplier)} except for the most-success behavior.
*
* @return the new Cffu
*/
public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyMostSuccessAsync(
Executor executor,long timeout, TimeUnit unit, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4, Supplier<? extends T5> supplier5) {
return create(CompletableFutureUtils.tupleMSupplyMostSuccessAsync(
executor, timeout, unit, supplier1, supplier2, supplier3, supplier4, supplier5));
}

/**
Expand All @@ -383,6 +509,19 @@ public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyAsync(
return create(CompletableFutureUtils.tupleMSupplyAsync(supplier1, supplier2));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
*
* @return the new Cffu
* @see #allResultsOf(CompletionStage[])
*/
public <T1, T2> Cffu<Tuple2<T1, T2>> tupleMSupplyAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2) {
return create(CompletableFutureUtils.tupleMSupplyAsync(executor,supplier1, supplier2));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -396,6 +535,19 @@ public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyAsync(
return create(CompletableFutureUtils.tupleMSupplyAsync(supplier1, supplier2, supplier3));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
*
* @return the new Cffu
* @see #allResultsOf(CompletionStage[])
*/
public <T1, T2, T3> Cffu<Tuple3<T1, T2, T3>> tupleMSupplyAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2, Supplier<? extends T3> supplier3) {
return create(CompletableFutureUtils.tupleMSupplyAsync(executor,supplier1, supplier2, supplier3));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -410,6 +562,21 @@ public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyAsync(
return create(CompletableFutureUtils.tupleMSupplyAsync(supplier1, supplier2, supplier3, supplier4));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
*
* @return the new Cffu
* @see #allResultsOf(CompletionStage[])
*/
public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> tupleMSupplyAsync(
Executor executor,
Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4) {
return create(CompletableFutureUtils.tupleMSupplyAsync(executor,supplier1, supplier2, supplier3, supplier4));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
Expand All @@ -424,6 +591,20 @@ public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyAsync(
return create(CompletableFutureUtils.tupleMSupplyAsync(supplier1, supplier2, supplier3, supplier4, supplier5));
}

/**
* Returns a new Cffu that is asynchronously completed
* by tasks running in the {@link #defaultExecutor()} with the values obtained by calling the given Suppliers
* in the <strong>same order</strong> of the given Suppliers arguments.
*
* @return the new Cffu
* @see #allResultsOf(CompletionStage[])
*/
public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> tupleMSupplyAsync(
Executor executor, Supplier<? extends T1> supplier1, Supplier<? extends T2> supplier2,
Supplier<? extends T3> supplier3, Supplier<? extends T4> supplier4, Supplier<? extends T5> supplier5) {
return create(CompletableFutureUtils.tupleMSupplyAsync(supplier1, supplier2, supplier3, supplier4, supplier5));
}

// endregion
////////////////////////////////////////////////////////////////////////////////
// region## allOf* Methods(including mostResultsOfSuccess)
Expand Down
12 changes: 12 additions & 0 deletions cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,24 @@ void test_tupleMSupplyAsync() throws Exception {
return n + n;
};
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());
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());

assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyAsync(executorService,supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyFastFailAsync(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(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.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, 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());
}

@Test
Expand All @@ -735,12 +743,16 @@ void test_tupleMSupplyMostSuccessAsync() throws Exception {
return n + n;
};
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());

assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.tupleMSupplyMostSuccessAsync(executorService,100, TimeUnit.MILLISECONDS, supplier_n, supplier_s, supplier_d).get());

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());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4dc50e0

Please sign in to comment.