diff options
author | Daniil Demin <deminds@ydb.tech> | 2025-02-03 22:07:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-03 22:07:38 +0300 |
commit | 5dee4a13189b84e7e29218be4cad71f7295af48c (patch) | |
tree | 2fe0664db45242799c2f38999d6d5c69ff803aad | |
parent | 89138f8edd74b1e1d9267a5c1857806f275332c1 (diff) | |
download | ydb-5dee4a13189b84e7e29218be4cad71f7295af48c.tar.gz |
TOPIC: add tests for local backups (#14158)
-rw-r--r-- | ydb/services/ydb/backup_ut/ydb_backup_ut.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp index 402c535d4db..f39555770f5 100644 --- a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp +++ b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp @@ -214,6 +214,12 @@ TViewDescription DescribeView(TViewClient& viewClient, const TString& path) { return describeResult.GetViewDescription(); } +NTopic::TTopicDescription DescribeTopic(NTopic::TTopicClient& topicClient, const TString& path) { + const auto describeResult = topicClient.DescribeTopic(path).ExtractValueSync(); + UNIT_ASSERT_C(describeResult.IsSuccess(), describeResult.GetIssues().ToString()); + return describeResult.GetTopicDescription(); +} + // note: the storage pool kind must be preconfigured in the server void CreateDatabase(TTenants& tenants, TStringBuf path, TStringBuf storagePoolKind) { Ydb::Cms::CreateDatabaseRequest request; @@ -643,6 +649,58 @@ void TestViewReferenceTableIsPreserved( TestViewReferenceTableIsPreserved(view, table, view, session, std::move(backup), std::move(restore)); } +void TestTopicSettingsArePreserved( + const char* topic, NQuery::TSession& session, NTopic::TTopicClient& topicClient, + TBackupFunction&& backup, TRestoreFunction&& restore +) { + constexpr int minPartitions = 2; + constexpr int maxPartitions = 5; + constexpr const char* autoPartitioningStrategy = "scale_up"; + constexpr int retentionPeriodDays = 7; + + ExecuteQuery(session, Sprintf(R"( + CREATE TOPIC `%s` ( + CONSUMER basic_consumer, + CONSUMER important_consumer WITH (important = TRUE) + ) WITH ( + min_active_partitions = %d, + max_active_partitions = %d, + auto_partitioning_strategy = '%s', + retention_period = Interval('%s') + ); + )", + topic, minPartitions, maxPartitions, autoPartitioningStrategy, Sprintf("P%dD", retentionPeriodDays).c_str() + ), true); + + const auto checkDescription = [&](const NTopic::TTopicDescription& description, const TString& debugHint) { + UNIT_ASSERT_VALUES_EQUAL_C(description.GetConsumers().at(0).GetConsumerName(), "basic_consumer", debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetConsumers().at(0).GetImportant(), false, debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetConsumers().at(1).GetConsumerName(), "important_consumer", debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetConsumers().at(1).GetImportant(), true, debugHint); + + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitioningSettings().GetMinActivePartitions(), minPartitions, debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitioningSettings().GetMaxActivePartitions(), maxPartitions, debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitioningSettings().GetAutoPartitioningSettings().GetStrategy(), NTopic::EAutoPartitioningStrategy::ScaleUp, debugHint); + + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitions().size(), 2, debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitions().at(0).GetActive(), true, debugHint); + UNIT_ASSERT_VALUES_EQUAL_C(description.GetPartitions().at(1).GetActive(), true, debugHint); + + UNIT_ASSERT_VALUES_EQUAL_C(description.GetRetentionPeriod(), TDuration::Days(retentionPeriodDays), debugHint); + }; + checkDescription(DescribeTopic(topicClient, topic), DEBUG_HINT); + + backup(); + + ExecuteQuery(session, Sprintf(R"( + DROP TOPIC `%s`; + )", topic + ), true); + + restore(); + checkDescription(DescribeTopic(topicClient, topic), DEBUG_HINT); +} + } Y_UNIT_TEST_SUITE(BackupRestore) { @@ -896,6 +954,26 @@ Y_UNIT_TEST_SUITE(BackupRestore) { ); } + void TestTopicBackupRestoreWithoutData() { + TKikimrWithGrpcAndRootSchema server; + auto driver = TDriver(TDriverConfig().SetEndpoint(Sprintf("localhost:%u", server.GetPort()))); + NQuery::TQueryClient queryClient(driver); + auto session = queryClient.GetSession().ExtractValueSync().GetSession(); + NTopic::TTopicClient topicClient(driver); + TTempDir tempDir; + const auto& pathToBackup = tempDir.Path(); + + constexpr const char* topic = "/Root/topic"; + + TestTopicSettingsArePreserved( + topic, + session, + topicClient, + CreateBackupLambda(driver, pathToBackup), + CreateRestoreLambda(driver, pathToBackup) + ); + } + Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) { using namespace NKikimrSchemeOp; @@ -913,7 +991,8 @@ Y_UNIT_TEST_SUITE(BackupRestore) { TestDirectoryBackupRestore(); break; case EPathTypePersQueueGroup: - break; // https://github.com/ydb-platform/ydb/issues/10431 + TestTopicBackupRestoreWithoutData(); + break; case EPathTypeSubDomain: case EPathTypeExtSubDomain: break; // https://github.com/ydb-platform/ydb/issues/10432 |