Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tests for dst creator #2600

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions ydb/core/tx/replication/controller/dst_creator_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,132 @@ Y_UNIT_TEST_SUITE(DstCreator) {
auto ev = env.GetRuntime().GrabEdgeEvent<TEvPrivate::TEvCreateDstResult>(env.GetSender());
UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Status, NKikimrScheme::StatusSchemeError);
}

template <typename T>
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<TEvPrivate::TEvCreateDstResult>(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"},
},
});
}
}

}
Loading