Skip to content

Commit

Permalink
Add missing rejectionPropagatesToOutput tests.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=116137704
  • Loading branch information
cpovirk committed Mar 2, 2016
1 parent 2d97fd8 commit f5855cd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
Expand Up @@ -1233,6 +1233,33 @@ public void testCatching_listenerThrowsError() throws Exception {
}
}

public void testCatching_rejectionPropagatesToOutput() throws Exception {
com.google.common.util.concurrent.FuturesTest testCase = new com.google.common.util.concurrent.FuturesTest();
testCase.setUp();
Throwable failure = null;
try {
testCase.testCatching_rejectionPropagatesToOutput();
} catch (Throwable t) {
failure = t;
}
try {
testCase.tearDown();
} catch (Throwable t) {
if (failure == null) {
failure = t;
}
}
if (failure instanceof Exception) {
throw (Exception) failure;
}
if (failure instanceof Error) {
throw (Error) failure;
}
if (failure != null) {
throw new RuntimeException(failure);
}
}

public void testCatching_resultCancelledBeforeFallback() throws Exception {
com.google.common.util.concurrent.FuturesTest testCase = new com.google.common.util.concurrent.FuturesTest();
testCase.setUp();
Expand Down Expand Up @@ -1989,6 +2016,33 @@ public void testTransformAsync_listenerThrowsError() throws Exception {
}
}

public void testTransformAsync_rejectionPropagatesToOutput() throws Exception {
com.google.common.util.concurrent.FuturesTest testCase = new com.google.common.util.concurrent.FuturesTest();
testCase.setUp();
Throwable failure = null;
try {
testCase.testTransformAsync_rejectionPropagatesToOutput();
} catch (Throwable t) {
failure = t;
}
try {
testCase.tearDown();
} catch (Throwable t) {
if (failure == null) {
failure = t;
}
}
if (failure instanceof Exception) {
throw (Exception) failure;
}
if (failure instanceof Error) {
throw (Error) failure;
}
if (failure != null) {
throw new RuntimeException(failure);
}
}

public void testTransformValueRemainsMemoized() throws Exception {
com.google.common.util.concurrent.FuturesTest testCase = new com.google.common.util.concurrent.FuturesTest();
testCase.setUp();
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.google.common.util.concurrent;

import static com.google.common.base.Functions.constant;
import static com.google.common.base.Functions.identity;
import static com.google.common.base.Throwables.propagateIfInstanceOf;
import static com.google.common.collect.Iterables.getOnlyElement;
Expand Down Expand Up @@ -655,8 +656,22 @@ public void run() {
public void testTransform_rejectionPropagatesToOutput()
throws Exception {
SettableFuture<Foo> input = SettableFuture.create();
ListenableFuture<String> transformed =
Futures.transform(input, Functions.toStringFunction(), REJECTING_EXECUTOR);
Function<Foo, Foo> identity = identity();
ListenableFuture<Foo> transformed = Futures.transform(input, identity, REJECTING_EXECUTOR);
input.set(new Foo());
try {
transformed.get(5, TimeUnit.SECONDS);
fail();
} catch (ExecutionException expected) {
assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class);
}
}

public void testTransformAsync_rejectionPropagatesToOutput() throws Exception {
SettableFuture<Foo> input = SettableFuture.create();
AsyncFunction<Foo, Foo> asyncIdentity = asyncIdentity();
ListenableFuture<Foo> transformed =
Futures.transformAsync(input, asyncIdentity, REJECTING_EXECUTOR);
input.set(new Foo());
try {
transformed.get(5, TimeUnit.SECONDS);
Expand Down Expand Up @@ -1549,10 +1564,27 @@ public void run() {
}
}

public void testCatching_rejectionPropagatesToOutput() throws Exception {
SettableFuture<String> input = SettableFuture.create();
ListenableFuture<String> transformed =
Futures.catching(input, Throwable.class, constant("foo"), REJECTING_EXECUTOR);
input.setException(new Exception());
try {
transformed.get(5, TimeUnit.SECONDS);
fail();
} catch (ExecutionException expected) {
assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class);
}
}

public void testCatchingAsync_rejectionPropagatesToOutput() throws Exception {
SettableFuture<String> input = SettableFuture.create();
ListenableFuture<String> transformed =
Futures.catching(input, Throwable.class, Functions.toStringFunction(), REJECTING_EXECUTOR);
Futures.catchingAsync(
input,
Throwable.class,
constantAsyncFunction(immediateFuture("foo")),
REJECTING_EXECUTOR);
input.setException(new Exception());
try {
transformed.get(5, TimeUnit.SECONDS);
Expand Down

0 comments on commit f5855cd

Please sign in to comment.