@@ -235,6 +235,153 @@ public void testProcessRequest_UnregisterBroker() throws RemotingCommandExceptio
235
235
assertThat ((Map ) brokerAddrTable .get (routes )).isNotEmpty ();
236
236
}
237
237
238
+ @ Test
239
+ public void testGetRouteInfoByTopic () throws RemotingCommandException {
240
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
241
+ when (ctx .channel ()).thenReturn (null );
242
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_ROUTEINFO_BY_TOPIC );
243
+ RemotingCommand remotingCommandSuccess = defaultRequestProcessor .processRequest (ctx , request );
244
+ assertThat (remotingCommandSuccess .getCode ()).isEqualTo (ResponseCode .SUCCESS );
245
+ request .getExtFields ().put ("topic" , "test" );
246
+ RemotingCommand remotingCommandNoTopicRouteInfo = defaultRequestProcessor .processRequest (ctx , request );
247
+ assertThat (remotingCommandNoTopicRouteInfo .getCode ()).isEqualTo (ResponseCode .TOPIC_NOT_EXIST );
248
+ }
249
+
250
+ @ Test
251
+ public void testGetBrokerClusterInfo () throws RemotingCommandException {
252
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
253
+ when (ctx .channel ()).thenReturn (null );
254
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_BROKER_CLUSTER_INFO );
255
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
256
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
257
+ }
258
+
259
+ @ Test
260
+ public void testWipeWritePermOfBroker () throws RemotingCommandException {
261
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
262
+ when (ctx .channel ()).thenReturn (null );
263
+ RemotingCommand request = getRemotingCommand (RequestCode .WIPE_WRITE_PERM_OF_BROKER );
264
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
265
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
266
+ }
267
+
268
+ @ Test
269
+ public void testGetAllTopicListFromNameserver () throws RemotingCommandException {
270
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
271
+ when (ctx .channel ()).thenReturn (null );
272
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_ALL_TOPIC_LIST_FROM_NAMESERVER );
273
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
274
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
275
+ }
276
+
277
+ @ Test
278
+ public void testDeleteTopicInNamesrv () throws RemotingCommandException {
279
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
280
+ when (ctx .channel ()).thenReturn (null );
281
+ RemotingCommand request = getRemotingCommand (RequestCode .DELETE_TOPIC_IN_NAMESRV );
282
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
283
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
284
+ }
285
+
286
+ @ Test
287
+ public void testGetKVListByNamespace () throws RemotingCommandException {
288
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
289
+ when (ctx .channel ()).thenReturn (null );
290
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_KVLIST_BY_NAMESPACE );
291
+ request .addExtField ("namespace" , "default-namespace-1" );
292
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
293
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .QUERY_NOT_FOUND );
294
+ namesrvController .getKvConfigManager ().putKVConfig ("default-namespace-1" , "key" , "value" );
295
+ RemotingCommand remotingCommandSuccess = defaultRequestProcessor .processRequest (ctx , request );
296
+ assertThat (remotingCommandSuccess .getCode ()).isEqualTo (ResponseCode .SUCCESS );
297
+ }
298
+
299
+ @ Test
300
+ public void testGetTopicsByCluster () throws RemotingCommandException {
301
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
302
+ when (ctx .channel ()).thenReturn (null );
303
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_TOPICS_BY_CLUSTER );
304
+ request .addExtField ("cluster" , "default-cluster" );
305
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
306
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
307
+ }
308
+
309
+ @ Test
310
+ public void testGetSystemTopicListFromNs () throws RemotingCommandException {
311
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
312
+ when (ctx .channel ()).thenReturn (null );
313
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_SYSTEM_TOPIC_LIST_FROM_NS );
314
+ request .addExtField ("cluster" , "default-cluster" );
315
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
316
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
317
+ }
318
+
319
+ @ Test
320
+ public void testGetUnitTopicList () throws RemotingCommandException {
321
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
322
+ when (ctx .channel ()).thenReturn (null );
323
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_UNIT_TOPIC_LIST );
324
+ request .addExtField ("cluster" , "default-cluster" );
325
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
326
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
327
+ }
328
+
329
+ @ Test
330
+ public void testGetHasUnitSubTopicList () throws RemotingCommandException {
331
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
332
+ when (ctx .channel ()).thenReturn (null );
333
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_HAS_UNIT_SUB_TOPIC_LIST );
334
+ request .addExtField ("cluster" , "default-cluster" );
335
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
336
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
337
+ }
338
+
339
+ @ Test
340
+ public void testGetHasUnitSubUnUnitTopicList () throws RemotingCommandException {
341
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
342
+ when (ctx .channel ()).thenReturn (null );
343
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_HAS_UNIT_SUB_UNUNIT_TOPIC_LIST );
344
+ request .addExtField ("cluster" , "default-cluster" );
345
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
346
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
347
+ }
348
+
349
+ @ Test
350
+ public void testUpdateConfig () throws RemotingCommandException {
351
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
352
+ when (ctx .channel ()).thenReturn (null );
353
+ RemotingCommand request = getRemotingCommand (RequestCode .UPDATE_NAMESRV_CONFIG );
354
+ request .addExtField ("cluster" , "default-cluster" );
355
+ Map <String , String > propertiesMap = new HashMap <>();
356
+ propertiesMap .put ("key" , "value" );
357
+ request .setBody (propertiesMap .toString ().getBytes ());
358
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
359
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
360
+ }
361
+
362
+ @ Test
363
+ public void testGetConfig () throws RemotingCommandException {
364
+ ChannelHandlerContext ctx = mock (ChannelHandlerContext .class );
365
+ when (ctx .channel ()).thenReturn (null );
366
+ RemotingCommand request = getRemotingCommand (RequestCode .GET_NAMESRV_CONFIG );
367
+ request .addExtField ("cluster" , "default-cluster" );
368
+ RemotingCommand remotingCommand = defaultRequestProcessor .processRequest (ctx , request );
369
+ assertThat (remotingCommand .getCode ()).isEqualTo (ResponseCode .SUCCESS );
370
+ }
371
+
372
+ private RemotingCommand getRemotingCommand (int code ) {
373
+ RegisterBrokerRequestHeader header = new RegisterBrokerRequestHeader ();
374
+ header .setBrokerName ("broker" );
375
+ RemotingCommand request = RemotingCommand .createRequestCommand (code , header );
376
+ request .addExtField ("brokerName" , "broker" );
377
+ request .addExtField ("brokerAddr" , "10.10.1.1" );
378
+ request .addExtField ("clusterName" , "cluster" );
379
+ request .addExtField ("haServerAddr" , "10.10.2.1" );
380
+ request .addExtField ("brokerId" , "2333" );
381
+ request .addExtField ("topic" , "unit-test" );
382
+ return request ;
383
+ }
384
+
238
385
private static RemotingCommand genSampleRegisterCmd (boolean reg ) {
239
386
RegisterBrokerRequestHeader header = new RegisterBrokerRequestHeader ();
240
387
header .setBrokerName ("broker" );
@@ -268,7 +415,7 @@ private void registerRouteInfoManager() {
268
415
topicConfigConcurrentHashMap .put ("unit-test" , topicConfig );
269
416
topicConfigSerializeWrapper .setTopicConfigTable (topicConfigConcurrentHashMap );
270
417
Channel channel = mock (Channel .class );
271
- RegisterBrokerResult registerBrokerResult = routeInfoManager .registerBroker ("default-cluster" , "127.0.0.1:10911" , "default-broker" , 1234 , "127.0.0.1:1001" ,
418
+ RegisterBrokerResult registerBrokerResult = routeInfoManager .registerBroker ("default-cluster" , "127.0.0.1:10911" , "default-broker" , 0 , "127.0.0.1:1001" ,
272
419
topicConfigSerializeWrapper , new ArrayList <String >(), channel );
273
420
274
421
}
0 commit comments