|
22 | 22 | import java.util.concurrent.CountDownLatch; |
23 | 23 | import java.util.concurrent.TimeUnit; |
24 | 24 | import java.util.concurrent.atomic.AtomicInteger; |
| 25 | +import java.util.concurrent.atomic.AtomicReference; |
25 | 26 |
|
26 | 27 | import org.junit.jupiter.api.Test; |
27 | 28 |
|
| 29 | +import org.springframework.integration.core.MessageSource; |
28 | 30 | import org.springframework.integration.util.IntegrationReactiveUtils; |
| 31 | +import org.springframework.messaging.MessagingException; |
29 | 32 | import org.springframework.messaging.support.GenericMessage; |
30 | 33 |
|
31 | 34 | import reactor.core.Disposable; |
|
41 | 44 | * |
42 | 45 | * @since 5.1.9 |
43 | 46 | */ |
44 | | -class MessageChannelReactiveUtilsTests { |
| 47 | +class IntegrationReactiveUtilsTests { |
45 | 48 |
|
46 | 49 | @Test |
47 | 50 | void testBackpressureWithSubscribableChannel() { |
@@ -116,4 +119,28 @@ void testPublisherPayloadWithNullChannel() throws InterruptedException { |
116 | 119 | assertThat(publisherSubscribed.await(10, TimeUnit.SECONDS)).isTrue(); |
117 | 120 | } |
118 | 121 |
|
| 122 | + |
| 123 | + @Test |
| 124 | + void testRetryOnMessagingExceptionOnly() { |
| 125 | + AtomicInteger retryAttempts = new AtomicInteger(3); |
| 126 | + AtomicReference<Throwable> finalException = new AtomicReference<>(); |
| 127 | + MessageSource<?> messageSource = |
| 128 | + () -> { |
| 129 | + if (retryAttempts.getAndDecrement() > 0) { |
| 130 | + throw new MessagingException("retryable MessagingException"); |
| 131 | + } |
| 132 | + else { |
| 133 | + throw new RuntimeException("non-retryable RuntimeException"); |
| 134 | + } |
| 135 | + }; |
| 136 | + |
| 137 | + StepVerifier.create(IntegrationReactiveUtils.messageSourceToFlux(messageSource).doOnError(finalException::set)) |
| 138 | + .expectSubscription() |
| 139 | + .expectErrorMessage("non-retryable RuntimeException") |
| 140 | + .verify(Duration.ofSeconds(1)); |
| 141 | + |
| 142 | + assertThat(retryAttempts.get()).isEqualTo(-1); |
| 143 | + assertThat(finalException.get()).hasMessage("non-retryable RuntimeException"); |
| 144 | + } |
| 145 | + |
119 | 146 | } |
0 commit comments