(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestClientDoesntCachePartitionsForTopicsWithErrors(t *testing.T) { |
| 89 | seedBroker := NewMockBroker(t, 1) |
| 90 | |
| 91 | replicas := []int32{seedBroker.BrokerID()} |
| 92 | |
| 93 | metadataResponse := new(MetadataResponse) |
| 94 | metadataResponse.AddBroker(seedBroker.Addr(), seedBroker.BrokerID()) |
| 95 | metadataResponse.AddTopicPartition("my_topic", 1, replicas[0], replicas, replicas, []int32{}, ErrNoError) |
| 96 | metadataResponse.AddTopicPartition("my_topic", 2, replicas[0], replicas, replicas, []int32{}, ErrNoError) |
| 97 | seedBroker.Returns(metadataResponse) |
| 98 | |
| 99 | config := NewTestConfig() |
| 100 | config.Metadata.Retry.Max = 0 |
| 101 | client, err := NewClient([]string{seedBroker.Addr()}, config) |
| 102 | if err != nil { |
| 103 | t.Fatal(err) |
| 104 | } |
| 105 | |
| 106 | metadataResponse = new(MetadataResponse) |
| 107 | metadataResponse.AddBroker(seedBroker.Addr(), seedBroker.BrokerID()) |
| 108 | metadataResponse.AddTopic("unknown", ErrUnknownTopicOrPartition) |
| 109 | seedBroker.Returns(metadataResponse) |
| 110 | |
| 111 | partitions, err := client.Partitions("unknown") |
| 112 | |
| 113 | if !errors.Is(err, ErrUnknownTopicOrPartition) { |
| 114 | t.Error("Expected ErrUnknownTopicOrPartition, found", err) |
| 115 | } |
| 116 | if partitions != nil { |
| 117 | t.Errorf("Should return nil as partition list, found %v", partitions) |
| 118 | } |
| 119 | |
| 120 | // Should still use the cache of a known topic |
| 121 | _, err = client.Partitions("my_topic") |
| 122 | if err != nil { |
| 123 | t.Errorf("Expected no error, found %v", err) |
| 124 | } |
| 125 | |
| 126 | metadataResponse = new(MetadataResponse) |
| 127 | metadataResponse.AddBroker(seedBroker.Addr(), seedBroker.BrokerID()) |
| 128 | metadataResponse.AddTopic("unknown", ErrUnknownTopicOrPartition) |
| 129 | seedBroker.Returns(metadataResponse) |
| 130 | |
| 131 | // Should not use cache for unknown topic |
| 132 | partitions, err = client.Partitions("unknown") |
| 133 | if !errors.Is(err, ErrUnknownTopicOrPartition) { |
| 134 | t.Error("Expected ErrUnknownTopicOrPartition, found", err) |
| 135 | } |
| 136 | if partitions != nil { |
| 137 | t.Errorf("Should return nil as partition list, found %v", partitions) |
| 138 | } |
| 139 | |
| 140 | seedBroker.Close() |
| 141 | safeClose(t, client) |
| 142 | } |
| 143 | |
| 144 | func TestClientSeedBrokers(t *testing.T) { |
| 145 | seedBroker := NewMockBroker(t, 1) |
nothing calls this directly
no test coverage detected