Search in sources :

Example 1 with ExponentialBackOff

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());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 2 with ExponentialBackOff

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());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 3 with ExponentialBackOff

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);
}
Also used : ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 4 with ExponentialBackOff

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());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 5 with ExponentialBackOff

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());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ExponentialBackOff (org.springframework.util.backoff.ExponentialBackOff)9 BackOffExecution (org.springframework.util.backoff.BackOffExecution)8