@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Object> reload(Object key, Object oldValue) { return Futures.immediateFailedFuture(e); } };
@Override public ListenableFuture<Integer> apply(Throwable t) throws Exception { if (!wrapInFuture) { throw expectedException; } else { return immediateFailedFuture(expectedException); } } });
@Override public ListenableFuture<String> call() throws Exception { assertTrue(futureInteger.isDone()); assertTrue(futureBoolean.isDone()); return immediateFailedFuture(thrown); } };
public void testAllAsList_immediateFailure() throws Exception { Throwable exception = new Throwable("failed"); ListenableFuture<String> future1 = immediateFailedFuture(exception); ListenableFuture<String> future2 = immediateFuture("results"); ListenableFuture<List<String>> compound = allAsList(ImmutableList.of(future1, future2)); try { getDone(compound); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
public void testAllAsList_singleFailure() throws Exception { Throwable exception = new Throwable("failed"); ListenableFuture<String> future = immediateFailedFuture(exception); ListenableFuture<List<String>> compound = allAsList(ImmutableList.of(future)); try { getDone(compound); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
/** The same exception happening on multiple futures should not be logged. */ @SuppressWarnings("unchecked") public void testAllAsList_logging_same_exception() throws Exception { try { MyException sameInstance = new MyException(); getDone(allAsList(immediateFailedFuture(sameInstance), immediateFailedFuture(sameInstance))); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyException.class); assertEquals( "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } }
/** Ensure that errors are always logged. */ @SuppressWarnings("unchecked") public void testAllAsList_logging_error() throws Exception { try { getDone(allAsList(immediateFailedFuture(new MyError()))); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyError.class); List<LogRecord> logged = aggregateFutureLogHandler.getStoredLogRecords(); assertThat(logged).hasSize(1); // errors are always logged assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); } }
public void testCatchingAsync_Throwable() throws Exception { AsyncFunction<Throwable, Integer> fallback = asyncFunctionReturningOne(); ListenableFuture<Integer> originalFuture = immediateFailedFuture(new IOException()); ListenableFuture<Integer> faultTolerantFuture = catchingAsync(originalFuture, Throwable.class, fallback, directExecutor()); assertEquals(1, (int) getDone(faultTolerantFuture)); }
public void testFailed() { Exception failureCause = new Exception(); try { getDone(immediateFailedFuture(failureCause)); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(failureCause); } }
public void testCatching_Throwable() throws Exception { Function<Throwable, Integer> fallback = functionReturningOne(); ListenableFuture<Integer> originalFuture = immediateFailedFuture(new IOException()); ListenableFuture<Integer> faultTolerantFuture = catching(originalFuture, Throwable.class, fallback, directExecutor()); assertEquals(1, (int) getDone(faultTolerantFuture)); }
/** A single non-error failure is not logged because it is reported via the output future. */ @SuppressWarnings("unchecked") public void testAllAsList_logging_exception() throws Exception { try { getDone(allAsList(immediateFailedFuture(new MyException()))); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyException.class); assertEquals( "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } }
/** Ensure that errors are always logged. */ @SuppressWarnings("unchecked") public void testSuccessfulAsList_logging_error() throws Exception { assertEquals( newArrayList((Object) null), getDone(successfulAsList(immediateFailedFuture(new MyError())))); List<LogRecord> logged = aggregateFutureLogHandler.getStoredLogRecords(); assertThat(logged).hasSize(1); // errors are always logged assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); }
@GwtIncompatible // non-Throwable exceptionType public void testCatching_customTypeNoMatch() throws Exception { Function<IOException, Integer> fallback = functionReturningOne(); ListenableFuture<Integer> originalFuture = immediateFailedFuture(new RuntimeException()); ListenableFuture<Integer> faultTolerantFuture = catching(originalFuture, IOException.class, fallback, directExecutor()); try { getDone(faultTolerantFuture); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RuntimeException.class); } }
@GwtIncompatible // non-Throwable exceptionType public void testCatching_customTypeMatch() throws Exception { Function<IOException, Integer> fallback = functionReturningOne(); ListenableFuture<Integer> originalFuture = immediateFailedFuture(new FileNotFoundException()); ListenableFuture<Integer> faultTolerantFuture = catching(originalFuture, IOException.class, fallback, directExecutor()); assertEquals(1, (int) getDone(faultTolerantFuture)); }
@GwtIncompatible // non-Throwable exceptionType public void testCatchingAsync_customTypeMatch() throws Exception { AsyncFunction<IOException, Integer> fallback = asyncFunctionReturningOne(); ListenableFuture<Integer> originalFuture = immediateFailedFuture(new FileNotFoundException()); ListenableFuture<Integer> faultTolerantFuture = catchingAsync(originalFuture, IOException.class, fallback, directExecutor()); assertEquals(1, (int) getDone(faultTolerantFuture)); }