MCPcopy
hub / github.com/IBM/sarama / TestClientMetadata

Function TestClientMetadata

client_test.go:160–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func TestClientMetadata(t *testing.T) {
161 seedBroker := NewMockBroker(t, 1)
162 leader := NewMockBroker(t, 5)
163
164 replicas := []int32{3, 1, 5}
165 isr := []int32{5, 1}
166
167 metadataResponse := new(MetadataResponse)
168 metadataResponse.AddBroker(leader.Addr(), leader.BrokerID())
169 metadataResponse.AddTopicPartition("my_topic", 0, leader.BrokerID(), replicas, isr, []int32{}, ErrNoError)
170 metadataResponse.AddTopicPartition("my_topic", 1, leader.BrokerID(), replicas, isr, []int32{}, ErrLeaderNotAvailable)
171 seedBroker.Returns(metadataResponse)
172
173 config := NewTestConfig()
174 config.Metadata.Retry.Max = 0
175 client, err := NewClient([]string{seedBroker.Addr()}, config)
176 if err != nil {
177 t.Fatal(err)
178 }
179
180 topics, err := client.Topics()
181 if err != nil {
182 t.Error(err)
183 } else if len(topics) != 1 || topics[0] != "my_topic" {
184 t.Error("Client returned incorrect topics:", topics)
185 }
186
187 parts, err := client.Partitions("my_topic")
188 if err != nil {
189 t.Error(err)
190 } else if len(parts) != 2 || parts[0] != 0 || parts[1] != 1 {
191 t.Error("Client returned incorrect partitions for my_topic:", parts)
192 }
193
194 parts, err = client.WritablePartitions("my_topic")
195 if err != nil {
196 t.Error(err)
197 } else if len(parts) != 1 || parts[0] != 0 {
198 t.Error("Client returned incorrect writable partitions for my_topic:", parts)
199 }
200
201 tst, err := client.Leader("my_topic", 0)
202 if err != nil {
203 t.Error(err)
204 } else if tst.ID() != 5 {
205 t.Error("Leader for my_topic had incorrect ID.")
206 }
207
208 replicas, err = client.Replicas("my_topic", 0)
209 if err != nil {
210 t.Error(err)
211 } else if replicas[0] != 3 {
212 t.Error("Incorrect (or sorted) replica")
213 } else if replicas[1] != 1 {
214 t.Error("Incorrect (or sorted) replica")
215 } else if replicas[2] != 5 {
216 t.Error("Incorrect (or sorted) replica")
217 }

Callers

nothing calls this directly

Calls 15

AddrMethod · 0.95
BrokerIDMethod · 0.95
ReturnsMethod · 0.95
TopicsMethod · 0.95
PartitionsMethod · 0.95
WritablePartitionsMethod · 0.95
LeaderMethod · 0.95
ReplicasMethod · 0.95
InSyncReplicasMethod · 0.95
CloseMethod · 0.95
NewMockBrokerFunction · 0.85
AddBrokerMethod · 0.80

Tested by

no test coverage detected