Skip to content

Commit c1675a6

Browse files
committed
More test utils (#17125)
1 parent ed5fb29 commit c1675a6

File tree

1 file changed

+45
-8
lines changed
  • ydb/tests/functional/replication

1 file changed

+45
-8
lines changed

ydb/tests/functional/replication/utils.h

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ struct Checker : public IChecker {
4747
UNIT_ASSERT_VALUES_EQUAL_C(Get(value), Expected, msg);
4848
}
4949

50-
T Get(const ::Ydb::Value& value);
50+
virtual T Get(const ::Ydb::Value& value);
5151

5252
T Expected;
5353
};
5454

55+
struct DateTimeChecker : public Checker<TInstant> {
56+
DateTimeChecker(TInstant&& expected)
57+
: Checker<TInstant>(std::move(expected)) {
58+
}
59+
60+
TInstant Get(const ::Ydb::Value& value) override {
61+
return TInstant::Seconds(value.uint32_value());
62+
}
63+
};
64+
5565
template<>
5666
inline bool Checker<bool>::Get(const ::Ydb::Value& value) {
5767
return value.bool_value();
@@ -95,6 +105,14 @@ std::pair<TString, std::shared_ptr<IChecker>> _C(TString&& name, T&& expected) {
95105
};
96106
}
97107

108+
template<typename C, typename T>
109+
std::pair<TString, std::shared_ptr<IChecker>> _T(TString&& name, T&& expected) {
110+
return {
111+
std::move(name),
112+
std::make_shared<C>(std::move(expected))
113+
};
114+
}
115+
98116
struct TMessage {
99117
TString Message;
100118
std::optional<ui32> Partition = std::nullopt;
@@ -150,6 +168,7 @@ struct MainTestCase {
150168
, ConnectionString(GetEnv("YDB_ENDPOINT") + "/?database=" + GetEnv("YDB_DATABASE"))
151169
, TopicName(TStringBuilder() << "Topic_" << Id)
152170
, SourceTableName(TStringBuilder() << "SourceTable_" << Id)
171+
, ChangefeedName(TStringBuilder() << "cdc_" << Id)
153172
, TableName(TStringBuilder() << "Table_" << Id)
154173
, ReplicationName(TStringBuilder() << "Replication_" << Id)
155174
, TransferName(TStringBuilder() << "Transfer_" << Id)
@@ -209,6 +228,16 @@ struct MainTestCase {
209228
ExecuteDDL(Sprintf("DROP TABLE `%s`", SourceTableName.data()));
210229
}
211230

231+
void AddChangefeed() {
232+
ExecuteDDL(Sprintf(R"(
233+
ALTER TABLE `%s`
234+
ADD CHANGEFEED `%s` WITH (
235+
MODE = 'UPDATES',
236+
FORMAT = 'JSON'
237+
)
238+
)", SourceTableName.data(), ChangefeedName.data()));
239+
}
240+
212241
void CreateTopic(size_t partitionCount = 10) {
213242
ExecuteDDL(Sprintf(R"(
214243
CREATE TOPIC `%s`
@@ -230,14 +259,19 @@ struct MainTestCase {
230259
}
231260

232261
struct CreateTransferSettings {
262+
std::optional<TString> TopicName = std::nullopt;
233263
std::optional<TString> ConsumerName = std::nullopt;
234-
std::optional<TDuration> FlushInterval;
235-
std::optional<ui64> BatchSizeBytes;
264+
std::optional<TDuration> FlushInterval = TDuration::Seconds(1);
265+
std::optional<ui64> BatchSizeBytes = 8_MB;
266+
267+
CreateTransferSettings() {};
236268

237-
CreateTransferSettings()
238-
: ConsumerName(std::nullopt)
239-
, FlushInterval(TDuration::Seconds(1))
240-
, BatchSizeBytes(8_MB) {}
269+
static CreateTransferSettings WithTopic(const TString& topicName, std::optional<TString> consumerName = std::nullopt) {
270+
CreateTransferSettings result;
271+
result.TopicName = topicName;
272+
result.ConsumerName = consumerName;
273+
return result;
274+
}
241275

242276
static CreateTransferSettings WithConsumerName(const TString& consumerName) {
243277
CreateTransferSettings result;
@@ -265,6 +299,8 @@ struct MainTestCase {
265299
sb << ", BATCH_SIZE_BYTES = " << *settings.BatchSizeBytes << Endl;
266300
}
267301

302+
TString topicName = settings.TopicName.value_or(TopicName);
303+
268304
auto ddl = Sprintf(R"(
269305
%s;
270306
@@ -274,7 +310,7 @@ struct MainTestCase {
274310
CONNECTION_STRING = 'grpc://%s'
275311
%s
276312
);
277-
)", lambda.data(), TransferName.data(), TopicName.data(), TableName.data(), ConnectionString.data(), sb.data());
313+
)", lambda.data(), TransferName.data(), topicName.data(), TableName.data(), ConnectionString.data(), sb.data());
278314

279315
ExecuteDDL(ddl);
280316
}
@@ -558,6 +594,7 @@ struct MainTestCase {
558594

559595
const TString TopicName;
560596
const TString SourceTableName;
597+
const TString ChangefeedName;
561598
const TString TableName;
562599
const TString ReplicationName;
563600
const TString TransferName;

0 commit comments

Comments
 (0)