25
25
26
26
import static org .assertj .core .api .Assertions .assertThat ;
27
27
import static org .mockito .Mockito .mock ;
28
+ import static org .springframework .core .retry .RetryPolicy .Builder .DEFAULT_DELAY ;
28
29
import static org .springframework .util .backoff .BackOffExecution .STOP ;
29
30
30
31
/**
@@ -38,14 +39,14 @@ class MaxAttemptsRetryPolicyTests {
38
39
39
40
@ Test
40
41
void maxAttempts () {
41
- var retryPolicy = RetryPolicy .builder ().maxAttempts (2 ).delay (Duration .ofMillis (1 )).build ();
42
+ var retryPolicy = RetryPolicy .builder ().maxAttempts (2 ).delay (Duration .ofMillis (0 )).build ();
42
43
var backOffExecution = retryPolicy .getBackOff ().start ();
43
44
var throwable = mock (Throwable .class );
44
45
45
46
assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
46
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
47
+ assertThat (backOffExecution .nextBackOff ()).isZero ( );
47
48
assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
48
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
49
+ assertThat (backOffExecution .nextBackOff ()).isZero ( );
49
50
50
51
assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
51
52
assertThat (backOffExecution .nextBackOff ()).isEqualTo (STOP );
@@ -65,13 +66,13 @@ void maxAttemptsAndPredicate() {
65
66
66
67
// 4 retries
67
68
assertThat (retryPolicy .shouldRetry (new NumberFormatException ())).isTrue ();
68
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
69
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
69
70
assertThat (retryPolicy .shouldRetry (new IllegalStateException ())).isFalse ();
70
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
71
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
71
72
assertThat (retryPolicy .shouldRetry (new IllegalStateException ())).isFalse ();
72
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
73
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
73
74
assertThat (retryPolicy .shouldRetry (new CustomNumberFormatException ())).isTrue ();
74
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
75
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
75
76
76
77
// After policy exhaustion
77
78
assertThat (retryPolicy .shouldRetry (new NumberFormatException ())).isTrue ();
@@ -92,17 +93,17 @@ void maxAttemptsWithIncludesAndExcludes() {
92
93
93
94
// 6 retries
94
95
assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
95
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
96
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
96
97
assertThat (retryPolicy .shouldRetry (new RuntimeException ())).isTrue ();
97
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
98
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
98
99
assertThat (retryPolicy .shouldRetry (new FileNotFoundException ())).isFalse ();
99
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
100
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
100
101
assertThat (retryPolicy .shouldRetry (new FileSystemException ("file" ))).isTrue ();
101
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
102
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
102
103
assertThat (retryPolicy .shouldRetry (new CustomFileSystemException ("file" ))).isFalse ();
103
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
104
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
104
105
assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
105
- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
106
+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
106
107
107
108
// After policy exhaustion
108
109
assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
0 commit comments