github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/alterpartitionreassignments_test.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "testing" 6 7 ktesting "github.com/segmentio/kafka-go/testing" 8 ) 9 10 func TestClientAlterPartitionReassignments(t *testing.T) { 11 if !ktesting.KafkaIsAtLeast("2.4.0") { 12 return 13 } 14 15 ctx := context.Background() 16 client, shutdown := newLocalClient() 17 defer shutdown() 18 19 topic := makeTopic() 20 createTopic(t, topic, 2) 21 defer deleteTopic(t, topic) 22 23 // Local kafka only has 1 broker, so any partition reassignments are really no-ops. 24 resp, err := client.AlterPartitionReassignments( 25 ctx, 26 &AlterPartitionReassignmentsRequest{ 27 Topic: topic, 28 Assignments: []AlterPartitionReassignmentsRequestAssignment{ 29 { 30 PartitionID: 0, 31 BrokerIDs: []int{1}, 32 }, 33 { 34 PartitionID: 1, 35 BrokerIDs: []int{1}, 36 }, 37 }, 38 }, 39 ) 40 41 if err != nil { 42 t.Fatal(err) 43 } 44 if resp.Error != nil { 45 t.Error( 46 "Unexpected error in response", 47 "expected", nil, 48 "got", resp.Error, 49 ) 50 } 51 if len(resp.PartitionResults) != 2 { 52 t.Error( 53 "Unexpected length of partition results", 54 "expected", 2, 55 "got", len(resp.PartitionResults), 56 ) 57 } 58 } 59 60 func TestClientAlterPartitionReassignmentsMultiTopics(t *testing.T) { 61 if !ktesting.KafkaIsAtLeast("2.4.0") { 62 return 63 } 64 65 ctx := context.Background() 66 client, shutdown := newLocalClient() 67 defer shutdown() 68 69 topic1 := makeTopic() 70 topic2 := makeTopic() 71 createTopic(t, topic1, 2) 72 createTopic(t, topic2, 2) 73 defer func() { 74 deleteTopic(t, topic1) 75 deleteTopic(t, topic2) 76 }() 77 78 // Local kafka only has 1 broker, so any partition reassignments are really no-ops. 79 resp, err := client.AlterPartitionReassignments( 80 ctx, 81 &AlterPartitionReassignmentsRequest{ 82 Assignments: []AlterPartitionReassignmentsRequestAssignment{ 83 { 84 Topic: topic1, 85 PartitionID: 0, 86 BrokerIDs: []int{1}, 87 }, 88 { 89 Topic: topic1, 90 PartitionID: 1, 91 BrokerIDs: []int{1}, 92 }, 93 { 94 Topic: topic2, 95 PartitionID: 0, 96 BrokerIDs: []int{1}, 97 }, 98 }, 99 }, 100 ) 101 102 if err != nil { 103 t.Fatal(err) 104 } 105 if resp.Error != nil { 106 t.Error( 107 "Unexpected error in response", 108 "expected", nil, 109 "got", resp.Error, 110 ) 111 } 112 if len(resp.PartitionResults) != 3 { 113 t.Error( 114 "Unexpected length of partition results", 115 "expected", 3, 116 "got", len(resp.PartitionResults), 117 ) 118 } 119 }