public void testStop_failed() {
final Exception exception = new Exception("deliberate");
TestService service = new TestService() {
@Override protected void shutDown() throws Exception {
super.shutDown();
throw exception;
}
};
service.startAsync().awaitRunning();
assertEquals(1, service.startUpCalled);
assertEquals(0, service.shutDownCalled);
try {
service.stopAsync().awaitTerminated();
fail();
} catch (RuntimeException e) {
assertSame(exception, e.getCause());
}
assertEquals(1, service.startUpCalled);
assertEquals(1, service.shutDownCalled);
assertEquals(Service.State.FAILED, service.state());
assertThat(service.transitionStates)
.containsExactly(Service.State.STARTING, Service.State.STOPPING).inOrder();
}