|
62 | 62 | import static org.mockito.ArgumentMatchers.anyInt; |
63 | 63 | import static org.mockito.ArgumentMatchers.anyLong; |
64 | 64 | import static org.mockito.ArgumentMatchers.anyString; |
65 | | -import static org.mockito.ArgumentMatchers.eq; |
66 | 65 | import static org.mockito.Mockito.when; |
67 | 66 |
|
68 | 67 | public class TieredMessageStoreTest { |
@@ -275,19 +274,43 @@ public void testGetMessageStoreTimeStampAsync() { |
275 | 274 |
|
276 | 275 | @Test |
277 | 276 | public void testGetOffsetInQueueByTime() { |
| 277 | + final long earliestMsgTime = 100L; |
278 | 278 | Properties properties = new Properties(); |
279 | 279 | properties.setProperty("tieredStorageLevel", "FORCE"); |
280 | 280 | configuration.update(properties); |
281 | 281 |
|
282 | | - Mockito.when(fetcher.getOffsetInQueueByTime(anyString(), anyInt(), anyLong(), eq(BoundaryType.LOWER))).thenReturn(1L); |
283 | | - Mockito.when(defaultStore.getOffsetInQueueByTime(anyString(), anyInt(), anyLong())).thenReturn(2L); |
284 | | - Mockito.when(defaultStore.getEarliestMessageTime()).thenReturn(100L); |
| 282 | + Mockito.when(fetcher.getOffsetInQueueByTime(anyString(), anyInt(), anyLong(), any(BoundaryType.class))) |
| 283 | + .thenAnswer(ivk -> ivk.getArgument(3, BoundaryType.class) == BoundaryType.LOWER ? 1L : 2L); |
| 284 | + Mockito.when(defaultStore.getOffsetInQueueByTime(anyString(), anyInt(), anyLong(), any(BoundaryType.class))) |
| 285 | + .thenAnswer(ivk -> { |
| 286 | + long time = ivk.getArgument(2, Long.class); |
| 287 | + if (time < earliestMsgTime) { |
| 288 | + return -1L; |
| 289 | + } |
| 290 | + return ivk.getArgument(3, BoundaryType.class) == BoundaryType.LOWER ? 3L : 4L; |
| 291 | + }); |
| 292 | + Mockito.when(defaultStore.getEarliestMessageTime()).thenReturn(earliestMsgTime); |
| 293 | + |
| 294 | + // Message not in disk, but force, found in tired storage. |
285 | 295 | Assert.assertEquals(1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 1000, BoundaryType.LOWER)); |
| 296 | + Assert.assertEquals(2L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 1000, BoundaryType.UPPER)); |
| 297 | + // Message in disk, and force, found in tired storage. |
286 | 298 | Assert.assertEquals(1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0, BoundaryType.LOWER)); |
| 299 | + Assert.assertEquals(2L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0, BoundaryType.UPPER)); |
287 | 300 |
|
288 | | - Mockito.when(fetcher.getOffsetInQueueByTime(anyString(), anyInt(), anyLong(), eq(BoundaryType.LOWER))).thenReturn(-1L); |
| 301 | + // Message in disk, but force, and not found in tired storage. |
| 302 | + Mockito.when(fetcher.getOffsetInQueueByTime(anyString(), anyInt(), anyLong(), any(BoundaryType.class))).thenReturn(-1L); |
289 | 303 | Assert.assertEquals(-1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0)); |
290 | 304 | Assert.assertEquals(-1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0, BoundaryType.LOWER)); |
| 305 | + |
| 306 | + properties.setProperty("tieredStorageLevel", "NOT_IN_DISK"); |
| 307 | + configuration.update(properties); |
| 308 | + // Message not in disk, and not found in tired storage. |
| 309 | + Assert.assertEquals(-1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0, BoundaryType.LOWER)); |
| 310 | + Assert.assertEquals(-1L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 0, BoundaryType.UPPER)); |
| 311 | + // Message in disk, and found in disk. |
| 312 | + Assert.assertEquals(3L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 1000, BoundaryType.LOWER)); |
| 313 | + Assert.assertEquals(4L, currentStore.getOffsetInQueueByTime(mq.getTopic(), mq.getQueueId(), 1000, BoundaryType.UPPER)); |
291 | 314 | } |
292 | 315 |
|
293 | 316 | @Test |
|
0 commit comments