Skip to content

Commit 90ae6d2

Browse files
committed
statistics: move row count helpers to ut_common
1 parent 8d8b0d8 commit 90ae6d2

File tree

3 files changed

+61
-74
lines changed

3 files changed

+61
-74
lines changed

ydb/core/statistics/service/ut/ut_basic_statistics.cpp

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -52,79 +52,6 @@ void CreateTableWithGlobalIndex(TTestEnv& env, const TString& databaseName, cons
5252
FillTable(env, databaseName, tableName, rowCount);
5353
}
5454

55-
void ValidateRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId, size_t expectedRowCount) {
56-
auto statServiceId = NStat::MakeStatServiceID(runtime.GetNodeId(nodeIndex));
57-
ui64 rowCount = 0;
58-
while (rowCount == 0) {
59-
NStat::TRequest req;
60-
req.PathId = pathId;
61-
62-
auto evGet = std::make_unique<TEvStatistics::TEvGetStatistics>();
63-
evGet->StatType = NStat::EStatType::SIMPLE;
64-
evGet->StatRequests.push_back(req);
65-
66-
auto sender = runtime.AllocateEdgeActor(nodeIndex);
67-
runtime.Send(statServiceId, sender, evGet.release(), nodeIndex, true);
68-
auto evResult = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvGetStatisticsResult>(sender);
69-
70-
UNIT_ASSERT(evResult);
71-
UNIT_ASSERT(evResult->Get());
72-
UNIT_ASSERT(evResult->Get()->StatResponses.size() == 1);
73-
74-
auto rsp = evResult->Get()->StatResponses[0];
75-
auto stat = rsp.Simple;
76-
77-
rowCount = stat.RowCount;
78-
79-
if (rowCount != 0) {
80-
UNIT_ASSERT(stat.RowCount == expectedRowCount);
81-
break;
82-
}
83-
84-
runtime.SimulateSleep(TDuration::Seconds(1));
85-
}
86-
}
87-
88-
ui64 GetRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId) {
89-
auto statServiceId = NStat::MakeStatServiceID(runtime.GetNodeId(nodeIndex));
90-
NStat::TRequest req;
91-
req.PathId = pathId;
92-
93-
auto evGet = std::make_unique<TEvStatistics::TEvGetStatistics>();
94-
evGet->StatType = NStat::EStatType::SIMPLE;
95-
evGet->StatRequests.push_back(req);
96-
97-
auto sender = runtime.AllocateEdgeActor(nodeIndex);
98-
runtime.Send(statServiceId, sender, evGet.release(), nodeIndex, true);
99-
auto evResult = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvGetStatisticsResult>(sender);
100-
101-
UNIT_ASSERT(evResult);
102-
UNIT_ASSERT(evResult->Get());
103-
UNIT_ASSERT(evResult->Get()->StatResponses.size() == 1);
104-
105-
auto rsp = evResult->Get()->StatResponses[0];
106-
auto stat = rsp.Simple;
107-
108-
return stat.RowCount;
109-
}
110-
111-
void waitForRowCount(
112-
TTestActorRuntime& runtime, ui32 nodeIndex,
113-
TPathId pathId, size_t expectedRowCount, size_t timeoutSec = 130) {
114-
ui64 lastRowCount = 0;
115-
for (size_t i = 0; i <= timeoutSec; ++i) {
116-
lastRowCount = GetRowCount(runtime, nodeIndex, pathId);
117-
if (i % 5 == 0) {
118-
Cerr << "row count: " << lastRowCount << " (expected: " << expectedRowCount << ")\n";
119-
}
120-
if (lastRowCount == expectedRowCount) {
121-
return;
122-
}
123-
runtime.SimulateSleep(TDuration::Seconds(1));
124-
}
125-
UNIT_ASSERT_C(false, "timed out, last row count: " << lastRowCount);
126-
}
127-
12855
} // namespace
12956

