@@ -22,11 +22,11 @@ TTopicSdkTestSetup::TTopicSdkTestSetup(const TString& testCaseName, const NKikim
22
22
}
23
23
}
24
24
25
- void TTopicSdkTestSetup::CreateTopicWithAutoscale (const TString & path, const TString & consumer, size_t partitionCount, size_t maxPartitionCount) {
25
+ void TTopicSdkTestSetup::CreateTopicWithAutoscale (const std::string & path, const std::string & consumer, size_t partitionCount, size_t maxPartitionCount) {
26
26
CreateTopic (path, consumer, partitionCount, maxPartitionCount);
27
27
}
28
28
29
- void TTopicSdkTestSetup::CreateTopic (const TString & path, const TString & consumer, size_t partitionCount, std::optional<size_t > maxPartitionCount)
29
+ void TTopicSdkTestSetup::CreateTopic (const std::string & path, const std::string & consumer, size_t partitionCount, std::optional<size_t > maxPartitionCount)
30
30
{
31
31
TTopicClient client (MakeDriver ());
32
32
@@ -49,10 +49,10 @@ void TTopicSdkTestSetup::CreateTopic(const TString& path, const TString& consume
49
49
auto status = client.CreateTopic (path, topics).GetValueSync ();
50
50
UNIT_ASSERT (status.IsSuccess ());
51
51
52
- Server.WaitInit (path);
52
+ Server.WaitInit (TString{ path} );
53
53
}
54
54
55
- TTopicDescription TTopicSdkTestSetup::DescribeTopic (const TString & path)
55
+ TTopicDescription TTopicSdkTestSetup::DescribeTopic (const std::string & path)
56
56
{
57
57
TTopicClient client (MakeDriver ());
58
58
@@ -66,7 +66,7 @@ TTopicDescription TTopicSdkTestSetup::DescribeTopic(const TString& path)
66
66
return status.GetTopicDescription ();
67
67
}
68
68
69
- TConsumerDescription TTopicSdkTestSetup::DescribeConsumer (const TString & path, const TString & consumer)
69
+ TConsumerDescription TTopicSdkTestSetup::DescribeConsumer (const std::string & path, const std::string & consumer)
70
70
{
71
71
TTopicClient client (MakeDriver ());
72
72
@@ -80,22 +80,79 @@ TConsumerDescription TTopicSdkTestSetup::DescribeConsumer(const TString& path, c
80
80
return status.GetConsumerDescription ();
81
81
}
82
82
83
- void TTopicSdkTestSetup::Write (const std::string& message, ui32 partitionId) {
83
+ void TTopicSdkTestSetup::Write (const std::string& message, ui32 partitionId, const std::optional<std::string> producer, std::optional<ui64> seqNo ) {
84
84
TTopicClient client (MakeDriver ());
85
85
86
86
TWriteSessionSettings settings;
87
87
settings.Path (TEST_TOPIC);
88
88
settings.PartitionId (partitionId);
89
- settings.DeduplicationEnabled (false );
89
+ settings.DeduplicationEnabled (producer.has_value ());
90
+ if (producer) {
91
+ settings.ProducerId (producer.value ())
92
+ .MessageGroupId (producer.value ());
93
+ }
90
94
auto session = client.CreateSimpleBlockingWriteSession (settings);
91
95
92
- TWriteMessage msg (TStringBuilder () << message);
93
- UNIT_ASSERT (session->Write (std::move (msg)));
96
+ UNIT_ASSERT (session->Write (message, seqNo));
94
97
95
98
session->Close (TDuration::Seconds (5 ));
96
99
}
97
100
98
- TStatus TTopicSdkTestSetup::Commit (const TString& path, const TString& consumerName, size_t partitionId, size_t offset, std::optional<std::string> sessionId) {
101
+ TTopicSdkTestSetup::ReadResult TTopicSdkTestSetup::Read (const std::string& topic, const std::string& consumer, std::function<bool (NYdb::NTopic::TReadSessionEvent::TDataReceivedEvent&)> handler, const TDuration timeout) {
102
+ TTopicClient client (MakeDriver ());
103
+
104
+ auto reader = client.CreateReadSession (
105
+ TReadSessionSettings ()
106
+ .AutoPartitioningSupport (true )
107
+ .AppendTopics (TTopicReadSettings (topic))
108
+ .ConsumerName (consumer));
109
+
110
+ TInstant deadlineTime = TInstant::Now () + timeout;
111
+
112
+ ReadResult result;
113
+ result.Reader = reader;
114
+
115
+ bool continueFlag = true ;
116
+ while (continueFlag && deadlineTime > TInstant::Now ()) {
117
+ for (auto event : reader->GetEvents (false )) {
118
+ if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TDataReceivedEvent>(&event)) {
119
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
120
+ if (!handler (*x)) {
121
+ continueFlag = false ;
122
+ break ;
123
+ }
124
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStartPartitionSessionEvent>(&event)) {
125
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
126
+ x->Confirm ();
127
+ result.StartPartitionSessionEvents .push_back (*x);
128
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TCommitOffsetAcknowledgementEvent>(&event)) {
129
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
130
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionStatusEvent>(&event)) {
131
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
132
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStopPartitionSessionEvent>(&event)) {
133
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
134
+ x->Confirm ();
135
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionClosedEvent>(&event)) {
136
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
137
+ } else if (auto * x = std::get_if<NYdb::NTopic::TReadSessionEvent::TEndPartitionSessionEvent>(&event)) {
138
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
139
+ x->Confirm ();
140
+ } else if (auto * x = std::get_if<NYdb::NTopic::TSessionClosedEvent>(&event)) {
141
+ Cerr << " SESSION EVENT " << x->DebugString () << Endl << Flush;
142
+ } else {
143
+ Cerr << " SESSION EVENT unhandled \n " ;
144
+ }
145
+ }
146
+
147
+ Sleep (TDuration::MilliSeconds (250 ));
148
+ }
149
+
150
+ result.Timeout = continueFlag;
151
+
152
+ return result;
153
+ }
154
+
155
+ TStatus TTopicSdkTestSetup::Commit (const std::string& path, const std::string& consumerName, size_t partitionId, size_t offset, std::optional<std::string> sessionId) {
99
156
TTopicClient client (MakeDriver ());
100
157
101
158
TCommitOffsetSettings commitSettings {.ReadSessionId_ = sessionId};
0 commit comments