use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.
the class ExponentialBackOffTests method maxAttemptsReached.
@Test
public void maxAttemptsReached() {
ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
backOff.setMaxElapsedTime(4000L);
BackOffExecution execution = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
// > 4 sec wait in total
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
}
use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.
the class ExponentialBackOffTests method maxIntervalReached.
@Test
public void maxIntervalReached() {
ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
backOff.setMaxInterval(4000L);
BackOffExecution execution = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
// max reached
assertEquals(4000l, execution.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
}
use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.
the class ExponentialBackOffTests method invalidInterval.
@Test
public void invalidInterval() {
ExponentialBackOff backOff = new ExponentialBackOff();
thrown.expect(IllegalArgumentException.class);
backOff.setMultiplier(0.9);
}
use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.
the class ExponentialBackOffTests method simpleIncrease.
@Test
public void simpleIncrease() {
ExponentialBackOff backOff = new ExponentialBackOff(100L, 2.0);
BackOffExecution execution = backOff.start();
assertEquals(100l, execution.nextBackOff());
assertEquals(200l, execution.nextBackOff());
assertEquals(400l, execution.nextBackOff());
assertEquals(800l, execution.nextBackOff());
}
use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.
the class ExponentialBackOffTests method startReturnDifferentInstances.
@Test
public void startReturnDifferentInstances() {
ExponentialBackOff backOff = new ExponentialBackOff();
backOff.setInitialInterval(2000L);
backOff.setMultiplier(2.0);
backOff.setMaxElapsedTime(4000L);
BackOffExecution execution = backOff.start();
BackOffExecution execution2 = backOff.start();
assertEquals(2000l, execution.nextBackOff());
assertEquals(2000l, execution2.nextBackOff());
assertEquals(4000l, execution.nextBackOff());
assertEquals(4000l, execution2.nextBackOff());
assertEquals(BackOffExecution.STOP, execution.nextBackOff());
assertEquals(BackOffExecution.STOP, execution2.nextBackOff());
}
Aggregations