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

Function TestSyncProducerFailTxn

mocks/sync_producer_test.go:60–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func TestSyncProducerFailTxn(t *testing.T) {
61 config := NewTestConfig()
62 config.Producer.Transaction.ID = "test"
63 config.Producer.RequiredAcks = sarama.WaitForAll
64 config.Producer.Retry.Backoff = 0
65 config.Producer.Idempotent = true
66 config.Net.MaxOpenRequests = 1
67 config.Version = sarama.V0_11_0_0
68
69 tfm := newTestReporterMock()
70
71 sp := NewSyncProducer(tfm, config)
72 defer func() {
73 if err := sp.Close(); err != nil {
74 t.Error(err)
75 }
76 }()
77
78 msg := &sarama.ProducerMessage{Topic: "test", Value: sarama.StringEncoder("test")}
79
80 _, _, err := sp.SendMessage(msg)
81 if err == nil {
82 t.Errorf("must have failed with txn begin error")
83 }
84
85 if len(tfm.errors) != 1 {
86 t.Errorf("must have failed with txn begin error")
87 }
88}
89
90func TestSyncProducerUseTxn(t *testing.T) {
91 config := NewTestConfig()

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
SendMessageMethod · 0.95
StringEncoderTypeAlias · 0.92
newTestReporterMockFunction · 0.85
NewTestConfigFunction · 0.70
NewSyncProducerFunction · 0.70
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected