|
1 | 1 | package com.github.sonus21.rqueue.listener; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
3 | 4 | import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 5 | import static org.mockito.ArgumentMatchers.any; |
5 | 6 | import static org.mockito.ArgumentMatchers.anyInt; |
6 | 7 | import static org.mockito.ArgumentMatchers.anyString; |
7 | 8 | import static org.mockito.ArgumentMatchers.eq; |
8 | 9 | import static org.mockito.Mockito.lenient; |
9 | 10 | import static org.mockito.Mockito.mock; |
| 11 | +import static org.mockito.Mockito.never; |
10 | 12 | import static org.mockito.Mockito.spy; |
| 13 | +import static org.mockito.Mockito.verify; |
11 | 14 | import static org.mockito.Mockito.when; |
12 | 15 |
|
13 | 16 | import com.github.sonus21.TestBase; |
14 | 17 | import com.github.sonus21.rqueue.CoreUnitTest; |
15 | 18 | import com.github.sonus21.rqueue.core.RqueueBeanProvider; |
16 | 19 | import com.github.sonus21.rqueue.listener.RqueueMessageListenerContainer.QueueStateMgr; |
| 20 | +import com.github.sonus21.rqueue.listener.RqueueMessagePoller.DeactivateType; |
17 | 21 | import com.github.sonus21.rqueue.utils.Constants; |
18 | 22 | import com.github.sonus21.rqueue.utils.QueueThreadPool; |
19 | 23 | import com.github.sonus21.rqueue.utils.TimeoutUtils; |
@@ -67,7 +71,7 @@ public void setUp() { |
67 | 71 | rqueueBeanProvider, |
68 | 72 | queueStateMgr, |
69 | 73 | Collections.emptyList(), |
70 | | - 50L, |
| 74 | + 60_000L, // Keep deactivation from expiring during assertions. |
71 | 75 | 50L, |
72 | 76 | postProcessingHandler, |
73 | 77 | new MessageHeaders(Collections.emptyMap()), |
@@ -109,6 +113,35 @@ void testExistMessagesInHigherPriorityQueueReturnsTrue() { |
109 | 113 | assertTrue(result, "Should return true because high priority queue has messages"); |
110 | 114 | } |
111 | 115 |
|
| 116 | + @Test |
| 117 | + void testBusyPoolDoesNotHideHighPriorityMessages() throws Exception { |
| 118 | + QueueThreadPool busyPool = mock(QueueThreadPool.class); |
| 119 | + when(busyPool.acquire(1, poller.getSemaphoreWaitTime())).thenReturn(false); |
| 120 | + lenient().doReturn(true).when(poller).existAvailableMessagesForPoll(highDetail); |
| 121 | + lenient().doReturn(false).when(poller).existAvailableMessagesForPoll(lowDetail); |
| 122 | + |
| 123 | + poller.poll(-1, highPriorityQueue, highDetail, busyPool); |
| 124 | + |
| 125 | + verify(busyPool).acquire(1, poller.getSemaphoreWaitTime()); |
| 126 | + assertTrue( |
| 127 | + poller.existMessagesInCurrentQueueOrHigherPriorityQueue(lowPriorityQueue, poller.queues), |
| 128 | + "A busy pool must not hide pending high-priority messages"); |
| 129 | + verify(poller, never()).existAvailableMessagesForPoll(lowDetail); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + void testEmptyQueueIsTemporarilySkipped() { |
| 134 | + lenient().doReturn(false).when(poller).existAvailableMessagesForPoll(lowDetail); |
| 135 | + |
| 136 | + poller.deactivate(-1, highPriorityQueue, DeactivateType.NO_MESSAGE); |
| 137 | + |
| 138 | + assertFalse( |
| 139 | + poller.existMessagesInCurrentQueueOrHigherPriorityQueue(lowPriorityQueue, poller.queues), |
| 140 | + "An empty high-priority queue should remain inactive during the polling interval"); |
| 141 | + verify(poller, never()).existAvailableMessagesForPoll(highDetail); |
| 142 | + verify(poller).existAvailableMessagesForPoll(lowDetail); |
| 143 | + } |
| 144 | + |
112 | 145 | @Test |
113 | 146 | void testStrictExecutionPreventsLowPriorityPoll() throws Exception { |
114 | 147 | AtomicInteger highQueuePollCount = new AtomicInteger(0); |
|
0 commit comments