Daemon implements InvestmentMode { @Override public ReturnCode get() { try { scheduleJobs(); scheduleDaemons(scheduler); lifecycle.suspend(); LOGGER.trace("Request to stop received."); return (lifecycle.isFailed()) ? ReturnCode.ERROR_UNEXPECTED : ReturnCode.OK; } catch (Exception ex) { throw new IllegalStateException(ex); } } Daemon(final PowerTenant tenant, final Lifecycle lifecycle);   Daemon(final PowerTenant tenant, final Lifecycle lifecycle, Scheduler scheduler); @Override SessionInfo getSessionInfo(); @Override ReturnCode get(); @Override void close();  }
@Test void get() throws Exception { final PowerTenant a = mockTenant(harmlessZonky(), true); final ExecutorService e = Executors.newFixedThreadPool(1); final Scheduler s = Scheduler.create(); try (final Daemon d = spy(new Daemon(a, lifecycle, s))) { assertThat(d.getSessionInfo()).isSameAs(a.getSessionInfo()); doNothing().when(d) .submitWithTenant(any(), any(), any(), any(), any(), any()); doNothing().when(d) .submitTenantless(any(), any(), any(), any(), any(), any()); final Future<ReturnCode> f = e.submit(d::get); assertThatThrownBy(() -> f.get(1, TimeUnit.SECONDS)).isInstanceOf(TimeoutException.class); lifecycle.resumeToShutdown(); assertThat(f.get()).isEqualTo(ReturnCode.OK); verify(d, times(1)).submitTenantless(any(), any(SimplePayload.class), any(), any(), any(), any()); verify(d, times(8)).submitWithTenant(any(), any(), any(), any(), any(), any()); } finally { e.shutdownNow(); } verify(a).close(); assertThat(s.isClosed()).isTrue(); }