Search in sources :

Example 11 with BackOffExecution

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

the class FixedBackOffTests method maxAttemptsReached.

@Test
void maxAttemptsReached() {
    FixedBackOff backOff = new FixedBackOff(200L, 2);
    BackOffExecution execution = backOff.start();
    assertThat(execution.nextBackOff()).isEqualTo(200L);
    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 12 with BackOffExecution

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

the class DefaultMessageListenerContainerTests method recoverResetBackOff.

@Test
public void recoverResetBackOff() {
    BackOff backOff = mock(BackOff.class);
    BackOffExecution execution = mock(BackOffExecution.class);
    // 3 attempts max
    given(execution.nextBackOff()).willReturn(50L, 50L, 50L);
    given(backOff.start()).willReturn(execution);
    DefaultMessageListenerContainer container = createContainer(createRecoverableContainerFactory(1));
    container.setBackOff(backOff);
    container.start();
    container.refreshConnectionUntilSuccessful();
    assertThat(container.isRunning()).isTrue();
    verify(backOff).start();
    // only on attempt as the second one lead to a recovery
    verify(execution, times(1)).nextBackOff();
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) BackOff(org.springframework.util.backoff.BackOff) Test(org.junit.jupiter.api.Test)

Example 13 with BackOffExecution

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

the class DefaultMessageListenerContainerTests method applyBackOff.

@Test
public void applyBackOff() {
    BackOff backOff = mock(BackOff.class);
    BackOffExecution execution = mock(BackOffExecution.class);
    given(execution.nextBackOff()).willReturn(BackOffExecution.STOP);
    given(backOff.start()).willReturn(execution);
    DefaultMessageListenerContainer container = createContainer(createFailingContainerFactory());
    container.setBackOff(backOff);
    container.start();
    assertThat(container.isRunning()).isTrue();
    container.refreshConnectionUntilSuccessful();
    assertThat(container.isRunning()).isFalse();
    verify(backOff).start();
    verify(execution).nextBackOff();
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) BackOff(org.springframework.util.backoff.BackOff) Test(org.junit.jupiter.api.Test)

Example 14 with BackOffExecution

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

the class DefaultMessageListenerContainerTests method applyBackOffRetry.

@Test
public void applyBackOffRetry() {
    BackOff backOff = mock(BackOff.class);
    BackOffExecution execution = mock(BackOffExecution.class);
    given(execution.nextBackOff()).willReturn(50L, BackOffExecution.STOP);
    given(backOff.start()).willReturn(execution);
    DefaultMessageListenerContainer container = createContainer(createFailingContainerFactory());
    container.setBackOff(backOff);
    container.start();
    container.refreshConnectionUntilSuccessful();
    assertThat(container.isRunning()).isFalse();
    verify(backOff).start();
    verify(execution, times(2)).nextBackOff();
}
Also used : BackOffExecution(org.springframework.util.backoff.BackOffExecution) BackOff(org.springframework.util.backoff.BackOff) Test(org.junit.jupiter.api.Test)

Example 15 with BackOffExecution

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

the class FixedBackOffTests method noAttemptAtAll.

@Test
void noAttemptAtAll() {
    FixedBackOff backOff = new FixedBackOff(100L, 0L);
    BackOffExecution execution = backOff.start();
    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)

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