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

Function TestConnCreateTopics

createtopics_test.go:14–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestConnCreateTopics(t *testing.T) {
15 topic1 := makeTopic()
16 topic2 := makeTopic()
17
18 conn, err := DialContext(context.Background(), "tcp", "localhost:9092")
19 if err != nil {
20 t.Fatal(err)
21 }
22
23 defer func() {
24 err := conn.Close()
25 if err != nil {
26 t.Fatalf("failed to close connection: %v", err)
27 }
28 }()
29
30 controller, _ := conn.Controller()
31
32 controllerConn, err := Dial("tcp", net.JoinHostPort(controller.Host, strconv.Itoa(controller.Port)))
33 if err != nil {
34 t.Fatal(err)
35 }
36 defer controllerConn.Close()
37
38 err = controllerConn.CreateTopics(TopicConfig{
39 Topic: topic1,
40 NumPartitions: 1,
41 ReplicationFactor: 1,
42 })
43 if err != nil {
44 t.Fatalf("unexpected error creating topic: %s", err.Error())
45 }
46
47 err = controllerConn.CreateTopics(TopicConfig{
48 Topic: topic1,
49 NumPartitions: 1,
50 ReplicationFactor: 1,
51 })
52
53 // Duplicate topic should not return an error
54 if err != nil {
55 t.Fatalf("unexpected error creating duplicate topic topic: %v", err)
56 }
57
58 err = controllerConn.CreateTopics(
59 TopicConfig{
60 Topic: topic1,
61 NumPartitions: 1,
62 ReplicationFactor: 1,
63 },
64 TopicConfig{
65 Topic: topic2,
66 NumPartitions: 1,
67 ReplicationFactor: 1,
68 },
69 TopicConfig{
70 Topic: topic2,
71 NumPartitions: 1,

Callers

nothing calls this directly

Calls 8

DialContextFunction · 0.85
DialFunction · 0.85
deleteTopicFunction · 0.85
ControllerMethod · 0.80
makeTopicFunction · 0.70
CloseMethod · 0.45
CreateTopicsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected