Skip to content

Commit 68ef320

Browse files
authored
(refactoring) Move TTestTableDescription to ut_helpers KIKIMR-21006 (#1985)
1 parent 68afe24 commit 68ef320

File tree

5 files changed

+85
-56
lines changed

5 files changed

+85
-56
lines changed

ydb/core/tx/replication/service/table_writer_ut.cpp

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "worker.h"
33

44
#include <ydb/core/tx/replication/ut_helpers/test_env.h>
5+
#include <ydb/core/tx/replication/ut_helpers/test_table.h>
56

67
#include <library/cpp/string_utils/base64/base64.h>
78
#include <library/cpp/testing/unittest/registar.h>
@@ -11,63 +12,11 @@
1112
namespace NKikimr::NReplication::NService {
1213

1314
Y_UNIT_TEST_SUITE(LocalTableWriter) {
14-
struct TTestTableDescription {
15-
struct TColumn {
16-
TString Name;
17-
TString Type;
18-
19-
void SerializeTo(NKikimrSchemeOp::TColumnDescription& proto) const {
20-
proto.SetName(Name);
21-
proto.SetType(Type);
22-
}
23-
};
24-
25-
TString Name;
26-
TVector<TString> KeyColumns;
27-
TVector<TColumn> Columns;
28-
29-
void SerializeTo(NKikimrSchemeOp::TTableDescription& proto) const {
30-
proto.SetName("Table");
31-
proto.MutableReplicationConfig()->SetMode(NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_READ_ONLY);
32-
proto.MutableReplicationConfig()->SetConsistency(NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_WEAK);
33-
34-
for (const auto& keyColumn : KeyColumns) {
35-
proto.AddKeyColumnNames(keyColumn);
36-
}
37-
38-
for (const auto& column : Columns) {
39-
column.SerializeTo(*proto.AddColumns());
40-
}
41-
}
42-
};
43-
44-
NKikimrSchemeOp::TTableDescription MakeTableDescription(const TTestTableDescription& desc) {
45-
NKikimrSchemeOp::TTableDescription proto;
46-
desc.SerializeTo(proto);
47-
return proto;
48-
}
49-
50-
template <typename Env>
51-
auto GetDescription(Env& env, const TString& path) {
52-
auto resp = env.Describe(path);
53-
return resp->Record;
54-
}
55-
56-
template <typename Env>
57-
TPathId GetPathId(Env& env, const TString& path) {
58-
const auto& desc = GetDescription(env, path);
59-
UNIT_ASSERT(desc.HasPathDescription());
60-
UNIT_ASSERT(desc.GetPathDescription().HasSelf());
61-
62-
const auto& self = desc.GetPathDescription().GetSelf();
63-
return TPathId(self.GetSchemeshardId(), self.GetPathId());
64-
}
65-
6615
Y_UNIT_TEST(WriteTable) {
6716
TEnv env;
6817
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_SERVICE, NLog::PRI_DEBUG);
6918

70-
env.CreateTable("/Root", MakeTableDescription(TTestTableDescription{
19+
env.CreateTable("/Root", *MakeTableDescription(TTestTableDescription{
7120
.Name = "Test",
7221
.KeyColumns = {"key"},
7322
.Columns = {
@@ -76,7 +25,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
7625
},
7726
}));
7827

79-
auto writer = env.GetRuntime().Register(CreateLocalTableWriter(GetPathId(env, "/Root/Table")));
28+
auto writer = env.GetRuntime().Register(CreateLocalTableWriter(env.GetPathId("/Root/Table")));
8029
env.Send<TEvWorker::TEvHandshake>(writer, new TEvWorker::TEvHandshake());
8130

8231
using TRecord = TEvWorker::TEvData::TRecord;
@@ -91,7 +40,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
9140
TEnv env;
9241
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_SERVICE, NLog::PRI_DEBUG);
9342

94-
env.CreateTable("/Root", MakeTableDescription(TTestTableDescription{
43+
env.CreateTable("/Root", *MakeTableDescription(TTestTableDescription{
9544
.Name = "Test",
9645
.KeyColumns = {"key"},
9746
.Columns = {
@@ -117,7 +66,7 @@ Y_UNIT_TEST_SUITE(LocalTableWriter) {
11766
},
11867
}));
11968

120-
auto writer = env.GetRuntime().Register(CreateLocalTableWriter(GetPathId(env, "/Root/Table")));
69+
auto writer = env.GetRuntime().Register(CreateLocalTableWriter(env.GetPathId("/Root/Table")));
12170
env.Send<TEvWorker::TEvHandshake>(writer, new TEvWorker::TEvHandshake());
12271

12372
using TRecord = TEvWorker::TEvData::TRecord;

ydb/core/tx/replication/ut_helpers/test_env.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include <ydb/core/base/ticket_parser.h>
24
#include <ydb/core/protos/replication.pb.h>
35
#include <ydb/core/testlib/test_client.h>
@@ -105,6 +107,20 @@ class TEnv {
105107
return Client.Ls(std::forward<Args>(args)...);
106108
}
107109

110+
auto GetDescription(const TString& path) {
111+
auto resp = Describe(path);
112+
return resp->Record;
113+
}
114+
115+
TPathId GetPathId(const TString& path) {
116+
const auto& desc = GetDescription(path);
117+
UNIT_ASSERT(desc.HasPathDescription());
118+
UNIT_ASSERT(desc.GetPathDescription().HasSelf());
119+
120+
const auto& self = desc.GetPathDescription().GetSelf();
121+
return TPathId(self.GetSchemeshardId(), self.GetPathId());
122+
}
123+
108124
template <typename... Args>
109125
auto CreateTable(Args&&... args) {
110126
return Client.CreateTable(std::forward<Args>(args)...);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "test_table.h"
2+
3+
#include <ydb/core/protos/flat_scheme_op.pb.h>
4+
5+
namespace NKikimr::NReplication {
6+
7+
void TTestTableDescription::TColumn::SerializeTo(NKikimrSchemeOp::TColumnDescription& proto) const {
8+
proto.SetName(Name);
9+
proto.SetType(Type);
10+
}
11+
12+
void TTestTableDescription::SerializeTo(NKikimrSchemeOp::TTableDescription& proto) const {
13+
proto.SetName("Table");
14+
proto.MutableReplicationConfig()->SetMode(NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_READ_ONLY);
15+
proto.MutableReplicationConfig()->SetConsistency(NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_WEAK);
16+
17+
for (const auto& keyColumn : KeyColumns) {
18+
proto.AddKeyColumnNames(keyColumn);
19+
}
20+
21+
for (const auto& column : Columns) {
22+
column.SerializeTo(*proto.AddColumns());
23+
}
24+
}
25+
26+
THolder<NKikimrSchemeOp::TTableDescription> MakeTableDescription(const TTestTableDescription& desc) {
27+
auto result = MakeHolder<NKikimrSchemeOp::TTableDescription>();
28+
desc.SerializeTo(*result);
29+
return result;
30+
}
31+
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <util/generic/ptr.h>
4+
#include <util/generic/string.h>
5+
#include <util/generic/vector.h>
6+
7+
namespace NKikimrSchemeOp {
8+
class TColumnDescription;
9+
class TTableDescription;
10+
}
11+
12+
namespace NKikimr::NReplication {
13+
14+
struct TTestTableDescription {
15+
struct TColumn {
16+
TString Name;
17+
TString Type;
18+
19+
void SerializeTo(NKikimrSchemeOp::TColumnDescription& proto) const;
20+
};
21+
22+
TString Name;
23+
TVector<TString> KeyColumns;
24+
TVector<TColumn> Columns;
25+
26+
void SerializeTo(NKikimrSchemeOp::TTableDescription& proto) const;
27+
};
28+
29+
THolder<NKikimrSchemeOp::TTableDescription> MakeTableDescription(const TTestTableDescription& desc);
30+
31+
}

ydb/core/tx/replication/ut_helpers/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PEERDIR(
1111

1212
SRCS(
1313
test_env.h
14+
test_table.cpp
1415
write_topic.h
1516
)
1617

0 commit comments

Comments
 (0)