Search in sources :

Example 6 with BackOffExecution

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

the class ExponentialBackOffTests method startReturnDifferentInstances.

@Test
void startReturnDifferentInstances() {
    ExponentialBackOff backOff = new ExponentialBackOff();
    backOff.setInitialInterval(2000L);
    backOff.setMultiplier(2.0);
    backOff.setMaxElapsedTime(4000L);
    BackOffExecution execution = backOff.start();
    BackOffExecution execution2 = backOff.start();
    assertThat(execution.nextBackOff()).isEqualTo(2000L);
    assertThat(execution2.nextBackOff()).isEqualTo(2000L);
    assertThat(execution.nextBackOff()).isEqualTo(4000L);
    assertThat(execution2.nextBackOff()).isEqualTo(4000L);
    assertThat(execution.nextBackOff()).isEqualTo(BackOffExecution.STOP);
    assertThat(execution2.nextBackOff()).isEqualTo(BackOffExecution.STOP);
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.jupiter.api.Test)

Example 7 with BackOffExecution

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

the class ExponentialBackOffTests method simpleIncrease.

@Test
void simpleIncrease() {
    ExponentialBackOff backOff = new ExponentialBackOff(100L, 2.0);
    BackOffExecution execution = backOff.start();
    assertThat(execution.nextBackOff()).isEqualTo(100L);
    assertThat(execution.nextBackOff()).isEqualTo(200L);
    assertThat(execution.nextBackOff()).isEqualTo(400L);
    assertThat(execution.nextBackOff()).isEqualTo(800L);
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) ExponentialBackOff(org.springframework.util.backoff.ExponentialBackOff) Test(org.junit.jupiter.api.Test)

Example 8 with BackOffExecution

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

the class FixedBackOffTests method liveUpdate.

@Test
void liveUpdate() {
    FixedBackOff backOff = new FixedBackOff(100L, 1);
    BackOffExecution execution = backOff.start();
    assertThat(execution.nextBackOff()).isEqualTo(100L);
    backOff.setInterval(200L);
    backOff.setMaxAttempts(2);
    assertThat(execution.nextBackOff()).isEqualTo(200L);
    assertThat(execution.nextBackOff()).isEqualTo(BackOffExecution.STOP);
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.jupiter.api.Test)

Example 9 with BackOffExecution

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

the class FixedBackOffTests method startReturnDifferentInstances.

@Test
void startReturnDifferentInstances() {
    FixedBackOff backOff = new FixedBackOff(100L, 1);
    BackOffExecution execution = backOff.start();
    BackOffExecution execution2 = backOff.start();
    assertThat(execution.nextBackOff()).isEqualTo(100L);
    assertThat(execution2.nextBackOff()).isEqualTo(100L);
    assertThat(execution.nextBackOff()).isEqualTo(BackOffExecution.STOP);
    assertThat(execution2.nextBackOff()).isEqualTo(BackOffExecution.STOP);
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.jupiter.api.Test)

Example 10 with BackOffExecution

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

the class FixedBackOffTests method defaultInstance.

@Test
void defaultInstance() {
    FixedBackOff backOff = new FixedBackOff();
    BackOffExecution execution = backOff.start();
    for (int i = 0; i < 100; i++) {
        assertThat(execution.nextBackOff()).isEqualTo(FixedBackOff.DEFAULT_INTERVAL);
    }
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.jupiter.api.Test)

Aggregations

BackOffExecution (org.springframework.util.backoff.BackOffExecution)19 Test (org.junit.jupiter.api.Test)17 ExponentialBackOff (org.springframework.util.backoff.ExponentialBackOff)9 FixedBackOff (org.springframework.util.backoff.FixedBackOff)6 BackOff (org.springframework.util.backoff.BackOff)3 Connection (jakarta.jms.Connection)1 JMSException (jakarta.jms.JMSException)1 ArrayList (java.util.ArrayList)1 JmsException (org.springframework.jms.JmsException)1