Search in sources :

Example 1 with ConsumeStatus

use of org.apache.rocketmq.common.protocol.body.ConsumeStatus in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ConsumerStatusSubCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingException, MQClientException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    topicRouteData.setQueueDatas(new ArrayList<QueueData>());
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    connections.add(new Connection());
    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>());
    consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection);
    ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo();
    consumerRunningInfo.setJstack("test");
    consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>());
    consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>());
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) List(java.util.List) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) HashSet(java.util.HashSet) ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Example 2 with ConsumeStatus

use of org.apache.rocketmq.common.protocol.body.ConsumeStatus in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMonitorListenerTest method testReportConsumerRunningInfo.

@Test
public void testReportConsumerRunningInfo() {
    TreeMap<String, ConsumerRunningInfo> criTable = new TreeMap<>();
    ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo();
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>());
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>());
    consumerRunningInfo.setProperties(new Properties());
    criTable.put("test", consumerRunningInfo);
    defaultMonitorListener.reportConsumerRunningInfo(criTable);
}
Also used : ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) TreeMap(java.util.TreeMap) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ConsumeStatus

use of org.apache.rocketmq.common.protocol.body.ConsumeStatus in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ConsumeStatusTest method testFromJson.

@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
Also used : ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) Test(org.junit.Test)

Example 4 with ConsumeStatus

use of org.apache.rocketmq.common.protocol.body.ConsumeStatus in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method consumerRunningInfo.

@Override
public ConsumerRunningInfo consumerRunningInfo() {
    ConsumerRunningInfo info = new ConsumerRunningInfo();
    Properties prop = MixAll.object2Properties(this.defaultMQPushConsumer);
    prop.put(ConsumerRunningInfo.PROP_CONSUME_ORDERLY, String.valueOf(this.consumeOrderly));
    prop.put(ConsumerRunningInfo.PROP_THREADPOOL_CORE_SIZE, String.valueOf(this.consumeMessageService.getCorePoolSize()));
    prop.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, String.valueOf(this.consumerStartTimestamp));
    info.setProperties(prop);
    Set<SubscriptionData> subSet = this.subscriptions();
    info.getSubscriptionSet().addAll(subSet);
    Iterator<Entry<MessageQueue, ProcessQueue>> it = this.rebalanceImpl.getProcessQueueTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, ProcessQueue> next = it.next();
        MessageQueue mq = next.getKey();
        ProcessQueue pq = next.getValue();
        ProcessQueueInfo pqinfo = new ProcessQueueInfo();
        pqinfo.setCommitOffset(this.offsetStore.readOffset(mq, ReadOffsetType.MEMORY_FIRST_THEN_STORE));
        pq.fillProcessQueueInfo(pqinfo);
        info.getMqTable().put(mq, pqinfo);
    }
    for (SubscriptionData sd : subSet) {
        ConsumeStatus consumeStatus = this.mQClientFactory.getConsumerStatsManager().consumeStatus(this.groupName(), sd.getTopic());
        info.getStatusTable().put(sd.getTopic(), consumeStatus);
    }
    return info;
}
Also used : ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) Entry(java.util.Map.Entry) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) Properties(java.util.Properties) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus)

Example 5 with ConsumeStatus

use of org.apache.rocketmq.common.protocol.body.ConsumeStatus in project rocketmq by apache.

the class ConsumeStatusTest method testFromJson.

@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
Also used : ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) Test(org.junit.Test)

Aggregations

ConsumeStatus (org.apache.rocketmq.common.protocol.body.ConsumeStatus)12 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)10 ConsumerRunningInfo (org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo)10 ProcessQueueInfo (org.apache.rocketmq.common.protocol.body.ProcessQueueInfo)10 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)10 Field (java.lang.reflect.Field)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Properties (java.util.Properties)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)6 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)6 Connection (org.apache.rocketmq.common.protocol.body.Connection)6 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)6 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)6 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)6 BeforeClass (org.junit.BeforeClass)6 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)6