@@ -172,6 +172,8 @@ class TFixture : public NUnitTest::TBaseFixture {
172172 void CheckTabletKeys (const TString& topicName);
173173 void DumpPQTabletKeys (const TString& topicName);
174174
175+ NTable::TDataQueryResult ExecuteDataQuery (NTable::TSession session, const TString& query, const NTable::TTxControl& control);
176+
175177private:
176178 template <class E >
177179 E ReadEvent (TTopicReadSessionPtr reader, NTable::TTransaction& tx);
@@ -1535,6 +1537,13 @@ void TFixture::TestTheCompletionOfATransaction(const TTransactionCompletionTestD
15351537 }
15361538}
15371539
1540+ NTable::TDataQueryResult TFixture::ExecuteDataQuery (NTable::TSession session, const TString& query, const NTable::TTxControl& control)
1541+ {
1542+ auto status = session.ExecuteDataQuery (query, control).GetValueSync ();
1543+ UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
1544+ return status;
1545+ }
1546+
15381547Y_UNIT_TEST_F (WriteToTopic_Demo_11, TFixture)
15391548{
15401549 for (auto endOfTransaction : {Commit, Rollback, CloseTableSession}) {
@@ -2148,6 +2157,69 @@ Y_UNIT_TEST_F(WriteToTopic_Demo_41, TFixture)
21482157 CommitTx (tx, EStatus::SESSION_EXPIRED);
21492158}
21502159
2160+ Y_UNIT_TEST_F (WriteToTopic_Demo_42, TFixture)
2161+ {
2162+ CreateTopic (" topic_A" , TEST_CONSUMER);
2163+
2164+ NTable::TSession tableSession = CreateTableSession ();
2165+ NTable::TTransaction tx = BeginTx (tableSession);
2166+
2167+ for (size_t k = 0 ; k < 100 ; ++k) {
2168+ WriteToTopic (" topic_A" , TEST_MESSAGE_GROUP_ID, TString (1'000'000 , ' a' ), &tx);
2169+ }
2170+
2171+ CloseTopicWriteSession (" topic_A" , TEST_MESSAGE_GROUP_ID); // gracefully close
2172+
2173+ CommitTx (tx, EStatus::SUCCESS);
2174+
2175+ auto messages = ReadFromTopic (" topic_A" , TEST_CONSUMER, TDuration::Seconds (2 ));
2176+ UNIT_ASSERT_VALUES_EQUAL (messages.size (), 100 );
2177+ }
2178+
2179+ Y_UNIT_TEST_F (WriteToTopic_Demo_43, TFixture)
2180+ {
2181+ // The recording stream will run into a quota. Before the commit, the client will receive confirmations
2182+ // for some of the messages. The `ExecuteDataQuery` call will wait for the rest.
2183+ CreateTopic (" topic_A" , TEST_CONSUMER);
2184+
2185+ NTable::TSession tableSession = CreateTableSession ();
2186+ NTable::TTransaction tx = BeginTx (tableSession);
2187+
2188+ for (size_t k = 0 ; k < 100 ; ++k) {
2189+ WriteToTopic (" topic_A" , TEST_MESSAGE_GROUP_ID, TString (1'000'000 , ' a' ), &tx);
2190+ }
2191+
2192+ ExecuteDataQuery (tableSession, " SELECT 1" , NTable::TTxControl::Tx (tx).CommitTx (true ));
2193+
2194+ auto messages = ReadFromTopic (" topic_A" , TEST_CONSUMER, TDuration::Seconds (60 ));
2195+ UNIT_ASSERT_VALUES_EQUAL (messages.size (), 100 );
2196+ }
2197+
2198+ Y_UNIT_TEST_F (WriteToTopic_Demo_44, TFixture)
2199+ {
2200+ CreateTopic (" topic_A" , TEST_CONSUMER);
2201+
2202+ NTable::TSession tableSession = CreateTableSession ();
2203+
2204+ auto result = ExecuteDataQuery (tableSession, " SELECT 1" , NTable::TTxControl::BeginTx ());
2205+
2206+ NTable::TTransaction tx = *result.GetTransaction ();
2207+
2208+ for (size_t k = 0 ; k < 100 ; ++k) {
2209+ WriteToTopic (" topic_A" , TEST_MESSAGE_GROUP_ID, TString (1'000'000 , ' a' ), &tx);
2210+ }
2211+
2212+ WaitForAcks (" topic_A" , TEST_MESSAGE_GROUP_ID);
2213+
2214+ auto messages = ReadFromTopic (" topic_A" , TEST_CONSUMER, TDuration::Seconds (60 ));
2215+ UNIT_ASSERT_VALUES_EQUAL (messages.size (), 0 );
2216+
2217+ ExecuteDataQuery (tableSession, " SELECT 2" , NTable::TTxControl::Tx (tx).CommitTx (true ));
2218+
2219+ messages = ReadFromTopic (" topic_A" , TEST_CONSUMER, TDuration::Seconds (60 ));
2220+ UNIT_ASSERT_VALUES_EQUAL (messages.size (), 100 );
2221+ }
2222+
21512223}
21522224
21532225}
0 commit comments