aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java82
1 files changed, 50 insertions, 32 deletions
diff --git a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java
index dc020fb20..89d92c8c4 100644
--- a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java
+++ b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java
@@ -16,6 +16,8 @@
package com.google.common.util.concurrent;
+import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
+import static com.google.common.base.StandardSystemProperty.OS_NAME;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
@@ -23,6 +25,7 @@ import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.Iterables;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
+import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
import java.util.ArrayList;
import java.util.Arrays;
@@ -46,6 +49,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Tests for {@link AbstractFuture}.
@@ -293,6 +297,13 @@ public class AbstractFutureTest extends TestCase {
@SuppressWarnings({"DeprecatedThreadMethods", "ThreadPriorityCheck"})
@AndroidIncompatible // Thread.suspend
public void testToString_delayedTimeout() throws Exception {
+ Integer javaVersion = Ints.tryParse(JAVA_SPECIFICATION_VERSION.value());
+ // Parsing to an integer might fail because Java 8 returns "1.8" instead of "8."
+ // We can continue if it's 1.8, and we can continue if it's an integer in [9, 20).
+ if (javaVersion != null && javaVersion >= 20) {
+ // TODO(b/261217224): Make this test work under newer JDKs.
+ return;
+ }
TimedWaiterThread thread =
new TimedWaiterThread(new AbstractFuture<Object>() {}, 2, TimeUnit.SECONDS);
thread.start();
@@ -426,6 +437,9 @@ public class AbstractFutureTest extends TestCase {
*/
public void testFutureBash() {
+ if (isWindows()) {
+ return; // TODO: b/136041958 - Running very slowly on Windows CI.
+ }
final CyclicBarrier barrier =
new CyclicBarrier(
6 // for the setter threads
@@ -435,10 +449,10 @@ public class AbstractFutureTest extends TestCase {
final ExecutorService executor = Executors.newFixedThreadPool(barrier.getParties());
final AtomicReference<AbstractFuture<String>> currentFuture = Atomics.newReference();
final AtomicInteger numSuccessfulSetCalls = new AtomicInteger();
- Callable<Void> completeSuccessfullyRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> completeSuccessfullyRunnable =
+ new Callable<@Nullable Void>() {
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().set("set")) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -446,12 +460,12 @@ public class AbstractFutureTest extends TestCase {
return null;
}
};
- Callable<Void> completeExceptionallyRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> completeExceptionallyRunnable =
+ new Callable<@Nullable Void>() {
Exception failureCause = new Exception("setException");
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().setException(failureCause)) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -459,10 +473,10 @@ public class AbstractFutureTest extends TestCase {
return null;
}
};
- Callable<Void> cancelRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> cancelRunnable =
+ new Callable<@Nullable Void>() {
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().cancel(true)) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -470,12 +484,12 @@ public class AbstractFutureTest extends TestCase {
return null;
}
};
- Callable<Void> setFutureCompleteSuccessfullyRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> setFutureCompleteSuccessfullyRunnable =
+ new Callable<@Nullable Void>() {
ListenableFuture<String> future = Futures.immediateFuture("setFuture");
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().setFuture(future)) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -483,13 +497,13 @@ public class AbstractFutureTest extends TestCase {
return null;
}
};
- Callable<Void> setFutureCompleteExceptionallyRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> setFutureCompleteExceptionallyRunnable =
+ new Callable<@Nullable Void>() {
ListenableFuture<String> future =
Futures.immediateFailedFuture(new Exception("setFuture"));
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().setFuture(future)) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -497,12 +511,12 @@ public class AbstractFutureTest extends TestCase {
return null;
}
};
- Callable<Void> setFutureCancelRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> setFutureCancelRunnable =
+ new Callable<@Nullable Void>() {
ListenableFuture<String> future = Futures.immediateCancelledFuture();
@Override
- public Void call() {
+ public @Nullable Void call() {
if (currentFuture.get().setFuture(future)) {
numSuccessfulSetCalls.incrementAndGet();
}
@@ -559,15 +573,15 @@ public class AbstractFutureTest extends TestCase {
allTasks.add(setFutureCancelRunnable);
for (int k = 0; k < 50; k++) {
// For each listener we add a task that submits it to the executor directly for the blocking
- // get usecase and another task that adds it as a listener to the future to exercise both
+ // get use case and another task that adds it as a listener to the future to exercise both
// racing addListener calls and addListener calls completing after the future completes.
final Runnable listener =
k % 2 == 0 ? collectResultsRunnable : collectResultsTimedGetRunnable;
allTasks.add(Executors.callable(listener));
allTasks.add(
- new Callable<Void>() {
+ new Callable<@Nullable Void>() {
@Override
- public Void call() throws Exception {
+ public @Nullable Void call() throws Exception {
currentFuture.get().addListener(listener, executor);
return null;
}
@@ -607,6 +621,9 @@ public class AbstractFutureTest extends TestCase {
// setFuture and cancel() interact in more complicated ways than the other setters.
public void testSetFutureCancelBash() {
+ if (isWindows()) {
+ return; // TODO: b/136041958 - Running very slowly on Windows CI.
+ }
final int size = 50;
final CyclicBarrier barrier =
new CyclicBarrier(
@@ -683,7 +700,7 @@ public class AbstractFutureTest extends TestCase {
allTasks.add(setFutureCompleteSuccessfullyRunnable);
for (int k = 0; k < size; k++) {
// For each listener we add a task that submits it to the executor directly for the blocking
- // get usecase and another task that adds it as a listener to the future to exercise both
+ // get use case and another task that adds it as a listener to the future to exercise both
// racing addListener calls and addListener calls completing after the future completes.
final Runnable listener =
k % 2 == 0 ? collectResultsRunnable : collectResultsTimedGetRunnable;
@@ -751,21 +768,21 @@ public class AbstractFutureTest extends TestCase {
final AtomicReference<AbstractFuture<String>> currentFuture = Atomics.newReference();
final AtomicBoolean setFutureSuccess = new AtomicBoolean();
final AtomicBoolean cancellationSuccess = new AtomicBoolean();
- Callable<Void> cancelRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> cancelRunnable =
+ new Callable<@Nullable Void>() {
@Override
- public Void call() {
+ public @Nullable Void call() {
cancellationSuccess.set(currentFuture.get().cancel(true));
awaitUnchecked(barrier);
return null;
}
};
- Callable<Void> setFutureCompleteSuccessfullyRunnable =
- new Callable<Void>() {
+ Callable<@Nullable Void> setFutureCompleteSuccessfullyRunnable =
+ new Callable<@Nullable Void>() {
final ListenableFuture<String> future = Futures.immediateFuture("hello");
@Override
- public Void call() {
+ public @Nullable Void call() {
setFutureSuccess.set(currentFuture.get().setFuture(future));
awaitUnchecked(barrier);
return null;
@@ -1200,13 +1217,10 @@ public class AbstractFutureTest extends TestCase {
throws InterruptedException {
try {
String got = future.get();
- fail("Expected exception but got " + got);
+ throw new AssertionError("Expected exception but got " + got);
} catch (ExecutionException e) {
return e;
}
-
- // unreachable, but compiler doesn't know that fail() always throws
- return null;
}
private static final class WaiterThread extends Thread {
@@ -1318,4 +1332,8 @@ public class AbstractFutureTest extends TestCase {
interruptTaskWasCalled = true;
}
}
+
+ private static boolean isWindows() {
+ return OS_NAME.value().startsWith("Windows");
+ }
}