|
21 | 21 | import org.apache.rocketmq.store.DefaultMessageStore; |
22 | 22 | import org.apache.rocketmq.store.config.MessageStoreConfig; |
23 | 23 | import org.apache.rocketmq.store.stats.BrokerStatsManager; |
| 24 | +import org.junit.Before; |
24 | 25 | import org.junit.Test; |
25 | 26 |
|
| 27 | +import java.util.Collections; |
26 | 28 | import java.util.concurrent.ConcurrentHashMap; |
27 | 29 |
|
| 30 | +import static org.junit.Assert.assertEquals; |
| 31 | +import static org.junit.Assert.assertNotNull; |
28 | 32 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
29 | 33 |
|
30 | | - |
31 | 34 | public class IndexServiceTest { |
32 | 35 |
|
| 36 | + private IndexService indexService; |
| 37 | + |
| 38 | + @Before |
| 39 | + public void setUp() throws Exception { |
| 40 | + DefaultMessageStore store = new DefaultMessageStore( |
| 41 | + new MessageStoreConfig(), |
| 42 | + new BrokerStatsManager(new BrokerConfig()), |
| 43 | + null, |
| 44 | + new BrokerConfig(), |
| 45 | + new ConcurrentHashMap<>() |
| 46 | + ); |
| 47 | + indexService = new IndexService(store); |
| 48 | + } |
| 49 | + |
33 | 50 | @Test |
34 | | - public void testQueryOffsetThrow() throws Exception { |
| 51 | + public void testQueryOffsetThrow() { |
35 | 52 | assertDoesNotThrow(() -> { |
36 | | - DefaultMessageStore store = new DefaultMessageStore( |
37 | | - new MessageStoreConfig(), |
38 | | - new BrokerStatsManager(new BrokerConfig()), |
39 | | - null, |
40 | | - new BrokerConfig(), |
41 | | - new ConcurrentHashMap<>() |
42 | | - ); |
43 | | - |
44 | | - IndexService indexService = new IndexService(store); |
45 | 53 | indexService.queryOffset("test", "", Integer.MAX_VALUE, 10, 100); |
46 | 54 | }); |
47 | 55 | } |
48 | 56 |
|
| 57 | + @Test |
| 58 | + public void testQueryOffsetWithoutIndexType() { |
| 59 | + QueryOffsetResult result = indexService.queryOffset("test", "testKey", 10, 0, 100); |
| 60 | + assertNotNull(result); |
| 61 | + assertEquals(Collections.emptyList(), result.getPhyOffsets()); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testQueryOffsetWithIndexType() { |
| 66 | + QueryOffsetResult result = indexService.queryOffset("test", "testKey", 10, 0, 100, "TAG"); |
| 67 | + assertNotNull(result); |
| 68 | + assertEquals(Collections.emptyList(), result.getPhyOffsets()); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testQueryOffsetWithNullKey() { |
| 73 | + QueryOffsetResult result = indexService.queryOffset("test", null, 10, 0, 100); |
| 74 | + assertNotNull(result); |
| 75 | + assertEquals(Collections.emptyList(), result.getPhyOffsets()); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testQueryOffsetWithZeroMaxNum() { |
| 80 | + QueryOffsetResult result = indexService.queryOffset("test", "testKey", 0, 0, 100); |
| 81 | + assertNotNull(result); |
| 82 | + assertEquals(Collections.emptyList(), result.getPhyOffsets()); |
| 83 | + } |
49 | 84 | } |
0 commit comments