MCPcopy
hub / github.com/segmentio/kafka-go / TestClientElectLeaders

Function TestClientElectLeaders

electleaders_test.go:10–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestClientElectLeaders(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 leader elections are no-ops.
24 resp, err := client.ElectLeaders(
25 ctx,
26 &ElectLeadersRequest{
27 Topic: topic,
28 Partitions: []int{0, 1},
29 },
30 )
31
32 if err != nil {
33 t.Fatal(err)
34 }
35 if resp.Error != nil {
36 t.Error(
37 "Unexpected error in response",
38 "expected", nil,
39 "got", resp.Error,
40 )
41 }
42 if len(resp.PartitionResults) != 2 {
43 t.Error(
44 "Unexpected length of partition results",
45 "expected", 2,
46 "got", len(resp.PartitionResults),
47 )
48 }
49}

Callers

nothing calls this directly

Calls 6

createTopicFunction · 0.85
deleteTopicFunction · 0.85
ElectLeadersMethod · 0.80
newLocalClientFunction · 0.70
makeTopicFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected