@Test default void retryingIsNotAppliedForKeyRegistrations() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .when(eventCollector).event(EVENT); eventBus().register(eventCollector, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); assertThat(eventCollector.getEvents()) .isEmpty(); }
@Test default void listenerShouldNotReceiveWhenFailsGreaterThanMaxRetries() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); TimeUnit.SECONDS.sleep(1); assertThat(eventCollector.getEvents()) .isEmpty(); }
@Test default void listenerShouldReceiveWhenFailsLessThanMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); }
@Test default void listenerShouldReceiveWhenFailsEqualsMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); }
@Test default void deadLetterShouldStoreWhenFailsGreaterThanMaxRetries() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION.until(() -> assertThat(deadLetter().failedEventIds(GROUP_A).toIterable()) .containsOnly(EVENT.getEventId())); assertThat(eventCollector.getEvents()) .isEmpty(); } }
@Test default void deadLetterShouldNotStoreWhenFailsLessThanMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, new EventBusTestFixture.GroupA()); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); assertThat(deadLetter().groupsWithFailedEvents().toIterable()) .isEmpty(); }
@Test default void deadLettersIsNotAppliedForKeyRegistrations() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); TimeUnit.SECONDS.sleep(1); SoftAssertions.assertSoftly(softly -> { softly.assertThat(eventCollector.getEvents()).isEmpty(); softly.assertThat(deadLetter().groupsWithFailedEvents().toIterable()) .isEmpty(); }); }