mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-16 17:54:50 +00:00
Allow to pass-in via cmake all the kafka config options for testing: broker, partitions and topics
This commit is contained in:
@@ -1,12 +1,34 @@
|
|||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/)
|
||||||
include_directories(SYSTEM ${CATCH_INCLUDE})
|
include_directories(SYSTEM ${CATCH_INCLUDE})
|
||||||
|
|
||||||
set(KAFKA_TEST_INSTANCE "kafka-vm:9092"
|
if (NOT KAFKA_TEST_INSTANCE)
|
||||||
|
set(KAFKA_TEST_INSTANCE kafka-vm:9092
|
||||||
CACHE STRING "The kafka instance to which to connect to run tests")
|
CACHE STRING "The kafka instance to which to connect to run tests")
|
||||||
|
endif()
|
||||||
|
if (NOT KAFKA_NUM_PARTITIONS)
|
||||||
|
set(KAFKA_NUM_PARTITIONS 3 CACHE STRING "Kafka Number of partitions")
|
||||||
|
endif()
|
||||||
|
if (NOT KAFKA_TOPICS)
|
||||||
|
set(KAFKA_TOPICS "cppkafka_test1;cppkafka_test2" CACHE STRING "Kafka topics")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Convert list of topics into a C++ initializer list
|
||||||
|
FOREACH(TOPIC ${KAFKA_TOPICS})
|
||||||
|
if (NOT TOPIC_LIST)
|
||||||
|
set(TOPIC_LIST "\"${TOPIC}\"")
|
||||||
|
else()
|
||||||
|
set(TOPIC_LIST "${TOPIC_LIST},\"${TOPIC}\"")
|
||||||
|
endif()
|
||||||
|
ENDFOREACH()
|
||||||
|
|
||||||
add_custom_target(tests)
|
add_custom_target(tests)
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
add_definitions("-DKAFKA_TEST_INSTANCE=\"${KAFKA_TEST_INSTANCE}\"")
|
add_definitions(
|
||||||
|
"-DKAFKA_TEST_INSTANCE=\"${KAFKA_TEST_INSTANCE}\""
|
||||||
|
-DKAFKA_NUM_PARTITIONS=${KAFKA_NUM_PARTITIONS}
|
||||||
|
-DKAFKA_TOPIC_NAMES=${TOPIC_LIST}
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(cppkafka_tests
|
add_executable(cppkafka_tests
|
||||||
buffer_test.cpp
|
buffer_test.cpp
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ using Catch::TestCaseStats;
|
|||||||
using Catch::Totals;
|
using Catch::Totals;
|
||||||
using Catch::Session;
|
using Catch::Session;
|
||||||
|
|
||||||
std::vector<std::string> KAFKA_TOPICS = {"cppkafka_test1", "cppkafka_test2"};
|
std::vector<std::string> KAFKA_TOPICS = {KAFKA_TOPIC_NAMES};
|
||||||
int KAFKA_NUM_PARTITIONS = 3;
|
|
||||||
|
|
||||||
namespace cppkafka {
|
namespace cppkafka {
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "cppkafka/utils/consumer_dispatcher.h"
|
#include "cppkafka/utils/consumer_dispatcher.h"
|
||||||
|
|
||||||
extern const std::vector<std::string> KAFKA_TOPICS;
|
extern const std::vector<std::string> KAFKA_TOPICS;
|
||||||
extern const int KAFKA_NUM_PARTITIONS;
|
|
||||||
|
|
||||||
using namespace cppkafka;
|
using namespace cppkafka;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user