|
33 | 33 | import com.github.sonus21.rqueue.common.RqueueLockManager; |
34 | 34 | import com.github.sonus21.rqueue.config.RqueueConfig; |
35 | 35 | import com.github.sonus21.rqueue.config.RqueueWebConfig; |
| 36 | +import com.github.sonus21.rqueue.core.EndpointRegistry; |
36 | 37 | import com.github.sonus21.rqueue.core.RqueueBeanProvider; |
37 | 38 | import com.github.sonus21.rqueue.core.RqueueMessage; |
38 | 39 | import com.github.sonus21.rqueue.core.RqueueMessageTemplate; |
39 | 40 | import com.github.sonus21.rqueue.dao.RqueueSystemConfigDao; |
| 41 | +import com.github.sonus21.rqueue.models.Concurrency; |
40 | 42 | import com.github.sonus21.rqueue.models.db.MessageMetadata; |
41 | 43 | import com.github.sonus21.rqueue.models.db.QueueConfig; |
42 | 44 | import com.github.sonus21.rqueue.models.enums.MessageStatus; |
|
67 | 69 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
68 | 70 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
69 | 71 | import org.springframework.util.LinkedMultiValueMap; |
| 72 | +import org.springframework.util.MultiValueMap; |
70 | 73 |
|
71 | 74 | @CoreUnitTest |
72 | 75 | class RqueueMessageListenerContainerTest extends TestBase { |
@@ -172,6 +175,68 @@ void setTaskExecutor() { |
172 | 175 | ((ThreadPoolTaskExecutor) container.getTaskExecutor()).getThreadNamePrefix()); |
173 | 176 | } |
174 | 177 |
|
| 178 | + @Test |
| 179 | + void globalMaxRetryCapsDefaultRetryForever() throws Exception { |
| 180 | + beanProvider.getRqueueConfig().setMaxRetry(5); |
| 181 | + doReturn(handlerMap(mapping(slowQueue, -1, null))) |
| 182 | + .when(rqueueMessageHandler) |
| 183 | + .getHandlerMethodMap(); |
| 184 | + |
| 185 | + container.afterPropertiesSet(); |
| 186 | + |
| 187 | + assertEquals(5, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + void globalMaxRetryDoesNotOverrideExplicitRetryCount() throws Exception { |
| 192 | + beanProvider.getRqueueConfig().setMaxRetry(2); |
| 193 | + doReturn(handlerMap(mapping(slowQueue, 10, null))) |
| 194 | + .when(rqueueMessageHandler) |
| 195 | + .getHandlerMethodMap(); |
| 196 | + |
| 197 | + container.afterPropertiesSet(); |
| 198 | + |
| 199 | + assertEquals(10, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 200 | + } |
| 201 | + |
| 202 | + @Test |
| 203 | + void globalMaxRetryDoesNotRaiseLowerExplicitRetryCount() throws Exception { |
| 204 | + beanProvider.getRqueueConfig().setMaxRetry(5); |
| 205 | + doReturn(handlerMap(mapping(slowQueue, 2, null))) |
| 206 | + .when(rqueueMessageHandler) |
| 207 | + .getHandlerMethodMap(); |
| 208 | + |
| 209 | + container.afterPropertiesSet(); |
| 210 | + |
| 211 | + assertEquals(2, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 212 | + } |
| 213 | + |
| 214 | + @Test |
| 215 | + void globalMaxRetryCanDisableRetries() throws Exception { |
| 216 | + beanProvider.getRqueueConfig().setMaxRetry(0); |
| 217 | + doReturn(handlerMap(mapping(slowQueue, -1, null))) |
| 218 | + .when(rqueueMessageHandler) |
| 219 | + .getHandlerMethodMap(); |
| 220 | + |
| 221 | + container.afterPropertiesSet(); |
| 222 | + |
| 223 | + assertEquals(0, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 224 | + } |
| 225 | + |
| 226 | + @Test |
| 227 | + void globalMaxRetryDoesNotOverrideDeadLetterDefaultRetryCount() throws Exception { |
| 228 | + beanProvider.getRqueueConfig().setMaxRetry(0); |
| 229 | + doReturn(handlerMap(mapping(slowQueue, -1, slowQueue + "-dlq"))) |
| 230 | + .when(rqueueMessageHandler) |
| 231 | + .getHandlerMethodMap(); |
| 232 | + |
| 233 | + container.afterPropertiesSet(); |
| 234 | + |
| 235 | + assertEquals( |
| 236 | + Constants.DEFAULT_RETRY_DEAD_LETTER_QUEUE, |
| 237 | + EndpointRegistry.get(slowQueue).getNumRetry()); |
| 238 | + } |
| 239 | + |
175 | 240 | @Test |
176 | 241 | void phaseSetting() { |
177 | 242 | assertEquals(Integer.MAX_VALUE, container.getPhase()); |
@@ -534,6 +599,28 @@ private class TestListenerContainer extends RqueueMessageListenerContainer { |
534 | 599 | } |
535 | 600 | } |
536 | 601 |
|
| 602 | + private MultiValueMap<MappingInformation, RqueueMessageHandler.HandlerMethodWithPrimary> |
| 603 | + handlerMap(MappingInformation mappingInformation) { |
| 604 | + LinkedMultiValueMap<MappingInformation, RqueueMessageHandler.HandlerMethodWithPrimary> map = |
| 605 | + new LinkedMultiValueMap<>(); |
| 606 | + map.add(mappingInformation, new RqueueMessageHandler.HandlerMethodWithPrimary(null, false)); |
| 607 | + return map; |
| 608 | + } |
| 609 | + |
| 610 | + private MappingInformation mapping(String queue, int numRetry, String deadLetterQueueName) { |
| 611 | + return MappingInformation.builder() |
| 612 | + .queueNames(Collections.singleton(queue)) |
| 613 | + .numRetry(numRetry) |
| 614 | + .deadLetterQueueName(deadLetterQueueName) |
| 615 | + .deadLetterConsumerEnabled(false) |
| 616 | + .visibilityTimeout(VISIBILITY_TIMEOUT) |
| 617 | + .active(false) |
| 618 | + .concurrency(new Concurrency(0, 0)) |
| 619 | + .priority(Collections.singletonMap(Constants.DEFAULT_PRIORITY_KEY, 1)) |
| 620 | + .batchSize(1) |
| 621 | + .build(); |
| 622 | + } |
| 623 | + |
537 | 624 | @Getter |
538 | 625 | private class StubMessageSchedulerListenerContainer extends RqueueMessageListenerContainer { |
539 | 626 |
|
|
0 commit comments