本文整理汇总了Java中java.util.concurrent.CompletableFuture.minimalCompletionStage方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.minimalCompletionStage方法的具体用法?Java CompletableFuture.minimalCompletionStage怎么用?Java CompletableFuture.minimalCompletionStage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletableFuture
的用法示例。
在下文中一共展示了CompletableFuture.minimalCompletionStage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMinimalCompletionStage_toCompletableFuture_normalCompletion
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() returns a CompletableFuture that
* is completed normally, with the same value, when source is.
*/
public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() {
for (boolean createIncomplete : new boolean[] { true, false })
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> minimal = f.minimalCompletionStage();
if (!createIncomplete) assertTrue(f.complete(v1));
CompletableFuture<Integer> g = minimal.toCompletableFuture();
if (createIncomplete) {
checkIncomplete(f);
checkIncomplete(g);
assertTrue(f.complete(v1));
}
checkCompletedNormally(f, v1);
checkCompletedNormally(g, v1);
}}
示例2: testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() returns a CompletableFuture that
* is completed exceptionally when source is.
*/
public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() {
for (boolean createIncomplete : new boolean[] { true, false })
{
CFException ex = new CFException();
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> minimal = f.minimalCompletionStage();
if (!createIncomplete) f.completeExceptionally(ex);
CompletableFuture<Integer> g = minimal.toCompletableFuture();
if (createIncomplete) {
checkIncomplete(f);
checkIncomplete(g);
f.completeExceptionally(ex);
}
checkCompletedExceptionally(f, ex);
checkCompletedWithWrappedException(g, ex);
}}
示例3: testMinimalCompletionStage_join_by_hand
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* Joining a minimal stage "by hand" works
*/
public void testMinimalCompletionStage_join_by_hand() {
for (boolean createIncomplete : new boolean[] { true, false })
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> minimal = f.minimalCompletionStage();
CompletableFuture<Integer> g = new CompletableFuture<>();
if (!createIncomplete) assertTrue(f.complete(v1));
minimal.thenAccept(x -> g.complete(x));
if (createIncomplete) assertTrue(f.complete(v1));
g.join();
checkCompletedNormally(g, v1);
checkCompletedNormally(f, v1);
assertEquals(v1, join(minimal));
}}
示例4: testMinimalCompletionStage
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalCompletionStage returns a CompletableFuture that is
* completed normally, with the same value, when source is.
*/
public void testMinimalCompletionStage() {
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> g = f.minimalCompletionStage();
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<>();
checkIncomplete(f);
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
f.complete(1);
checkCompletedNormally(f, 1);
assertEquals(x.get(), 1);
assertNull(r.get());
}
示例5: testMinimalCompletionStage2
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalCompletionStage returns a CompletableFuture that is
* completed exceptionally when source is.
*/
public void testMinimalCompletionStage2() {
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> g = f.minimalCompletionStage();
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<>();
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
checkIncomplete(f);
CFException ex = new CFException();
f.completeExceptionally(ex);
checkCompletedExceptionally(f, ex);
assertEquals(x.get(), 0);
assertEquals(r.get().getCause(), ex);
}
示例6: testMinimalCompletionStage_toCompletableFuture_mutable
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() gives mutable CompletableFuture
*/
public void testMinimalCompletionStage_toCompletableFuture_mutable() {
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage minimal = f.minimalCompletionStage();
CompletableFuture<Integer> g = minimal.toCompletableFuture();
assertTrue(g.complete(v1));
checkCompletedNormally(g, v1);
checkIncomplete(f);
checkIncomplete(minimal.toCompletableFuture());
}}
示例7: testMinimalCompletionStage_toCompletableFuture_join
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture().join() awaits completion
*/
public void testMinimalCompletionStage_toCompletableFuture_join() throws Exception {
for (boolean createIncomplete : new boolean[] { true, false })
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
if (!createIncomplete) assertTrue(f.complete(v1));
CompletionStage<Integer> minimal = f.minimalCompletionStage();
if (createIncomplete) assertTrue(f.complete(v1));
assertEquals(v1, minimal.toCompletableFuture().join());
assertEquals(v1, minimal.toCompletableFuture().get());
checkCompletedNormally(minimal.toCompletableFuture(), v1);
}}
示例8: testMinimalCompletionStage_toCompletableFuture_oneWayPropagation
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
* Completion of a toCompletableFuture copy of a minimal stage
* does not complete its source.
*/
public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() {
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> g = f.minimalCompletionStage();
assertTrue(g.toCompletableFuture().complete(1));
assertTrue(g.toCompletableFuture().complete(null));
assertTrue(g.toCompletableFuture().cancel(true));
assertTrue(g.toCompletableFuture().cancel(false));
assertTrue(g.toCompletableFuture().completeExceptionally(new CFException()));
checkIncomplete(g.toCompletableFuture());
f.complete(1);
checkCompletedNormally(g.toCompletableFuture(), 1);
}