當前位置: 首頁>>代碼示例>>Java>>正文


Java CompletableFuture.minimalCompletionStage方法代碼示例

本文整理匯總了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);
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CompletableFutureTest.java

示例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);
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CompletableFutureTest.java

示例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));
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:CompletableFutureTest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CompletableFutureTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:CompletableFutureTest.java

示例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());
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:CompletableFutureTest.java

示例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);
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:CompletableFutureTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CompletableFutureTest.java


注:本文中的java.util.concurrent.CompletableFuture.minimalCompletionStage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。