Java Code Examples for org.apache.rocketmq.common.protocol.route.BrokerData#setCluster()

The following examples show how to use org.apache.rocketmq.common.protocol.route.BrokerData#setCluster() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMQProducerTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example 2
Source File: DefaultMQProducerWithTraceTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example 3
Source File: DefaultMQConsumerWithTraceTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example 4
Source File: ConsumerProgressSubCommandTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);
}
 
Example 5
Source File: TopicRouteDataTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopicRouteDataClone() throws Exception {

    TopicRouteData topicRouteData = new TopicRouteData();

    QueueData queueData = new QueueData();
    queueData.setBrokerName("broker-a");
    queueData.setPerm(6);
    queueData.setReadQueueNums(8);
    queueData.setWriteQueueNums(8);
    queueData.setTopicSynFlag(0);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    queueDataList.add(queueData);

    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "192.168.0.47:10911");
    brokerAddrs.put(1L, "192.168.0.47:10921");

    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerData.setBrokerName("broker-a");
    brokerData.setCluster("TestCluster");

    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    brokerDataList.add(brokerData);

    topicRouteData.setBrokerDatas(brokerDataList);
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    topicRouteData.setQueueDatas(queueDataList);

    assertThat(topicRouteData.cloneTopicRouteData()).isEqualTo(topicRouteData);

}
 
Example 6
Source File: ClusterTestRequestProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    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 = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    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);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
 
Example 7
Source File: ClusterTestRequestProcessorTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(
        new NamesrvConfig(),
        new NettyServerConfig()
    );

    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);

    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 = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);

    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);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
 
Example 8
Source File: MQClientInstanceTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopicRouteData2TopicPublishInfo() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);

    TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);

    assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse();
    assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4);
}
 
Example 9
Source File: CommandUtilTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws MQClientException, NoSuchFieldException, IllegalAccessException, InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    defaultMQAdminExt = mock(DefaultMQAdminExt.class);
    MQClientAPIImpl mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 3000);

    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);

    ClusterInfo clusterInfo = new ClusterInfo();
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
    HashMap<String, Set<String>> clusterAddrTable = new HashMap<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("default-broker");
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerAddrTable.put("default-broker", brokerData);
    brokerAddrTable.put("broker-test", new BrokerData());
    Set<String> brokerSet = new HashSet<>();
    brokerSet.add("default-broker");
    brokerSet.add("default-broker-one");
    clusterAddrTable.put("default-cluster", brokerSet);
    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(clusterAddrTable);
    when(mQClientAPIImpl.getBrokerClusterInfo(anyLong())).thenReturn(clusterInfo);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
}
 
Example 10
Source File: ResetOffsetByTimeCommandTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@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);

    Map<MessageQueue, Long> messageQueueLongMap = new HashMap<>();
    when(mQClientAPIImpl.invokeBrokerToResetOffset(anyString(), anyString(), anyString(), anyLong(), anyBoolean(), anyLong())).thenReturn(messageQueueLongMap);
}
 
Example 11
Source File: ConsumerProgressSubCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);
}
 
Example 12
Source File: CommandUtilTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws MQClientException, NoSuchFieldException, IllegalAccessException, InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    defaultMQAdminExt = mock(DefaultMQAdminExt.class);
    MQClientAPIImpl mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 3000);

    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);

    ClusterInfo clusterInfo = new ClusterInfo();
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
    HashMap<String, Set<String>> clusterAddrTable = new HashMap<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("default-broker");
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerAddrTable.put("default-broker", brokerData);
    brokerAddrTable.put("broker-test", new BrokerData());
    Set<String> brokerSet = new HashSet<>();
    brokerSet.add("default-broker");
    brokerSet.add("default-broker-one");
    clusterAddrTable.put("default-cluster", brokerSet);
    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(clusterAddrTable);
    when(mQClientAPIImpl.getBrokerClusterInfo(anyLong())).thenReturn(clusterInfo);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
}
 
Example 13
Source File: CommandUtilTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws MQClientException, NoSuchFieldException, IllegalAccessException, InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    defaultMQAdminExt = mock(DefaultMQAdminExt.class);
    MQClientAPIImpl mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 3000);

    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);

    ClusterInfo clusterInfo = new ClusterInfo();
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
    HashMap<String, Set<String>> clusterAddrTable = new HashMap<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("default-broker");
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerAddrTable.put("default-broker", brokerData);
    brokerAddrTable.put("broker-test", new BrokerData());
    Set<String> brokerSet = new HashSet<>();
    brokerSet.add("default-broker");
    brokerSet.add("default-broker-one");
    clusterAddrTable.put("default-cluster", brokerSet);
    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(clusterAddrTable);
    when(mQClientAPIImpl.getBrokerClusterInfo(anyLong())).thenReturn(clusterInfo);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
}
 
Example 14
Source File: MonitorServiceTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    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);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(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>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
 
Example 15
Source File: MonitorServiceTest.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    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);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(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>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
 
Example 16
Source File: MonitorServiceTest.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    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);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(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>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
 
Example 17
Source File: ConsumerStatusSubCommandTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 18
Source File: MonitorServiceTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    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);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(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>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
 
Example 19
Source File: MonitorServiceTest.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    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);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    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);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(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>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
 
Example 20
Source File: ConsumerStatusSubCommandTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@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);
}