|
16 | 16 |
|
17 | 17 | #include <library/cpp/logger/stream.h>
|
18 | 18 | #include <library/cpp/testing/unittest/registar.h>
|
| 19 | +#include <library/cpp/streams/bzip2/bzip2.h> |
19 | 20 |
|
20 | 21 | namespace NYdb::NTopic::NTests {
|
21 | 22 |
|
@@ -87,6 +88,7 @@ class TFixture : public NUnitTest::TBaseFixture {
|
87 | 88 | TTopicDescription DescribeTopic(const TString& path);
|
88 | 89 |
|
89 | 90 | void AddConsumer(const TString& topicPath, const TVector<TString>& consumers);
|
| 91 | + void DropConsumer(const TString& topicPath, const TVector<TString>& consumers); |
90 | 92 | void AlterAutoPartitioning(const TString& topicPath,
|
91 | 93 | ui64 minActivePartitions,
|
92 | 94 | ui64 maxActivePartitions,
|
@@ -148,6 +150,9 @@ class TFixture : public NUnitTest::TBaseFixture {
|
148 | 150 | void RestartLongTxService();
|
149 | 151 | void RestartPQTablet(const TString& topicPath, ui32 partition);
|
150 | 152 | void DumpPQTabletKeys(const TString& topicName, ui32 partition);
|
| 153 | + void PQTabletPrepareFromResource(const TString& topicPath, |
| 154 | + ui32 partitionId, |
| 155 | + const TString& resourceName); |
151 | 156 |
|
152 | 157 | void DeleteSupportivePartition(const TString& topicName,
|
153 | 158 | ui32 partition);
|
@@ -483,6 +488,20 @@ void TFixture::AddConsumer(const TString& topicPath,
|
483 | 488 | UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
|
484 | 489 | }
|
485 | 490 |
|
| 491 | +void TFixture::DropConsumer(const TString& topicPath, |
| 492 | + const TVector<TString>& consumers) |
| 493 | +{ |
| 494 | + NTopic::TTopicClient client(GetDriver()); |
| 495 | + NTopic::TAlterTopicSettings settings; |
| 496 | + |
| 497 | + for (const auto& consumer : consumers) { |
| 498 | + settings.AppendDropConsumers(consumer); |
| 499 | + } |
| 500 | + |
| 501 | + auto result = client.AlterTopic(topicPath, settings).GetValueSync(); |
| 502 | + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); |
| 503 | +} |
| 504 | + |
486 | 505 | void TFixture::AlterAutoPartitioning(const TString& topicPath,
|
487 | 506 | ui64 minActivePartitions,
|
488 | 507 | ui64 maxActivePartitions,
|
@@ -1843,6 +1862,51 @@ void TFixture::DumpPQTabletKeys(const TString& topicName)
|
1843 | 1862 | }
|
1844 | 1863 | }
|
1845 | 1864 |
|
| 1865 | +void TFixture::PQTabletPrepareFromResource(const TString& topicPath, |
| 1866 | + ui32 partitionId, |
| 1867 | + const TString& resourceName) |
| 1868 | +{ |
| 1869 | + auto& runtime = Setup->GetRuntime(); |
| 1870 | + TActorId edge = runtime.AllocateEdgeActor(); |
| 1871 | + ui64 tabletId = GetTopicTabletId(edge, "/Root/" + topicPath, partitionId); |
| 1872 | + |
| 1873 | + auto request = MakeHolder<TEvKeyValue::TEvRequest>(); |
| 1874 | + size_t count = 0; |
| 1875 | + |
| 1876 | + for (TStringStream stream(NResource::Find(resourceName)); true; ++count) { |
| 1877 | + TString key, encoded; |
| 1878 | + |
| 1879 | + if (!stream.ReadTo(key, ' ')) { |
| 1880 | + break; |
| 1881 | + } |
| 1882 | + encoded = stream.ReadLine(); |
| 1883 | + |
| 1884 | + auto decoded = Base64Decode(encoded); |
| 1885 | + TStringInput decodedStream(decoded); |
| 1886 | + TBZipDecompress decompressor(&decodedStream); |
| 1887 | + |
| 1888 | + auto* cmd = request->Record.AddCmdWrite(); |
| 1889 | + cmd->SetKey(key); |
| 1890 | + cmd->SetValue(decompressor.ReadAll()); |
| 1891 | + } |
| 1892 | + |
| 1893 | + runtime.SendToPipe(tabletId, edge, request.Release(), 0, GetPipeConfigWithRetries()); |
| 1894 | + |
| 1895 | + TAutoPtr<IEventHandle> handle; |
| 1896 | + auto* response = runtime.GrabEdgeEvent<TEvKeyValue::TEvResponse>(handle); |
| 1897 | + UNIT_ASSERT(response); |
| 1898 | + UNIT_ASSERT(response->Record.HasStatus()); |
| 1899 | + UNIT_ASSERT_EQUAL(response->Record.GetStatus(), NMsgBusProxy::MSTATUS_OK); |
| 1900 | + |
| 1901 | + UNIT_ASSERT_VALUES_EQUAL(response->Record.WriteResultSize(), count); |
| 1902 | + |
| 1903 | + for (size_t i = 0; i < response->Record.WriteResultSize(); ++i) { |
| 1904 | + const auto &result = response->Record.GetWriteResult(i); |
| 1905 | + UNIT_ASSERT(result.HasStatus()); |
| 1906 | + UNIT_ASSERT_EQUAL(result.GetStatus(), NKikimrProto::OK); |
| 1907 | + } |
| 1908 | +} |
| 1909 | + |
1846 | 1910 | void TFixture::TestTheCompletionOfATransaction(const TTransactionCompletionTestDescription& d)
|
1847 | 1911 | {
|
1848 | 1912 | for (auto& topic : d.Topics) {
|
@@ -3059,6 +3123,51 @@ Y_UNIT_TEST_F(Write_Random_Sized_Messages_In_Wide_Transactions, TFixture)
|
3059 | 3123 | }
|
3060 | 3124 | }
|
3061 | 3125 |
|
| 3126 | +Y_UNIT_TEST_F(The_Configuration_Is_Changing_As_We_Write_To_The_Topic, TFixture) |
| 3127 | +{ |
| 3128 | + // To test that you can change the topic configuration while writing to the partition |
| 3129 | + |
| 3130 | + CreateTopic("topic_A", TEST_CONSUMER, 2); |
| 3131 | + |
| 3132 | + AddConsumer("topic_A", {"consumer1", "consumer2"}); |
| 3133 | + |
| 3134 | + auto session = CreateTableSession(); |
| 3135 | + auto tx = BeginTx(session); |
| 3136 | + |
| 3137 | + WriteToTopic("topic_A", TEST_MESSAGE_GROUP_ID_1, TString(100, 'x'), &tx, 0); |
| 3138 | + WriteToTopic("topic_A", TEST_MESSAGE_GROUP_ID_2, TString(100, 'x'), &tx, 1); |
| 3139 | + |
| 3140 | + WaitForAcks("topic_A", TEST_MESSAGE_GROUP_ID_1); |
| 3141 | + WaitForAcks("topic_A", TEST_MESSAGE_GROUP_ID_2); |
| 3142 | + |
| 3143 | + RestartPQTablet("topic_A", 0); |
| 3144 | + |
| 3145 | + DropConsumer("topic_A", {"consumer1"}); |
| 3146 | + |
| 3147 | + WriteToTopic("topic_A", TEST_MESSAGE_GROUP_ID_3, TString(100, 'x'), &tx, 0); |
| 3148 | + WaitForAcks("topic_A", TEST_MESSAGE_GROUP_ID_3); |
| 3149 | + |
| 3150 | + RestartPQTablet("topic_A", 0); |
| 3151 | + |
| 3152 | + CommitTx(tx); |
| 3153 | + |
| 3154 | + CheckTabletKeys("topic_A"); |
| 3155 | +} |
| 3156 | + |
| 3157 | +Y_UNIT_TEST_F(The_Transaction_Starts_On_One_Version_And_Ends_On_The_Other, TFixture) |
| 3158 | +{ |
| 3159 | + // In the test, we check the compatibility between versions `24-4-2` and `24-4-*/25-1-*`. To do this, the data |
| 3160 | + // obtained on the `24-4-2` version is loaded into the PQ tablets. |
| 3161 | + |
| 3162 | + CreateTopic("topic_A", TEST_CONSUMER, 2); |
| 3163 | + |
| 3164 | + PQTabletPrepareFromResource("topic_A", 0, "topic_A_partition_0_v24-4-2.dat"); |
| 3165 | + PQTabletPrepareFromResource("topic_A", 1, "topic_A_partition_1_v24-4-2.dat"); |
| 3166 | + |
| 3167 | + RestartPQTablet("topic_A", 0); |
| 3168 | + RestartPQTablet("topic_A", 1); |
| 3169 | +} |
| 3170 | + |
3062 | 3171 | }
|
3063 | 3172 |
|
3064 | 3173 | }
|
0 commit comments