(t *testing.T)
| 233 | } |
| 234 | |
| 235 | func TestClientMetadataWithOfflineReplicas(t *testing.T) { |
| 236 | seedBroker := NewMockBroker(t, 1) |
| 237 | leader := NewMockBroker(t, 5) |
| 238 | |
| 239 | replicas := []int32{1, 2, 3} |
| 240 | isr := []int32{1, 2} |
| 241 | offlineReplicas := []int32{3} |
| 242 | |
| 243 | metadataResponse := new(MetadataResponse) |
| 244 | metadataResponse.AddBroker(leader.Addr(), leader.BrokerID()) |
| 245 | metadataResponse.AddTopicPartition("my_topic", 0, leader.BrokerID(), replicas, isr, offlineReplicas, ErrNoError) |
| 246 | metadataResponse.AddTopicPartition("my_topic", 1, leader.BrokerID(), replicas, isr, []int32{}, ErrNoError) |
| 247 | metadataResponse.Version = 5 |
| 248 | |
| 249 | seedBroker.Returns(metadataResponse) |
| 250 | |
| 251 | config := NewTestConfig() |
| 252 | config.Version = V1_0_0_0 |
| 253 | config.Metadata.Retry.Max = 0 |
| 254 | client, err := NewClient([]string{seedBroker.Addr()}, config) |
| 255 | if err != nil { |
| 256 | t.Fatal(err) |
| 257 | } |
| 258 | |
| 259 | topics, err := client.Topics() |
| 260 | if err != nil { |
| 261 | t.Error(err) |
| 262 | } else if len(topics) != 1 || topics[0] != "my_topic" { |
| 263 | t.Error("Client returned incorrect topics:", topics) |
| 264 | } |
| 265 | |
| 266 | parts, err := client.Partitions("my_topic") |
| 267 | if err != nil { |
| 268 | t.Error(err) |
| 269 | } else if len(parts) != 2 || parts[0] != 0 || parts[1] != 1 { |
| 270 | t.Error("Client returned incorrect partitions for my_topic:", parts) |
| 271 | } |
| 272 | |
| 273 | parts, err = client.WritablePartitions("my_topic") |
| 274 | if err != nil { |
| 275 | t.Error(err) |
| 276 | } else if len(parts) != 2 { |
| 277 | t.Error("Client returned incorrect writable partitions for my_topic:", parts) |
| 278 | } |
| 279 | |
| 280 | tst, err := client.Leader("my_topic", 0) |
| 281 | if err != nil { |
| 282 | t.Error(err) |
| 283 | } else if tst.ID() != 5 { |
| 284 | t.Error("Leader for my_topic had incorrect ID.") |
| 285 | } |
| 286 | |
| 287 | replicas, err = client.Replicas("my_topic", 0) |
| 288 | if err != nil { |
| 289 | t.Error(err) |
| 290 | } else if replicas[0] != 1 { |
| 291 | t.Error("Incorrect (or sorted) replica") |
| 292 | } else if replicas[1] != 2 { |
nothing calls this directly
no test coverage detected