aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlnaz Nizametdinov <ilnaz@ydb.tech>2024-01-30 00:21:14 +0300
committerGitHub <noreply@github.com>2024-01-30 00:21:14 +0300
commit6b76771e776d48c5899e1126f0242b6c118b2c37 (patch)
tree614c75ef3275e951c2131a38b09c1f2bb3ab60fb
parentd0648a18e88f140d909c3047133e1f02ac3d240e (diff)
downloadydb-6b76771e776d48c5899e1126f0242b6c118b2c37.tar.gz
(refactoring) UT helpers lib KIKIMR-20902 (#1391)
-rw-r--r--ydb/core/tx/replication/ut_helpers/test_env.h148
-rw-r--r--ydb/core/tx/replication/ut_helpers/ya.make16
-rw-r--r--ydb/core/tx/replication/ydb_proxy/ut/ya.make4
-rw-r--r--ydb/core/tx/replication/ydb_proxy/ydb_proxy_ut.cpp146
4 files changed, 168 insertions, 146 deletions
diff --git a/ydb/core/tx/replication/ut_helpers/test_env.h b/ydb/core/tx/replication/ut_helpers/test_env.h
new file mode 100644
index 0000000000..d4ca801b45
--- /dev/null
+++ b/ydb/core/tx/replication/ut_helpers/test_env.h
@@ -0,0 +1,148 @@
+#include <ydb/core/base/ticket_parser.h>
+#include <ydb/core/protos/replication.pb.h>
+#include <ydb/core/testlib/test_client.h>
+#include <ydb/core/tx/schemeshard/schemeshard.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+namespace NKikimr::NReplication {
+
+template <bool UseDatabase = true>
+class TEnv {
+ static constexpr char DomainName[] = "Root";
+
+ static NKikimrPQ::TPQConfig MakePqConfig() {
+ NKikimrPQ::TPQConfig config;
+ config.SetRequireCredentialsInNewProtocol(false);
+ return config;
+ }
+
+ template <typename... Args>
+ void Init(Args&&... args) {
+ auto grpcPort = PortManager.GetPort();
+
+ Server.EnableGRpc(grpcPort);
+ Server.SetupDefaultProfiles();
+ Client.InitRootScheme(DomainName);
+
+ Endpoint = "localhost:" + ToString(grpcPort);
+ Database = "/" + ToString(DomainName);
+
+ YdbProxy = Server.GetRuntime()->Register(CreateYdbProxy(
+ Endpoint, UseDatabase ? Database : "", std::forward<Args>(args)...));
+ Sender = Server.GetRuntime()->AllocateEdgeActor();
+ }
+
+ void Login(ui64 schemeShardId, const TString& user, const TString& password) {
+ auto req = MakeHolder<NSchemeShard::TEvSchemeShard::TEvLogin>();
+ req->Record.SetUser(user);
+ req->Record.SetPassword(password);
+ ForwardToTablet(*Server.GetRuntime(), schemeShardId, Sender, req.Release());
+
+ auto resp = Server.GetRuntime()->GrabEdgeEvent<NSchemeShard::TEvSchemeShard::TEvLoginResult>(Sender);
+ UNIT_ASSERT(resp->Get()->Record.GetError().empty());
+ UNIT_ASSERT(!resp->Get()->Record.GetToken().empty());
+ }
+
+public:
+ TEnv(bool init = true)
+ : Settings(Tests::TServerSettings(PortManager.GetPort(), {}, MakePqConfig())
+ .SetDomainName(DomainName)
+ )
+ , Server(Settings)
+ , Client(Settings)
+ {
+ if (init) {
+ Init();
+ }
+ }
+
+ explicit TEnv(const TString& user, const TString& password)
+ : TEnv(false)
+ {
+ NKikimrReplication::TStaticCredentials staticCreds;
+ staticCreds.SetUser(user);
+ staticCreds.SetPassword(password);
+ Init(staticCreds);
+
+ const auto db = "/" + ToString(DomainName);
+ // create user & set owner
+ {
+ auto st = Client.CreateUser(db, user, password);
+ UNIT_ASSERT_VALUES_EQUAL(st, NMsgBusProxy::EResponseStatus::MSTATUS_OK);
+
+ Client.ModifyOwner("/", DomainName, user);
+ }
+ // init security state
+ {
+ auto resp = Client.Ls(db);
+
+ const auto& desc = resp->Record;
+ UNIT_ASSERT(desc.HasPathDescription());
+ UNIT_ASSERT(desc.GetPathDescription().HasDomainDescription());
+ UNIT_ASSERT(desc.GetPathDescription().GetDomainDescription().HasDomainKey());
+
+ Login(desc.GetPathDescription().GetDomainDescription().GetDomainKey().GetSchemeShard(), user, password);
+ }
+ // update security state
+ {
+ auto resp = Client.Ls(db);
+
+ const auto& desc = resp->Record;
+ UNIT_ASSERT(desc.HasPathDescription());
+ UNIT_ASSERT(desc.GetPathDescription().HasDomainDescription());
+ UNIT_ASSERT(desc.GetPathDescription().GetDomainDescription().HasSecurityState());
+
+ const auto& secState = desc.GetPathDescription().GetDomainDescription().GetSecurityState();
+ Server.GetRuntime()->Send(new IEventHandle(MakeTicketParserID(), Sender,
+ new TEvTicketParser::TEvUpdateLoginSecurityState(secState)));
+ }
+ }
+
+ void SendAsync(const TActorId& recipient, IEventBase* ev) {
+ Server.GetRuntime()->Send(new IEventHandle(recipient, Sender, ev));
+ }
+
+ template <typename TEvResponse>
+ auto Send(const TActorId& recipient, IEventBase* ev) {
+ SendAsync(recipient, ev);
+ return Server.GetRuntime()->GrabEdgeEvent<TEvResponse>(Sender);
+ }
+
+ template <typename TEvResponse>
+ auto Send(IEventBase* ev) {
+ return Send<TEvResponse>(YdbProxy, ev);
+ }
+
+ auto& GetRuntime() {
+ return *Server.GetRuntime();
+ }
+
+ const NYdb::TDriver& GetDriver() const {
+ return Server.GetDriver();
+ }
+
+ const TString& GetEndpoint() const {
+ return Endpoint;
+ }
+
+ const TString& GetDatabase() const {
+ return Database;
+ }
+
+ const TActorId& GetSender() const {
+ return Sender;
+ }
+
+private:
+ TPortManager PortManager;
+ Tests::TServerSettings Settings;
+ Tests::TServer Server;
+ Tests::TClient Client;
+ TString Endpoint;
+ TString Database;
+ TActorId YdbProxy;
+ TActorId Sender;
+};
+
+}
diff --git a/ydb/core/tx/replication/ut_helpers/ya.make b/ydb/core/tx/replication/ut_helpers/ya.make
new file mode 100644
index 0000000000..43d2e7ab02
--- /dev/null
+++ b/ydb/core/tx/replication/ut_helpers/ya.make
@@ -0,0 +1,16 @@
+LIBRARY()
+
+PEERDIR(
+ ydb/core/base
+ ydb/core/protos
+ ydb/core/testlib/default
+ library/cpp/testing/unittest
+)
+
+SRCS(
+ test_env.h
+)
+
+YQL_LAST_ABI_VERSION()
+
+END()
diff --git a/ydb/core/tx/replication/ydb_proxy/ut/ya.make b/ydb/core/tx/replication/ydb_proxy/ut/ya.make
index 5ab140af11..befb75975e 100644
--- a/ydb/core/tx/replication/ydb_proxy/ut/ya.make
+++ b/ydb/core/tx/replication/ydb_proxy/ut/ya.make
@@ -7,9 +7,9 @@ SIZE(MEDIUM)
TIMEOUT(600)
PEERDIR(
- library/cpp/testing/unittest
- ydb/core/testlib/default
+ ydb/core/tx/replication/ut_helpers
ydb/public/sdk/cpp/client/ydb_topic
+ library/cpp/testing/unittest
)
SRCS(
diff --git a/ydb/core/tx/replication/ydb_proxy/ydb_proxy_ut.cpp b/ydb/core/tx/replication/ydb_proxy/ydb_proxy_ut.cpp
index 7e7cb303b8..1fc3b8d973 100644
--- a/ydb/core/tx/replication/ydb_proxy/ydb_proxy_ut.cpp
+++ b/ydb/core/tx/replication/ydb_proxy/ydb_proxy_ut.cpp
@@ -1,155 +1,13 @@
#include "ydb_proxy.h"
-#include <ydb/core/protos/replication.pb.h>
-#include <ydb/core/testlib/test_client.h>
-#include <ydb/core/tx/schemeshard/schemeshard.h>
+#include <ydb/core/tx/replication/ut_helpers/test_env.h>
+#include <ydb/public/sdk/cpp/client/ydb_topic/topic.h>
#include <library/cpp/testing/unittest/registar.h>
-#include <ydb/core/base/ticket_parser.h>
-#include <ydb/public/sdk/cpp/client/ydb_topic/topic.h>
-
namespace NKikimr::NReplication {
Y_UNIT_TEST_SUITE(YdbProxyTests) {
- template <bool UseDatabase = true>
- class TEnv {
- static constexpr char DomainName[] = "Root";
-
- static NKikimrPQ::TPQConfig MakePqConfig() {
- NKikimrPQ::TPQConfig config;
- config.SetRequireCredentialsInNewProtocol(false);
- return config;
- }
-
- template <typename... Args>
- void Init(Args&&... args) {
- auto grpcPort = PortManager.GetPort();
-
- Server.EnableGRpc(grpcPort);
- Server.SetupDefaultProfiles();
- Client.InitRootScheme(DomainName);
-
- Endpoint = "localhost:" + ToString(grpcPort);
- Database = "/" + ToString(DomainName);
-
- YdbProxy = Server.GetRuntime()->Register(CreateYdbProxy(
- Endpoint, UseDatabase ? Database : "", std::forward<Args>(args)...));
- Sender = Server.GetRuntime()->AllocateEdgeActor();
- }
-
- void Login(ui64 schemeShardId, const TString& user, const TString& password) {
- auto req = MakeHolder<NSchemeShard::TEvSchemeShard::TEvLogin>();
- req->Record.SetUser(user);
- req->Record.SetPassword(password);
- ForwardToTablet(*Server.GetRuntime(), schemeShardId, Sender, req.Release());
-
- auto resp = Server.GetRuntime()->GrabEdgeEvent<NSchemeShard::TEvSchemeShard::TEvLoginResult>(Sender);
- UNIT_ASSERT(resp->Get()->Record.GetError().empty());
- UNIT_ASSERT(!resp->Get()->Record.GetToken().empty());
- }
-
- public:
- TEnv(bool init = true)
- : Settings(Tests::TServerSettings(PortManager.GetPort(), {}, MakePqConfig())
- .SetDomainName(DomainName)
- )
- , Server(Settings)
- , Client(Settings)
- {
- if (init) {
- Init();
- }
- }
-
- explicit TEnv(const TString& user, const TString& password)
- : TEnv(false)
- {
- NKikimrReplication::TStaticCredentials staticCreds;
- staticCreds.SetUser(user);
- staticCreds.SetPassword(password);
- Init(staticCreds);
-
- const auto db = "/" + ToString(DomainName);
- // create user & set owner
- {
- auto st = Client.CreateUser(db, user, password);
- UNIT_ASSERT_VALUES_EQUAL(st, NMsgBusProxy::EResponseStatus::MSTATUS_OK);
-
- Client.ModifyOwner("/", DomainName, user);
- }
- // init security state
- {
- auto resp = Client.Ls(db);
-
- const auto& desc = resp->Record;
- UNIT_ASSERT(desc.HasPathDescription());
- UNIT_ASSERT(desc.GetPathDescription().HasDomainDescription());
- UNIT_ASSERT(desc.GetPathDescription().GetDomainDescription().HasDomainKey());
-
- Login(desc.GetPathDescription().GetDomainDescription().GetDomainKey().GetSchemeShard(), user, password);
- }
- // update security state
- {
- auto resp = Client.Ls(db);
-
- const auto& desc = resp->Record;
- UNIT_ASSERT(desc.HasPathDescription());
- UNIT_ASSERT(desc.GetPathDescription().HasDomainDescription());
- UNIT_ASSERT(desc.GetPathDescription().GetDomainDescription().HasSecurityState());
-
- const auto& secState = desc.GetPathDescription().GetDomainDescription().GetSecurityState();
- Server.GetRuntime()->Send(new IEventHandle(MakeTicketParserID(), Sender,
- new TEvTicketParser::TEvUpdateLoginSecurityState(secState)));
- }
- }
-
- void SendAsync(const TActorId& recipient, IEventBase* ev) {
- Server.GetRuntime()->Send(new IEventHandle(recipient, Sender, ev));
- }
-
- template <typename TEvResponse>
- auto Send(const TActorId& recipient, IEventBase* ev) {
- SendAsync(recipient, ev);
- return Server.GetRuntime()->GrabEdgeEvent<TEvResponse>(Sender);
- }
-
- template <typename TEvResponse>
- auto Send(IEventBase* ev) {
- return Send<TEvResponse>(YdbProxy, ev);
- }
-
- auto& GetRuntime() {
- return *Server.GetRuntime();
- }
-
- const NYdb::TDriver& GetDriver() const {
- return Server.GetDriver();
- }
-
- const TString& GetEndpoint() const {
- return Endpoint;
- }
-
- const TString& GetDatabase() const {
- return Database;
- }
-
- const TActorId& GetSender() const {
- return Sender;
- }
-
- private:
- TPortManager PortManager;
- Tests::TServerSettings Settings;
- Tests::TServer Server;
- Tests::TClient Client;
- TString Endpoint;
- TString Database;
- TActorId YdbProxy;
- TActorId Sender;
- };
-
Y_UNIT_TEST(MakeDirectory) {
TEnv env;
// ok