void smartAssertTrue( ImmutableSet<ListenableFuture<String>> inputs, Exception cause, boolean expression) { if (!expression) { throw failureWithCause(cause, smartToString(inputs)); } }
static void verifyGetOnPendingFuture(Future<?> future) { checkNotNull(future); try { pseudoTimedGetUninterruptibly(future, 10, MILLISECONDS); fail(); } catch (TimeoutException expected) { } catch (ExecutionException e) { throw failureWithCause(e, ""); } }
static void verifyTimedGetOnPendingFuture(Future<?> future) { try { getUninterruptibly(future, 0, SECONDS); fail(); } catch (TimeoutException expected) { } catch (ExecutionException e) { throw failureWithCause(e, ""); } }
propagateIfInstanceOf(e.getCause(), ExecutionException.class); propagateIfInstanceOf(e.getCause(), CancellationException.class); throw failureWithCause(e, "Unexpected exception"); } finally { executor.shutdownNow();
void smartAssertTrue(ImmutableSet<ListenableFuture<String>> inputs, Exception cause, boolean expression) { if (!expression) { throw failureWithCause(cause, smartToString(inputs)); } }
static void verifyGetOnPendingFuture(Future<?> future) { checkNotNull(future); try { pseudoTimedGetUninterruptibly(future, 10, MILLISECONDS); fail(); } catch (TimeoutException expected) { } catch (ExecutionException e) { throw failureWithCause(e, ""); } }
static void verifyTimedGetOnPendingFuture(Future<?> future) { try { getUninterruptibly(future, 0, SECONDS); fail(); } catch (TimeoutException expected) { } catch (ExecutionException e) { throw failureWithCause(e, ""); } }
/** * Very rough equivalent of a timed get, produced by calling the no-arg get method in another * thread and waiting a short time for it. * * <p>We need this to test the behavior of no-arg get methods without hanging the main test thread * forever in the case of failure. */ @CanIgnoreReturnValue @GwtIncompatible // threads static <V> V pseudoTimedGetUninterruptibly(final Future<V> input, long timeout, TimeUnit unit) throws ExecutionException, TimeoutException { ExecutorService executor = newSingleThreadExecutor(); Future<V> waiter = executor.submit(new Callable<V>() { @Override public V call() throws Exception { return input.get(); } }); try { return getUninterruptibly(waiter, timeout, unit); } catch (ExecutionException e) { propagateIfInstanceOf(e.getCause(), ExecutionException.class); propagateIfInstanceOf(e.getCause(), CancellationException.class); throw failureWithCause(e, "Unexpected exception"); } finally { executor.shutdownNow(); // TODO(cpovirk: assertTrue(awaitTerminationUninterruptibly(executor, 10, SECONDS)); } }