@@ -332,6 +332,167 @@ func TestClusterAdminCreatePartitionsWithoutAuthorization(t *testing.T) {
332
332
}
333
333
}
334
334
335
+ func TestClusterAdminAlterPartitionReassignments (t * testing.T ) {
336
+ seedBroker := NewMockBroker (t , 1 )
337
+ defer seedBroker .Close ()
338
+
339
+ secondBroker := NewMockBroker (t , 2 )
340
+ defer secondBroker .Close ()
341
+
342
+ seedBroker .SetHandlerByMap (map [string ]MockResponse {
343
+ "MetadataRequest" : NewMockMetadataResponse (t ).
344
+ SetController (secondBroker .BrokerID ()).
345
+ SetBroker (seedBroker .Addr (), seedBroker .BrokerID ()).
346
+ SetBroker (secondBroker .Addr (), secondBroker .BrokerID ()),
347
+ })
348
+
349
+ secondBroker .SetHandlerByMap (map [string ]MockResponse {
350
+ "AlterPartitionReassignmentsRequest" : NewMockAlterPartitionReassignmentsResponse (t ),
351
+ })
352
+
353
+ config := NewConfig ()
354
+ config .Version = V2_4_0_0
355
+ admin , err := NewClusterAdmin ([]string {seedBroker .Addr ()}, config )
356
+ if err != nil {
357
+ t .Fatal (err )
358
+ }
359
+
360
+ var topicAssignment = make ([][]int32 , 0 , 3 )
361
+
362
+ err = admin .AlterPartitionReassignments ("my_topic" , topicAssignment )
363
+ if err != nil {
364
+ t .Fatal (err )
365
+ }
366
+
367
+ err = admin .Close ()
368
+ if err != nil {
369
+ t .Fatal (err )
370
+ }
371
+ }
372
+
373
+ func TestClusterAdminAlterPartitionReassignmentsWithDiffVersion (t * testing.T ) {
374
+ seedBroker := NewMockBroker (t , 1 )
375
+ defer seedBroker .Close ()
376
+
377
+ secondBroker := NewMockBroker (t , 2 )
378
+ defer secondBroker .Close ()
379
+
380
+ seedBroker .SetHandlerByMap (map [string ]MockResponse {
381
+ "MetadataRequest" : NewMockMetadataResponse (t ).
382
+ SetController (secondBroker .BrokerID ()).
383
+ SetBroker (seedBroker .Addr (), seedBroker .BrokerID ()).
384
+ SetBroker (secondBroker .Addr (), secondBroker .BrokerID ()),
385
+ })
386
+
387
+ secondBroker .SetHandlerByMap (map [string ]MockResponse {
388
+ "AlterPartitionReassignmentsRequest" : NewMockAlterPartitionReassignmentsResponse (t ),
389
+ })
390
+
391
+ config := NewConfig ()
392
+ config .Version = V2_3_0_0
393
+ admin , err := NewClusterAdmin ([]string {seedBroker .Addr ()}, config )
394
+ if err != nil {
395
+ t .Fatal (err )
396
+ }
397
+
398
+ var topicAssignment = make ([][]int32 , 0 , 3 )
399
+
400
+ err = admin .AlterPartitionReassignments ("my_topic" , topicAssignment )
401
+
402
+ if ! strings .ContainsAny (err .Error (), ErrUnsupportedVersion .Error ()) {
403
+ t .Fatal (err )
404
+ }
405
+
406
+ err = admin .Close ()
407
+ if err != nil {
408
+ t .Fatal (err )
409
+ }
410
+ }
411
+
412
+ func TestClusterAdminListPartitionReassignments (t * testing.T ) {
413
+ seedBroker := NewMockBroker (t , 1 )
414
+ defer seedBroker .Close ()
415
+
416
+ secondBroker := NewMockBroker (t , 2 )
417
+ defer secondBroker .Close ()
418
+
419
+ seedBroker .SetHandlerByMap (map [string ]MockResponse {
420
+ "MetadataRequest" : NewMockMetadataResponse (t ).
421
+ SetController (secondBroker .BrokerID ()).
422
+ SetBroker (seedBroker .Addr (), seedBroker .BrokerID ()).
423
+ SetBroker (secondBroker .Addr (), secondBroker .BrokerID ()),
424
+ })
425
+
426
+ secondBroker .SetHandlerByMap (map [string ]MockResponse {
427
+ "ListPartitionReassignmentsRequest" : NewMockListPartitionReassignmentsResponse (t ),
428
+ })
429
+
430
+ config := NewConfig ()
431
+ config .Version = V2_4_0_0
432
+ admin , err := NewClusterAdmin ([]string {seedBroker .Addr ()}, config )
433
+ if err != nil {
434
+ t .Fatal (err )
435
+ }
436
+
437
+ response , err := admin .ListPartitionReassignments ("my_topic" , []int32 {0 , 1 })
438
+ if err != nil {
439
+ t .Fatal (err )
440
+ }
441
+
442
+ partitionStatus , ok := response ["my_topic" ]
443
+ if ! ok {
444
+ t .Fatalf ("topic missing in response" )
445
+ } else {
446
+ if len (partitionStatus ) != 2 {
447
+ t .Fatalf ("partition missing in response" )
448
+ }
449
+ }
450
+
451
+ err = admin .Close ()
452
+ if err != nil {
453
+ t .Fatal (err )
454
+ }
455
+ }
456
+
457
+ func TestClusterAdminListPartitionReassignmentsWithDiffVersion (t * testing.T ) {
458
+ seedBroker := NewMockBroker (t , 1 )
459
+ defer seedBroker .Close ()
460
+
461
+ secondBroker := NewMockBroker (t , 2 )
462
+ defer secondBroker .Close ()
463
+
464
+ seedBroker .SetHandlerByMap (map [string ]MockResponse {
465
+ "MetadataRequest" : NewMockMetadataResponse (t ).
466
+ SetController (secondBroker .BrokerID ()).
467
+ SetBroker (seedBroker .Addr (), seedBroker .BrokerID ()).
468
+ SetBroker (secondBroker .Addr (), secondBroker .BrokerID ()),
469
+ })
470
+
471
+ secondBroker .SetHandlerByMap (map [string ]MockResponse {
472
+ "ListPartitionReassignmentsRequest" : NewMockListPartitionReassignmentsResponse (t ),
473
+ })
474
+
475
+ config := NewConfig ()
476
+ config .Version = V2_3_0_0
477
+ admin , err := NewClusterAdmin ([]string {seedBroker .Addr ()}, config )
478
+ if err != nil {
479
+ t .Fatal (err )
480
+ }
481
+
482
+ var partitions = make ([]int32 , 0 )
483
+
484
+ _ , err = admin .ListPartitionReassignments ("my_topic" , partitions )
485
+
486
+ if ! strings .ContainsAny (err .Error (), ErrUnsupportedVersion .Error ()) {
487
+ t .Fatal (err )
488
+ }
489
+
490
+ err = admin .Close ()
491
+ if err != nil {
492
+ t .Fatal (err )
493
+ }
494
+ }
495
+
335
496
func TestClusterAdminDeleteRecords (t * testing.T ) {
336
497
topicName := "my_topic"
337
498
seedBroker := NewMockBroker (t , 1 )
0 commit comments