From a98d26e55ab5cf5abe4cda2caf67b6c9bb565d86 Mon Sep 17 00:00:00 2001 From: Ladislav Macoun Date: Tue, 1 Feb 2022 13:55:31 +0100 Subject: [PATCH 1/4] Replace deprecated zookeeper flag with bootstrap Fixes: #3699 Signed-off-by: Ladislav Macoun --- tests/test.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test.c b/tests/test.c index 399a967372..ca999a43e9 100644 --- a/tests/test.c +++ b/tests/test.c @@ -4507,17 +4507,18 @@ void test_kafka_topics(const char *fmt, ...) { int r; va_list ap; test_timing_t t_cmd; - const char *kpath, *zk; + const char *kpath, *brokers; kpath = test_getenv("KAFKA_PATH", NULL); - zk = test_getenv("ZK_ADDRESS", NULL); + brokers = test_getenv("BROKERS", NULL); - if (!kpath || !zk) - TEST_FAIL("%s: KAFKA_PATH and ZK_ADDRESS must be set", + if (!kpath || !brokers) + TEST_FAIL("%s: KAFKA_PATH and BROKERS must be set", __FUNCTION__); r = rd_snprintf(cmd, sizeof(cmd), - "%s/bin/kafka-topics.sh --zookeeper %s ", kpath, zk); + "%s/bin/kafka-topics.sh --bootstrap-server %s ", + kpath, brokers); TEST_ASSERT(r < (int)sizeof(cmd)); va_start(ap, fmt); @@ -5164,7 +5165,7 @@ void test_report_add(struct test *test, const char *fmt, ...) { } /** - * Returns 1 if KAFKA_PATH and ZK_ADDRESS is set to se we can use the + * Returns 1 if KAFKA_PATH and BROKERS is set to se we can use the * kafka-topics.sh script to manually create topics. * * If \p skip is set TEST_SKIP() will be called with a helpful message. @@ -5181,11 +5182,11 @@ int test_can_create_topics(int skip) { #else if (!test_getenv("KAFKA_PATH", NULL) || - !test_getenv("ZK_ADDRESS", NULL)) { + !test_getenv("BROKERS", NULL)) { if (skip) TEST_SKIP( "Cannot create topics " - "(set KAFKA_PATH and ZK_ADDRESS)\n"); + "(set KAFKA_PATH and BROKERS)\n"); return 0; } From 7a8b07cba644c03d137efead09947c3d484a086a Mon Sep 17 00:00:00 2001 From: Ladislav Macoun Date: Tue, 1 Feb 2022 18:00:23 +0100 Subject: [PATCH 2/4] Add backwards compatibility Signed-off-by: Ladislav Macoun --- tests/test.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/test.c b/tests/test.c index ca999a43e9..53927be0a9 100644 --- a/tests/test.c +++ b/tests/test.c @@ -4507,18 +4507,26 @@ void test_kafka_topics(const char *fmt, ...) { int r; va_list ap; test_timing_t t_cmd; - const char *kpath, *brokers; + const char *kpath, *bootstrap_env, *flag, *bootstrap_srvs; + + if (test_broker_version >= TEST_BRKVER(3, 0, 0, 0)) { + bootstrap_env = "BROKERS"; + flag = "--bootstrap-server"; + } else { + bootstrap_env = "ZK_ADDRESS"; + flag = "--zookeeper"; + } kpath = test_getenv("KAFKA_PATH", NULL); - brokers = test_getenv("BROKERS", NULL); + bootstrap_srvs = test_getenv(bootstrap_env, NULL); - if (!kpath || !brokers) - TEST_FAIL("%s: KAFKA_PATH and BROKERS must be set", - __FUNCTION__); + if (!kpath || !bootstrap_srvs) + TEST_FAIL("%s: KAFKA_PATH and %s must be set", + __FUNCTION__, bootstrap_env); r = rd_snprintf(cmd, sizeof(cmd), - "%s/bin/kafka-topics.sh --bootstrap-server %s ", - kpath, brokers); + "%s/bin/kafka-topics.sh %s %s ", + kpath, flag, bootstrap_srvs); TEST_ASSERT(r < (int)sizeof(cmd)); va_start(ap, fmt); @@ -5165,12 +5173,14 @@ void test_report_add(struct test *test, const char *fmt, ...) { } /** - * Returns 1 if KAFKA_PATH and BROKERS is set to se we can use the - * kafka-topics.sh script to manually create topics. + * Returns 1 if KAFKA_PATH and BROKERS (or ZK_ADDRESS) is set to se we can use + * the kafka-topics.sh script to manually create topics. * * If \p skip is set TEST_SKIP() will be called with a helpful message. */ int test_can_create_topics(int skip) { + const char *bootstrap; + /* Has AdminAPI */ if (test_broker_version >= TEST_BRKVER(0, 10, 2, 0)) return 1; @@ -5181,12 +5191,15 @@ int test_can_create_topics(int skip) { return 0; #else + bootstrap = test_broker_version >= TEST_BRKVER(3, 0, 0, 0) + ? "BROKERS" : "ZK_ADDRESS"; + if (!test_getenv("KAFKA_PATH", NULL) || - !test_getenv("BROKERS", NULL)) { + !test_getenv(bootstrap, NULL)) { if (skip) TEST_SKIP( "Cannot create topics " - "(set KAFKA_PATH and BROKERS)\n"); + "(set KAFKA_PATH and %s)\n", bootstrap); return 0; } From a2d16df23147fd251dd5b9ce7bb7e159321bb813 Mon Sep 17 00:00:00 2001 From: Ladislav Macoun Date: Tue, 1 Feb 2022 18:28:17 +0100 Subject: [PATCH 3/4] Add assertion for cmd fitting inside buffer Signed-off-by: Ladislav Macoun --- tests/test.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test.c b/tests/test.c index 53927be0a9..316b4e42e5 100644 --- a/tests/test.c +++ b/tests/test.c @@ -4504,7 +4504,7 @@ void test_kafka_topics(const char *fmt, ...) { TEST_FAIL("%s not supported on Windows, yet", __FUNCTION__); #else char cmd[512]; - int r; + int r, bytes_left; va_list ap; test_timing_t t_cmd; const char *kpath, *bootstrap_env, *flag, *bootstrap_srvs; @@ -4527,11 +4527,14 @@ void test_kafka_topics(const char *fmt, ...) { r = rd_snprintf(cmd, sizeof(cmd), "%s/bin/kafka-topics.sh %s %s ", kpath, flag, bootstrap_srvs); - TEST_ASSERT(r < (int)sizeof(cmd)); + TEST_ASSERT(r > 0 && r < (int)sizeof(cmd)); + + bytes_left = sizeof(cmd) - r; va_start(ap, fmt); - rd_vsnprintf(cmd + r, sizeof(cmd) - r, fmt, ap); + r = rd_vsnprintf(cmd + r, bytes_left, fmt, ap); va_end(ap); + TEST_ASSERT(r > 0 && r < bytes_left); TEST_SAY("Executing: %s\n", cmd); TIMING_START(&t_cmd, "exec"); From 33339cfd2a37464a2efe69ae7afe6a59a6a10890 Mon Sep 17 00:00:00 2001 From: Ladislav Macoun Date: Tue, 1 Feb 2022 19:20:46 +0100 Subject: [PATCH 4/4] Increase command buffer Signed-off-by: Ladislav Macoun --- tests/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.c b/tests/test.c index 316b4e42e5..48d96b4c3f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -4503,7 +4503,7 @@ void test_kafka_topics(const char *fmt, ...) { #ifdef _WIN32 TEST_FAIL("%s not supported on Windows, yet", __FUNCTION__); #else - char cmd[512]; + char cmd[1024]; int r, bytes_left; va_list ap; test_timing_t t_cmd;