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+ #include < ydb-cpp-sdk/client/iam/iam.h>
8+
9+
10+ using namespace NYdb ::NScheme;
11+ using namespace NYdb ::NTable;
612
713namespace NYdb ::inline V3::NTopic::NTests {
814
@@ -18,20 +24,54 @@ void TTopicTestFixture::SetUp() {
1824 TTopicClient client (MakeDriver ());
1925
2026 const testing::TestInfo* const testInfo = testing::UnitTest::GetInstance ()->current_test_info ();
21- std::filesystem::path execPath (std::string{GetExecPath ()});
2227
2328 std::stringstream topicBuilder;
2429 topicBuilder << std::getenv (" YDB_TEST_ROOT" ) << " /" << testInfo->test_suite_name () << " -" << testInfo->name () << " /" ;
2530 TopicPrefix_ = topicBuilder.str ();
26-
31+
2732 std::stringstream consumerBuilder;
2833 consumerBuilder << testInfo->test_suite_name () << " -" << testInfo->name () << " -" ;
2934 ConsumerPrefix_ = consumerBuilder.str ();
3035
31- client.DropTopic (GetTopicPath ()).GetValueSync ();
36+ try {
37+ RemoveDirectoryRecurive (GetDatabase () + " /" + TopicPrefix_);
38+ } catch (const TYdbException& e) {
39+ std::cerr << " Couldn't drop topic on SetUp: " << e.what () << std::endl;
40+ }
41+
3242 CreateTopic ();
3343}
3444
45+ void TTopicTestFixture::RemoveDirectoryRecurive (const std::string& path) const {
46+ TSchemeClient schemeClient (MakeDriver ());
47+
48+ auto describeResult = schemeClient.DescribePath (path).GetValueSync ();
49+ NStatusHelpers::ThrowOnError (describeResult);
50+ auto entry = describeResult.GetEntry ();
51+
52+ if (entry.Type == ESchemeEntryType::Table || entry.Type == ESchemeEntryType::ColumnTable) {
53+ TTableClient client (MakeDriver ());
54+ NStatusHelpers::ThrowOnError (client.RetryOperationSync([&path](TSession session) {
55+ return session.DropTable (path).GetValueSync ();
56+ }));
57+ } else if (entry.Type == ESchemeEntryType::Topic) {
58+ TTopicClient client (MakeDriver ());
59+ NStatusHelpers::ThrowOnError (client.DropTopic(path).GetValueSync());
60+ } else if (entry.Type == ESchemeEntryType::Directory) {
61+ auto listResult = schemeClient.ListDirectory (path).GetValueSync ();
62+ NStatusHelpers::ThrowOnError (listResult);
63+ for (const auto & entry : listResult.GetChildren ()) {
64+ RemoveDirectoryRecurive (path + " /" + entry.Name );
65+ }
66+ } else {
67+ ythrow TYdbException () << " Entry type " << entry.Type << " is not supported" << Endl;
68+ }
69+ }
70+
71+ void TTopicTestFixture::TearDown () {
72+ RemoveDirectoryRecurive (GetDatabase () + " /" + TopicPrefix_);
73+ }
74+
3575std::string TTopicTestFixture::GetEndpoint () const {
3676 auto endpoint = std::getenv (" YDB_ENDPOINT" );
3777 Y_ENSURE_BT (endpoint, " YDB_ENDPOINT is not set" );
@@ -54,6 +94,7 @@ TDriverConfig TTopicTestFixture::MakeDriverConfig() const {
5494 return TDriverConfig ()
5595 .SetEndpoint (GetEndpoint ())
5696 .SetDatabase (GetDatabase ())
97+ .SetCredentialsProviderFactory (CreateIamJwtFileCredentialsProviderFactory ({.JwtFilename = " /home/brgayazov/sa-key" }))
5798 .SetLog (std::unique_ptr<TLogBackend>(CreateLogBackend (" cerr" , ELogPriority::TLOG_DEBUG).Release ()));
5899}
59100
0 commit comments