Search in sources :

Example 6 with ExponentialBackOff

use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.

the class ExponentialBackOffTests method defaultInstance.

@Test
public void defaultInstance() {
    ExponentialBackOff backOff = new ExponentialBackOff();
    BackOffExecution execution = backOff.start();
    assertEquals(2000l, execution.nextBackOff());
    assertEquals(3000l, execution.nextBackOff());
    assertEquals(4500l, execution.nextBackOff());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 7 with ExponentialBackOff

use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.

the class ExponentialBackOffTests method fixedIncrease.

@Test
public void fixedIncrease() {
    ExponentialBackOff backOff = new ExponentialBackOff(100L, 1.0);
    backOff.setMaxElapsedTime(300l);
    BackOffExecution execution = backOff.start();
    assertEquals(100l, execution.nextBackOff());
    assertEquals(100l, execution.nextBackOff());
    assertEquals(100l, execution.nextBackOff());
    assertEquals(BackOffExecution.STOP, execution.nextBackOff());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 8 with ExponentialBackOff

use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.

the class ExponentialBackOffTests method maxIntervalReachedImmediately.

@Test
public void maxIntervalReachedImmediately() {
    ExponentialBackOff backOff = new ExponentialBackOff(1000L, 2.0);
    backOff.setMaxInterval(50L);
    BackOffExecution execution = backOff.start();
    assertEquals(50L, execution.nextBackOff());
    assertEquals(50L, execution.nextBackOff());
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.Test)

Example 9 with ExponentialBackOff

use of org.springframework.util.backoff.ExponentialBackOff in project spring-framework by spring-projects.

the class ExponentialBackOffTests method toStringContent.

@Test
public void toStringContent() {
    ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
    BackOffExecution execution = backOff.start();
    assertEquals("ExponentialBackOff{currentInterval=n/a, multiplier=2.0}", execution.toString());
    execution.nextBackOff();
    assertEquals("ExponentialBackOff{currentInterval=2000ms, multiplier=2.0}", execution.toString());
    execution.nextBackOff();
    assertEquals("ExponentialBackOff{currentInterval=4000ms, multiplier=2.0}", execution.toString());
}
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