use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class FuturesTest method testWhenAllCompleteRunnable_resultCanceledWithInterrupt_InterruptsRunnable.
// threads
@GwtIncompatible
public void testWhenAllCompleteRunnable_resultCanceledWithInterrupt_InterruptsRunnable() throws Exception {
SettableFuture<String> stringFuture = SettableFuture.create();
SettableFuture<Boolean> booleanFuture = SettableFuture.create();
final CountDownLatch inFunction = new CountDownLatch(1);
final CountDownLatch gotException = new CountDownLatch(1);
Runnable combiner = new Runnable() {
@Override
public void run() {
inFunction.countDown();
try {
// wait for interrupt
new CountDownLatch(1).await();
} catch (InterruptedException expected) {
// Ensure the thread's interrupt status is preserved.
Thread.currentThread().interrupt();
gotException.countDown();
}
}
};
ListenableFuture<?> futureResult = whenAllComplete(stringFuture, booleanFuture).run(combiner, newSingleThreadExecutor());
stringFuture.set("value");
booleanFuture.set(true);
inFunction.await();
futureResult.cancel(true);
try {
futureResult.get();
fail();
} catch (CancellationException expected) {
}
gotException.await();
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class FuturesTest method testCatchingAsync_functionToString.
// Threads
@GwtIncompatible
public void testCatchingAsync_functionToString() throws Exception {
final CountDownLatch functionCalled = new CountDownLatch(1);
final CountDownLatch functionBlocking = new CountDownLatch(1);
AsyncFunction<Object, Object> function = tagged("Called my toString", new AsyncFunction<Object, Object>() {
@Override
public ListenableFuture<Object> apply(Object input) throws Exception {
functionCalled.countDown();
functionBlocking.await();
return immediateFuture(null);
}
});
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
ListenableFuture<?> output = Futures.catchingAsync(immediateFailedFuture(new RuntimeException()), Throwable.class, function, executor);
functionCalled.await();
assertThat(output.toString()).contains(function.toString());
} finally {
functionBlocking.countDown();
executor.shutdown();
}
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class Futures method lazyTransform.
/**
* Like {@link #transform(ListenableFuture, Function, Executor)} except that the transformation
* {@code function} is invoked on each call to {@link Future#get() get()} on the returned future.
*
* <p>The returned {@code Future} reflects the input's cancellation state directly, and any
* attempt to cancel the returned Future is likewise passed through to the input Future.
*
* <p>Note that calls to {@linkplain Future#get(long, TimeUnit) timed get} only apply the timeout
* to the execution of the underlying {@code Future}, <em>not</em> to the execution of the
* transformation function.
*
* <p>The primary audience of this method is callers of {@code transform} who don't have a {@code
* ListenableFuture} available and do not mind repeated, lazy function evaluation.
*
* @param input The future to transform
* @param function A Function to transform the results of the provided future to the results of
* the returned future.
* @return A future that returns the result of the transformation.
* @since 10.0
*/
@Beta
// TODO
@GwtIncompatible
public static <I extends @Nullable Object, O extends @Nullable Object> Future<O> lazyTransform(final Future<I> input, final Function<? super I, ? extends O> function) {
checkNotNull(input);
checkNotNull(function);
return new Future<O>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return input.cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return input.isCancelled();
}
@Override
public boolean isDone() {
return input.isDone();
}
@Override
public O get() throws InterruptedException, ExecutionException {
return applyTransformation(input.get());
}
@Override
public O get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return applyTransformation(input.get(timeout, unit));
}
private O applyTransformation(I input) throws ExecutionException {
try {
return function.apply(input);
} catch (Throwable t) {
throw new ExecutionException(t);
}
}
};
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testRoundToDouble_negativeWayTooBig.
@GwtIncompatible
public void testRoundToDouble_negativeWayTooBig() {
BigInteger bi = BigInteger.ONE.shiftLeft(2 * Double.MAX_EXPONENT).negate();
new RoundToDoubleTester(bi).setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN).setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR).roundUnnecessaryShouldThrow().test();
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class BigIntegerMathTest method testNullPointers.
// NullPointerTester
@GwtIncompatible
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.setDefault(BigInteger.class, ONE);
tester.setDefault(int.class, 1);
tester.setDefault(long.class, 1L);
tester.testAllPublicStaticMethods(BigIntegerMath.class);
}
Aggregations