diff options
author | yuryalekseev <yuryalekseev@yandex-team.com> | 2022-09-02 16:15:56 +0300 |
---|---|---|
committer | yuryalekseev <yuryalekseev@yandex-team.com> | 2022-09-02 16:15:56 +0300 |
commit | 95dc8597d32cf006e8e1bb475ff2018042cfd3bf (patch) | |
tree | 179e0f48f9e2b5f84ba678ee981565cf9141a7e5 | |
parent | 3aee423fc13b315cbe5df6913a0fa382deab955c (diff) | |
download | ydb-95dc8597d32cf006e8e1bb475ff2018042cfd3bf.tar.gz |
Add unit test for TEvGet reader params.
-rw-r--r-- | ydb/core/blobstorage/ut_blobstorage/CMakeLists.darwin.txt | 1 | ||||
-rw-r--r-- | ydb/core/blobstorage/ut_blobstorage/CMakeLists.linux.txt | 1 | ||||
-rw-r--r-- | ydb/core/blobstorage/ut_blobstorage/get.cpp | 86 |
3 files changed, 88 insertions, 0 deletions
diff --git a/ydb/core/blobstorage/ut_blobstorage/CMakeLists.darwin.txt b/ydb/core/blobstorage/ut_blobstorage/CMakeLists.darwin.txt index 0d52fa73458..99d510ca828 100644 --- a/ydb/core/blobstorage/ut_blobstorage/CMakeLists.darwin.txt +++ b/ydb/core/blobstorage/ut_blobstorage/CMakeLists.darwin.txt @@ -54,6 +54,7 @@ target_sources(ydb-core-blobstorage-ut_blobstorage PRIVATE ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/sync.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/replication.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/big_cluster.cpp + ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/get.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/multiget.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/osiris.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/patch.cpp diff --git a/ydb/core/blobstorage/ut_blobstorage/CMakeLists.linux.txt b/ydb/core/blobstorage/ut_blobstorage/CMakeLists.linux.txt index d045be58494..cd3f401d757 100644 --- a/ydb/core/blobstorage/ut_blobstorage/CMakeLists.linux.txt +++ b/ydb/core/blobstorage/ut_blobstorage/CMakeLists.linux.txt @@ -58,6 +58,7 @@ target_sources(ydb-core-blobstorage-ut_blobstorage PRIVATE ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/sync.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/replication.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/big_cluster.cpp + ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/get.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/multiget.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/osiris.cpp ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/ut_blobstorage/patch.cpp diff --git a/ydb/core/blobstorage/ut_blobstorage/get.cpp b/ydb/core/blobstorage/ut_blobstorage/get.cpp new file mode 100644 index 00000000000..311b1daea66 --- /dev/null +++ b/ydb/core/blobstorage/ut_blobstorage/get.cpp @@ -0,0 +1,86 @@ +#include <ydb/core/blobstorage/ut_blobstorage/lib/env.h> +#include <ydb/core/blobstorage/ut_blobstorage/lib/common.h> + +Y_UNIT_TEST_SUITE(Get) { + + void SendGet(const TTestInfo &test, const TLogoBlobID &blobId, const TString &data, + NKikimrProto::EReplyStatus status, std::optional<ui64> readerTabletId = {}, std::optional<ui32> readerTabletGeneration = {}) + { + TArrayHolder<TEvBlobStorage::TEvGet::TQuery> getQueries{new TEvBlobStorage::TEvGet::TQuery[1]}; + getQueries[0].Id = blobId; + auto ev = std::make_unique<TEvBlobStorage::TEvGet>(getQueries, 1, TInstant::Max(), + NKikimrBlobStorage::AsyncRead); + if (readerTabletId) { + ev->ReaderTabletId = *readerTabletId; + } + if (readerTabletGeneration) { + ev->ReaderTabletGeneration = *readerTabletGeneration; + } + test.Runtime->WrapInActorContext(test.Edge, [&] { + SendToBSProxy(test.Edge, test.Info->GroupID, ev.release()); + }); + std::unique_ptr<IEventHandle> handle = test.Runtime->WaitForEdgeActorEvent({test.Edge}); + UNIT_ASSERT_EQUAL(handle->Type, TEvBlobStorage::EvGetResult); + TEvBlobStorage::TEvGetResult *getResult = handle->Get<TEvBlobStorage::TEvGetResult>(); + UNIT_ASSERT(getResult); + UNIT_ASSERT_VALUES_EQUAL(getResult->ResponseSz, 1); + UNIT_ASSERT_VALUES_EQUAL(getResult->Responses[0].Status, status); + if (status == NKikimrProto::EReplyStatus::OK) { + UNIT_ASSERT_VALUES_EQUAL(getResult->Responses[0].Buffer, data); + } + } + + void SendPut(const TTestInfo &test, const TLogoBlobID &blobId, const TString &data, + NKikimrProto::EReplyStatus status) + { + std::unique_ptr<IEventBase> ev = std::make_unique<TEvBlobStorage::TEvPut>(blobId, data, TInstant::Max()); + + test.Runtime->WrapInActorContext(test.Edge, [&] { + SendToBSProxy(test.Edge, test.Info->GroupID, ev.release()); + }); + std::unique_ptr<IEventHandle> handle = test.Runtime->WaitForEdgeActorEvent({test.Edge}); + + UNIT_ASSERT_EQUAL(handle->Type, TEvBlobStorage::EvPutResult); + TEvBlobStorage::TEvPutResult *putResult = handle->Get<TEvBlobStorage::TEvPutResult>(); + UNIT_ASSERT_EQUAL(putResult->Status, status); + } + + void MakeGetTest() { + TEnvironmentSetup env(true); + TTestInfo test = InitTest(env); + + ui64 tabletId = 1; + ui32 tabletGeneration = 1; + + constexpr ui32 size = 100; + TString data(size, 'a'); + TLogoBlobID originalBlobId(tabletId, tabletGeneration, 0, 0, size, 0); + + // check that TEvGet returns OK without reader params + SendPut(test, originalBlobId, data, NKikimrProto::OK); + // check that TEvGet returns OK with reader params + SendGet(test, originalBlobId, data, NKikimrProto::OK, tabletId, tabletGeneration); + + // block tablet generation + ui32 blockedTabletGeneration = tabletGeneration + 1; + auto ev = std::make_unique<TEvBlobStorage::TEvBlock>(tabletId, blockedTabletGeneration, TInstant::Max()); + + test.Runtime->WrapInActorContext(test.Edge, [&] { + SendToBSProxy(test.Edge, test.Info->GroupID, ev.release()); + }); + + auto handle = test.Runtime->WaitForEdgeActorEvent({test.Edge}); + UNIT_ASSERT_EQUAL(handle->Type, TEvBlobStorage::EvBlockResult); + auto blockResult = handle->Get<TEvBlobStorage::TEvBlockResult>(); + UNIT_ASSERT(blockResult); + + // check that TEvGet still returns OK for blocked generation without reader params + SendGet(test, originalBlobId, data, NKikimrProto::OK); + // check that now TEvGet returns ERROR for blocked generation with reader params + SendGet(test, originalBlobId, data, NKikimrProto::ERROR, tabletId, tabletGeneration); + } + + Y_UNIT_TEST(EvGetReaderParams) { + MakeGetTest(); + } +} |