public void run() { // Give the services 5 seconds to stop to ensure that we are responsive to shutdown // requests. try { manager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (TimeoutException timeout) { // stopping timed out } } });
private void stopServices() { if (this.serviceManager != null) { try { // Give the services 5 minutes to stop to ensure that we are responsive to shutdown requests this.serviceManager.stopAsync().awaitStopped(5, TimeUnit.MINUTES); } catch (TimeoutException te) { logger.error("Timeout in stopping the service manager", te); } } }
private void shutdownServices() { logger.info("SingleTaskRunner shutting down services."); this.serviceManager.stopAsync(); try { this.serviceManager.awaitStopped(1, TimeUnit.MINUTES); } catch (final TimeoutException e) { logger.error("Timeout waiting for services to shutdown.", e); } }
@Override public void run() { manager.stopAsync().awaitStopped(); } };
@Override public void close() throws IOException { try { // Stop all dependent services this.serviceManager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (TimeoutException te) { LOG.warn("Timed out while waiting for the service manager to be stopped", te); } finally { super.close(); } }
@AfterClass public void tearDown() throws TimeoutException, IOException { if (jobConfigDir != null) { FileUtils.forceDelete(new File(jobConfigDir)); } this.serviceManager.stopAsync().awaitStopped(30, TimeUnit.SECONDS); } }
@Override protected void shutDown() throws Exception { getLog().info("Shutting down driver ..."); super.shutDown(); if (null != _subservices) { getLog().info("Shutting down subservices ..."); _subservices.stopAsync(); _subservices.awaitStopped(getInstanceCfg().getShutdownTimeoutMs(), TimeUnit.MILLISECONDS); getLog().info("All subservices have been shutdown."); } }
@Override public void run() { String msg = "SIGNAL received. Shutting down."; LOG.info(msg); activityWriter.write(new Activity(msg, Main.class)); auditEventSender.success(AuditActor.system(nodeId), NODE_SHUTDOWN_INITIATE); gracefulShutdown.runWithoutExit(); serviceManager.stopAsync().awaitStopped(); } }
/** * Start this {@link GobblinTaskRunner} instance. */ public void start() { logger.info(String.format("Starting %s in container %s", this.helixInstanceName, this.taskRunnerId)); // Add a shutdown hook so the task scheduler gets properly shutdown addShutdownHook(); connectHelixManager(); addInstanceTags(); // Start metric reporting if (this.containerMetrics.isPresent()) { this.containerMetrics.get() .startMetricReportingWithFileSuffix(ConfigUtils.configToState(this.config), this.taskRunnerId); } if (this.serviceManager != null) { this.serviceManager.startAsync(); this.serviceManager.awaitStopped(); } }
public void testNotifyStoppedAfterFailure() throws TimeoutException { Service a = new AbstractService() { @Override protected void doStart() { notifyFailed(new IllegalStateException("start failure")); notifyStopped(); // This will be a no-op. } @Override protected void doStop() { notifyStopped(); } }; final ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); assertThat(manager.servicesByState().keySet()).containsExactly(Service.State.FAILED); }
/** * This test is for a case where two Service.Listener callbacks for the same service would call * transitionService in the wrong order due to a race. Due to the fact that it is a race this test * isn't guaranteed to expose the issue, but it is at least likely to become flaky if the race * sneaks back in, and in this case flaky means something is definitely wrong. * * <p>Before the bug was fixed this test would fail at least 30% of the time. */ public void testTransitionRace() throws TimeoutException { for (int k = 0; k < 1000; k++) { List<Service> services = Lists.newArrayList(); for (int i = 0; i < 5; i++) { services.add(new SnappyShutdownService(i)); } ServiceManager manager = new ServiceManager(services); manager.startAsync().awaitHealthy(); manager.stopAsync().awaitStopped(1, TimeUnit.SECONDS); } }
public void testTimeouts() throws Exception { Service a = new NoOpDelayedService(50); ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); try { manager.awaitHealthy(1, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException expected) { } manager.awaitHealthy(5, SECONDS); // no exception thrown manager.stopAsync(); try { manager.awaitStopped(1, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException expected) { } manager.awaitStopped(5, SECONDS); // no exception thrown }
@AfterClass public void tearDown() throws IOException { cleanUpDir(TESTDIR); try { this.specCompiler.getServiceManager().stopAsync().awaitStopped(5, TimeUnit.SECONDS); } catch (Exception e) { log.warn("Could not stop Service Manager"); } }
/** * This covers a bug where if a listener was installed that would stop the manager if any service * fails and something failed during startup before service.start was called on all the services, * then awaitStopped would deadlock due to an IllegalStateException that was thrown when trying to * stop the timer(!). */ public void testFailStart_stopOthers() throws TimeoutException { Service a = new FailStartService(); Service b = new NoOpService(); final ServiceManager manager = new ServiceManager(asList(a, b)); manager.addListener( new Listener() { @Override public void failure(Service service) { manager.stopAsync(); } }); manager.startAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); }
public void testDoCancelStart() throws TimeoutException { Service a = new AbstractService() { @Override protected void doStart() { // Never starts! } @Override protected void doCancelStart() { assertThat(state()).isEqualTo(Service.State.STOPPING); notifyStopped(); } @Override protected void doStop() { throw new AssertionError(); // Should not be called. } }; final ServiceManager manager = new ServiceManager(asList(a)); manager.startAsync(); manager.stopAsync(); manager.awaitStopped(10, TimeUnit.MILLISECONDS); assertThat(manager.servicesByState().keySet()).containsExactly(Service.State.TERMINATED); }
public void testFailStop() throws Exception { Service a = new NoOpService(); Service b = new FailStopService(); Service c = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); manager.startAsync().awaitHealthy(); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); manager.stopAsync().awaitStopped(); assertTrue(listener.stoppedCalled); assertEquals(ImmutableSet.of(b), listener.failedServices); assertState(manager, Service.State.FAILED, b); assertState(manager, Service.State.TERMINATED, a, c); }
public void testFailRun() throws Exception { Service a = new NoOpService(); Service b = new FailRunService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertTrue(listener.healthyCalled); assertEquals(ImmutableSet.of(b), listener.failedServices); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.FAILED, b); assertState(manager, Service.State.TERMINATED, a); assertTrue(listener.stoppedCalled); }
assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled);
public void testServiceStartStop() { Service a = new NoOpService(); Service b = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b); assertFalse(manager.isHealthy()); manager.startAsync().awaitHealthy(); assertState(manager, Service.State.RUNNING, a, b); assertTrue(manager.isHealthy()); assertTrue(listener.healthyCalled); assertFalse(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); manager.stopAsync().awaitStopped(); assertState(manager, Service.State.TERMINATED, a, b); assertFalse(manager.isHealthy()); assertTrue(listener.stoppedCalled); assertTrue(listener.failedServices.isEmpty()); }
public void testFailStart() throws Exception { Service a = new NoOpService(); Service b = new FailStartService(); Service c = new NoOpService(); Service d = new FailStartService(); Service e = new NoOpService(); ServiceManager manager = new ServiceManager(asList(a, b, c, d, e)); RecordingListener listener = new RecordingListener(); manager.addListener(listener); assertState(manager, Service.State.NEW, a, b, c, d, e); try { manager.startAsync().awaitHealthy(); fail(); } catch (IllegalStateException expected) { } assertFalse(listener.healthyCalled); assertState(manager, Service.State.RUNNING, a, c, e); assertEquals(ImmutableSet.of(b, d), listener.failedServices); assertState(manager, Service.State.FAILED, b, d); assertFalse(manager.isHealthy()); manager.stopAsync().awaitStopped(); assertFalse(manager.isHealthy()); assertFalse(listener.healthyCalled); assertTrue(listener.stoppedCalled); }