@Override public String get() { return serviceName() + " " + state(); } }
@Override protected final void doStop() { MoreExecutors.renamingDecorator(executor(), threadNameSupplier) .execute( new Runnable() { @Override public void run() { try { shutDown(); notifyStopped(); } catch (Throwable t) { notifyFailed(t); } } }); }
@Override public String toString() { return AbstractIdleService.this.toString(); } }
public void testServiceToString() { AbstractIdleService service = new TestService(); assertEquals("TestService [NEW]", service.toString()); service.startAsync().awaitRunning(); assertEquals("TestService [RUNNING]", service.toString()); service.stopAsync().awaitTerminated(); assertEquals("TestService [TERMINATED]", service.toString()); }
public void testServiceStartStop() throws Exception { AbstractIdleService service = new DefaultService(); service.startAsync().awaitRunning(); assertEquals(Service.State.RUNNING, service.state()); service.stopAsync().awaitTerminated(); assertEquals(Service.State.TERMINATED, service.state()); }
@Override public String toString() { return getServiceName() + " [" + state() + "]"; }
public void testStart_failed() throws Exception { final Exception exception = new Exception("deliberate"); AbstractIdleService service = new DefaultService() { @Override protected void startUp() throws Exception { throw exception; } }; try { service.startAsync().awaitRunning(); fail(); } catch (RuntimeException e) { assertThat(e).hasCauseThat().isSameAs(exception); } assertEquals(Service.State.FAILED, service.state()); }
/** * Returns the {@link Executor} that will be used to run this service. * Subclasses may override this method to use a custom {@link Executor}, which * may configure its worker thread with a specific name, thread group or * priority. The returned executor's {@link Executor#execute(Runnable) * execute()} method is called when this service is started and stopped, * and should return promptly. */ protected Executor executor() { final State state = state(); return new Executor() { @Override public void execute(Runnable command) { MoreExecutors.newThread(serviceName() + " " + state, command).start(); } }; }
@Override public void execute(Runnable command) { MoreExecutors.newThread(serviceName() + " " + state, command).start(); } };
@Override public void run() { try { shutDown(); notifyStopped(); } catch (Throwable t) { notifyFailed(t); } } });
@Override public void run() { try { startUp(); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } } });
public void testStop_failed() throws Exception { final Exception exception = new Exception("deliberate"); AbstractIdleService service = new DefaultService() { @Override protected void shutDown() throws Exception { throw exception; } }; service.startAsync().awaitRunning(); try { service.stopAsync().awaitTerminated(); fail(); } catch (RuntimeException e) { assertThat(e).hasCauseThat().isSameAs(exception); } assertEquals(Service.State.FAILED, service.state()); } }
@Override public String toString() { return getServiceName() + " [" + state() + "]"; }
public void testStart_failed() throws Exception { final Exception exception = new Exception("deliberate"); AbstractIdleService service = new DefaultService() { @Override protected void startUp() throws Exception { throw exception; } }; try { service.startAsync().awaitRunning(); fail(); } catch (RuntimeException e) { assertSame(exception, e.getCause()); } assertEquals(Service.State.FAILED, service.state()); }
@Override public void run() { try { shutDown(); notifyStopped(); } catch (Throwable t) { notifyFailed(t); } } });
@Override public void run() { try { startUp(); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } } });
public void testServiceToString() { AbstractIdleService service = new TestService(); assertEquals("TestService [NEW]", service.toString()); service.startAsync().awaitRunning(); assertEquals("TestService [RUNNING]", service.toString()); service.stopAsync().awaitTerminated(); assertEquals("TestService [TERMINATED]", service.toString()); }
@Override public String toString() { return serviceName() + " [" + state() + "]"; }
@Override protected final void doStart() { MoreExecutors.renamingDecorator(executor(), threadNameSupplier) .execute( new Runnable() { @Override public void run() { try { startUp(); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } } }); }
public void testServiceStartStop() throws Exception { AbstractIdleService service = new DefaultService(); service.startAsync().awaitRunning(); assertEquals(Service.State.RUNNING, service.state()); service.stopAsync().awaitTerminated(); assertEquals(Service.State.TERMINATED, service.state()); }