From dc18d702a35c20d1794d2a3d3ffae64a0ed3884d Mon Sep 17 00:00:00 2001 From: Anton Myagkov Date: Tue, 2 Jul 2024 16:18:57 +0200 Subject: [PATCH] issue-1377: remove mutable endpoint storage & add unit tests (#1466) Issue: #1377 Refactoring: Remove TFileMutableEndpointStorage implementation, use production implementation of FileEndpointStorage in the tests and use TTempDir to create/cleanup endpoints directory. New tests for fs endpoint storage: remove existing/non-existing endpoints adding endpoint twice --- .../libs/endpoints/endpoint_manager_ut.cpp | 18 +- .../libs/endpoints/service_endpoint_ut.cpp | 62 +----- .../testing/loadtest/lib/load_test_runner.cpp | 9 +- .../testing/loadtest/lib/load_test_runner.h | 3 +- cloud/filestore/libs/endpoint/service_ut.cpp | 37 +--- .../libs/endpoints/fs/fs_endpoints_test.cpp | 76 ------- .../libs/endpoints/fs/fs_endpoints_test.h | 14 -- .../libs/endpoints/fs/fs_endpoints_ut.cpp | 193 +++++++++--------- cloud/storage/core/libs/endpoints/fs/ya.make | 1 - .../keyring/keyring_endpoints_test.cpp | 48 ----- 10 files changed, 123 insertions(+), 338 deletions(-) delete mode 100644 cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.cpp delete mode 100644 cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h diff --git a/cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp b/cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp index 85c159a85a..e5a5237f9b 100644 --- a/cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp +++ b/cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -270,23 +269,18 @@ struct TBootstrap IServerStatsPtr ServerStats = CreateServerStatsStub(); ISessionManagerPtr SessionManager; IEndpointStoragePtr EndpointStorage = CreateFileEndpointStorage(DirPath); - IMutableEndpointStoragePtr MutableStorage = CreateFileMutableEndpointStorage(DirPath); + TTempDir EndpointsDir = TTempDir(DirPath); THashMap EndpointListeners; NBD::IDeviceFactoryPtr NbdDeviceFactory; IEndpointEventProxyPtr EndpointEventHandler = CreateEndpointEventProxy(); TEndpointManagerOptions Options; IEndpointManagerPtr EndpointManager; - TBootstrap() - { - MutableStorage->Init(); - } + TBootstrap() = default; ~TBootstrap() { Stop(); - - MutableStorage->Remove(); } void Start() @@ -1675,10 +1669,10 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest) auto [str, error] = SerializeEndpoint(request); UNIT_ASSERT_C(!HasError(error), error); - auto keyOrError = bootstrap.MutableStorage->AddEndpoint( + auto ret = bootstrap.EndpointStorage->AddEndpoint( request.GetUnixSocketPath(), str); - UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); } NMonitoring::TDynamicCountersPtr counters = new NMonitoring::TDynamicCounters(); @@ -1754,10 +1748,10 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest) auto [str, error] = SerializeEndpoint(request); UNIT_ASSERT_C(!HasError(error), error); - auto keyOrError = bootstrap.MutableStorage->AddEndpoint( + auto ret = bootstrap.EndpointStorage->AddEndpoint( request.GetUnixSocketPath(), str); - UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); } NMonitoring::TDynamicCountersPtr counters = new NMonitoring::TDynamicCounters(); diff --git a/cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp b/cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp index 69f327ae6f..ba41c589ba 100644 --- a/cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp +++ b/cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -234,16 +233,8 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) auto keyringId = 13; const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; + TTempDir endpointsDir(dirPath); TTempDir dir; TString unixSocket = (dir.Path() / "testSocket").GetPath(); TString diskId = "testDiskId"; @@ -322,16 +313,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) { const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + TTempDir endpointsDir(dirPath); auto logging = CreateLoggingService("console"); auto scheduler = CreateScheduler(); @@ -510,15 +492,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; + TTempDir endpointsDir(dirPath); size_t counter = 0; size_t wrongDataCount = 3; @@ -679,15 +653,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; + TTempDir endpointsDir(dirPath); TTempDir dir; size_t endpointCount = 5; @@ -754,15 +720,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) { const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; + TTempDir endpointsDir(dirPath); TTempDir dir; ui32 endpointCount = 42; @@ -1030,15 +988,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) auto keyringId = 13; const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; + TTempDir endpointsDir(dirPath); TAtomic trigger = 0; TManualEvent event; diff --git a/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.cpp b/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.cpp index 85ecdbc8cc..42c026729a 100644 --- a/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.cpp +++ b/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -103,7 +103,7 @@ TLoadTestRunner::TLoadTestRunner( { const auto& endpointStorageDir = ClientFactory.GetEndpointStorageDir(); if (endpointStorageDir) { - EndpointStorage = CreateFileMutableEndpointStorage(endpointStorageDir); + EndpointStorage = CreateFileEndpointStorage(endpointStorageDir); } } @@ -258,8 +258,8 @@ void TLoadTestRunner::SetupTest( << ", endpointsDir: " << ClientFactory.GetEndpointStorageDir()); if (EndpointStorage) { - auto error = EndpointStorage->Init(); - Y_ABORT_UNLESS(!HasError(error)); + EndpointsDir = std::make_unique( + ClientFactory.GetEndpointStorageDir()); auto strOrError = SerializeEndpoint(*request); Y_ABORT_UNLESS(!HasError(strOrError)); @@ -538,6 +538,7 @@ void TLoadTestRunner::TeardownTest( if (EndpointStorage) { auto error = EndpointStorage->RemoveEndpoint(EndpointSocketPath); Y_ABORT_UNLESS(!HasError(error)); + EndpointsDir.reset(); } WaitForCompletion( diff --git a/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.h b/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.h index 502129ddc5..006b38e079 100644 --- a/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.h +++ b/cloud/blockstore/tools/testing/loadtest/lib/load_test_runner.h @@ -34,7 +34,8 @@ class TLoadTestRunner IVolumeStatsPtr VolumeStats; IClientFactory& ClientFactory; TTestContext& TestContext; - IMutableEndpointStoragePtr EndpointStorage; + IEndpointStoragePtr EndpointStorage; + std::unique_ptr EndpointsDir; TString EndpointSocketPath; diff --git a/cloud/filestore/libs/endpoint/service_ut.cpp b/cloud/filestore/libs/endpoint/service_ut.cpp index 2caefbf55d..987d22eb47 100644 --- a/cloud/filestore/libs/endpoint/service_ut.cpp +++ b/cloud/filestore/libs/endpoint/service_ut.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include @@ -16,6 +15,7 @@ #include #include #include +#include namespace NCloud::NFileStore::NServer { @@ -159,16 +159,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + TTempDir endpointDir(dirPath); auto endpoint = std::make_shared(*config, false); auto listener = std::make_shared(); listener->CreateEndpointHandler = @@ -240,16 +231,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + TTempDir endpointDir(dirPath); auto endpoint = std::make_shared(*config, false); auto listener = std::make_shared(); listener->CreateEndpointHandler = @@ -295,7 +277,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) // change endpoint settings - mutableStorage->RemoveEndpoint(id); + endpointStorage->RemoveEndpoint(id); { NProto::TStartEndpointRequest start; @@ -360,16 +342,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest) const TString dirPath = "./" + CreateGuidAsString(); auto endpointStorage = CreateFileEndpointStorage(dirPath); - auto mutableStorage = CreateFileMutableEndpointStorage(dirPath); - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + TTempDir endpointDir(dirPath); auto endpoint = std::make_shared(*config, false); endpoint->Start.SetValue(NProto::TError{}); diff --git a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.cpp b/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.cpp deleted file mode 100644 index b034d9de11..0000000000 --- a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "fs_endpoints_test.h" - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace NCloud { - -namespace { - -//////////////////////////////////////////////////////////////////////////////// - -class TFileMutableEndpointStorage final - : public IMutableEndpointStorage -{ -private: - const TFsPath DirPath; - -public: - TFileMutableEndpointStorage(TString dirPath) - : DirPath(std::move(dirPath)) - {} - - NProto::TError Init() override - { - DirPath.MkDir(); - - if (!DirPath.IsDirectory()) { - return MakeError(E_FAIL, TStringBuilder() - << "Failed to create directory " << DirPath.GetPath()); - } - - return {}; - } - - NProto::TError Remove() override - { - DirPath.ForceDelete(); - return {}; - } - - TResultOrError AddEndpoint( - const TString& key, - const TString& data) override - { - auto filepath = DirPath.Child(Base64EncodeUrl(key)); - TFile file(filepath, EOpenModeFlag::CreateAlways); - TFileOutput(file).Write(data); - return key; - } - - NProto::TError RemoveEndpoint(const TString& key) override - { - DirPath.Child(Base64EncodeUrl(key)).DeleteIfExists(); - return {}; - } -}; - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// - -IMutableEndpointStoragePtr CreateFileMutableEndpointStorage(TString dirPath) -{ - return std::make_shared( - std::move(dirPath)); -} - -} // namespace NCloud diff --git a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h b/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h deleted file mode 100644 index ed40ef48f7..0000000000 --- a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace NCloud { - -//////////////////////////////////////////////////////////////////////////////// - -IMutableEndpointStoragePtr CreateFileMutableEndpointStorage(TString dirPath); - -} // namespace NCloud diff --git a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_ut.cpp b/cloud/storage/core/libs/endpoints/fs/fs_endpoints_ut.cpp index 92d081a595..710ea8d587 100644 --- a/cloud/storage/core/libs/endpoints/fs/fs_endpoints_ut.cpp +++ b/cloud/storage/core/libs/endpoints/fs/fs_endpoints_ut.cpp @@ -1,13 +1,13 @@ #include "fs_endpoints.h" -#include "fs_endpoints_test.h" - #include -#include - +#include #include #include +#include + +#include namespace NCloud { @@ -30,27 +30,16 @@ const TString& GetProtoMessageId(const TProtoMessage& msg) return msg.GetMessage(); } -//////////////////////////////////////////////////////////////////////////////// - -struct TStorages -{ - IEndpointStoragePtr EndpointStorage; - IMutableEndpointStoragePtr MutableEndpointStorage; -}; - - -//////////////////////////////////////////////////////////////////////////////// - -TStorages InitFileStorages() +struct TFixture: public NUnitTest::TBaseFixture { - const TString dirPath = "./" + CreateGuidAsString(); - - auto endpointStorage = CreateFileEndpointStorage(dirPath); + const TString DirPath = "./" + CreateGuidAsString(); + std::unique_ptr EndpointsDir; - auto mutableEndpointStorage = CreateFileMutableEndpointStorage(dirPath); - - return {endpointStorage, mutableEndpointStorage}; -} + void SetUp(NUnitTest::TTestContext& /*testContext*/) override + { + EndpointsDir = std::make_unique(DirPath); + } +}; } // namespace @@ -58,19 +47,9 @@ TStorages InitFileStorages() Y_UNIT_TEST_SUITE(TFileEndpointsTest) { - void ShouldGetStoredEndpoints(const TStorages& storages) + Y_UNIT_TEST_F(ShouldGetStoredEndpointsFromFiles, TFixture) { - auto endpointStorage = storages.EndpointStorage; - auto mutableStorage = storages.MutableEndpointStorage; - - auto error = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(error), error); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + auto endpointStorage = CreateFileEndpointStorage(DirPath); THashMap loadedEndpoints; for (size_t i = 0; i < 3; ++i) { TString diskId = "TestDisk" + ToString(i); @@ -78,10 +57,9 @@ Y_UNIT_TEST_SUITE(TFileEndpointsTest) auto strOrError = SerializeEndpoint(request); UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); - auto keyOrError = mutableStorage->AddEndpoint( - diskId, - strOrError.GetResult()); - UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetResult()); + auto ret = + endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); loadedEndpoints.emplace(diskId, request); } @@ -91,11 +69,13 @@ Y_UNIT_TEST_SUITE(TFileEndpointsTest) auto endpointIds = idsOrError.GetResult(); UNIT_ASSERT_EQUAL(loadedEndpoints.size(), endpointIds.size()); - for (auto keyringId: endpointIds) { + for (const auto& keyringId: endpointIds) { auto endpointOrError = endpointStorage->GetEndpoint(keyringId); - UNIT_ASSERT_C(!HasError(endpointOrError), endpointOrError.GetError()); - auto endpoint = DeserializeEndpoint( - endpointOrError.GetResult()); + UNIT_ASSERT_C( + !HasError(endpointOrError), + endpointOrError.GetError()); + auto endpoint = + DeserializeEndpoint(endpointOrError.GetResult()); UNIT_ASSERT(endpoint); auto it = loadedEndpoints.find(GetProtoMessageId(*endpoint)); @@ -106,88 +86,113 @@ Y_UNIT_TEST_SUITE(TFileEndpointsTest) } } - Y_UNIT_TEST(ShouldGetStoredEndpointsFromFiles) - { - ShouldGetStoredEndpoints(InitFileStorages()); - } - - void ShouldGetStoredEndpointById(const TStorages& storages) + Y_UNIT_TEST_F(ShouldGetStoredEndpointByIdFromFiles, TFixture) { - auto endpointStorage = storages.EndpointStorage; - auto mutableStorage = storages.MutableEndpointStorage; - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + auto endpointStorage = CreateFileEndpointStorage(DirPath); const TString diskId = "TestDiskId"; auto request = CreateTestProtoMessage(diskId); auto strOrError = SerializeEndpoint(request); UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); - auto keyOrError = mutableStorage->AddEndpoint( - diskId, - strOrError.GetResult()); - UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError()); + auto ret = endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); - auto requestOrError = endpointStorage->GetEndpoint( - ToString(keyOrError.GetResult())); + auto requestOrError = endpointStorage->GetEndpoint(diskId); UNIT_ASSERT_C(!HasError(requestOrError), requestOrError.GetError()); - auto storedRequest = DeserializeEndpoint( - requestOrError.GetResult()); + auto storedRequest = + DeserializeEndpoint(requestOrError.GetResult()); UNIT_ASSERT(storedRequest); google::protobuf::util::MessageDifferencer comparator; UNIT_ASSERT(comparator.Equals(*storedRequest, request)); } - Y_UNIT_TEST(ShouldGetStoredEndpointByIdFromFiles) + Y_UNIT_TEST_F(ShouldNotGetStoredEndpointByWrongIdFromFiles, TFixture) { - ShouldGetStoredEndpointById(InitFileStorages()); - } - - void ShouldNotGetStoredEndpointByWrongId(const TStorages& storages) - { - auto endpointStorage = storages.EndpointStorage; - auto mutableStorage = storages.MutableEndpointStorage; - - auto initError = mutableStorage->Init(); - UNIT_ASSERT_C(!HasError(initError), initError); - - Y_DEFER { - auto error = mutableStorage->Remove(); - UNIT_ASSERT_C(!HasError(error), error); - }; - + auto endpointStorage = CreateFileEndpointStorage(DirPath); const TString diskId = "TestDiskId"; auto request = CreateTestProtoMessage(diskId); auto strOrError = SerializeEndpoint(request); UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); - auto keyOrError = mutableStorage->AddEndpoint( - diskId, - strOrError.GetResult()); - UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError()); + auto ret = endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); - auto wrongKeyringId = keyOrError.GetResult() + 42; + const TString wrongKeyringId = "WrongTestDiskId"; - auto requestOrError = endpointStorage->GetEndpoint( - ToString(wrongKeyringId)); + auto requestOrError = endpointStorage->GetEndpoint(wrongKeyringId); UNIT_ASSERT_VALUES_EQUAL_C( E_INVALID_STATE, requestOrError.GetError().GetCode(), requestOrError.GetError()); } - Y_UNIT_TEST(ShouldNotGetStoredEndpointByWrongIdFromFiles) + Y_UNIT_TEST_F(ShouldRemoveEndpoint, TFixture) + { + auto endpointStorage = CreateFileEndpointStorage(DirPath); + const TString diskId = "TestDiskId"; + + auto request = CreateTestProtoMessage(diskId); + auto strOrError = SerializeEndpoint(request); + UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); + + auto ret = endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); + + auto endpointOrError = endpointStorage->GetEndpoint(diskId); + UNIT_ASSERT_C(!HasError(endpointOrError), endpointOrError.GetError()); + + ret = endpointStorage->RemoveEndpoint(diskId); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); + + endpointOrError = endpointStorage->GetEndpoint(diskId); + UNIT_ASSERT(HasError(endpointOrError)); + } + + Y_UNIT_TEST_F(RemoveNonExistentEndpoint, TFixture) { - ShouldNotGetStoredEndpointByWrongId(InitFileStorages()); + auto endpointStorage = CreateFileEndpointStorage(DirPath); + const TString diskId = "TestDiskId"; + + auto ret = endpointStorage->RemoveEndpoint(diskId); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); + } + + Y_UNIT_TEST_F(AddEndpointTwice, TFixture) + { + auto endpointStorage = CreateFileEndpointStorage(DirPath); + const TString diskId = "TestDiskId"; + { + auto request = CreateTestProtoMessage("request1"); + auto strOrError = SerializeEndpoint(request); + UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); + + auto ret = + endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); + } + + { + auto request = CreateTestProtoMessage("request2"); + auto strOrError = SerializeEndpoint(request); + UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError()); + + auto ret = + endpointStorage->AddEndpoint(diskId, strOrError.GetResult()); + UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage()); + + auto requestOrError = endpointStorage->GetEndpoint(diskId); + UNIT_ASSERT_EQUAL_C( + S_OK, + requestOrError.GetError().GetCode(), + requestOrError.GetError().GetMessage()); + + UNIT_ASSERT_EQUAL( + strOrError.GetResult(), + requestOrError.ExtractResult()); + } } } diff --git a/cloud/storage/core/libs/endpoints/fs/ya.make b/cloud/storage/core/libs/endpoints/fs/ya.make index 56a78b75b3..e439bf3a5d 100644 --- a/cloud/storage/core/libs/endpoints/fs/ya.make +++ b/cloud/storage/core/libs/endpoints/fs/ya.make @@ -2,7 +2,6 @@ LIBRARY() SRCS( fs_endpoints.cpp - fs_endpoints_test.cpp ) PEERDIR( diff --git a/cloud/storage/core/libs/endpoints/keyring/keyring_endpoints_test.cpp b/cloud/storage/core/libs/endpoints/keyring/keyring_endpoints_test.cpp index 508c83f4ef..a005b8a2d8 100644 --- a/cloud/storage/core/libs/endpoints/keyring/keyring_endpoints_test.cpp +++ b/cloud/storage/core/libs/endpoints/keyring/keyring_endpoints_test.cpp @@ -194,54 +194,6 @@ NProto::TError TKeyringMutableEndpointStorage::RemoveEndpoint( return {}; } -//////////////////////////////////////////////////////////////////////////////// - -class TFileMutableEndpointStorage final - : public IMutableEndpointStorage -{ -private: - const TFsPath DirPath; - -public: - TFileMutableEndpointStorage(TString dirPath) - : DirPath(std::move(dirPath)) - {} - - NProto::TError Init() override - { - DirPath.MkDir(); - - if (!DirPath.IsDirectory()) { - return MakeError(E_FAIL, TStringBuilder() - << "Failed to create directory " << DirPath.GetPath()); - } - - return {}; - } - - NProto::TError Remove() override - { - DirPath.ForceDelete(); - return {}; - } - - TResultOrError AddEndpoint( - const TString& key, - const TString& data) override - { - auto filepath = DirPath.Child(Base64EncodeUrl(key)); - TFile file(filepath, EOpenModeFlag::CreateAlways); - TFileOutput(file).Write(data); - return key; - } - - NProto::TError RemoveEndpoint(const TString& key) override - { - DirPath.Child(Base64EncodeUrl(key)).DeleteIfExists(); - return {}; - } -}; - } // namespace ////////////////////////////////////////////////////////////////////////////////