default Registration register(MailboxListener.GroupMailboxListener groupMailboxListener) { return register(groupMailboxListener, groupMailboxListener.getDefaultGroup()); } }
@Override public Mono<Void> handle(Event event) { return eventDeadLetters.store(group, event); } }
RetryBackoffConfiguration build() { return new RetryBackoffConfiguration(maxRetries, firstBackoff, jitterFactor); } }
@Test void buildShouldSuccessWhenZeroMaxRetries() { RetryBackoffConfiguration retryBackoff = RetryBackoffConfiguration.builder() .maxRetries(0) .firstBackoff(DEFAULT_FIRST_BACKOFF) .jitterFactor(DEFAULT_JITTER_FACTOR) .build(); assertThat(retryBackoff.getMaxRetries()) .isEqualTo(0L); }
@Test default void allGroupListenersShouldBeExecutedWhenGenericGroups() throws Exception { MailboxListener listener1 = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener1, new GenericGroup("a")); eventBus().register(listener2, new GenericGroup("b")); eventBus().dispatch(EVENT, NO_KEYS).block(); verify(listener1, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(listener2, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); } }
@Test default void registerShouldNotThrowOnAnUnregisteredGroup() { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, GROUP_A).unregister(); assertThatCode(() -> eventBus().register(listener2, GROUP_A)) .doesNotThrowAnyException(); }
@Test default void unregisterShouldBeIdempotentForKeyRegistrations() { MailboxListener listener = newListener(); Registration registration = eventBus().register(listener, KEY_1); registration.unregister(); assertThatCode(registration::unregister) .doesNotThrowAnyException(); }
default Stream<Event.EventId> allEventIds() { EventDeadLetters eventDeadLetters = eventDeadLetters(); return eventDeadLetters.groupsWithFailedEvents() .flatMap(eventDeadLetters::failedEventIds) .toStream(); }
@Override public String asString() { return super.asString() + "-" + groupName; }
static RequireMaxRetries builder() { return maxRetries -> firstBackoff -> jitterFactor -> new ReadyToBuild(maxRetries, firstBackoff, jitterFactor); }
public static EventId of(UUID uuid) { return new EventId(uuid); }
public static Builder builder() { return new Builder(); }
static Event event(Event.EventId eventId) { return new MailboxListener.MailboxAdded(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, eventId); }
@Test void buildShouldThrowWhenGreaterThanOneJitterFactor() { assertThatThrownBy(() -> RetryBackoffConfiguration.builder() .maxRetries(DEFAULT_MAX_RETRIES) .firstBackoff(DEFAULT_FIRST_BACKOFF) .jitterFactor(1.000001) .build()) .isInstanceOf(IllegalArgumentException.class) .hasMessage("jitterFactor is not allowed to be negative or greater than 1"); }
@Test default void unregisterShouldBeIdempotentForGroups() { MailboxListener listener = newListener(); Registration registration = eventBus().register(listener, GROUP_A); registration.unregister(); assertThatCode(registration::unregister) .doesNotThrowAnyException(); }
@Test void buildShouldThrowWhenNegativeJitterFactor() { assertThatThrownBy(() -> RetryBackoffConfiguration.builder() .maxRetries(DEFAULT_MAX_RETRIES) .firstBackoff(DEFAULT_FIRST_BACKOFF) .jitterFactor(-2.5) .build()) .isInstanceOf(IllegalArgumentException.class) .hasMessage("jitterFactor is not allowed to be negative or greater than 1"); }
@Test void buildShouldSuccessWhenZeroFirstBackoff() { RetryBackoffConfiguration retryBackoff = RetryBackoffConfiguration.builder() .maxRetries(DEFAULT_MAX_RETRIES) .firstBackoff(Duration.ZERO) .jitterFactor(DEFAULT_JITTER_FACTOR) .build(); assertThat(retryBackoff.getFirstBackoff().toMillis()) .isEqualTo(0L); }
@Test void buildShouldThrowWhenNegativeMaxRetries() { assertThatThrownBy(() -> RetryBackoffConfiguration.builder() .maxRetries(-6) .firstBackoff(DEFAULT_FIRST_BACKOFF) .jitterFactor(DEFAULT_JITTER_FACTOR) .build()) .isInstanceOf(IllegalArgumentException.class) .hasMessage("maxRetries is not allowed to be negative"); }
@Test void buildShouldSuccessWhenZeroJitterFactor() { RetryBackoffConfiguration retryBackoff = RetryBackoffConfiguration.builder() .maxRetries(DEFAULT_MAX_RETRIES) .firstBackoff(DEFAULT_FIRST_BACKOFF) .jitterFactor(0) .build(); assertThat(retryBackoff.getJitterFactor()) .isEqualTo(0); } @Test
@Test void buildShouldThrowWhenNegativeFirstBackoff() { assertThatThrownBy(() -> RetryBackoffConfiguration.builder() .maxRetries(DEFAULT_MAX_RETRIES) .firstBackoff(Duration.ofMillis(-1000L)) .jitterFactor(DEFAULT_JITTER_FACTOR) .build()) .isInstanceOf(IllegalArgumentException.class) .hasMessage("firstBackoff is not allowed to be negative"); }