Search in sources :

Example 1 with RoboZonkyStartingEvent

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;
    }
}
Also used : RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SystemExitServiceLoader(com.github.robozonky.util.SystemExitServiceLoader) Scheduler(com.github.robozonky.util.Scheduler) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) CommandLine(com.github.robozonky.app.configuration.CommandLine) Charset(java.nio.charset.Charset) Locale(java.util.Locale) Duration(java.time.Duration) Management(com.github.robozonky.app.management.Management) SystemExitService(com.github.robozonky.util.SystemExitService) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMode(com.github.robozonky.app.configuration.InvestmentMode) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) Management(com.github.robozonky.app.management.Management)

Example 2 with RoboZonkyStartingEvent

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());
}
Also used : RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) Test(org.junit.jupiter.api.Test)

Example 3 with RoboZonkyStartingEvent

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"));
}
Also used : ListenerService(com.github.robozonky.api.notifications.ListenerService) Test(org.junit.jupiter.api.Test) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Mockito(org.mockito.Mockito) Arrays(java.util.Arrays) List(java.util.List) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) EventListener(com.github.robozonky.api.notifications.EventListener) Condition(org.assertj.core.api.Condition) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) ListenerService(com.github.robozonky.api.notifications.ListenerService) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Test(org.junit.jupiter.api.Test)

Aggregations

RoboZonkyStartingEvent (com.github.robozonky.api.notifications.RoboZonkyStartingEvent)3 Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2 ReturnCode (com.github.robozonky.api.ReturnCode)1 EventListener (com.github.robozonky.api.notifications.EventListener)1 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)1 ListenerService (com.github.robozonky.api.notifications.ListenerService)1 RoboZonkyTestingEvent (com.github.robozonky.api.notifications.RoboZonkyTestingEvent)1 SessionInfo (com.github.robozonky.api.notifications.SessionInfo)1 CommandLine (com.github.robozonky.app.configuration.CommandLine)1 InvestmentMode (com.github.robozonky.app.configuration.InvestmentMode)1 Management (com.github.robozonky.app.management.Management)1 Lifecycle (com.github.robozonky.app.runtime.Lifecycle)1 UpdateMonitor (com.github.robozonky.app.version.UpdateMonitor)1 Scheduler (com.github.robozonky.util.Scheduler)1 SystemExitService (com.github.robozonky.util.SystemExitService)1 SystemExitServiceLoader (com.github.robozonky.util.SystemExitServiceLoader)1 Charset (java.nio.charset.Charset)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1