11#include " fixture.h"
22
33#include < ydb-cpp-sdk/client/discovery/discovery.h>
4+ #include < ydb-cpp-sdk/client/scheme/scheme.h>
5+ #include < ydb-cpp-sdk/client/table/table.h>
46
5- #include < util/system/execpath.h>
7+
8+ using namespace NYdb ::NScheme;
9+ using namespace NYdb ::NTable;
610
711namespace NYdb ::inline V3::NTopic::NTests {
812
@@ -18,12 +22,11 @@ void TTopicTestFixture::SetUp() {
1822 TTopicClient client (MakeDriver ());
1923
2024 const testing::TestInfo* const testInfo = testing::UnitTest::GetInstance ()->current_test_info ();
21- std::filesystem::path execPath (std::string{GetExecPath ()});
2225
2326 std::stringstream topicBuilder;
2427 topicBuilder << std::getenv (" YDB_TEST_ROOT" ) << " /" << testInfo->test_suite_name () << " -" << testInfo->name () << " /" ;
2528 TopicPrefix_ = topicBuilder.str ();
26-
29+
2730 std::stringstream consumerBuilder;
2831 consumerBuilder << testInfo->test_suite_name () << " -" << testInfo->name () << " -" ;
2932 ConsumerPrefix_ = consumerBuilder.str ();
@@ -32,6 +35,36 @@ void TTopicTestFixture::SetUp() {
3235 CreateTopic ();
3336}
3437
38+ void TTopicTestFixture::RemoveDirectoryRecurive (const std::string& path) const {
39+ TSchemeClient schemeClient (MakeDriver ());
40+
41+ auto describeResult = schemeClient.DescribePath (path).GetValueSync ();
42+ NStatusHelpers::ThrowOnError (describeResult);
43+ auto entry = describeResult.GetEntry ();
44+
45+ if (entry.Type == ESchemeEntryType::Table || entry.Type == ESchemeEntryType::ColumnTable) {
46+ TTableClient client (MakeDriver ());
47+ NStatusHelpers::ThrowOnError (client.RetryOperationSync([&path](TSession session) {
48+ return session.DropTable (path).GetValueSync ();
49+ }));
50+ } else if (entry.Type == ESchemeEntryType::Topic) {
51+ TTopicClient client (MakeDriver ());
52+ NStatusHelpers::ThrowOnError (client.DropTopic(path).GetValueSync());
53+ } else if (entry.Type == ESchemeEntryType::Directory) {
54+ auto listResult = schemeClient.ListDirectory (path).GetValueSync ();
55+ NStatusHelpers::ThrowOnError (listResult);
56+ for (const auto & entry : listResult.GetChildren ()) {
57+ RemoveDirectoryRecurive (path + " /" + entry.Name );
58+ }
59+ } else {
60+ ythrow TYdbException () << " Entry type " << entry.Type << " is not supported" << Endl;
61+ }
62+ }
63+
64+ void TTopicTestFixture::TearDown () {
65+ RemoveDirectoryRecurive (GetDatabase () + " /" + TopicPrefix_);
66+ }
67+
3568std::string TTopicTestFixture::GetEndpoint () const {
3669 auto endpoint = std::getenv (" YDB_ENDPOINT" );
3770 Y_ENSURE_BT (endpoint, " YDB_ENDPOINT is not set" );
0 commit comments