Skip to content

Commit c040ba8

Browse files
committed
unit test helpers
1 parent 8dce497 commit c040ba8

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,11 +1252,63 @@ TCheckFunc PartitionKeys(TVector<TString> lastShardKeys) {
12521252
const auto& pathDescr = record.GetPathDescription();
12531253
UNIT_ASSERT_VALUES_EQUAL(lastShardKeys.size(), pathDescr.TablePartitionsSize());
12541254
for (size_t i = 0; i < lastShardKeys.size(); ++i) {
1255-
UNIT_ASSERT_STRING_CONTAINS(pathDescr.GetTablePartitions(i).GetEndOfRangeKeyPrefix(), lastShardKeys[i]);
1255+
const auto& partition = pathDescr.GetTablePartitions(i);
1256+
UNIT_ASSERT_STRING_CONTAINS_C(
1257+
partition.GetEndOfRangeKeyPrefix(), lastShardKeys[i],
1258+
"partition index: " << i << '\n'
1259+
<< "actual key prefix: " << partition.GetEndOfRangeKeyPrefix().Quote() << '\n'
1260+
<< "expected key prefix: " << lastShardKeys[i].Quote() << '\n'
1261+
);
12561262
}
12571263
};
12581264
}
12591265

1266+
namespace {
1267+
1268+
// Serializes / deserializes a value of type T to a cell vector string representation.
1269+
template <typename T>
1270+
struct TSplitBoundarySerializer {
1271+
static TString Serialize(T splitBoundary) {
1272+
const auto cell = TCell::Make(splitBoundary);
1273+
TSerializedCellVec cellVec(TArrayRef<const TCell>(&cell, 1));
1274+
return cellVec.ReleaseBuffer();
1275+
}
1276+
1277+
static TVector<T> Deserialize(const TString& serializedCells) {
1278+
TSerializedCellVec cells(serializedCells);
1279+
TVector<T> values;
1280+
for (const auto& cell : cells.GetCells()) {
1281+
if (cell.IsNull()) {
1282+
// the last cell
1283+
break;
1284+
}
1285+
values.emplace_back(cell.AsValue<T>());
1286+
}
1287+
return values;
1288+
}
1289+
};
1290+
1291+
}
1292+
1293+
template <typename T>
1294+
TCheckFunc SplitBoundaries(TVector<T>&& expectedBoundaries) {
1295+
return [expectedBoundaries = std::move(expectedBoundaries)] (const NKikimrScheme::TEvDescribeSchemeResult& record) {
1296+
const auto& pathDescr = record.GetPathDescription();
1297+
UNIT_ASSERT_VALUES_EQUAL(pathDescr.TablePartitionsSize(), expectedBoundaries.size() + 1);
1298+
for (size_t i = 0; i < expectedBoundaries.size(); ++i) {
1299+
const auto& partition = pathDescr.GetTablePartitions(i);
1300+
const auto actualBoundary = TSplitBoundarySerializer<T>::Deserialize(partition.GetEndOfRangeKeyPrefix()).at(0);
1301+
UNIT_ASSERT_VALUES_EQUAL_C(
1302+
actualBoundary, expectedBoundaries[i],
1303+
"partition index: " << i << '\n'
1304+
<< "actual key prefix: " << partition.GetEndOfRangeKeyPrefix().Quote() << '\n'
1305+
);
1306+
}
1307+
};
1308+
}
1309+
1310+
template TCheckFunc SplitBoundaries<ui32>(TVector<ui32>&&);
1311+
12601312
TCheckFunc ServerlessComputeResourcesMode(NKikimrSubDomains::EServerlessComputeResourcesMode serverlessComputeResourcesMode) {
12611313
return [=] (const NKikimrScheme::TEvDescribeSchemeResult& record) {
12621314
UNIT_ASSERT_C(IsGoodDomainStatus(record.GetStatus()), "Unexpected status: " << record.GetStatus());

ydb/core/tx/schemeshard/ut_helpers/ls_checks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ namespace NLs {
9999
void CheckBoundaries(const NKikimrScheme::TEvDescribeSchemeResult& record);
100100
TCheckFunc PartitionCount(ui32 count);
101101
TCheckFunc PartitionKeys(TVector<TString> lastShardKeys);
102+
// Checks if the serialized representation of an expected boundary is a prefix of the actual one.
103+
// Similar to PartitionKeys check, but does not require you to pass split boundaries in a serialized form.
104+
template <typename T>
105+
TCheckFunc SplitBoundaries(TVector<T>&& expectedBoundaries);
102106
TCheckFunc FollowerCount(ui32 count);
103107
TCheckFunc CrossDataCenterFollowerCount(ui32 count);
104108
TCheckFunc AllowFollowerPromotion(bool val);

0 commit comments

Comments
 (0)