(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestClusterAdminCreateTopic(t *testing.T) { |
| 68 | seedBroker := NewMockBroker(t, 1) |
| 69 | defer seedBroker.Close() |
| 70 | |
| 71 | seedBroker.SetHandlerByMap(map[string]MockResponse{ |
| 72 | "MetadataRequest": NewMockMetadataResponse(t). |
| 73 | SetController(seedBroker.BrokerID()). |
| 74 | SetBroker(seedBroker.Addr(), seedBroker.BrokerID()), |
| 75 | "CreateTopicsRequest": NewMockCreateTopicsResponse(t), |
| 76 | }) |
| 77 | |
| 78 | config := NewTestConfig() |
| 79 | config.Version = V0_10_2_0 |
| 80 | admin, err := NewClusterAdmin([]string{seedBroker.Addr()}, config) |
| 81 | if err != nil { |
| 82 | t.Fatal(err) |
| 83 | } |
| 84 | err = admin.CreateTopic("my_topic", &TopicDetail{NumPartitions: 1, ReplicationFactor: 1}, false) |
| 85 | if err != nil { |
| 86 | t.Fatal(err) |
| 87 | } |
| 88 | |
| 89 | err = admin.Close() |
| 90 | if err != nil { |
| 91 | t.Fatal(err) |
| 92 | } |
| 93 | |
| 94 | t.Run("retries on the new controller after the controller stops", func(t *testing.T) { |
| 95 | b1 := NewMockBroker(t, 1) |
| 96 | b2 := NewMockBroker(t, 2) |
| 97 | t.Cleanup(b2.Close) |
| 98 | |
| 99 | var controllerID atomic.Int32 |
| 100 | controllerID.Store(b1.BrokerID()) |
| 101 | meta := func(req *request) encoderWithHeader { |
| 102 | return NewMockMetadataResponse(t).SetController(controllerID.Load()). |
| 103 | SetBroker(b1.Addr(), b1.BrokerID()). |
| 104 | SetBroker(b2.Addr(), b2.BrokerID()).For(req.body) |
| 105 | } |
| 106 | b1.SetHandlerFuncByMap(map[string]requestHandlerFunc{"MetadataRequest": meta}) |
| 107 | b2.SetHandlerFuncByMap(map[string]requestHandlerFunc{ |
| 108 | "MetadataRequest": meta, |
| 109 | "CreateTopicsRequest": func(req *request) encoderWithHeader { |
| 110 | return NewMockCreateTopicsResponse(t).For(req.body) |
| 111 | }, |
| 112 | }) |
| 113 | |
| 114 | config := NewTestConfig() |
| 115 | config.Version = V0_10_2_0 |
| 116 | config.Admin.Retry.Backoff = time.Millisecond |
| 117 | admin, err := NewClusterAdmin([]string{b1.Addr()}, config) |
| 118 | require.NoError(t, err) |
| 119 | t.Cleanup(func() { _ = admin.Close() }) |
| 120 | |
| 121 | // broker 1 goes away with the admin connected to it as the controller |
| 122 | controllerID.Store(b2.BrokerID()) |
| 123 | b1.Close() |
| 124 |
nothing calls this directly
no test coverage detected