|
23 | 23 | import static org.mockito.BDDMockito.given;
|
24 | 24 | import static org.mockito.BDDMockito.then;
|
25 | 25 | import static org.mockito.BDDMockito.willReturn;
|
| 26 | +import static org.mockito.Mockito.mock; |
26 | 27 | import static org.mockito.Mockito.never;
|
27 | 28 | import static org.mockito.Mockito.times;
|
28 | 29 |
|
|
59 | 60 | import org.springframework.kafka.listener.adapter.AbstractDelegatingMessageListenerAdapter;
|
60 | 61 | import org.springframework.kafka.listener.adapter.KafkaBackoffAwareMessageListenerAdapter;
|
61 | 62 | import org.springframework.kafka.support.Acknowledgment;
|
| 63 | +import org.springframework.util.backoff.BackOff; |
| 64 | +import org.springframework.util.backoff.BackOffExecution; |
62 | 65 |
|
63 | 66 | /**
|
64 | 67 | * @author Tomaz Fernandes
|
@@ -408,6 +411,34 @@ void shouldDecorateFactory() {
|
408 | 411 | then(this.configurerContainerCustomizer).should(times(1)).accept(container);
|
409 | 412 | }
|
410 | 413 |
|
| 414 | + @Test |
| 415 | + void shouldUseGivenBackOff() { |
| 416 | + |
| 417 | + // given |
| 418 | + given(container.getContainerProperties()).willReturn(containerProperties); |
| 419 | + given(deadLetterPublishingRecovererFactory.create()).willReturn(recoverer); |
| 420 | + given(containerProperties.getMessageListener()).willReturn(listener); |
| 421 | + given(configuration.forContainerFactoryConfigurer()).willReturn(lcfcConfiguration); |
| 422 | + willReturn(container).given(containerFactory).createListenerContainer(endpoint); |
| 423 | + BackOff backOffMock = mock(BackOff.class); |
| 424 | + BackOffExecution backOffExecutionMock = mock(BackOffExecution.class); |
| 425 | + given(backOffMock.start()).willReturn(backOffExecutionMock); |
| 426 | + |
| 427 | + ListenerContainerFactoryConfigurer configurer = |
| 428 | + new ListenerContainerFactoryConfigurer(kafkaConsumerBackoffManager, |
| 429 | + deadLetterPublishingRecovererFactory, clock); |
| 430 | + |
| 431 | + configurer.setBlockingRetriesBackOff(backOffMock); |
| 432 | + |
| 433 | + // when |
| 434 | + KafkaListenerContainerFactory<?> decoratedFactory = |
| 435 | + configurer.decorateFactory(this.containerFactory, configuration.forContainerFactoryConfigurer()); |
| 436 | + decoratedFactory.createListenerContainer(endpoint); |
| 437 | + |
| 438 | + // then |
| 439 | + then(backOffMock).should().start(); |
| 440 | + } |
| 441 | + |
411 | 442 | @Test
|
412 | 443 | void shouldCacheFactoryInstances() {
|
413 | 444 |
|
|
0 commit comments