diff options
author | abcdef <akotov@ydb.tech> | 2023-07-06 18:42:53 +0300 |
---|---|---|
committer | abcdef <akotov@ydb.tech> | 2023-07-06 18:42:53 +0300 |
commit | 8f4f6d0694064b02f553612f24dbb0bd57901fc5 (patch) | |
tree | 87140510b1ae8bcc9fe57d97ae93c877d9dfac50 | |
parent | 5d1f1a59dee5baebd1e19d7c3777b382010326a5 (diff) | |
download | ydb-8f4f6d0694064b02f553612f24dbb0bd57901fc5.tar.gz |
environment variable `YDB_CLI_BINARY`
в тестах используется переменная окружения YDB_CLI_BINARY
-rw-r--r-- | ydb/apps/ydb/ut/CMakeLists.linux-aarch64.txt | 1 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/CMakeLists.linux-x86_64.txt | 1 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/run_ydb.cpp | 41 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/run_ydb.h | 9 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/workload-topic.cpp | 44 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp | 39 | ||||
-rw-r--r-- | ydb/apps/ydb/ut/ya.make | 3 |
7 files changed, 75 insertions, 63 deletions
diff --git a/ydb/apps/ydb/ut/CMakeLists.linux-aarch64.txt b/ydb/apps/ydb/ut/CMakeLists.linux-aarch64.txt index e8a767d104..f6bfcce26e 100644 --- a/ydb/apps/ydb/ut/CMakeLists.linux-aarch64.txt +++ b/ydb/apps/ydb/ut/CMakeLists.linux-aarch64.txt @@ -29,6 +29,7 @@ target_link_options(ydb-apps-ydb-ut PRIVATE target_sources(ydb-apps-ydb-ut PRIVATE ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/workload-topic.cpp ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp + ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/run_ydb.cpp ) set_property( TARGET diff --git a/ydb/apps/ydb/ut/CMakeLists.linux-x86_64.txt b/ydb/apps/ydb/ut/CMakeLists.linux-x86_64.txt index e194688952..4ef3e88724 100644 --- a/ydb/apps/ydb/ut/CMakeLists.linux-x86_64.txt +++ b/ydb/apps/ydb/ut/CMakeLists.linux-x86_64.txt @@ -30,6 +30,7 @@ target_link_options(ydb-apps-ydb-ut PRIVATE target_sources(ydb-apps-ydb-ut PRIVATE ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/workload-topic.cpp ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp + ${CMAKE_SOURCE_DIR}/ydb/apps/ydb/ut/run_ydb.cpp ) set_property( TARGET diff --git a/ydb/apps/ydb/ut/run_ydb.cpp b/ydb/apps/ydb/ut/run_ydb.cpp new file mode 100644 index 0000000000..67d848f01a --- /dev/null +++ b/ydb/apps/ydb/ut/run_ydb.cpp @@ -0,0 +1,41 @@ +#include "run_ydb.h" + +#include <util/generic/yexception.h> +#include <util/system/shellcommand.h> +#include <util/system/env.h> + +#include <library/cpp/testing/common/env.h> + +TString GetYdbEndpoint() +{ + return GetEnv("YDB_ENDPOINT"); +} + +TString GetYdbDatabase() +{ + return GetEnv("YDB_DATABASE"); +} + +TString RunYdb(const TList<TString>& args1, const TList<TString>& args2) +{ + TShellCommand command(BinaryPath(GetEnv("YDB_CLI_BINARY"))); + + command << "-e" << ("grpc://" + GetYdbEndpoint()); + command << "-d" << ("/" + GetYdbDatabase()); + + for (auto& arg : args1) { + command << arg; + } + + for (auto& arg : args2) { + command << arg; + } + + command.Run().Wait(); + + if (command.GetExitCode() != 0) { + ythrow yexception() << "command `" << command.GetQuotedCommand() << "` exit with code " << command.GetExitCode(); + } + + return command.GetOutput(); +} diff --git a/ydb/apps/ydb/ut/run_ydb.h b/ydb/apps/ydb/ut/run_ydb.h new file mode 100644 index 0000000000..974a79ff87 --- /dev/null +++ b/ydb/apps/ydb/ut/run_ydb.h @@ -0,0 +1,9 @@ +#pragma once + +#include <util/generic/fwd.h> +#include <util/generic/list.h> + +TString GetYdbEndpoint(); +TString GetYdbDatabase(); + +TString RunYdb(const TList<TString>& args1, const TList<TString>& args2); diff --git a/ydb/apps/ydb/ut/workload-topic.cpp b/ydb/apps/ydb/ut/workload-topic.cpp index 056561dd13..a9bd5c8d74 100644 --- a/ydb/apps/ydb/ut/workload-topic.cpp +++ b/ydb/apps/ydb/ut/workload-topic.cpp @@ -1,3 +1,5 @@ +#include "run_ydb.h" + #include <library/cpp/testing/common/env.h> #include <library/cpp/testing/unittest/registar.h> @@ -10,28 +12,12 @@ Y_UNIT_TEST_SUITE(YdbWorkloadTopic) { -TString ExecYdbWorkloadTopic(TList<TString> args) +TString ExecYdb(const TList<TString>& args) { // // ydb -e grpc://${YDB_ENDPOINT} -d /${YDB_DATABASE} workload topic ${args} // - args.push_front("topic"); - args.push_front("workload"); - - args.push_front("/" + GetEnv("YDB_DATABASE")); - args.push_front("-d"); - - args.push_front("grpc://" + GetEnv("YDB_ENDPOINT")); - args.push_front("-e"); - - TShellCommand command(BinaryPath("ydb/apps/ydb/ydb"), args); - command.Run().Wait(); - - if (command.GetExitCode() != 0) { - ythrow yexception() << "command `" << command.GetQuotedCommand() << "` exit with code " << command.GetExitCode(); - } - - return command.GetOutput(); + return RunYdb({"workload", "topic"}, args); } struct TTopicConfigurationMatcher { @@ -58,9 +44,9 @@ void ExpectTopic(const TTopicConfigurationMatcher& matcher) } Y_UNIT_TEST(RunFull) { - ExecYdbWorkloadTopic({"init"}); - auto output = ExecYdbWorkloadTopic({"run", "full", "-s", "10"}); - ExecYdbWorkloadTopic({"clean"}); + ExecYdb({"init"}); + auto output = ExecYdb({"run", "full", "-s", "10"}); + ExecYdb({"clean"}); TVector<TString> lines, columns; @@ -78,33 +64,33 @@ Y_UNIT_TEST(Init_Clean) // // default `init` + `clean` // - ExecYdbWorkloadTopic({"init"}); + ExecYdb({"init"}); ExpectTopic({.Topic="workload-topic", .Partitions=128, .Consumers=1}); - ExecYdbWorkloadTopic({"clean"}); + ExecYdb({"clean"}); ExpectTopic({.Topic="workload-topic", .Partitions=0, .Consumers=0}); // // specific `init` + `clean` // - ExecYdbWorkloadTopic({"init", "--topic", "qqqq", "-p", "3", "-c", "5"}); + ExecYdb({"init", "--topic", "qqqq", "-p", "3", "-c", "5"}); ExpectTopic({.Topic="qqqq", .Partitions=3, .Consumers=5}); - UNIT_ASSERT_EXCEPTION(ExecYdbWorkloadTopic({"clean"}), yexception); + UNIT_ASSERT_EXCEPTION(ExecYdb({"clean"}), yexception); - ExecYdbWorkloadTopic({"clean", "--topic", "qqqq"}); + ExecYdb({"clean", "--topic", "qqqq"}); ExpectTopic({.Topic="qqqq", .Partitions=0, .Consumers=0}); } Y_UNIT_TEST(Clean_Without_Init) { - UNIT_ASSERT_EXCEPTION(ExecYdbWorkloadTopic({"clean"}), yexception); + UNIT_ASSERT_EXCEPTION(ExecYdb({"clean"}), yexception); } Y_UNIT_TEST(Double_Init) { - ExecYdbWorkloadTopic({"init"}); - UNIT_ASSERT_EXCEPTION(ExecYdbWorkloadTopic({"init"}), yexception); + ExecYdb({"init"}); + UNIT_ASSERT_EXCEPTION(ExecYdb({"init"}), yexception); } } diff --git a/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp b/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp index c966eebd7d..74fb027cc2 100644 --- a/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp +++ b/ydb/apps/ydb/ut/workload-transfer-topic-to-table.cpp @@ -1,14 +1,11 @@ +#include "run_ydb.h" + #include <library/cpp/testing/common/env.h> #include <library/cpp/testing/unittest/registar.h> #include <ydb/public/sdk/cpp/client/ydb_topic/topic.h> #include <ydb/public/sdk/cpp/client/ydb_table/table.h> -#include <util/string/cast.h> -#include <util/string/split.h> -#include <util/system/env.h> -#include <util/system/shellcommand.h> - Y_UNIT_TEST_SUITE(YdbWorkloadTransferTopicToTable) { struct TTopicConfigMatcher { @@ -22,16 +19,6 @@ struct TTableConfigMatcher { ui32 Partitions = 128; }; -TString GetYdbEndpoint() -{ - return GetEnv("YDB_ENDPOINT"); -} - -TString GetYdbDatabase() -{ - return GetEnv("YDB_DATABASE"); -} - NYdb::NTable::TSession GetSession(NYdb::NTable::TTableClient& client) { auto result = client.GetSession().GetValueSync(); @@ -87,28 +74,12 @@ void ExpectTable(const TTableConfigMatcher& matcher) } } -TString ExecYdb(TList<TString> args) +TString ExecYdb(const TList<TString>& args) { // - // ydb -e grpc://${YDB_ENDPOINT} -d /${YDB_DATABASE} workload topic ${args} + // ydb -e grpc://${YDB_ENDPOINT} -d /${YDB_DATABASE} workload transfer topic-to-table ${args} // - TShellCommand command(BinaryPath("ydb/apps/ydb/ydb")); - - command << "-e" << ("grpc://" + GetYdbEndpoint()); - command << "-d" << ("/" + GetYdbDatabase()); - command << "workload" << "transfer" << "topic-to-table"; - - for (auto& arg : args) { - command << arg; - } - - command.Run().Wait(); - - if (command.GetExitCode() != 0) { - ythrow yexception() << "command `" << command.GetQuotedCommand() << "` exit with code " << command.GetExitCode(); - } - - return command.GetOutput(); + return RunYdb({"workload", "transfer", "topic-to-table"}, args); } void RunYdb(const TList<TString>& args, diff --git a/ydb/apps/ydb/ut/ya.make b/ydb/apps/ydb/ut/ya.make index 6063398822..57355ef0f2 100644 --- a/ydb/apps/ydb/ut/ya.make +++ b/ydb/apps/ydb/ut/ya.make @@ -4,9 +4,12 @@ DEPENDS( ydb/apps/ydb ) +ENV(YDB_CLI_BINARY="ydb/apps/ydb/ydb") + SRCS( workload-topic.cpp workload-transfer-topic-to-table.cpp + run_ydb.cpp ) PEERDIR( |