Skip to content

Commit

Permalink
spring-projectsGH-427: Fix unit tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aftabshk committed May 10, 2024
1 parent f4df7c2 commit 70b1e1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@
* Evaluates to a value. In the exponential case ({@link #multiplier()} > 1.0) set
* this to true to have the backoff delays randomized, so that the maximum delay is
* multiplier times the previous delay and the distribution is uniform between the two
* values. Use {@code #{...}} for one-time evaluation during initialization, omit the
* delimiters for evaluation at runtime. This expression is always evaluated at
* configuration phase. If the expression returns true then
* {@link org.springframework.retry.backoff.ExponentialRandomBackOffPolicy} is used
* else {@link org.springframework.retry.backoff.ExponentialBackOffPolicy} is used.
* values. This expression is always evaluated during initialization. If the expression
* returns true then {@link org.springframework.retry.backoff.ExponentialRandomBackOffPolicy}
* is used else {@link org.springframework.retry.backoff.ExponentialBackOffPolicy} is used.
* @return the flag to signal randomization is required (default false)
*/
String randomExpression() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ public void shouldCreateExponentialRandomBackOffWhenProvidedRandomSupplier() {
.randomSupplier(() -> true)
.sleeper(mockSleeper)
.build();

assertThat(ExponentialRandomBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
ExponentialRandomBackOffPolicy policy = (ExponentialRandomBackOffPolicy) backOffPolicy;
assertThat(policy.getInitialInterval()).isEqualTo(10000);
assertThat(policy.getMaxInterval()).isEqualTo(100000);
assertThat(policy.getMultiplier()).isEqualTo(10);
assertThat(new DirectFieldAccessor(policy).getPropertyValue("sleeper")).isEqualTo(mockSleeper);
}

@Test
public void shouldCreateExponentialRandomBackOffWithProvidedSuppliers() {
Sleeper mockSleeper = mock(Sleeper.class);
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder()
.delaySupplier(() -> 10000L)
.maxDelaySupplier(() -> 100000L)
.multiplierSupplier(() -> 10d)
.randomSupplier(() -> true)
.sleeper(mockSleeper)
.build();

assertThat(ExponentialRandomBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
ExponentialRandomBackOffPolicy policy = (ExponentialRandomBackOffPolicy) backOffPolicy;
assertThat(policy.getInitialInterval()).isEqualTo(10000);
Expand All @@ -135,10 +155,10 @@ public void shouldCreateExponentialBackOffWhenProvidedRandomSupplier() {
.delay(100)
.maxDelay(1000)
.multiplier(2)
.randomSupplier(() -> true)
.randomSupplier(() -> false)
.sleeper(mockSleeper)
.build();
assertThat(ExponentialBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
assertThat(backOffPolicy instanceof ExponentialBackOffPolicy).isTrue();
ExponentialBackOffPolicy policy = (ExponentialBackOffPolicy) backOffPolicy;
assertThat(policy.getInitialInterval()).isEqualTo(100);
assertThat(policy.getMaxInterval()).isEqualTo(1000);
Expand Down

0 comments on commit 70b1e1b

Please sign in to comment.