Search in sources :

Example 1 with MQClientInstance

use of org.apache.rocketmq.client.impl.factory.MQClientInstance in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class CommandUtilTest method setup.

@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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Field(java.lang.reflect.Field) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 2 with MQClientInstance

use of org.apache.rocketmq.client.impl.factory.MQClientInstance in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerConsumeStatsSubCommadTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException {
    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);
    ConsumeStatsList consumeStatsList = new ConsumeStatsList();
    consumeStatsList.setBrokerAddr("127.0l.0.1:10911");
    consumeStatsList.setConsumeStatsList(new ArrayList<Map<String, List<ConsumeStats>>>());
    consumeStatsList.setTotalDiff(123);
    when(mQClientAPIImpl.fetchConsumeStatsInBroker(anyString(), anyBoolean(), anyLong())).thenReturn(consumeStatsList);
}
Also used : Field(java.lang.reflect.Field) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) Map(java.util.Map) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Example 3 with MQClientInstance

use of org.apache.rocketmq.client.impl.factory.MQClientInstance in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class CleanExpiredCQSubCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, 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);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
}
Also used : Field(java.lang.reflect.Field) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Example 4 with MQClientInstance

use of org.apache.rocketmq.client.impl.factory.MQClientInstance in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class CleanUnusedTopicCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, 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);
    when(mQClientAPIImpl.cleanUnusedTopicByAddr(anyString(), anyLong())).thenReturn(true);
}
Also used : Field(java.lang.reflect.Field) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Example 5 with MQClientInstance

use of org.apache.rocketmq.client.impl.factory.MQClientInstance in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class GetBrokerConfigCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
    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);
    Properties properties = new Properties();
    properties.setProperty("maxMessageSize", "5000000");
    properties.setProperty("flushDelayOffsetInterval", "15000");
    properties.setProperty("serverSocketRcvBufSize", "655350");
    when(mQClientAPIImpl.getBrokerConfig(anyString(), anyLong())).thenReturn(properties);
}
Also used : Field(java.lang.reflect.Field) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) Properties(java.util.Properties) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)41 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)39 Field (java.lang.reflect.Field)38 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)36 DefaultMQAdminExtImpl (org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl)36 BeforeClass (org.junit.BeforeClass)34 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)16 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)14 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)14 HashSet (java.util.HashSet)12 List (java.util.List)10 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)10 Connection (org.apache.rocketmq.common.protocol.body.Connection)10 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)10 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)10 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)8 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)8 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)8