use of com.github.robozonky.api.ReturnCode in project robozonky by RoboZonky.
the class App method main.
public static void main(final String... args) {
App.LOGGER.debug("Current working directory is '{}'.", System.getProperty("user.dir"));
App.LOGGER.debug("Running {} {} v{} on {} v{} ({}, {} CPUs, {}, {}).", System.getProperty("java.vm.vendor"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"), Runtime.getRuntime().availableProcessors(), Locale.getDefault(), Charset.defaultCharset());
final ReturnCode code = configure(args).map(App::execute).orElse(ReturnCode.ERROR_SETUP);
// call the core code
App.exit(code);
}
use of com.github.robozonky.api.ReturnCode 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.api.ReturnCode in project robozonky by RoboZonky.
the class DaemonInvestmentModeTest method get.
@Test
void get() throws Exception {
final Authenticated a = mockAuthentication(mock(Zonky.class));
final Investor.Builder b = new Investor.Builder().asDryRun();
final ExecutorService e = Executors.newFixedThreadPool(1);
final PortfolioUpdater p = mock(PortfolioUpdater.class);
try {
final DaemonInvestmentMode d = new DaemonInvestmentMode(t -> {
}, a, p, b, mock(StrategyProvider.class), Duration.ofSeconds(1), Duration.ofSeconds(1));
// will block
final Future<ReturnCode> f = e.submit(() -> d.apply(lifecycle));
assertThatThrownBy(() -> f.get(1, TimeUnit.SECONDS)).isInstanceOf(TimeoutException.class);
// unblock
lifecycle.resumeToShutdown();
// should now finish
assertThat(f.get()).isEqualTo(ReturnCode.OK);
verify(p).run();
} finally {
e.shutdownNow();
}
}
Aggregations