|
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; |
| 40 | +import com.github.sonus21.rqueue.models.Concurrency; |
39 | 41 | import com.github.sonus21.rqueue.dao.RqueueSystemConfigDao; |
40 | 42 | import com.github.sonus21.rqueue.models.db.MessageMetadata; |
41 | 43 | import com.github.sonus21.rqueue.models.db.QueueConfig; |
|
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,62 @@ 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))).when(rqueueMessageHandler) |
| 182 | + .getHandlerMethodMap(); |
| 183 | + |
| 184 | + container.afterPropertiesSet(); |
| 185 | + |
| 186 | + assertEquals(5, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + void globalMaxRetryDoesNotOverrideExplicitRetryCount() throws Exception { |
| 191 | + beanProvider.getRqueueConfig().setMaxRetry(2); |
| 192 | + doReturn(handlerMap(mapping(slowQueue, 10, null))).when(rqueueMessageHandler) |
| 193 | + .getHandlerMethodMap(); |
| 194 | + |
| 195 | + container.afterPropertiesSet(); |
| 196 | + |
| 197 | + assertEquals(10, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 198 | + } |
| 199 | + |
| 200 | + @Test |
| 201 | + void globalMaxRetryDoesNotRaiseLowerExplicitRetryCount() throws Exception { |
| 202 | + beanProvider.getRqueueConfig().setMaxRetry(5); |
| 203 | + doReturn(handlerMap(mapping(slowQueue, 2, null))).when(rqueueMessageHandler) |
| 204 | + .getHandlerMethodMap(); |
| 205 | + |
| 206 | + container.afterPropertiesSet(); |
| 207 | + |
| 208 | + assertEquals(2, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 209 | + } |
| 210 | + |
| 211 | + @Test |
| 212 | + void globalMaxRetryCanDisableRetries() throws Exception { |
| 213 | + beanProvider.getRqueueConfig().setMaxRetry(0); |
| 214 | + doReturn(handlerMap(mapping(slowQueue, -1, null))).when(rqueueMessageHandler) |
| 215 | + .getHandlerMethodMap(); |
| 216 | + |
| 217 | + container.afterPropertiesSet(); |
| 218 | + |
| 219 | + assertEquals(0, EndpointRegistry.get(slowQueue).getNumRetry()); |
| 220 | + } |
| 221 | + |
| 222 | + @Test |
| 223 | + void globalMaxRetryDoesNotOverrideDeadLetterDefaultRetryCount() throws Exception { |
| 224 | + beanProvider.getRqueueConfig().setMaxRetry(0); |
| 225 | + doReturn(handlerMap(mapping(slowQueue, -1, slowQueue + "-dlq"))).when(rqueueMessageHandler) |
| 226 | + .getHandlerMethodMap(); |
| 227 | + |
| 228 | + container.afterPropertiesSet(); |
| 229 | + |
| 230 | + assertEquals(Constants.DEFAULT_RETRY_DEAD_LETTER_QUEUE, |
| 231 | + EndpointRegistry.get(slowQueue).getNumRetry()); |
| 232 | + } |
| 233 | + |
175 | 234 | @Test |
176 | 235 | void phaseSetting() { |
177 | 236 | assertEquals(Integer.MAX_VALUE, container.getPhase()); |
@@ -534,6 +593,28 @@ private class TestListenerContainer extends RqueueMessageListenerContainer { |
534 | 593 | } |
535 | 594 | } |
536 | 595 |
|
| 596 | + private MultiValueMap<MappingInformation, RqueueMessageHandler.HandlerMethodWithPrimary> |
| 597 | + handlerMap(MappingInformation mappingInformation) { |
| 598 | + LinkedMultiValueMap<MappingInformation, RqueueMessageHandler.HandlerMethodWithPrimary> map = |
| 599 | + new LinkedMultiValueMap<>(); |
| 600 | + map.add(mappingInformation, new RqueueMessageHandler.HandlerMethodWithPrimary(null, false)); |
| 601 | + return map; |
| 602 | + } |
| 603 | + |
| 604 | + private MappingInformation mapping(String queue, int numRetry, String deadLetterQueueName) { |
| 605 | + return MappingInformation.builder() |
| 606 | + .queueNames(Collections.singleton(queue)) |
| 607 | + .numRetry(numRetry) |
| 608 | + .deadLetterQueueName(deadLetterQueueName) |
| 609 | + .deadLetterConsumerEnabled(false) |
| 610 | + .visibilityTimeout(VISIBILITY_TIMEOUT) |
| 611 | + .active(false) |
| 612 | + .concurrency(new Concurrency(0, 0)) |
| 613 | + .priority(Collections.singletonMap(Constants.DEFAULT_PRIORITY_KEY, 1)) |
| 614 | + .batchSize(1) |
| 615 | + .build(); |
| 616 | + } |
| 617 | + |
537 | 618 | @Getter |
538 | 619 | private class StubMessageSchedulerListenerContainer extends RqueueMessageListenerContainer { |
539 | 620 |
|
|
0 commit comments