68
68
import org .apache .rocketmq .remoting .exception .RemotingSendRequestException ;
69
69
import org .apache .rocketmq .remoting .exception .RemotingTimeoutException ;
70
70
import org .apache .rocketmq .tools .admin .api .MessageTrack ;
71
- import org .junit .After ;
72
- import org .junit .Before ;
71
+ import org .junit .AfterClass ;
72
+ import org .junit .BeforeClass ;
73
73
import org .junit .Test ;
74
74
import org .junit .runner .RunWith ;
75
75
import org .mockito .junit .MockitoJUnitRunner ;
83
83
84
84
@ RunWith (MockitoJUnitRunner .class )
85
85
public class DefaultMQAdminExtTest {
86
- private DefaultMQAdminExtImpl defaultMQAdminExtImpl ;
87
- private MQClientInstance mqClientInstance = MQClientManager .getInstance ().getAndCreateMQClientInstance (new ClientConfig ());
88
- private MQClientAPIImpl mQClientAPIImpl ;
89
- private Properties properties = new Properties ();
90
- private TopicList topicList = new TopicList ();
91
- private TopicRouteData topicRouteData = new TopicRouteData ();
92
- private KVTable kvTable = new KVTable ();
93
- private ClusterInfo clusterInfo = new ClusterInfo ();
94
-
95
- @ Before
96
- public void init () throws Exception {
86
+ private static DefaultMQAdminExt defaultMQAdminExt ;
87
+ private static DefaultMQAdminExtImpl defaultMQAdminExtImpl ;
88
+ private static MQClientInstance mqClientInstance = MQClientManager .getInstance ().getAndCreateMQClientInstance (new ClientConfig ());
89
+ private static MQClientAPIImpl mQClientAPIImpl ;
90
+ private static Properties properties = new Properties ();
91
+ private static TopicList topicList = new TopicList ();
92
+ private static TopicRouteData topicRouteData = new TopicRouteData ();
93
+ private static KVTable kvTable = new KVTable ();
94
+ private static ClusterInfo clusterInfo = new ClusterInfo ();
95
+
96
+ @ BeforeClass
97
+ public static void init () throws Exception {
97
98
mQClientAPIImpl = mock (MQClientAPIImpl .class );
98
- DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt ();
99
+ defaultMQAdminExt = new DefaultMQAdminExt ();
99
100
defaultMQAdminExtImpl = new DefaultMQAdminExtImpl (defaultMQAdminExt , 1000 );
100
101
101
102
Field field = DefaultMQAdminExtImpl .class .getDeclaredField ("mqClientInstance" );
@@ -104,6 +105,9 @@ public void init() throws Exception {
104
105
field = MQClientInstance .class .getDeclaredField ("mQClientAPIImpl" );
105
106
field .setAccessible (true );
106
107
field .set (mqClientInstance , mQClientAPIImpl );
108
+ field = DefaultMQAdminExt .class .getDeclaredField ("defaultMQAdminExtImpl" );
109
+ field .setAccessible (true );
110
+ field .set (defaultMQAdminExt , defaultMQAdminExtImpl );
107
111
108
112
properties .setProperty ("maxMessageSize" , "5000000" );
109
113
properties .setProperty ("flushDelayOffsetInterval" , "15000" );
@@ -223,37 +227,37 @@ public void init() throws Exception {
223
227
when (mQClientAPIImpl .getConsumerRunningInfo (anyString (), anyString (), anyString (), anyBoolean (), anyLong ())).thenReturn (consumerRunningInfo );
224
228
}
225
229
226
- @ After
227
- public void terminate () throws Exception {
230
+ @ AfterClass
231
+ public static void terminate () throws Exception {
228
232
if (defaultMQAdminExtImpl != null )
229
- defaultMQAdminExtImpl .shutdown ();
233
+ defaultMQAdminExt .shutdown ();
230
234
}
231
235
232
236
@ Test
233
237
public void testUpdateBrokerConfig () throws InterruptedException , RemotingConnectException , UnsupportedEncodingException , RemotingTimeoutException , MQBrokerException , RemotingSendRequestException {
234
- Properties result = defaultMQAdminExtImpl .getBrokerConfig ("127.0.0.1:10911" );
238
+ Properties result = defaultMQAdminExt .getBrokerConfig ("127.0.0.1:10911" );
235
239
assertThat (result .getProperty ("maxMessageSize" )).isEqualTo ("5000000" );
236
240
assertThat (result .getProperty ("flushDelayOffsetInterval" )).isEqualTo ("15000" );
237
241
assertThat (result .getProperty ("serverSocketRcvBufSize" )).isEqualTo ("655350" );
238
242
}
239
243
240
244
@ Test
241
245
public void testFetchAllTopicList () throws RemotingException , MQClientException , InterruptedException {
242
- TopicList topicList = defaultMQAdminExtImpl .fetchAllTopicList ();
246
+ TopicList topicList = defaultMQAdminExt .fetchAllTopicList ();
243
247
assertThat (topicList .getTopicList ().size ()).isEqualTo (2 );
244
248
assertThat (topicList .getTopicList ()).contains ("topic_one" );
245
249
}
246
250
247
251
@ Test
248
252
public void testFetchBrokerRuntimeStats () throws InterruptedException , MQBrokerException , RemotingTimeoutException , RemotingSendRequestException , RemotingConnectException {
249
- KVTable brokerStats = defaultMQAdminExtImpl .fetchBrokerRuntimeStats ("127.0.0.1:10911" );
253
+ KVTable brokerStats = defaultMQAdminExt .fetchBrokerRuntimeStats ("127.0.0.1:10911" );
250
254
assertThat (brokerStats .getTable ().get ("id" )).isEqualTo ("1234" );
251
255
assertThat (brokerStats .getTable ().get ("brokerName" )).isEqualTo ("default-broker" );
252
256
}
253
257
254
258
@ Test
255
259
public void testExamineBrokerClusterInfo () throws InterruptedException , MQBrokerException , RemotingTimeoutException , RemotingSendRequestException , RemotingConnectException {
256
- ClusterInfo clusterInfo = defaultMQAdminExtImpl .examineBrokerClusterInfo ();
260
+ ClusterInfo clusterInfo = defaultMQAdminExt .examineBrokerClusterInfo ();
257
261
HashMap <String , BrokerData > brokerList = clusterInfo .getBrokerAddrTable ();
258
262
assertThat (brokerList .get ("default-broker" ).getBrokerName ()).isEqualTo ("default-broker" );
259
263
assertThat (brokerList .containsKey ("broker-test" )).isTrue ();
@@ -272,32 +276,32 @@ public void testExamineBrokerClusterInfo() throws InterruptedException, MQBroker
272
276
273
277
@ Test
274
278
public void testExamineConsumeStats () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
275
- ConsumeStats consumeStats = defaultMQAdminExtImpl .examineConsumeStats ("default-consumer-group" , "unit-test" );
279
+ ConsumeStats consumeStats = defaultMQAdminExt .examineConsumeStats ("default-consumer-group" , "unit-test" );
276
280
assertThat (consumeStats .getConsumeTps ()).isEqualTo (1234 );
277
281
}
278
282
279
283
@ Test
280
284
public void testExamineConsumerConnectionInfo () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
281
- ConsumerConnection consumerConnection = defaultMQAdminExtImpl .examineConsumerConnectionInfo ("default-consumer-group" );
285
+ ConsumerConnection consumerConnection = defaultMQAdminExt .examineConsumerConnectionInfo ("default-consumer-group" );
282
286
assertThat (consumerConnection .getConsumeType ()).isEqualTo (ConsumeType .CONSUME_PASSIVELY );
283
287
assertThat (consumerConnection .getMessageModel ()).isEqualTo (MessageModel .CLUSTERING );
284
288
}
285
289
286
290
@ Test
287
291
public void testExamineProducerConnectionInfo () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
288
- ProducerConnection producerConnection = defaultMQAdminExtImpl .examineProducerConnectionInfo ("default-producer-group" , "unit-test" );
292
+ ProducerConnection producerConnection = defaultMQAdminExt .examineProducerConnectionInfo ("default-producer-group" , "unit-test" );
289
293
assertThat (producerConnection .getConnectionSet ().size ()).isEqualTo (1 );
290
294
}
291
295
292
296
@ Test
293
297
public void testWipeWritePermOfBroker () throws InterruptedException , RemotingCommandException , RemotingSendRequestException , RemotingTimeoutException , MQClientException , RemotingConnectException {
294
- int result = defaultMQAdminExtImpl .wipeWritePermOfBroker ("127.0.0.1:9876" , "default-broker" );
298
+ int result = defaultMQAdminExt .wipeWritePermOfBroker ("127.0.0.1:9876" , "default-broker" );
295
299
assertThat (result ).isEqualTo (6 );
296
300
}
297
301
298
302
@ Test
299
303
public void testExamineTopicRouteInfo () throws RemotingException , MQClientException , InterruptedException {
300
- TopicRouteData topicRouteData = defaultMQAdminExtImpl .examineTopicRouteInfo ("UnitTest" );
304
+ TopicRouteData topicRouteData = defaultMQAdminExt .examineTopicRouteInfo ("UnitTest" );
301
305
assertThat (topicRouteData .getBrokerDatas ().get (0 ).getBrokerName ()).isEqualTo ("default-broker" );
302
306
assertThat (topicRouteData .getBrokerDatas ().get (0 ).getCluster ()).isEqualTo ("default-cluster" );
303
307
}
@@ -308,53 +312,53 @@ public void testGetNameServerAddressList() {
308
312
result .add ("default-name-one" );
309
313
result .add ("default-name-two" );
310
314
when (mqClientInstance .getMQClientAPIImpl ().getNameServerAddressList ()).thenReturn (result );
311
- List <String > nameList = defaultMQAdminExtImpl .getNameServerAddressList ();
315
+ List <String > nameList = defaultMQAdminExt .getNameServerAddressList ();
312
316
assertThat (nameList .get (0 )).isEqualTo ("default-name-one" );
313
317
assertThat (nameList .get (1 )).isEqualTo ("default-name-two" );
314
318
}
315
319
316
320
@ Test
317
321
public void testPutKVConfig () throws RemotingException , MQClientException , InterruptedException {
318
- String topicConfig = defaultMQAdminExtImpl .getKVConfig (NamesrvUtil .NAMESPACE_ORDER_TOPIC_CONFIG , "UnitTest" );
322
+ String topicConfig = defaultMQAdminExt .getKVConfig (NamesrvUtil .NAMESPACE_ORDER_TOPIC_CONFIG , "UnitTest" );
319
323
assertThat (topicConfig ).isEqualTo ("topicListConfig" );
320
- KVTable kvs = defaultMQAdminExtImpl .getKVListByNamespace (NamesrvUtil .NAMESPACE_ORDER_TOPIC_CONFIG );
324
+ KVTable kvs = defaultMQAdminExt .getKVListByNamespace (NamesrvUtil .NAMESPACE_ORDER_TOPIC_CONFIG );
321
325
assertThat (kvs .getTable ().get ("broker-name" )).isEqualTo ("broker-one" );
322
326
assertThat (kvs .getTable ().get ("cluster-name" )).isEqualTo ("default-cluster" );
323
327
}
324
328
325
329
@ Test
326
330
public void testQueryTopicConsumeByWho () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
327
- GroupList groupList = defaultMQAdminExtImpl .queryTopicConsumeByWho ("UnitTest" );
331
+ GroupList groupList = defaultMQAdminExt .queryTopicConsumeByWho ("UnitTest" );
328
332
assertThat (groupList .getGroupList ().contains ("consumer-group-two" )).isTrue ();
329
333
}
330
334
331
335
@ Test
332
336
public void testQueryConsumeTimeSpan () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
333
- List <QueueTimeSpan > result = defaultMQAdminExtImpl .queryConsumeTimeSpan ("unit-test" , "default-broker-group" );
337
+ List <QueueTimeSpan > result = defaultMQAdminExt .queryConsumeTimeSpan ("unit-test" , "default-broker-group" );
334
338
assertThat (result .size ()).isEqualTo (0 );
335
339
}
336
340
337
341
@ Test
338
342
public void testCleanExpiredConsumerQueue () throws InterruptedException , RemotingTimeoutException , MQClientException , RemotingSendRequestException , RemotingConnectException {
339
- boolean result = defaultMQAdminExtImpl .cleanExpiredConsumerQueue ("default-cluster" );
343
+ boolean result = defaultMQAdminExt .cleanExpiredConsumerQueue ("default-cluster" );
340
344
assertThat (result ).isFalse ();
341
345
}
342
346
343
347
@ Test
344
348
public void testCleanExpiredConsumerQueueByAddr () throws InterruptedException , RemotingTimeoutException , MQClientException , RemotingSendRequestException , RemotingConnectException {
345
- boolean clean = defaultMQAdminExtImpl .cleanExpiredConsumerQueueByAddr ("127.0.0.1:10911" );
349
+ boolean clean = defaultMQAdminExt .cleanExpiredConsumerQueueByAddr ("127.0.0.1:10911" );
346
350
assertThat (clean ).isTrue ();
347
351
}
348
352
349
353
@ Test
350
354
public void testCleanUnusedTopic () throws InterruptedException , RemotingTimeoutException , MQClientException , RemotingSendRequestException , RemotingConnectException {
351
- boolean result = defaultMQAdminExtImpl .cleanUnusedTopic ("default-cluster" );
355
+ boolean result = defaultMQAdminExt .cleanUnusedTopic ("default-cluster" );
352
356
assertThat (result ).isFalse ();
353
357
}
354
358
355
359
@ Test
356
360
public void testGetConsumerRunningInfo () throws RemotingException , MQClientException , InterruptedException {
357
- ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExtImpl .getConsumerRunningInfo ("consumer-group" , "cid_123" , false );
361
+ ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt .getConsumerRunningInfo ("consumer-group" , "cid_123" , false );
358
362
assertThat (consumerRunningInfo .getJstack ()).isEqualTo ("test" );
359
363
}
360
364
@@ -363,25 +367,25 @@ public void testMessageTrackDetail() throws InterruptedException, RemotingExcept
363
367
MessageExt messageExt = new MessageExt ();
364
368
messageExt .setMsgId ("msgId" );
365
369
messageExt .setTopic ("unit-test" );
366
- List <MessageTrack > messageTrackList = defaultMQAdminExtImpl .messageTrackDetail (messageExt );
370
+ List <MessageTrack > messageTrackList = defaultMQAdminExt .messageTrackDetail (messageExt );
367
371
assertThat (messageTrackList .size ()).isEqualTo (2 );
368
372
}
369
373
370
374
@ Test
371
375
public void testGetConsumeStatus () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
372
- Map <String , Map <MessageQueue , Long >> result = defaultMQAdminExtImpl .getConsumeStatus ("unit-test" , "default-broker-group" , "127.0.0.1:10911" );
376
+ Map <String , Map <MessageQueue , Long >> result = defaultMQAdminExt .getConsumeStatus ("unit-test" , "default-broker-group" , "127.0.0.1:10911" );
373
377
assertThat (result .size ()).isEqualTo (0 );
374
378
}
375
379
376
380
@ Test
377
381
public void testGetTopicClusterList () throws InterruptedException , RemotingException , MQClientException , MQBrokerException {
378
- Set <String > result = defaultMQAdminExtImpl .getTopicClusterList ("unit-test" );
382
+ Set <String > result = defaultMQAdminExt .getTopicClusterList ("unit-test" );
379
383
assertThat (result .size ()).isEqualTo (0 );
380
384
}
381
385
382
386
@ Test
383
387
public void testGetClusterList () throws InterruptedException , RemotingTimeoutException , MQClientException , RemotingSendRequestException , RemotingConnectException {
384
- Set <String > clusterlist = defaultMQAdminExtImpl .getClusterList ("UnitTest" );
388
+ Set <String > clusterlist = defaultMQAdminExt .getClusterList ("UnitTest" );
385
389
assertThat (clusterlist .contains ("default-cluster-one" )).isTrue ();
386
390
assertThat (clusterlist .contains ("default-cluster-two" )).isTrue ();
387
391
}
@@ -391,13 +395,13 @@ public void testFetchConsumeStatsInBroker() throws InterruptedException, Remotin
391
395
ConsumeStatsList result = new ConsumeStatsList ();
392
396
result .setBrokerAddr ("127.0.0.1:10911" );
393
397
when (mqClientInstance .getMQClientAPIImpl ().fetchConsumeStatsInBroker ("127.0.0.1:10911" , false , 10000 )).thenReturn (result );
394
- ConsumeStatsList consumeStatsList = defaultMQAdminExtImpl .fetchConsumeStatsInBroker ("127.0.0.1:10911" , false , 10000 );
398
+ ConsumeStatsList consumeStatsList = defaultMQAdminExt .fetchConsumeStatsInBroker ("127.0.0.1:10911" , false , 10000 );
395
399
assertThat (consumeStatsList .getBrokerAddr ()).isEqualTo ("127.0.0.1:10911" );
396
400
}
397
401
398
402
@ Test
399
403
public void testGetAllSubscriptionGroup () throws InterruptedException , MQBrokerException , RemotingTimeoutException , RemotingSendRequestException , RemotingConnectException {
400
- SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExtImpl .getAllSubscriptionGroup ("127.0.0.1:10911" , 10000 );
404
+ SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt .getAllSubscriptionGroup ("127.0.0.1:10911" , 10000 );
401
405
assertThat (subscriptionGroupWrapper .getSubscriptionGroupTable ().get ("Consumer-group-one" ).getBrokerId ()).isEqualTo (1234 );
402
406
assertThat (subscriptionGroupWrapper .getSubscriptionGroupTable ().get ("Consumer-group-one" ).getGroupName ()).isEqualTo ("Consumer-group-one" );
403
407
assertThat (subscriptionGroupWrapper .getSubscriptionGroupTable ().get ("Consumer-group-one" ).isConsumeBroadcastEnable ()).isTrue ();
0 commit comments