memgraph/tests/unit/kafka_mock.hpp
János Benjamin Antal d6a6d280dd Add Streams on top of Kafka Consumer (#172)
* Stop the Consumer grafefully when it is destroyed

* Add Streams

* Add Streams to InterpreterContext

* Remove options to limit processed batches in Consumer

* Add Streams unit tests

* Stop waiting for a full batch if the Consumer stopped

* Add ReadLock functionality to Synchronized

* Use per Consumer-based locking

* Replace shared_mutex with RWLock
2021-07-07 15:57:36 +02:00

39 lines
1.1 KiB
C++

#pragma once
#include <memory>
#include <span>
#include <string>
#include <string_view>
#include <vector>
#include <librdkafka/rdkafka.h>
#include <librdkafka/rdkafka_mock.h>
#include <librdkafka/rdkafkacpp.h>
// Based on https://github.com/edenhill/librdkafka/issues/2693
namespace details {
struct RdKafkaDeleter {
void operator()(rd_kafka_t *rd);
};
struct RdKafkaMockClusterDeleter {
void operator()(rd_kafka_mock_cluster_t *rd);
};
} // namespace details
using RdKafkaUniquePtr = std::unique_ptr<rd_kafka_t, details::RdKafkaDeleter>;
using RdKafkaMockClusterUniquePtr = std::unique_ptr<rd_kafka_mock_cluster_t, details::RdKafkaMockClusterDeleter>;
class KafkaClusterMock {
public:
explicit KafkaClusterMock(const std::vector<std::string> &topics);
std::string Bootstraps() const;
void CreateTopic(const std::string &topic_name);
void SeedTopic(const std::string &topic_name, std::span<const char> message);
void SeedTopic(const std::string &topic_name, std::string_view message);
private:
RdKafkaUniquePtr rk_{nullptr};
RdKafkaMockClusterUniquePtr cluster_{nullptr};
};