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

Function TestClientReceivingUnknownTopicWithBackoffFunc

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

Source from the content-addressed store, hash-verified

369}
370
371func TestClientReceivingUnknownTopicWithBackoffFunc(t *testing.T) {
372 seedBroker := NewMockBroker(t, 1)
373
374 metadataResponse1 := new(MetadataResponse)
375 metadataResponse1.AddBroker(seedBroker.Addr(), seedBroker.BrokerID())
376 seedBroker.Returns(metadataResponse1)
377
378 var retryCount atomic.Int32
379
380 config := NewTestConfig()
381 config.Metadata.Retry.Max = 1
382 config.Metadata.Retry.BackoffFunc = func(retries, maxRetries int) time.Duration {
383 retryCount.Add(1)
384 return 0
385 }
386 client, err := NewClient([]string{seedBroker.Addr()}, config)
387 if err != nil {
388 t.Fatal(err)
389 }
390
391 metadataUnknownTopic := new(MetadataResponse)
392 metadataUnknownTopic.AddTopic("new_topic", ErrUnknownTopicOrPartition)
393 metadataUnknownTopic.AddBroker(seedBroker.Addr(), seedBroker.BrokerID())
394 seedBroker.Returns(metadataUnknownTopic)
395 seedBroker.Returns(metadataUnknownTopic)
396
397 if err := client.RefreshMetadata("new_topic"); !errors.Is(err, ErrUnknownTopicOrPartition) {
398 t.Error("ErrUnknownTopicOrPartition expected, got", err)
399 }
400
401 safeClose(t, client)
402 seedBroker.Close()
403
404 actualRetryCount := retryCount.Load()
405 if actualRetryCount != 1 {
406 t.Fatalf("Expected BackoffFunc to be called exactly once, but saw %d", actualRetryCount)
407 }
408}
409
410func TestClientReceivingUnknownTopic(t *testing.T) {
411 seedBroker := NewMockBroker(t, 1)

Callers

nothing calls this directly

Calls 15

AddrMethod · 0.95
BrokerIDMethod · 0.95
ReturnsMethod · 0.95
RefreshMetadataMethod · 0.95
CloseMethod · 0.95
NewMockBrokerFunction · 0.85
AddBrokerMethod · 0.80
FatalMethod · 0.80
AddTopicMethod · 0.80
IsMethod · 0.80
FatalfMethod · 0.80
NewTestConfigFunction · 0.70

Tested by

no test coverage detected