@@ -13,6 +13,26 @@ namespace NKikimr::NReplication::NController {
1313Y_UNIT_TEST_SUITE (DstCreator) {
1414 using namespace NTestHelpers ;
1515
16+ void CheckTableReplica (const TTestTableDescription& tableDesc, const NKikimrSchemeOp::TTableDescription& replicatedDesc) {
17+ UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.KeyColumnNamesSize (), tableDesc.KeyColumns .size ());
18+ for (ui32 i = 0 ; i < replicatedDesc.KeyColumnNamesSize (); ++i) {
19+ UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.GetKeyColumnNames (i), tableDesc.KeyColumns [i]);
20+ }
21+
22+ UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.ColumnsSize (), tableDesc.Columns .size ());
23+ for (ui32 i = 0 ; i < replicatedDesc.ColumnsSize (); ++i) {
24+ auto pred = [name = replicatedDesc.GetColumns (i).GetName ()](const auto & column) {
25+ return name == column.Name ;
26+ };
27+
28+ UNIT_ASSERT (FindIfPtr (tableDesc.Columns , pred));
29+ }
30+
31+ const auto & replCfg = replicatedDesc.GetReplicationConfig ();
32+ UNIT_ASSERT_VALUES_EQUAL (replCfg.GetMode (), NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_READ_ONLY);
33+ UNIT_ASSERT_VALUES_EQUAL (replCfg.GetConsistency (), NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_WEAK);
34+ }
35+
1636 void Basic (const TString& replicatedPath) {
1737 TEnv env;
1838 env.GetRuntime ().SetLogPriority (NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE);
@@ -39,24 +59,55 @@ Y_UNIT_TEST_SUITE(DstCreator) {
3959 auto desc = env.GetDescription (replicatedPath);
4060 const auto & replicatedDesc = desc.GetPathDescription ().GetTable ();
4161
42- UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.KeyColumnNamesSize (), tableDesc.KeyColumns .size ());
43- for (ui32 i = 0 ; i < replicatedDesc.KeyColumnNamesSize (); ++i) {
44- UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.GetKeyColumnNames (i), tableDesc.KeyColumns [i]);
45- }
62+ CheckTableReplica (tableDesc, replicatedDesc);
63+ }
4664
47- UNIT_ASSERT_VALUES_EQUAL (replicatedDesc.ColumnsSize (), tableDesc.Columns .size ());
48- for (ui32 i = 0 ; i < replicatedDesc.ColumnsSize (); ++i) {
49- auto pred = [name = replicatedDesc.GetColumns (i).GetName ()](const auto & column) {
50- return name == column.Name ;
51- };
65+ void WithSyncIndex (const TString& replicatedPath) {
66+ TEnv env;
67+ env.GetRuntime ().SetLogPriority (NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE);
5268
53- UNIT_ASSERT (FindIfPtr (tableDesc.Columns , pred));
69+ const auto tableDesc = TTestTableDescription{
70+ .Name = " Table" ,
71+ .KeyColumns = {" key" },
72+ .Columns = {
73+ {.Name = " key" , .Type = " Uint32" },
74+ {.Name = " value" , .Type = " Uint32" },
75+ },
76+ .ReplicationConfig = Nothing (),
77+ };
78+
79+ const TString indexName = " index_by_value" ;
80+
81+ env.CreateTableWithIndex (" /Root" , *MakeTableDescription (tableDesc),
82+ indexName, TVector<TString>{" value" }, NKikimrSchemeOp::EIndexTypeGlobal,
83+ TVector<TString>{}, TDuration::Seconds (5000 ));
84+ env.GetRuntime ().Register (CreateDstCreator (
85+ env.GetSender (), env.GetSchemeshardId (" /Root/Table" ), env.GetYdbProxy (), env.GetPathId (" /Root" ),
86+ 1 /* rid */ , 1 /* tid */ , TReplication::ETargetKind::Table, " /Root/Table" , replicatedPath
87+ ));
88+
89+ auto ev = env.GetRuntime ().GrabEdgeEvent <TEvPrivate::TEvCreateDstResult>(env.GetSender ());
90+ UNIT_ASSERT_VALUES_EQUAL (ev->Get ()->Status , NKikimrScheme::StatusSuccess);
91+
92+ auto desc = env.GetDescription (replicatedPath);
93+ const auto & replicatedDesc = desc.GetPathDescription ().GetTable ();
94+
95+ CheckTableReplica (tableDesc, replicatedDesc);
96+
97+ {
98+ auto desc = env.GetDescription (replicatedPath + " /" + indexName);
99+ UNIT_ASSERT_VALUES_EQUAL (desc.GetPathDescription ().GetTableIndex ().GetName (), indexName);
100+ UNIT_ASSERT_VALUES_EQUAL (desc.GetPathDescription ().GetTableIndex ().GetType (), NKikimrSchemeOp::EIndexType::EIndexTypeGlobal);
54101 }
55102
56- const auto & replCfg = replicatedDesc.GetReplicationConfig ();
57- UNIT_ASSERT_VALUES_EQUAL (replCfg.GetMode (), NKikimrSchemeOp::TTableReplicationConfig::REPLICATION_MODE_READ_ONLY);
58- UNIT_ASSERT_VALUES_EQUAL (replCfg.GetConsistency (), NKikimrSchemeOp::TTableReplicationConfig::CONSISTENCY_WEAK);
59- }
103+ {
104+ auto desc = env.GetDescription (replicatedPath + " /" + indexName + " /indexImplTable" );
105+ Cerr << desc.DebugString () << Endl;
106+ const auto & indexTableDesc = desc.GetPathDescription ().GetTable ();
107+ UNIT_ASSERT_VALUES_EQUAL (indexTableDesc.KeyColumnNamesSize (), 2 );
108+ }
109+ }
110+
60111
61112 Y_UNIT_TEST (Basic) {
62113 Basic (" /Root/Replicated" );
@@ -66,6 +117,15 @@ Y_UNIT_TEST_SUITE(DstCreator) {
66117 Basic (" /Root/Dir/Replicated" );
67118 }
68119
120+ Y_UNIT_TEST (WithSyncIndex) {
121+ WithSyncIndex (" /Root/Replicated" );
122+ }
123+
124+ Y_UNIT_TEST (WithSyncIndexWithIntermediateDir) {
125+ WithSyncIndex (" /Root/Dir/Replicated" );
126+ }
127+
128+
69129 Y_UNIT_TEST (SameOwner) {
70130 TEnv env;
71131 env.GetRuntime ().SetLogPriority (NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE);
0 commit comments