|
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.AfterAll; |
27 | 28 | import org.junit.jupiter.api.Test; |
28 | 29 |
|
| 30 | +import org.springframework.integration.core.MessageSource; |
29 | 31 | import org.springframework.integration.util.IntegrationReactiveUtils; |
| 32 | +import org.springframework.messaging.MessagingException; |
30 | 33 | import org.springframework.messaging.support.GenericMessage; |
31 | 34 |
|
32 | 35 | import reactor.core.Disposable; |
|
43 | 46 | * |
44 | 47 | * @since 5.1.9 |
45 | 48 | */ |
46 | | -class MessageChannelReactiveUtilsTests { |
| 49 | +class IntegrationReactiveUtilsTests { |
47 | 50 |
|
48 | 51 | private static final Scheduler SCHEDULER = Schedulers.boundedElastic(); |
49 | 52 |
|
@@ -125,4 +128,28 @@ void testPublisherPayloadWithNullChannel() throws InterruptedException { |
125 | 128 | assertThat(publisherSubscribed.await(10, TimeUnit.SECONDS)).isTrue(); |
126 | 129 | } |
127 | 130 |
|
| 131 | + |
| 132 | + @Test |
| 133 | + void testRetryOnMessagingExceptionOnly() { |
| 134 | + AtomicInteger retryAttempts = new AtomicInteger(3); |
| 135 | + AtomicReference<Throwable> finalException = new AtomicReference<>(); |
| 136 | + MessageSource<?> messageSource = |
| 137 | + () -> { |
| 138 | + if (retryAttempts.getAndDecrement() > 0) { |
| 139 | + throw new MessagingException("retryable MessagingException"); |
| 140 | + } |
| 141 | + else { |
| 142 | + throw new RuntimeException("non-retryable RuntimeException"); |
| 143 | + } |
| 144 | + }; |
| 145 | + |
| 146 | + StepVerifier.create(IntegrationReactiveUtils.messageSourceToFlux(messageSource).doOnError(finalException::set)) |
| 147 | + .expectSubscription() |
| 148 | + .expectErrorMessage("non-retryable RuntimeException") |
| 149 | + .verify(Duration.ofSeconds(1)); |
| 150 | + |
| 151 | + assertThat(retryAttempts.get()).isEqualTo(-1); |
| 152 | + assertThat(finalException.get()).hasMessage("non-retryable RuntimeException"); |
| 153 | + } |
| 154 | + |
128 | 155 | } |
0 commit comments