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,20 +22,57 @@ 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 ();
3033
31- client.DropTopic (GetTopicPath ()).GetValueSync ();
34+ RemoveDirectoryRecurive (GetDatabase () + " /" + TopicPrefix_);
35+
3236 CreateTopic ();
3337}
3438
39+ void TTopicTestFixture::RemoveDirectoryRecurive (const std::string& path) const {
40+ TSchemeClient schemeClient (MakeDriver ());
41+
42+ auto describeResult = schemeClient.DescribePath (path).GetValueSync ();
43+ if (describeResult.GetStatus () == EStatus::SCHEME_ERROR) {
44+ return ;
45+ }
46+ NStatusHelpers::ThrowOnError (describeResult);
47+ auto entry = describeResult.GetEntry ();
48+
49+ if (entry.Type == ESchemeEntryType::Table || entry.Type == ESchemeEntryType::ColumnTable) {
50+ TTableClient client (MakeDriver ());
51+ NStatusHelpers::ThrowOnError (client.RetryOperationSync([&path](TSession session) {
52+ return session.DropTable (path).GetValueSync ();
53+ }));
54+ } else if (entry.Type == ESchemeEntryType::Topic) {
55+ TTopicClient client (MakeDriver ());
56+ NStatusHelpers::ThrowOnError (client.DropTopic(path).GetValueSync());
57+ } else if (entry.Type == ESchemeEntryType::Directory) {
58+ auto listResult = schemeClient.ListDirectory (path).GetValueSync ();
59+ NStatusHelpers::ThrowOnError (listResult);
60+ for (const auto & entry : listResult.GetChildren ()) {
61+ RemoveDirectoryRecurive (path + " /" + entry.Name );
62+ }
63+ } else {
64+ ythrow TYdbException () << " Entry type " << entry.Type << " is not supported" << Endl;
65+ }
66+ }
67+
68+ void TTopicTestFixture::TearDown () {
69+ // try {
70+ // RemoveDirectoryRecurive(GetDatabase() + "/" + TopicPrefix_);
71+ // } catch (const std::exception& e) {
72+ // std::cerr << "Occurred error in TearDown: " << e.what() << std::endl;
73+ // }
74+ }
75+
3576std::string TTopicTestFixture::GetEndpoint () const {
3677 auto endpoint = std::getenv (" YDB_ENDPOINT" );
3778 Y_ENSURE_BT (endpoint, " YDB_ENDPOINT is not set" );
0 commit comments