mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 22:19:03 +00:00
Consistently implement toString() in BackOff strategies
Closes gh-35120
This commit is contained in:
@@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* Tests for {@link ExponentialBackOff}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class ExponentialBackOffTests {
|
||||
|
||||
@@ -128,14 +129,24 @@ class ExponentialBackOffTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void executionToStringContent() {
|
||||
void toStringContent() {
|
||||
ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
|
||||
assertThat(backOff).asString()
|
||||
.isEqualTo("""
|
||||
ExponentialBackOff[\
|
||||
initialInterval=2000, \
|
||||
jitter=0, \
|
||||
multiplier=2.0, \
|
||||
maxInterval=30000, \
|
||||
maxElapsedTime=%d, \
|
||||
maxAttempts=%d]""", Long.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
BackOffExecution execution = backOff.start();
|
||||
assertThat(execution.toString()).isEqualTo("ExponentialBackOffExecution{currentInterval=n/a, multiplier=2.0, attempts=0}");
|
||||
assertThat(execution).asString().isEqualTo("ExponentialBackOffExecution[currentInterval=n/a, multiplier=2.0, attempts=0]");
|
||||
execution.nextBackOff();
|
||||
assertThat(execution.toString()).isEqualTo("ExponentialBackOffExecution{currentInterval=2000ms, multiplier=2.0, attempts=1}");
|
||||
assertThat(execution).asString().isEqualTo("ExponentialBackOffExecution[currentInterval=2000ms, multiplier=2.0, attempts=1]");
|
||||
execution.nextBackOff();
|
||||
assertThat(execution.toString()).isEqualTo("ExponentialBackOffExecution{currentInterval=4000ms, multiplier=2.0, attempts=2}");
|
||||
assertThat(execution).asString().isEqualTo("ExponentialBackOffExecution[currentInterval=4000ms, multiplier=2.0, attempts=2]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link FixedBackOff}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class FixedBackOffTests {
|
||||
|
||||
@@ -86,12 +87,14 @@ class FixedBackOffTests {
|
||||
@Test
|
||||
void toStringContent() {
|
||||
FixedBackOff backOff = new FixedBackOff(200L, 10);
|
||||
assertThat(backOff).asString().isEqualTo("FixedBackOff[interval=200, maxAttempts=10]");
|
||||
|
||||
BackOffExecution execution = backOff.start();
|
||||
assertThat(execution.toString()).isEqualTo("FixedBackOff{interval=200, currentAttempts=0, maxAttempts=10}");
|
||||
assertThat(execution).asString().isEqualTo("FixedBackOffExecution[interval=200, currentAttempts=0, maxAttempts=10]");
|
||||
execution.nextBackOff();
|
||||
assertThat(execution.toString()).isEqualTo("FixedBackOff{interval=200, currentAttempts=1, maxAttempts=10}");
|
||||
assertThat(execution).asString().isEqualTo("FixedBackOffExecution[interval=200, currentAttempts=1, maxAttempts=10]");
|
||||
execution.nextBackOff();
|
||||
assertThat(execution.toString()).isEqualTo("FixedBackOff{interval=200, currentAttempts=2, maxAttempts=10}");
|
||||
assertThat(execution).asString().isEqualTo("FixedBackOffExecution[interval=200, currentAttempts=2, maxAttempts=10]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user