use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.
the class App method execute.
private static ReturnCode execute(final InvestmentMode mode) {
App.SHUTDOWN_HOOKS.register(() -> Optional.of((r) -> Scheduler.inBackground().close()));
Events.fire(new RoboZonkyStartingEvent());
try {
ensureLiveness();
Scheduler.inBackground().submit(new UpdateMonitor(), Duration.ofDays(1));
App.SHUTDOWN_HOOKS.register(new Management(LIFECYCLE));
final String sessionName = Events.getSessionInfo().flatMap(SessionInfo::getName).orElse(null);
App.SHUTDOWN_HOOKS.register(new RoboZonkyStartupNotifier(sessionName));
return mode.apply(LIFECYCLE);
} catch (final Throwable t) {
LOGGER.error("Caught unexpected exception, terminating daemon.", t);
return ReturnCode.ERROR_UNEXPECTED;
}
}
use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.
the class LifecycleTest method version.
@Test
void version() {
final Lifecycle l = mock(Lifecycle.class);
when(l.getZonkyApiVersion()).thenReturn(Optional.empty());
final Runtime r = new Runtime(l);
assertThat(r.getZonkyApiVersion()).isEqualTo("N/A");
}
use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.
the class LifecycleTest method shutdown.
@Test
void shutdown() {
final Lifecycle l = mock(Lifecycle.class);
final Runtime r = new Runtime(l);
r.stopDaemon();
verify(l).resumeToShutdown();
}
use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.
the class ManagementTest method registerAndUnregister.
@Test
void registerAndUnregister() {
final int beanCountBeforeRegister = ManagementTest.SERVER.getMBeanCount();
final Management m = new Management(new Lifecycle());
// register the mbeans
final Optional<Consumer<ShutdownHook.Result>> hook = m.get();
final int beanCountAfterRegister = ManagementTest.SERVER.getMBeanCount();
assertSoftly(softly -> {
softly.assertThat(hook).isPresent();
softly.assertThat(beanCountAfterRegister).isEqualTo(beanCountBeforeRegister + MBean.values().length);
});
// unregister the mbeans
hook.get().accept(new ShutdownHook.Result(ReturnCode.OK, null));
final int beanCountAfterUnregister = ManagementTest.SERVER.getMBeanCount();
assertThat(beanCountAfterUnregister).isEqualTo(beanCountBeforeRegister);
}
Aggregations