spring-retry
spring-retry copied to clipboard
The FixedBackOffPolicy method setBackOffPeriod(long) if set to 0 or less than .The backOffPeriod value not is 1000ms.
Class: org.springframework.retry.backoff.FixedBackOffPolicy
Method: public void setBackOffPeriod(long backOffPeriod)
source code:
private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;
private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;
....//omit
public void setBackOffPeriod(long backOffPeriod) {
this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1); //here
}
....//omit
suggest code:
private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;
private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;
....//omit
public void setBackOffPeriod(long backOffPeriod) {
this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : DEFAULT_BACK_OFF_PERIOD); //here
}
....//omit
test code:
@Test
public void fixedBackOffPolicyTest() {
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(0);
RetryTemplate retryTemplate = RetryTemplate.builder()
.customBackoff(backOffPolicy)
.build();
Object execute = null;
try {
execute = retryTemplate.execute(new RetryCallback<Object, Throwable>() {
@Override
public Object doWithRetry(RetryContext context) throws Throwable {
log.info("RetryCallback:" + context.getRetryCount());
throw new IllegalArgumentException();
//return "RetryCallback";
}
}, new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
log.info("RecoveryCallback:" + context.getRetryCount());
return "RecoveryCallback";
}
});
} catch (Throwable throwable) {
log.error(throwable.getMessage(), throwable);
}
log.info("result:" + execute);
}
This is indeed a bug, but I'm not sure that we can make a breaking change in behavior in the current point version.
So, pushing to Backlog for future consideration when we go 2.1 or even 3.0.