From 2cb5c7fb314bdec48198c4b7960c3169d964dc89 Mon Sep 17 00:00:00 2001 From: Ilnaz Nizametdinov Date: Mon, 11 Mar 2024 16:44:49 +0300 Subject: [PATCH] Additional tests for dst creator (#2600) --- .../replication/controller/dst_creator_ut.cpp | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/ydb/core/tx/replication/controller/dst_creator_ut.cpp b/ydb/core/tx/replication/controller/dst_creator_ut.cpp index 75719174ddb8..244b8964914d 100644 --- a/ydb/core/tx/replication/controller/dst_creator_ut.cpp +++ b/ydb/core/tx/replication/controller/dst_creator_ut.cpp @@ -65,6 +65,132 @@ Y_UNIT_TEST_SUITE(DstCreator) { auto ev = env.GetRuntime().GrabEdgeEvent(env.GetSender()); UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Status, NKikimrScheme::StatusSchemeError); } + + template + void ExistingDst(NKikimrScheme::EStatus status, const TString& error, T&& mod, const TTestTableDescription& desc) { + auto changeName = [](const TTestTableDescription& desc, const TString& name) { + auto copy = desc; + copy.Name = name; + return copy; + }; + + TEnv env; + env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE); + + env.CreateTable("/Root", *MakeTableDescription(changeName(desc, "Src"))); + env.CreateTable("/Root", *MakeTableDescription(mod(changeName(desc, "Dst")))); + + env.GetRuntime().Register(CreateDstCreator( + env.GetSender(), env.GetSchemeshardId("/Root"), env.GetYdbProxy(), 1 /* rid */, 1 /* tid */, + TReplication::ETargetKind::Table, "/Root/Src", "/Root/Dst" + )); + + auto ev = env.GetRuntime().GrabEdgeEvent(env.GetSender()); + UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Status, status); + if (error) { + UNIT_ASSERT_STRING_CONTAINS(ev->Get()->Error, error); + } + } + + Y_UNIT_TEST(ExistingDst) { + auto nop = [](const TTestTableDescription& desc) { + return desc; + }; + + ExistingDst(NKikimrScheme::StatusSuccess, "", nop, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } + + Y_UNIT_TEST(KeyColumnsSizeMismatch) { + auto addKeyColumn = [](const TTestTableDescription& desc) { + auto copy = desc; + copy.KeyColumns.push_back("value"); + return copy; + }; + + ExistingDst(NKikimrScheme::StatusSchemeError, "Key columns size mismatch", addKeyColumn, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } + + Y_UNIT_TEST(KeyColumnNameMismatch) { + auto changeKeyColumn = [](const TTestTableDescription& desc) { + auto copy = desc; + copy.KeyColumns = {"value"}; + return copy; + }; + + ExistingDst(NKikimrScheme::StatusSchemeError, "Key column name mismatch", changeKeyColumn, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } + + Y_UNIT_TEST(ColumnsSizeMismatch) { + auto addColumn = [](const TTestTableDescription& desc) { + auto copy = desc; + copy.Columns.push_back({.Name = "extra", .Type = "Utf8"}); + return copy; + }; + + ExistingDst(NKikimrScheme::StatusSchemeError, "Columns size mismatch", addColumn, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } + + Y_UNIT_TEST(CannotFindColumn) { + auto changeColumnName = [](const TTestTableDescription& desc) { + auto copy = desc; + copy.Columns[1] = {.Name = "value2", .Type = "Utf8"}; + return copy; + }; + + ExistingDst(NKikimrScheme::StatusSchemeError, "Cannot find column", changeColumnName, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } + + Y_UNIT_TEST(ColumnTypeMismatch) { + auto changeColumnType = [](const TTestTableDescription& desc) { + auto copy = desc; + copy.Columns[1] = {.Name = "value", .Type = "Uint32"}; + return copy; + }; + + ExistingDst(NKikimrScheme::StatusSchemeError, "Column type mismatch", changeColumnType, TTestTableDescription{ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + }); + } } }