4
4
#include < ydb/core/persqueue/events/internal.h>
5
5
#include < ydb/core/testlib/tenant_runtime.h>
6
6
#include < ydb/core/tx/scheme_board/cache.h>
7
- #include < ydb/public/sdk/cpp/src/client/persqueue_public /ut/ut_utils/ut_utils .h>
7
+ #include < ydb/public/sdk/cpp/src/client/topic /ut/ut_utils/topic_sdk_test_setup .h>
8
8
9
9
namespace NKikimr ::NPQ {
10
10
using namespace NPersQueue ;
11
11
// using namespace NYdb::NTopic;
12
- using namespace NYdb ::NPersQueue ::NTests;
12
+ using namespace NYdb ::NTopic ::NTests;
13
13
14
14
15
15
Y_UNIT_TEST_SUITE (TFetchRequestTests) {
@@ -26,7 +26,7 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
26
26
}
27
27
28
28
Y_UNIT_TEST (HappyWay) {
29
- auto setup = std::make_shared<TPersQueueYdbSdkTestSetup >(TEST_CASE_NAME);
29
+ auto setup = std::make_shared<TTopicSdkTestSetup >(TEST_CASE_NAME);
30
30
setup->GetServer ().EnableLogs (
31
31
{ NKikimrServices::TX_PROXY_SCHEME_CACHE, NKikimrServices::PQ_FETCH_REQUEST },
32
32
NActors::NLog::PRI_DEBUG
@@ -36,28 +36,18 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
36
36
37
37
ui32 totalPartitions = 5 ;
38
38
setup->CreateTopic (" topic1" , " dc1" , totalPartitions);
39
- setup->CreateTopic (" topic2" , " dc1" , totalPartitions);
40
- auto pqClient = setup->GetPersQueueClient ();
41
- auto settings1 = TWriteSessionSettings ().Path (" topic1" ).MessageGroupId (" src-id" ).PartitionGroupId (2 );
42
- auto settings2 = TWriteSessionSettings ().Path (" topic2" ).MessageGroupId (" src-id" ).PartitionGroupId (4 );
43
- auto ws1 = pqClient.CreateSimpleBlockingWriteSession (settings1);
44
- auto ws2 = pqClient.CreateSimpleBlockingWriteSession (settings2);
45
-
46
- ws1->Write (" Data 1-1" );
47
- ws1->Write (" Data 1-2" );
48
- ws1->Write (" Data 1-3" );
49
-
50
- ws2->Write (" Data 2-1" );
51
- ws2->Write (" Data 2-2" );
52
-
53
- ws1->Close ();
54
- ws2->Close ();
39
+ setup->Write (" /Root/topic1" , " Data 1-1" , 1 );
40
+ setup->Write (" /Root/topic1" , " Data 1-2" , 1 );
41
+ setup->Write (" /Root/topic1" , " Data 1-3" , 1 );
55
42
43
+ setup->CreateTopic (" topic2" , " dc1" , totalPartitions);
44
+ setup->Write (" /Root/topic1" , " Data 2-1" , 3 );
45
+ setup->Write (" /Root/topic1" , " Data 2-2" , 3 );
56
46
57
47
auto edgeId = runtime.AllocateEdgeActor ();
58
- TPartitionFetchRequest p1{" Root/PQ/rt3.dc1-- topic1" , 1 , 1 , 10000 };
59
- TPartitionFetchRequest p2{" Root/PQ/rt3.dc1-- topic2" , 3 , 0 , 10000 };
60
- TPartitionFetchRequest pbad{" Root/PQ/rt3.dc1-- topic2" , 2 , 1 , 10000 };
48
+ TPartitionFetchRequest p1{" / Root/topic1" , 1 , 1 , 10000 };
49
+ TPartitionFetchRequest p2{" / Root/topic2" , 3 , 0 , 10000 };
50
+ TPartitionFetchRequest pbad{" / Root/topic2" , 2 , 1 , 10000 };
61
51
62
52
TFetchRequestSettings settings{{}, NKikimr::NPQ::CLIENTID_WITHOUT_CONSUMER, {p1, p2, pbad}, 1000 , 1000 };
63
53
auto fetchId = runtime.Register (CreatePQFetchRequestActor (settings, MakeSchemeCacheID (), edgeId));
@@ -68,25 +58,143 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
68
58
UNIT_ASSERT_C (ev->Status == Ydb::StatusIds::SUCCESS, ev->Message );
69
59
Cerr << " Got event: " << ev->Response .DebugString () << Endl;
70
60
UNIT_ASSERT_VALUES_EQUAL (ev->Response .PartResultSize (), 3 );
71
- for (const auto & part : ev->Response .GetPartResult ()) {
72
- if (part.GetTopic ().Contains (" topic1" )) {
73
- UNIT_ASSERT (part.GetReadResult ().GetErrorCode () == NPersQueue::NErrorCode::EErrorCode::OK);
74
- UNIT_ASSERT_VALUES_EQUAL (part.GetPartition (), 1 );
75
- UNIT_ASSERT_VALUES_EQUAL (part.GetReadResult ().GetResult (0 ).GetOffset (), 1 );
76
- } else {
77
- UNIT_ASSERT (part.GetTopic ().Contains (" topic2" ));
78
- if (part.GetPartition () == 2 ) {
79
- UNIT_ASSERT (part.GetReadResult ().GetErrorCode () != NPersQueue::NErrorCode::EErrorCode::OK);
80
- } else {
81
- UNIT_ASSERT_VALUES_EQUAL (part.GetPartition (), 3 );
82
- UNIT_ASSERT_VALUES_EQUAL (part.GetReadResult ().GetResult (0 ).GetOffset (), 0 );
83
- }
84
- }
61
+
62
+ {
63
+ auto & result = ev->Response .GetPartResult (0 );
64
+ UNIT_ASSERT_VALUES_EQUAL (result.GetTopic (), " /Root/topic1" );
65
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 1 );
66
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
67
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::OK));
68
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 3 );
69
+ }
70
+
71
+ {
72
+ auto & result = ev->Response .GetPartResult (1 );
73
+ UNIT_ASSERT_VALUES_EQUAL (result.GetTopic (), " /Root/topic2" );
74
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 3 );
75
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
76
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::OK));
77
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 0 );
78
+ }
79
+
80
+ {
81
+ auto & result = ev->Response .GetPartResult (2 );
82
+ UNIT_ASSERT_VALUES_EQUAL (result.GetTopic (), " /Root/topic2" );
83
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 2 );
84
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
85
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::READ_ERROR_TOO_BIG_OFFSET));
86
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 0 );
87
+ }
88
+ }
89
+
90
+ Y_UNIT_TEST (SmallBytesRead) {
91
+ auto setup = std::make_shared<TTopicSdkTestSetup>(TEST_CASE_NAME);
92
+ setup->GetServer ().EnableLogs (
93
+ { NKikimrServices::TX_PROXY_SCHEME_CACHE, NKikimrServices::PQ_FETCH_REQUEST },
94
+ NActors::NLog::PRI_DEBUG
95
+ );
96
+ auto & runtime = setup->GetRuntime ();
97
+ StartSchemeCache (runtime);
98
+
99
+ setup->CreateTopic (" topic1" , " dc1" , 2 );
100
+ setup->Write (" /Root/topic1" , TString (2_KB, ' a' ), 0 );
101
+
102
+ TPartitionFetchRequest p1 {" /Root/topic1" , 0 , 0 , 1_KB};
103
+ TPartitionFetchRequest p2 {" /Root/topic1" , 1 , 0 , 1_KB};
104
+
105
+ TFetchRequestSettings settings{
106
+ .Database = {},
107
+ .Consumer = NKikimr::NPQ::CLIENTID_WITHOUT_CONSUMER,
108
+ .Partitions = {p1, p2},
109
+ .MaxWaitTimeMs = 1000 ,
110
+ .TotalMaxBytes = 100
111
+ };
112
+
113
+ auto edgeId = runtime.AllocateEdgeActor ();
114
+ auto fetchActorId = runtime.Register (CreatePQFetchRequestActor (settings, MakeSchemeCacheID (), edgeId));
115
+ runtime.EnableScheduleForActor (fetchActorId);
116
+ runtime.DispatchEvents ();
117
+
118
+ auto ev = runtime.GrabEdgeEvent <TEvPQ::TEvFetchResponse>();
119
+ Cerr << ev->Response .DebugString () << Endl;
120
+ UNIT_ASSERT_C (ev->Status == Ydb::StatusIds::SUCCESS, ev->Message );
121
+
122
+ UNIT_ASSERT_VALUES_EQUAL (ev->Response .PartResultSize (), 2 );
123
+
124
+ {
125
+ auto & result = ev->Response .GetPartResult (0 );
126
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 0 );
127
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
128
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::OK));
129
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 1 );
130
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().ResultSize (), 1 );
131
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetResult (0 ).GetUncompressedSize (), 2_KB);
132
+ }
133
+
134
+ {
135
+ auto & result = ev->Response .GetPartResult (1 );
136
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 1 );
137
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
138
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::READ_NOT_DONE));
139
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 0 );
140
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().ResultSize (), 0 );
141
+ }
142
+ }
143
+
144
+ Y_UNIT_TEST (EmptyTopic) {
145
+ auto setup = std::make_shared<TTopicSdkTestSetup>(TEST_CASE_NAME);
146
+ setup->GetServer ().EnableLogs (
147
+ { NKikimrServices::TX_PROXY_SCHEME_CACHE, NKikimrServices::PQ_FETCH_REQUEST },
148
+ NActors::NLog::PRI_DEBUG
149
+ );
150
+ auto & runtime = setup->GetRuntime ();
151
+ StartSchemeCache (runtime);
152
+
153
+ setup->CreateTopic (" topic1" , " dc1" , 2 );
154
+
155
+ TPartitionFetchRequest p1 {" /Root/topic1" , 0 , 0 , 1_KB};
156
+ TPartitionFetchRequest p2 {" /Root/topic1" , 1 , 0 , 1_KB};
157
+
158
+ TFetchRequestSettings settings{
159
+ .Database = {},
160
+ .Consumer = NKikimr::NPQ::CLIENTID_WITHOUT_CONSUMER,
161
+ .Partitions = {p1, p2},
162
+ .MaxWaitTimeMs = 100 ,
163
+ .TotalMaxBytes = 100
164
+ };
165
+
166
+ auto edgeId = runtime.AllocateEdgeActor ();
167
+ auto fetchActorId = runtime.Register (CreatePQFetchRequestActor (settings, MakeSchemeCacheID (), edgeId));
168
+ runtime.EnableScheduleForActor (fetchActorId);
169
+ runtime.DispatchEvents ();
170
+
171
+ auto ev = runtime.GrabEdgeEvent <TEvPQ::TEvFetchResponse>();
172
+ Cerr << ev->Response .DebugString () << Endl;
173
+ UNIT_ASSERT_C (ev->Status == Ydb::StatusIds::SUCCESS, ev->Message );
174
+
175
+ UNIT_ASSERT_VALUES_EQUAL (ev->Response .PartResultSize (), 2 );
176
+
177
+ {
178
+ auto & result = ev->Response .GetPartResult (0 );
179
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 0 );
180
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
181
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::READ_NOT_DONE));
182
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 0 );
183
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().ResultSize (), 0 );
184
+ }
185
+
186
+ {
187
+ auto & result = ev->Response .GetPartResult (1 );
188
+ UNIT_ASSERT_VALUES_EQUAL (result.GetPartition (), 1 );
189
+ UNIT_ASSERT_VALUES_EQUAL (NPersQueue::NErrorCode::EErrorCode_Name (result.GetReadResult ().GetErrorCode ()),
190
+ NPersQueue::NErrorCode::EErrorCode_Name (NPersQueue::NErrorCode::EErrorCode::READ_NOT_DONE));
191
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().GetMaxOffset (), 0 );
192
+ UNIT_ASSERT_VALUES_EQUAL (result.GetReadResult ().ResultSize (), 0 );
85
193
}
86
194
}
87
195
88
196
Y_UNIT_TEST (BadTopicName) {
89
- auto setup = std::make_shared<TPersQueueYdbSdkTestSetup >(TEST_CASE_NAME);
197
+ auto setup = std::make_shared<TTopicSdkTestSetup >(TEST_CASE_NAME);
90
198
auto & runtime = setup->GetRuntime ();
91
199
StartSchemeCache (runtime);
92
200
@@ -96,8 +204,8 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
96
204
setup->CreateTopic (" topic1" , " dc1" , totalPartitions);
97
205
98
206
auto edgeId = runtime.AllocateEdgeActor ();
99
- TPartitionFetchRequest p1{" Root/PQ/rt3.dc1-- topic1" , 1 , 1 , 10000 };
100
- TPartitionFetchRequest p2{" Root/PQ/rt3.dc1-- topic2" , 3 , 0 , 10000 };
207
+ TPartitionFetchRequest p1{" / Root/topic1" , 1 , 1 , 10000 };
208
+ TPartitionFetchRequest p2{" / Root/topic2" , 3 , 0 , 10000 };
101
209
102
210
TFetchRequestSettings settings{{}, NKikimr::NPQ::CLIENTID_WITHOUT_CONSUMER, {p1, p2}, 1000 , 1000 };
103
211
auto fetchId = runtime.Register (CreatePQFetchRequestActor (settings, MakeSchemeCacheID (), edgeId));
@@ -108,7 +216,7 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
108
216
}
109
217
110
218
Y_UNIT_TEST (CheckAccess) {
111
- auto setup = std::make_shared<TPersQueueYdbSdkTestSetup >(TEST_CASE_NAME);
219
+ auto setup = std::make_shared<TTopicSdkTestSetup >(TEST_CASE_NAME);
112
220
auto & runtime = setup->GetRuntime ();
113
221
runtime.SetLogPriority (NKikimrServices::PQ_FETCH_REQUEST, NActors::NLog::EPriority::PRI_DEBUG);
114
222
StartSchemeCache (runtime);
@@ -117,12 +225,12 @@ Y_UNIT_TEST_SUITE(TFetchRequestTests) {
117
225
setup->CreateTopic (" topic1" , " dc1" , totalPartitions);
118
226
119
227
auto edgeId = runtime.AllocateEdgeActor ();
120
- TPartitionFetchRequest p1{" Root/PQ/rt3.dc1-- topic1" , 1 , 1 , 10000 };
228
+ TPartitionFetchRequest p1{" / Root/topic1" , 1 , 1 , 10000 };
121
229
122
230
{
123
231
NACLib::TDiffACL acl;
124
232
acl.AddAccess (NACLib::EAccessType::Allow, NACLib::SelectRow, " user1@staff" );
125
- setup->GetServer ().AnnoyingClient ->ModifyACL (" /Root/PQ " , " rt3.dc1-- topic1" , acl.SerializeAsString ());
233
+ setup->GetServer ().AnnoyingClient ->ModifyACL (" /Root" , " topic1" , acl.SerializeAsString ());
126
234
127
235
auto goodToken = MakeIntrusiveConst<NACLib::TUserToken>(" user1@staff" , TVector<TString>{});
128
236
TFetchRequestSettings settings{
0 commit comments