use of com.github.robozonky.api.notifications.RoboZonkyStartingEvent 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.notifications.RoboZonkyStartingEvent in project robozonky by RoboZonky.
the class EventsTest method firingAndFailing.
@Test
void firingAndFailing() {
final EventListener<RoboZonkyStartingEvent> listener = mock(EventListener.class);
final EventListenerSupplier<RoboZonkyStartingEvent> r = () -> Optional.of(listener);
doThrow(RuntimeException.class).when(listener).handle(any(), any());
final Events.EventSpecific<RoboZonkyStartingEvent> event = Events.INSTANCE.loadListeners(RoboZonkyStartingEvent.class, r);
assertThat(event).isNotNull();
final RoboZonkyStartingEvent e = new RoboZonkyStartingEvent();
Events.fire(e);
assertThat(Events.getFired()).contains(e);
verify(listener).handle(eq(e), any());
}
use of com.github.robozonky.api.notifications.RoboZonkyStartingEvent in project robozonky by RoboZonky.
the class ListenerServiceLoaderTest method correctLoading.
@Test
void correctLoading() {
final RoboZonkyStartingEvent e = new RoboZonkyStartingEvent();
final EventListener<RoboZonkyStartingEvent> l = mock(EventListener.class);
final ListenerService s1 = mock(ListenerService.class);
final EventListenerSupplier<RoboZonkyStartingEvent> returned = () -> Optional.of(l);
doReturn(returned).when(s1).findListener(eq(e.getClass()));
final ListenerService s2 = mock(ListenerService.class);
doReturn((EventListenerSupplier<RoboZonkyStartingEvent>) Optional::empty).when(s2).findListener(eq(e.getClass()));
final Iterable<ListenerService> s = () -> Arrays.asList(s1, s2).iterator();
final List<EventListenerSupplier<RoboZonkyStartingEvent>> r = ListenerServiceLoader.load(RoboZonkyStartingEvent.class, s);
assertThat(r).hasSize(2);
assertThat(r).first().has(new Condition<>(result -> result.get().isPresent() && result.get().get() == l, "Exists"));
assertThat(r).last().has(new Condition<>(result -> !result.get().isPresent(), "Does not exist"));
}
Aggregations