public void testTimeout() throws Exception { // Create a service whose executor will never run its commands Service service = new TestService() { @Override protected Executor executor() { return new Executor() { @Override public void execute(Runnable command) {} }; } @Override protected String serviceName() { return "Foo"; } }; try { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { assertThat(e) .hasMessageThat() .isEqualTo("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } }
public void testStart_failed() { final Exception exception = new Exception("deliberate"); TestService service = new TestService() { @Override protected void startUp() throws Exception { super.startUp(); throw exception; } }; assertEquals(0, service.startUpCalled); try { service.startAsync().awaitRunning(); fail(); } catch (RuntimeException e) { assertThat(e).hasCauseThat().isSameAs(exception); } assertEquals(1, service.startUpCalled); assertEquals(Service.State.FAILED, service.state()); assertThat(service.transitionStates).containsExactly(Service.State.STARTING); }
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) { assertThat(e).hasCauseThat().isSameAs(exception); } 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(); }
public void testTimeout() throws Exception { // Create a service whose executor will never run its commands Service service = new TestService() { @Override protected Executor executor() { return new Executor() { @Override public void execute(Runnable command) {} }; } @Override protected String serviceName() { return "Foo"; } }; try { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { assertThat(e).hasMessage("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } }
public void testStart_failed() { final Exception exception = new Exception("deliberate"); TestService service = new TestService() { @Override protected void startUp() throws Exception { super.startUp(); throw exception; } }; assertEquals(0, service.startUpCalled); try { service.startAsync().awaitRunning(); fail(); } catch (RuntimeException e) { assertSame(exception, e.getCause()); } assertEquals(1, service.startUpCalled); assertEquals(Service.State.FAILED, service.state()); assertThat(service.transitionStates).containsExactly(Service.State.STARTING); }
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(); }