|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.HashMap; |
21 | 21 | import java.util.List; |
| 22 | +import java.util.Properties; |
22 | 23 | import java.util.concurrent.ConcurrentHashMap; |
23 | 24 | import java.util.concurrent.ConcurrentMap; |
24 | 25 | import org.apache.rocketmq.client.ClientConfig; |
|
29 | 30 | import org.apache.rocketmq.client.impl.consumer.MQConsumerInner; |
30 | 31 | import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; |
31 | 32 | import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; |
| 33 | +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; |
| 34 | +import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; |
32 | 35 | import org.apache.rocketmq.common.protocol.route.BrokerData; |
33 | 36 | import org.apache.rocketmq.common.protocol.route.QueueData; |
34 | 37 | import org.apache.rocketmq.common.protocol.route.TopicRouteData; |
|
41 | 44 |
|
42 | 45 | import static org.assertj.core.api.Assertions.assertThat; |
43 | 46 | import static org.mockito.Mockito.mock; |
| 47 | +import static org.mockito.Mockito.when; |
44 | 48 |
|
45 | 49 | @RunWith(MockitoJUnitRunner.class) |
46 | 50 | public class MQClientInstanceTest { |
@@ -139,6 +143,31 @@ public void testRegisterConsumer() throws RemotingException, InterruptedExceptio |
139 | 143 | assertThat(flag).isTrue(); |
140 | 144 | } |
141 | 145 |
|
| 146 | + |
| 147 | + @Test |
| 148 | + public void testConsumerRunningInfoWhenConsumersIsEmptyOrNot() throws RemotingException, InterruptedException, MQBrokerException { |
| 149 | + MQConsumerInner mockConsumerInner = mock(MQConsumerInner.class); |
| 150 | + ConsumerRunningInfo mockConsumerRunningInfo = mock(ConsumerRunningInfo.class); |
| 151 | + when(mockConsumerInner.consumerRunningInfo()).thenReturn(mockConsumerRunningInfo); |
| 152 | + when(mockConsumerInner.consumeType()).thenReturn(ConsumeType.CONSUME_PASSIVELY); |
| 153 | + Properties properties = new Properties(); |
| 154 | + when(mockConsumerRunningInfo.getProperties()).thenReturn(properties); |
| 155 | + mqClientInstance.unregisterConsumer(group); |
| 156 | + |
| 157 | + ConsumerRunningInfo runningInfo = mqClientInstance.consumerRunningInfo(group); |
| 158 | + assertThat(runningInfo).isNull(); |
| 159 | + boolean flag = mqClientInstance.registerConsumer(group, mockConsumerInner); |
| 160 | + assertThat(flag).isTrue(); |
| 161 | + |
| 162 | + runningInfo = mqClientInstance.consumerRunningInfo(group); |
| 163 | + assertThat(runningInfo).isNotNull(); |
| 164 | + assertThat(mockConsumerInner.consumerRunningInfo().getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)); |
| 165 | + |
| 166 | + mqClientInstance.unregisterConsumer(group); |
| 167 | + flag = mqClientInstance.registerConsumer(group, mock(MQConsumerInner.class)); |
| 168 | + assertThat(flag).isTrue(); |
| 169 | + } |
| 170 | + |
142 | 171 | @Test |
143 | 172 | public void testRegisterAdminExt() { |
144 | 173 | boolean flag = mqClientInstance.registerAdminExt(group, mock(MQAdminExtInner.class)); |
|
0 commit comments