|
@@ -2,6 +2,7 @@
|
|
|
#include "worker.h"
|
|
|
|
|
|
#include <ydb/core/tx/replication/ut_helpers/test_env.h>
|
|
|
+#include <ydb/core/tx/replication/ut_helpers/test_table.h>
|
|
|
|
|
|
#include <library/cpp/string_utils/base64/base64.h>
|
|
|
#include <library/cpp/testing/unittest/registar.h>
|
|
@@ -11,63 +12,11 @@
|
|
|
namespace NKikimr::NReplication::NService {
|
|
|
|
|
|
Y_UNIT_TEST_SUITE(LocalTableWriter) {
|
|
|
- struct TTestTableDescription {
|
|
|
- struct TColumn {
|
|
|
- TString Name;
|
|
|
- TString Type;
|
|
|
-
|
|
|
- void SerializeTo(NKikimrSchemeOp::TColumnDescription& proto) const {
|
|
|
- proto.SetName(Name);
|
|
|
- proto.SetType(Type);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- TString Name;
|
|
|
- TVector<TString> KeyColumns;
|
|
|
- TVector<TColumn> Columns;
|
|
|
-
|
|
|
- void SerializeTo(NKikimrSchemeOp::TTableDescription& proto) const {
|
|
|
- proto.SetName("Table");
|
|
|
- proto.MutableReplicationConfig()->SetMode(NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_READ_ONLY);
|
|
|
- proto.MutableReplicationConfig()->SetConsistency(NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_WEAK);
|
|
|
-
|
|
|
- for (const auto& keyColumn : KeyColumns) {
|
|
|
- proto.AddKeyColumnNames(keyColumn);
|
|
|
- }
|
|
|
-
|
|
|
- for (const auto& column : Columns) {
|
|
|
- column.SerializeTo(*proto.AddColumns());
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- NKikimrSchemeOp::TTableDescription MakeTableDescription(const TTestTableDescription& desc) {
|
|
|
- NKikimrSchemeOp::TTableDescription proto;
|
|
|
- desc.SerializeTo(proto);
|
|
|
- return proto;
|
|
|
- }
|
|
|
-
|
|
|
- template <typename Env>
|
|
|
- auto GetDescription(Env& env, const TString& path) {
|
|
|
- auto resp = env.Describe(path);
|
|
|
- return resp->Record;
|
|
|
- }
|
|
|
-
|
|
|
- template <typename Env>
|
|
|
- TPathId GetPathId(Env& env, const TString& path) {
|
|
|
- const auto& desc = GetDescription(env, path);
|
|
|
- UNIT_ASSERT(desc.HasPathDescription());
|
|
|
- UNIT_ASSERT(desc.GetPathDescription().HasSelf());
|
|
|
-
|
|
|
- const auto& self = desc.GetPathDescription().GetSelf();
|
|
|
- return TPathId(self.GetSchemeshardId(), self.GetPathId());
|
|
|
- }
|
|
|
-
|
|
|
Y_UNIT_TEST(WriteTable) {
|
|
|
TEnv env;
|
|
|
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_SERVICE, NLog::PRI_DEBUG);
|
|
|
|
|
|
- env.CreateTable("/Root", MakeTableDescription(TTestTableDescription{
|
|
|
+ env.CreateTable("/Root", *MakeTableDescription(TTestTableDescription{
|
|
|
.Name = "Test",
|
|
|
.KeyColumns = {"key"},
|
|
|
.Columns = {
|
|
@@ -76,7 +25,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
|
|
|
},
|
|
|
}));
|
|
|
|
|
|
- auto writer = env.GetRuntime().Register(CreateLocalTableWriter(GetPathId(env, "/Root/Table")));
|
|
|
+ auto writer = env.GetRuntime().Register(CreateLocalTableWriter(env.GetPathId("/Root/Table")));
|
|
|
env.Send<TEvWorker::TEvHandshake>(writer, new TEvWorker::TEvHandshake());
|
|
|
|
|
|
using TRecord = TEvWorker::TEvData::TRecord;
|
|
@@ -91,7 +40,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
|
|
|
TEnv env;
|
|
|
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_SERVICE, NLog::PRI_DEBUG);
|
|
|
|
|
|
- env.CreateTable("/Root", MakeTableDescription(TTestTableDescription{
|
|
|
+ env.CreateTable("/Root", *MakeTableDescription(TTestTableDescription{
|
|
|
.Name = "Test",
|
|
|
.KeyColumns = {"key"},
|
|
|
.Columns = {
|
|
@@ -117,7 +66,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
|
|
|
},
|
|
|
}));
|
|
|
|
|
|
- auto writer = env.GetRuntime().Register(CreateLocalTableWriter(GetPathId(env, "/Root/Table")));
|
|
|
+ auto writer = env.GetRuntime().Register(CreateLocalTableWriter(env.GetPathId("/Root/Table")));
|
|
|
env.Send<TEvWorker::TEvHandshake>(writer, new TEvWorker::TEvHandshake());
|
|
|
|
|
|
using TRecord = TEvWorker::TEvData::TRecord;
|