final static String ID = "TEST";
final static TopicPartition TOPIC_PARTITION = new TopicPartition("test", 0);
final static long OFFSET = 666;
- final static long OTHER_OFFSET = 1;
final static Instant NOW = Instant.now();
@Mock Clock clock;
assertThat(backOffState.isStarted(OFFSET)).isFalse();
}
- @Test
- @DisplayName("A not started BackOffState is not completed")
- void NotStartedBackOffStateIsNotCompleted()
- {
- // GIVEN
- BackOffState backOffState = NotStartedBackOffState();
-
- // WHEN
-
- // THEN
- assertThat(backOffState.isCompleted()).isFalse();
- }
-
private BackOffState StartedBackoffStateWithNoRetries()
{
assertThat(backOffState.isStarted(OFFSET)).isTrue();
}
- @Test
- @DisplayName("A started BackOffState is not started for other offsets if the time is not due")
- void StartedBackOffStateIsNotStartedForOtherOffsetsIfTheTimeIsNotDue()
- {
- // GIVEN
- BackOffState backOffState = StartedBackoffStateWithRetries();
- given(clock.instant()).willReturn(NOW.plusMillis(1000));
-
- // WHEN
- backOffState.isWaitingForNextRetry();
-
- // THEN
- assertThat(backOffState.isStarted(OTHER_OFFSET)).isFalse();
- }
-
@Test
@DisplayName("A started BackOffState is not completed if the time is not due")
void StartedBackOffStateIsNotCompletedIfTimeIsNotDue()
assertThat(backOffState.isStarted(OFFSET)).isTrue();
}
- @Test
- @DisplayName("A started BackOffState is not started for other offsets if the time is due but the retry not yet completed")
- void StartedBackOffStateIsNotStartedForOtherOffsetsIfTheTimeIsDueButRetryNotCompleted()
- {
- // GIVEN
- BackOffState backOffState = StartedBackoffStateWithRetries();
- given(clock.instant()).willReturn(NOW.plusMillis(1001));
- given(backOffExecution.nextBackOff()).willReturn(1000l);
-
- // WHEN
- backOffState.isWaitingForNextRetry();
-
- // THEN
- assertThat(backOffState.isStarted(OTHER_OFFSET)).isFalse();
- }
-
@Test
@DisplayName("A started BackOffState is not completed if the time is due but the retry not yet completed")
void StartedBackOffStateIsNotCompletedIfTheTimeIsDueButRetryNotCompleted()
assertThat(backOffState.isStarted(OFFSET)).isTrue();
}
- @Test
- @DisplayName("A started BackOffState is not started for other offsets if the time is due and the retry is completed")
- void StartedBackOffStateIsNotStartedForOtherOffsetsIfTheTimeIsDueAndRetryIsCompleted()
- {
- // GIVEN
- BackOffState backOffState = StartedBackoffStateWithRetries();
- given(clock.instant()).willReturn(NOW.plusMillis(1001));
- given(backOffExecution.nextBackOff()).willReturn(BackOffExecution.STOP);
-
- // WHEN
- backOffState.isWaitingForNextRetry();
-
- // THEN
- assertThat(backOffState.isStarted(OTHER_OFFSET)).isFalse();
- }
-
@Test
@DisplayName("A started BackOffState is completed if the time is due and the retry is completed")
void StartedBackOffStateIsCompletedIfTheTimeIsDueAndRetryIsCompleted()
// THEN
assertThat(backOffState.isStarted(OFFSET)).isFalse();
}
-
- @Test
- @DisplayName("A started BackOffState is not started for other offsets if it is marked as completed")
- void StartedBackOffStateIsNotStartedForOtherOffsetsIfMarkedCompleted()
- {
- // GIVEN
- BackOffState backOffState = StartedBackoffStateWithRetries();
-
- // WHEN
- backOffState.markAsCompleted();
-
- // THEN
- assertThat(backOffState.isStarted(OTHER_OFFSET)).isFalse();
- }
-
- @Test
- @DisplayName("A started BackOffState is not completed if it is marked as completed")
- void StartedBackOffStateIsNotCompletedIfMarkedCompleted()
- {
- // GIVEN
- BackOffState backOffState = StartedBackoffStateWithRetries();
-
- // WHEN
- backOffState.markAsCompleted();
-
- // THEN
- assertThat(backOffState.isCompleted()).isFalse(); // ??
- }
}