aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java69
1 files changed, 28 insertions, 41 deletions
diff --git a/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
index 958be1972..02815e3d1 100644
--- a/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
+++ b/android/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
@@ -16,10 +16,13 @@
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.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -120,6 +123,10 @@ public class ServiceManagerTest extends TestCase {
}
public void testServiceStartupTimes() {
+ if (isWindows() && isJava8()) {
+ // Flaky there: https://github.com/google/guava/pull/6731#issuecomment-1736298607
+ return;
+ }
Service a = new NoOpDelayedService(150);
Service b = new NoOpDelayedService(353);
ServiceManager serviceManager = new ServiceManager(asList(a, b));
@@ -195,11 +202,7 @@ public class ServiceManagerTest extends TestCase {
RecordingListener listener = new RecordingListener();
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b, c, d, e);
- try {
- manager.startAsync().awaitHealthy();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> manager.startAsync().awaitHealthy());
assertFalse(listener.healthyCalled);
assertState(manager, Service.State.RUNNING, a, c, e);
assertEquals(ImmutableSet.of(b, d), listener.failedServices);
@@ -219,11 +222,7 @@ public class ServiceManagerTest extends TestCase {
RecordingListener listener = new RecordingListener();
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b);
- try {
- manager.startAsync().awaitHealthy();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> manager.startAsync().awaitHealthy());
assertTrue(listener.healthyCalled);
assertEquals(ImmutableSet.of(b), listener.failedServices);
@@ -266,19 +265,11 @@ public class ServiceManagerTest extends TestCase {
Service a = new NoOpDelayedService(50);
ServiceManager manager = new ServiceManager(asList(a));
manager.startAsync();
- try {
- manager.awaitHealthy(1, TimeUnit.MILLISECONDS);
- fail();
- } catch (TimeoutException expected) {
- }
+ assertThrows(TimeoutException.class, () -> manager.awaitHealthy(1, TimeUnit.MILLISECONDS));
manager.awaitHealthy(5, SECONDS); // no exception thrown
manager.stopAsync();
- try {
- manager.awaitStopped(1, TimeUnit.MILLISECONDS);
- fail();
- } catch (TimeoutException expected) {
- }
+ assertThrows(TimeoutException.class, () -> manager.awaitStopped(1, TimeUnit.MILLISECONDS));
manager.awaitStopped(5, SECONDS); // no exception thrown
}
@@ -291,11 +282,7 @@ public class ServiceManagerTest extends TestCase {
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener, directExecutor());
- try {
- manager.startAsync().awaitHealthy();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> manager.startAsync().awaitHealthy());
assertTrue(listener.stoppedCalled);
}
@@ -308,11 +295,7 @@ public class ServiceManagerTest extends TestCase {
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener, directExecutor());
- try {
- manager.startAsync().awaitHealthy();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> manager.startAsync().awaitHealthy());
assertFalse(listener.healthyCalled);
}
@@ -511,11 +494,7 @@ public class ServiceManagerTest extends TestCase {
logger.addHandler(logHandler);
NoOpService service = new NoOpService();
service.startAsync();
- try {
- new ServiceManager(Arrays.asList(service));
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> new ServiceManager(Arrays.asList(service)));
service.stopAsync();
// Nothing was logged!
assertEquals(0, logHandler.getStoredLogRecords().size());
@@ -536,6 +515,7 @@ public class ServiceManagerTest extends TestCase {
service1.startAsync();
delegate.addListener(listener, executor);
}
+
// Delegates from here on down
@Override
public final Service startAsync() {
@@ -582,12 +562,11 @@ public class ServiceManagerTest extends TestCase {
return delegate.failureCause();
}
};
- try {
- new ServiceManager(Arrays.asList(service1, service2));
- fail();
- } catch (IllegalArgumentException expected) {
- assertThat(expected.getMessage()).contains("started transitioning asynchronously");
- }
+ IllegalArgumentException expected =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> new ServiceManager(Arrays.asList(service1, service2)));
+ assertThat(expected.getMessage()).contains("started transitioning asynchronously");
}
/**
@@ -666,4 +645,12 @@ public class ServiceManagerTest extends TestCase {
failedServices.add(service);
}
}
+
+ private static boolean isWindows() {
+ return OS_NAME.value().startsWith("Windows");
+ }
+
+ private static boolean isJava8() {
+ return JAVA_SPECIFICATION_VERSION.value().equals("1.8");
+ }
}