Search in sources :

Example 1 with BackOff

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

the class JmsNamespaceHandlerTests method getRecoveryInterval.

private long getRecoveryInterval(String containerBeanName) {
    BackOff backOff = getBackOff(containerBeanName);
    assertThat(backOff.getClass()).isEqualTo(FixedBackOff.class);
    return ((FixedBackOff) backOff).getInterval();
}
Also used : FixedBackOff(org.springframework.util.backoff.FixedBackOff) BackOff(org.springframework.util.backoff.BackOff) FixedBackOff(org.springframework.util.backoff.FixedBackOff)

Example 2 with BackOff

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

the class JmsNamespaceHandlerTests method testRecoveryInterval.

@Test
public void testRecoveryInterval() {
    Object testBackOff = context.getBean("testBackOff");
    BackOff backOff1 = getBackOff("listener1");
    BackOff backOff2 = getBackOff("listener2");
    long recoveryInterval3 = getRecoveryInterval(DefaultMessageListenerContainer.class.getName() + "#0");
    assertThat(backOff1).isSameAs(testBackOff);
    assertThat(backOff2).isSameAs(testBackOff);
    assertThat(recoveryInterval3).isEqualTo(DefaultMessageListenerContainer.DEFAULT_RECOVERY_INTERVAL);
}
Also used : BackOff(org.springframework.util.backoff.BackOff) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.jupiter.api.Test)

Example 3 with BackOff

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

the class JmsListenerContainerFactoryTests method backOffOverridesRecoveryInterval.

@Test
public void backOffOverridesRecoveryInterval() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    BackOff backOff = new FixedBackOff();
    factory.setBackOff(backOff);
    factory.setRecoveryInterval(2000L);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertThat(new DirectFieldAccessor(container).getPropertyValue("backOff")).isSameAs(backOff);
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageListener(jakarta.jms.MessageListener) FixedBackOff(org.springframework.util.backoff.FixedBackOff) BackOff(org.springframework.util.backoff.BackOff) FixedBackOff(org.springframework.util.backoff.FixedBackOff) Test(org.junit.jupiter.api.Test)

Example 4 with BackOff

use of org.springframework.util.backoff.BackOff 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 5 with BackOff

use of org.springframework.util.backoff.BackOff 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)

Aggregations

BackOff (org.springframework.util.backoff.BackOff)6 Test (org.junit.jupiter.api.Test)5 BackOffExecution (org.springframework.util.backoff.BackOffExecution)3 FixedBackOff (org.springframework.util.backoff.FixedBackOff)3 MessageListener (jakarta.jms.MessageListener)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)1 MessageListenerAdapter (org.springframework.jms.listener.adapter.MessageListenerAdapter)1