Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CreateTopic method to MockCluster #1047

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions kafka/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ func (mc *MockCluster) SetRoundtripDuration(brokerID int, duration time.Duration
return nil
}

// CreateTopic creates a topic without having to use a producer
func (mc *MockCluster) CreateTopic(topic string, partitons, replicationFactor int) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: partitons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed - thank you!

topicStr := C.CString(topic)
defer C.free(unsafe.Pointer(topicStr))

cError := C.rd_kafka_mock_topic_create(mc.mcluster, topicStr, C.int(partitons), C.int(replicationFactor))
if cError != C.RD_KAFKA_RESP_ERR_NO_ERROR {
return newError(cError)
}
return nil
}

// Close and destroy the MockCluster
func (mc *MockCluster) Close() {
C.rd_kafka_mock_cluster_destroy(mc.mcluster)
Expand Down