@Test default void registerShouldThrowWhenAGroupIsAlreadyUsed() { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, GROUP_A); assertThatThrownBy(() -> eventBus().register(listener2, GROUP_A)) .isInstanceOf(GroupAlreadyRegistered.class); }
@Test default void dispatchShouldNotifyLocalRegisteredListenerWithoutDelay() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, times(1)).event(any()); }
@Test default void allRegisteredListenersShouldBeExecutedWhenARegisteredListenerFails() throws Exception { MailboxListener listener = newListener(); MailboxListener failingListener = mock(MailboxListener.class); when(failingListener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS); doThrow(new RuntimeException()).when(failingListener).event(any()); eventBus().register(failingListener, KEY_1); eventBus().register(listener, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); } }
@Test default void localDispatchedListenersShouldBeDispatchedWithoutDelay() throws Exception { MailboxListener mailboxListener1 = newListener(); MailboxListener mailboxListener2 = newListener(); eventBus().register(mailboxListener1, KEY_1); eventBus2().register(mailboxListener2, KEY_1); eventBus2().dispatch(EVENT, KEY_1).block(); verify(mailboxListener2, times(1)).event(any()); verify(mailboxListener1, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void dispatchShouldNotifyAllListenersRegisteredOnAKey() throws Exception { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, KEY_1); eventBus().register(listener2, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(listener2, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void dispatchShouldNotifyOnlyRegisteredListener() throws Exception { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, KEY_1); eventBus().register(listener2, KEY_2); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(listener2, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void allGroupListenersShouldBeExecutedWhenAGroupListenerFails() throws Exception { MailboxListener listener = newListener(); MailboxListener failingListener = mock(MailboxListener.class); when(failingListener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS); doThrow(new RuntimeException()).when(failingListener).event(any()); eventBus().register(failingListener, GROUP_A); eventBus().register(listener, new GroupB()); eventBus().dispatch(EVENT, NO_KEYS).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void dispatchShouldNotifyRegisteredListeners() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void allRegisteredListenersShouldBeDispatched() throws Exception { MailboxListener mailboxListener1 = newListener(); MailboxListener mailboxListener2 = newListener(); eventBus().register(mailboxListener1, KEY_1); eventBus2().register(mailboxListener2, KEY_1); eventBus2().dispatch(EVENT, KEY_1).block(); verify(mailboxListener1, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(mailboxListener2, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void registerShouldNotDispatchPastEventsInDistributedContext() throws Exception { MailboxListener listener = newListener(); eventBus2().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); eventBus().register(listener, KEY_1); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void dispatchShouldNotThrowWhenAGroupListenerFails() throws Exception { MailboxListener listener = newListener(); doThrow(new RuntimeException()).when(listener).event(any()); eventBus().register(listener, GROUP_A); assertThatCode(() -> eventBus().dispatch(EVENT, NO_KEYS).block()) .doesNotThrowAnyException(); }
@Test default void registerShouldNotDispatchPastEvents() throws Exception { MailboxListener listener = newListener(); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); eventBus().register(listener, KEY_1); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void dispatchShouldNotThrowWhenARegisteredListenerFails() throws Exception { MailboxListener listener = newListener(); doThrow(new RuntimeException()).when(listener).event(any()); eventBus().register(listener, KEY_1); assertThatCode(() -> eventBus().dispatch(EVENT, NO_KEYS).block()) .doesNotThrowAnyException(); }
@Test default void dispatchShouldNotNotifyListenerRegisteredOnOtherKeys() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_2)).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void dispatchShouldAcceptSeveralKeys() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1, KEY_2)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void eachListenerGroupShouldReceiveEvents() throws Exception { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, GROUP_A); eventBus().register(listener2, new GroupB()); eventBus().dispatch(EVENT, NO_KEYS).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(listener2, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void unregisteredDistantListenersShouldNotBeNotified() throws Exception { MailboxListener mailboxListener = newListener(); eventBus().register(mailboxListener, KEY_1).unregister(); eventBus2().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(mailboxListener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void listenerGroupShouldReceiveEvents() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void crossEventBusRegistrationShouldBeAllowed() throws Exception { MailboxListener mailboxListener = newListener(); eventBus().register(mailboxListener, KEY_1); eventBus2().dispatch(EVENT, KEY_1).block(); verify(mailboxListener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }
@Test default void groupsDefinedOnlyOnSomeNodesShouldBeNotified() throws Exception { MailboxListener mailboxListener = newListener(); eventBus().register(mailboxListener, GROUP_A); eventBus2().dispatch(EVENT, NO_KEYS).block(); verify(mailboxListener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); }