13057
Y_UNIT_TEST_SUITE(BasicStatistics) {
@@ -485,7 +412,7 @@ Y_UNIT_TEST_SUITE(BasicStatistics) {
485412

486413
// After everything is healed, stats should get updated.
487414
blockSSUpdates.Stop();
488-
waitForRowCount(runtime, otherNodeIdx, pathId, rowCount2);
415+
WaitForRowCount(runtime, otherNodeIdx, pathId, rowCount2);
489416
}
490417
}
491418

ydb/core/statistics/ut_common/ut_common.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,59 @@ void WaitForSavedStatistics(TTestActorRuntime& runtime, const TPathId& pathId) {
525525
waiter.Wait();
526526
}
527527

528+
ui64 GetRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId) {
529+
auto statServiceId = NStat::MakeStatServiceID(runtime.GetNodeId(nodeIndex));
530+
NStat::TRequest req;
531+
req.PathId = pathId;
532+
533+
auto evGet = std::make_unique<TEvStatistics::TEvGetStatistics>();
534+
evGet->StatType = NStat::EStatType::SIMPLE;
535+
evGet->StatRequests.push_back(req);
536+
537+
auto sender = runtime.AllocateEdgeActor(nodeIndex);
538+
runtime.Send(statServiceId, sender, evGet.release(), nodeIndex, true);
539+
auto evResult = runtime.GrabEdgeEventRethrow<TEvStatistics::TEvGetStatisticsResult>(sender);
540+
541+
UNIT_ASSERT(evResult);
542+
UNIT_ASSERT(evResult->Get());
543+
UNIT_ASSERT(evResult->Get()->StatResponses.size() == 1);
544+
545+
auto rsp = evResult->Get()->StatResponses[0];
546+
auto stat = rsp.Simple;
547+
548+
return stat.RowCount;
549+
}
550+
551+
void ValidateRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId, size_t expectedRowCount) {
552+
ui64 rowCount = 0;
553+
while (rowCount == 0) {
554+
rowCount = GetRowCount(runtime, nodeIndex, pathId);
555+
556+
if (rowCount != 0) {
557+
UNIT_ASSERT_VALUES_EQUAL(rowCount, expectedRowCount);
558+
break;
559+
}
560+
561+
runtime.SimulateSleep(TDuration::Seconds(1));
562+
}
563+
}
564+
565+
void WaitForRowCount(
566+
TTestActorRuntime& runtime, ui32 nodeIndex,
567+
TPathId pathId, size_t expectedRowCount, size_t timeoutSec) {
568+
ui64 lastRowCount = 0;
569+
for (size_t i = 0; i <= timeoutSec; ++i) {
570+
lastRowCount = GetRowCount(runtime, nodeIndex, pathId);
571+
if (i % 5 == 0) {
572+
Cerr << "row count: " << lastRowCount << " (expected: " << expectedRowCount << ")\n";
573+
}
574+
if (lastRowCount == expectedRowCount) {
575+
return;
576+
}
577+
runtime.SimulateSleep(TDuration::Seconds(1));
578+
}
579+
UNIT_ASSERT_C(false, "timed out, last row count: " << lastRowCount);
580+
}
581+
528582
} // NStat
529583
} // NKikimr

ydb/core/statistics/ut_common/ut_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,11 @@ void AnalyzeStatus(TTestActorRuntime& runtime, TActorId sender, ui64 saTabletId,
120120

121121
void WaitForSavedStatistics(TTestActorRuntime& runtime, const TPathId& pathId);
122122

123+
ui64 GetRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId);
124+
void ValidateRowCount(TTestActorRuntime& runtime, ui32 nodeIndex, TPathId pathId, size_t expectedRowCount);
125+
void WaitForRowCount(
126+
TTestActorRuntime& runtime, ui32 nodeIndex,
127+
TPathId pathId, size_t expectedRowCount, size_t timeoutSec = 130);
128+
123129
} // namespace NStat
124130
} // namespace NKikimr

0 commit comments

Comments
 (0)