From: Kai Moritz Date: Fri, 10 Jan 2025 22:15:04 +0000 (+0100) Subject: BackOff-Zeit in `BackOffStateTest` in statische Variable ausgelagert X-Git-Tag: consumer/spring-consumer--error-handling--COMMITS--2025-02~11 X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=46dddbe852c8c74b2b82eced80f928b2faa42194;p=demos%2Fkafka%2Ftraining BackOff-Zeit in `BackOffStateTest` in statische Variable ausgelagert --- diff --git a/src/test/java/de/juplo/kafka/BackOffStateTest.java b/src/test/java/de/juplo/kafka/BackOffStateTest.java index 605d05d5..93abfee5 100644 --- a/src/test/java/de/juplo/kafka/BackOffStateTest.java +++ b/src/test/java/de/juplo/kafka/BackOffStateTest.java @@ -23,6 +23,8 @@ class BackOffStateTest final static TopicPartition TOPIC_PARTITION = new TopicPartition("test", 0); final static long OFFSET = 666; final static Instant NOW = Instant.now(); + final static long BACK_OFF = 1000l; + @Mock Clock clock; @Mock BackOff backOff; @@ -114,7 +116,7 @@ class BackOffStateTest { given(clock.instant()).willReturn(NOW); given(backOff.start()).willReturn(backOffExecution); - given(backOffExecution.nextBackOff()).willReturn(1000l); + given(backOffExecution.nextBackOff()).willReturn(BACK_OFF); return new BackOffState(ID, backOff, clock, TOPIC_PARTITION, OFFSET); } @@ -125,7 +127,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1000)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF)); // WHEN boolean result = backOffState.isWaitingForNextRetry(); @@ -140,7 +142,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1000)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF)); // WHEN backOffState.isWaitingForNextRetry(); @@ -155,7 +157,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1000)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF)); // WHEN backOffState.isWaitingForNextRetry(); @@ -170,8 +172,8 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); - given(backOffExecution.nextBackOff()).willReturn(1000l); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); + given(backOffExecution.nextBackOff()).willReturn(BACK_OFF); // WHEN boolean result = backOffState.isWaitingForNextRetry(); @@ -186,8 +188,8 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); - given(backOffExecution.nextBackOff()).willReturn(1000l); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); + given(backOffExecution.nextBackOff()).willReturn(BACK_OFF); // WHEN backOffState.isWaitingForNextRetry(); @@ -202,8 +204,8 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); - given(backOffExecution.nextBackOff()).willReturn(1000l); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); + given(backOffExecution.nextBackOff()).willReturn(BACK_OFF); // WHEN backOffState.isWaitingForNextRetry(); @@ -218,7 +220,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); given(backOffExecution.nextBackOff()).willReturn(BackOffExecution.STOP); // WHEN @@ -234,7 +236,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); given(backOffExecution.nextBackOff()).willReturn(BackOffExecution.STOP); // WHEN @@ -250,7 +252,7 @@ class BackOffStateTest { // GIVEN BackOffState backOffState = StartedBackoffStateWithRetries(); - given(clock.instant()).willReturn(NOW.plusMillis(1001)); + given(clock.instant()).willReturn(NOW.plusMillis(BACK_OFF).plusMillis(1)); given(backOffExecution.nextBackOff()).willReturn(BackOffExecution.STOP); // WHEN