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

Function newMockTxnManager

transaction_manager_test.go:446–465  ·  view source on GitHub ↗

newMockTxnManager wires a transaction manager to broker using the standard metadata, find-coordinator and init-producer-id handshake. The caller owns closing the returned client.

(t *testing.T, broker *MockBroker, config *Config)

Source from the content-addressed store, hash-verified

444// metadata, find-coordinator and init-producer-id handshake. The caller owns
445// closing the returned client.
446func newMockTxnManager(t *testing.T, broker *MockBroker, config *Config) (Client, *transactionManager) {
447 // the mock broker matches each response version to the request version, so
448 // MetadataResponse.Version is left at its zero value here
449 metadataLeader := new(MetadataResponse)
450 metadataLeader.ControllerID = broker.brokerID
451 metadataLeader.AddBroker(broker.Addr(), broker.BrokerID())
452 metadataLeader.AddTopic("test-topic", ErrNoError)
453 metadataLeader.AddTopicPartition("test-topic", 0, broker.BrokerID(), nil, nil, nil, ErrNoError)
454 broker.Returns(metadataLeader)
455
456 client, err := NewClient([]string{broker.Addr()}, config)
457 require.NoError(t, err)
458
459 broker.Returns(&FindCoordinatorResponse{Coordinator: client.Brokers()[0], Err: ErrNoError})
460 broker.Returns(&InitProducerIDResponse{Err: ErrNoError, ProducerID: 1, ProducerEpoch: 0})
461
462 txmng, err := newTransactionManager(config, client)
463 require.NoError(t, err)
464 return client, txmng
465}
466
467func TestTxnOffsetCommitGroupMetadata(t *testing.T) {
468 broker := NewMockBroker(t, 1)

Callers 6

TestAddOffsetsToTxnFunction · 0.85
TestTxnOffsetsCommitFunction · 0.85
TestEndTxnFunction · 0.85

Calls 9

BrokersMethod · 0.95
newTransactionManagerFunction · 0.85
AddBrokerMethod · 0.80
BrokerIDMethod · 0.80
AddTopicMethod · 0.80
ReturnsMethod · 0.80
NewClientFunction · 0.70
AddrMethod · 0.45
AddTopicPartitionMethod · 0.45

Tested by

no test coverage detected