diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fef94a09..e580e8be5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,11 @@ # v2.3.0 -This is a maintenance release. - -## Fixes +This is a feature release. * Fixes a bug in the mock schema registry client where the wrong ID was being returned for pre-registered schema (#971, @srlk). + * Adds `CreateTopic` method to the MockCluster. (#1047, @mimikwang). # v2.2.0 diff --git a/kafka/mockcluster.go b/kafka/mockcluster.go index 08bef23e9..cb395f930 100644 --- a/kafka/mockcluster.go +++ b/kafka/mockcluster.go @@ -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, partitions, replicationFactor int) error { + topicStr := C.CString(topic) + defer C.free(unsafe.Pointer(topicStr)) + + cError := C.rd_kafka_mock_topic_create(mc.mcluster, topicStr, C.int(partitions), 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)