|
| 1 | +#include <ydb/core/fq/libs/control_plane_storage/control_plane_storage.h> |
| 2 | + |
| 3 | +#include <ydb/library/actors/core/executor_pool_basic.h> |
| 4 | +#include <ydb/library/actors/core/scheduler_basic.h> |
| 5 | +#include <library/cpp/testing/unittest/registar.h> |
| 6 | + |
| 7 | +#include <ydb/core/testlib/basics/runtime.h> |
| 8 | +#include <ydb/core/testlib/tablet_helpers.h> |
| 9 | + |
| 10 | +#include <ydb/core/fq/libs/control_plane_storage/events/events.h> |
| 11 | +#include <ydb/core/fq/libs/ydb/util.h> |
| 12 | +#include <ydb/core/fq/libs/ydb/ydb.h> |
| 13 | +#include <ydb/core/fq/libs/actors/logging/log.h> |
| 14 | + |
| 15 | +namespace NFq { |
| 16 | + |
| 17 | +using namespace NActors; |
| 18 | +using namespace NKikimr; |
| 19 | + |
| 20 | +namespace { |
| 21 | + |
| 22 | +//////////////////////////////////////////////////////////////////////////////// |
| 23 | + |
| 24 | +using TRuntimePtr = std::unique_ptr<TTestActorRuntime>; |
| 25 | + |
| 26 | +struct TTestBootstrap { |
| 27 | + NConfig::TControlPlaneStorageConfig Config; |
| 28 | + TRuntimePtr Runtime; |
| 29 | + |
| 30 | + const TDuration RequestTimeout = TDuration::Seconds(10); |
| 31 | + |
| 32 | + TTestBootstrap() |
| 33 | + { |
| 34 | + Runtime = PrepareTestActorRuntime(); |
| 35 | + } |
| 36 | + |
| 37 | + std::pair<FederatedQuery::CreateQueryResult, NYql::TIssues> CreateQuery() |
| 38 | + { |
| 39 | + TActorId sender = Runtime->AllocateEdgeActor(); |
| 40 | + FederatedQuery::CreateQueryRequest proto; |
| 41 | + |
| 42 | + FederatedQuery::QueryContent& content = *proto.mutable_content(); |
| 43 | + content.set_name("my_query_1"); |
| 44 | + content.set_text("SELECT 1;"); |
| 45 | + content.set_type(FederatedQuery::QueryContent::ANALYTICS); |
| 46 | + content.mutable_acl()->set_visibility(FederatedQuery::Acl::SCOPE); |
| 47 | + |
| 48 | + auto request = std::make_unique<TEvControlPlaneStorage::TEvCreateQueryRequest>("yandexcloud://my_cloud_1/my_folder_1", proto, "user@staff", "", "mock_cloud", TPermissions{}, TQuotaMap{}, std::make_shared<TTenantInfo>(), FederatedQuery::Internal::ComputeDatabaseInternal{}); |
| 49 | + Runtime->Send(new IEventHandle(ControlPlaneStorageServiceActorId(), sender, request.release())); |
| 50 | + |
| 51 | + TAutoPtr<IEventHandle> handle; |
| 52 | + TEvControlPlaneStorage::TEvCreateQueryResponse* event = Runtime->GrabEdgeEvent<TEvControlPlaneStorage::TEvCreateQueryResponse>(handle); |
| 53 | + return {event->Result, event->Issues}; |
| 54 | + } |
| 55 | + |
| 56 | +private: |
| 57 | + TRuntimePtr PrepareTestActorRuntime() { |
| 58 | + TRuntimePtr runtime(new TTestBasicRuntime(1)); |
| 59 | + runtime->SetLogPriority(NKikimrServices::YQ_CONTROL_PLANE_STORAGE, NLog::PRI_DEBUG); |
| 60 | + |
| 61 | + auto controlPlaneProxy = CreateInMemoryControlPlaneStorageServiceActor(Config); |
| 62 | + |
| 63 | + runtime->AddLocalService( |
| 64 | + ControlPlaneStorageServiceActorId(), |
| 65 | + TActorSetupCmd(controlPlaneProxy, TMailboxType::Simple, 0)); |
| 66 | + |
| 67 | + SetupTabletServices(*runtime); |
| 68 | + |
| 69 | + return runtime; |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +Y_UNIT_TEST_SUITE(CreateQueryRequest) { |
| 76 | + Y_UNIT_TEST(ShouldCreateSimpleQuery) |
| 77 | + { |
| 78 | + TTestBootstrap bootstrap; |
| 79 | + const auto [result, issues] = bootstrap.CreateQuery(); |
| 80 | + UNIT_ASSERT(!issues); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +} // NFq |
0 commit comments