Merge branch '4.0.x'

This commit is contained in:
Ryan Baxter
2023-11-21 15:24:30 -05:00
3 changed files with 18 additions and 3 deletions

View File

@@ -50,6 +50,11 @@ public class RetryProperties {
*/
int maxAttempts = 6;
/**
* Use a random exponential backoff policy.
*/
boolean useRandomPolicy = false;
public long getInitialInterval() {
return this.initialInterval;
}
@@ -82,4 +87,12 @@ public class RetryProperties {
this.maxAttempts = maxAttempts;
}
public boolean isUseRandomPolicy() {
return this.useRandomPolicy;
}
public void setUseRandomPolicy(boolean useRandomPolicy) {
this.useRandomPolicy = useRandomPolicy;
}
}

View File

@@ -39,9 +39,9 @@ public final class RetryTemplateFactory {
}
public static RetryTemplate create(RetryProperties properties, Log log) {
RetryTemplate retryTemplate = RetryTemplate.builder().maxAttempts(properties.getMaxAttempts())
.exponentialBackoff(properties.getInitialInterval(), properties.getMultiplier(),
properties.getMaxInterval())
RetryTemplate retryTemplate = RetryTemplate
.builder().maxAttempts(properties.getMaxAttempts()).exponentialBackoff(properties.getInitialInterval(),
properties.getMultiplier(), properties.getMaxInterval(), properties.isUseRandomPolicy())
.build();
try {
field.set(retryTemplate, log);

View File

@@ -138,6 +138,7 @@ public class ConfigServerConfigDataLocationResolverTests {
assertThat(resource.getRetryProperties().getMaxInterval()).isEqualTo(defaultRetry.getMaxInterval());
assertThat(resource.getRetryProperties().getInitialInterval()).isEqualTo(defaultRetry.getInitialInterval());
assertThat(resource.getRetryProperties().getMultiplier()).isEqualTo(defaultRetry.getMultiplier());
assertThat(resource.getRetryProperties().isUseRandomPolicy()).isEqualTo(defaultRetry.isUseRandomPolicy());
}
@Test
@@ -158,6 +159,7 @@ public class ConfigServerConfigDataLocationResolverTests {
assertThat(resource.getRetryProperties().getMaxInterval()).isEqualTo(1500);
assertThat(resource.getRetryProperties().getInitialInterval()).isEqualTo(1100);
assertThat(resource.getRetryProperties().getMultiplier()).isEqualTo(1.2);
assertThat(resource.getRetryProperties().isUseRandomPolicy()).isEqualTo(false);
}
@Test