mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
Polish contribution
See gh-36932
This commit is contained in:
@@ -311,6 +311,8 @@ public class ExponentialBackOff implements BackOff {
|
||||
long jitter = getJitter();
|
||||
if (jitter > 0) {
|
||||
long initialInterval = getInitialInterval();
|
||||
// When initialInterval is 0 the interval never grows, so the scale factor
|
||||
// stays at its baseline value of 1 and the full configured jitter is applied.
|
||||
long applicableJitter = jitter * (initialInterval > 0 ? (interval / initialInterval) : 1);
|
||||
long min = Math.max(interval - applicableJitter, initialInterval);
|
||||
long max = Math.min(interval + applicableJitter, getMaxInterval());
|
||||
|
||||
@@ -119,17 +119,15 @@ class ExponentialBackOffTests {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> backOff.setMultiplier(0.9));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // gh-36932
|
||||
void jitterWithZeroInitialInterval() {
|
||||
// 'initialInterval = 0' and 'jitter > 0' are both individually accepted
|
||||
// configurations, so their combination must not throw. With initialInterval
|
||||
// of 0, the first nextBackOff() previously evaluated 'jitter * (0 / 0)',
|
||||
// resulting in an integer division by zero.
|
||||
ExponentialBackOff backOff = new ExponentialBackOff();
|
||||
backOff.setInitialInterval(0);
|
||||
backOff.setJitter(100);
|
||||
|
||||
BackOffExecution execution = backOff.start();
|
||||
|
||||
// 'initialInterval = 0' and 'jitter > 0' are both individually accepted
|
||||
// configurations, so their combination must not throw.
|
||||
assertThatNoException().isThrownBy(execution::nextBackOff);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user