#include <userver/kafka/utest/kafka_fixture.hpp>
Helper for Kafka unit testing.
KafkaCluster is useful for
KafkaCluster expects that topic names used in test are already exist in Kafka broker or auto-created on produce to it.
It is recommended to create all topics before tests started, because topic creation leads to disk IO operation and maybe too slow in tests' runtime.
If one run tests with Kafka testsuite plugin, use TESTSUITE_KAFKA_CUSTOM_TOPICS
environment variable to create topics before tests started.
TESTSUITE_KAFKA_SERVER_HOST
(by default localhost
) and TESTSUITE_KAFKA_SERVER_PORT
(by default 9099
) environment variables.Definition at line 56 of file kafka_fixture.hpp.
Public Member Functions | |
std::string | GenerateTopic () |
std::vector< std::string > | GenerateTopics (std::size_t count) |
impl::Configuration | MakeProducerConfiguration (const std::string &name, impl::ProducerConfiguration configuration={}, impl::Secret secrets={}) |
impl::Configuration | MakeConsumerConfiguration (const std::string &name, impl::ConsumerConfiguration configuration={}, impl::Secret secrets={}) |
Producer | MakeProducer (const std::string &name, impl::ProducerConfiguration configuration={}) |
std::deque< Producer > | MakeProducers (std::size_t count, std::function< std::string(std::size_t)> nameGenerator, impl::ProducerConfiguration configuration={}) |
void | SendMessages (utils::span< const Message > messages) |
Creates temporary producer and send messages span. | |
impl::Consumer | MakeConsumer (const std::string &name, const std::vector< std::string > &topics, impl::ConsumerConfiguration configuration={}, impl::ConsumerExecutionParams params={}) |
std::vector< Message > | ReceiveMessages (impl::Consumer &consumer, std::size_t expected_messages_count, bool commit_after_receive=true, std::optional< std::function< void(MessageBatchView)> > user_callback={}) |
Starts consumer, waits until expected_message_count messages are consumed, calls user_callback if set, stops consumer. | |
Static Public Attributes | |
static constexpr const std::chrono::milliseconds | kDefaultTestProducerTimeout |
|
staticconstexpr |
Kafka broker has some cold start issues on its. To stabilize tests KafkaCluster patches producer's default delivery timeout. To use custom delivery timeout in test, pass configuration
argument to MakeProducer.
Definition at line 62 of file kafka_fixture.hpp.