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