diff options
| author | max42 <[email protected]> | 2023-06-30 03:37:03 +0300 |
|---|---|---|
| committer | max42 <[email protected]> | 2023-06-30 03:37:03 +0300 |
| commit | fac2bd72b4b31ec3238292caf8fb2a8aaa6d6c4a (patch) | |
| tree | b8cbc1deb00309c7f1a7ab6df520a76cf0b5c6d7 /yt/cpp/mapreduce/tests | |
| parent | 7bf166b1a7ed0af927f230022b245af618e998c1 (diff) | |
YT-19324: move YT provider to ydb/library/yql
This commit is formed by the following script: https://paste.yandex-team.ru/6f92e4b8-efc5-4d34-948b-15ee2accd7e7/text.
This commit has zero effect on all projects that depend on YQL.
The summary of changes:
- `yql/providers/yt -> ydb/library/yql/providers/yt `- the whole implementation of YT provider is moved into YDB code base for further export as a part of YT YQL plugin shared library;
- `yql/providers/stat/{expr_nodes,uploader} -> ydb/library/yql/providers/stat/{expr_nodes,uploader}` - a small interface without implementation and the description of stat expr nodes;
- `yql/core/extract_predicate/ut -> ydb/library/yql/core/extract_predicate/ut`;
- `yql/core/{ut,ut_common} -> ydb/library/yql/core/{ut,ut_common}`;
- `yql/core` is gone;
- `yql/library/url_preprocessing -> ydb/library/yql/core/url_preprocessing`.
**NB**: all new targets inside `ydb/` are under `IF (NOT CMAKE_EXPORT)` clause which disables them from open-source cmake generation and ya make build. They will be enabled in the subsequent commits.
Diffstat (limited to 'yt/cpp/mapreduce/tests')
| -rw-r--r-- | yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib.h | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib.h b/yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib.h new file mode 100644 index 00000000000..37d9d501cd1 --- /dev/null +++ b/yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib.h @@ -0,0 +1,194 @@ +#pragma once + +#include <yt/cpp/mapreduce/interface/logging/logger.h> +#include <yt/cpp/mapreduce/interface/client.h> + +#include <yt/cpp/mapreduce/interface/config.h> + +#include <library/cpp/yson/node/node_io.h> + +#include <util/generic/bt_exception.h> + +#include <util/datetime/base.h> + +//////////////////////////////////////////////////////////////////////////////// + +template<> +void Out<NYT::TNode>(IOutputStream& s, const NYT::TNode& node); + +template<> +void Out<TGUID>(IOutputStream& s, const TGUID& guid); + +//////////////////////////////////////////////////////////////////////////////// + +namespace NYT { +namespace NTesting { + +//////////////////////////////////////////////////////////////////////////////// + +IClientPtr CreateTestClient(TString proxy = "", const TCreateClientOptions& options = {}); + +// Create map node by unique path in Cypress and return that path. +TYPath CreateTestDirectory(const IClientBasePtr& client); + +TString GenerateRandomData(size_t size, ui64 seed = 42); + +TVector<TNode> ReadTable(const IClientBasePtr& client, const TString& tablePath); + +//////////////////////////////////////////////////////////////////////////////// + +// TODO: should be removed, usages should be replaced with TConfigSaverGuard +class TZeroWaitLockPollIntervalGuard +{ +public: + TZeroWaitLockPollIntervalGuard(); + + ~TZeroWaitLockPollIntervalGuard(); + +private: + TDuration OldWaitLockPollInterval_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TConfigSaverGuard +{ +public: + TConfigSaverGuard(); + ~TConfigSaverGuard(); + +private: + TConfig Config_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TDebugMetricDiff +{ +public: + TDebugMetricDiff(TString name); + ui64 GetTotal() const; + +private: + TString Name_; + ui64 InitialValue_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +struct TOwningYaMRRow +{ + TString Key; + TString SubKey; + TString Value; + + TOwningYaMRRow(const TYaMRRow& row = {}); + TOwningYaMRRow(TString key, TString subKey, TString value); + + operator TYaMRRow() const; +}; + +bool operator == (const TOwningYaMRRow& row1, const TOwningYaMRRow& row2); + +//////////////////////////////////////////////////////////////////////////////// + +class TTestFixture +{ +public: + explicit TTestFixture(const TCreateClientOptions& options = {}); + ~TTestFixture(); + + // Return precreated client. + IClientPtr GetClient() const; + + // Return newly created client. Useful for cases: + // - when we want to have multiple clients objects; + // - when we want to control to control destruction of client object; + IClientPtr CreateClient(const TCreateClientOptions& options = {}) const; + + IClientPtr CreateClientForUser(const TString& user, TCreateClientOptions options = {}); + + TYPath GetWorkingDir() const; + +private: + TConfigSaverGuard ConfigGuard_; + IClientPtr Client_; + TYPath WorkingDir_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TTabletFixture + : public TTestFixture +{ +public: + TTabletFixture(); + +private: + void WaitForTabletCell(); +}; + +//////////////////////////////////////////////////////////////////////////////// + +// Compares only columns and only "name" and "type" fields of columns. +bool AreSchemasEqual(const TTableSchema& lhs, const TTableSchema& rhs); + +class TWaitFailedException + : public TWithBackTrace<yexception> +{ }; + +void WaitForPredicate(const std::function<bool()>& predicate, TDuration timeout = TDuration::Seconds(60)); + +//////////////////////////////////////////////////////////////////////////////// + +// Redirects all the LOG_* calls with the corresponding level to `stream`. +// Moreover, the LOG_* calls are delegated to `oldLogger`. +class TStreamTeeLogger + : public ILogger +{ +public: + TStreamTeeLogger(ELevel cutLevel, IOutputStream* stream, ILoggerPtr oldLogger); + void Log(ELevel level, const ::TSourceLocation& sourceLocation, const char* format, va_list args) override; + +private: + ILoggerPtr OldLogger_; + IOutputStream* Stream_; + ELevel Level_; +}; + +//////////////////////////////////////////////////////////////////////////////// + +template <typename T> +TString ToYson(const T& x) +{ + TNode result; + TNodeBuilder builder(&result); + Serialize(x, &builder); + return NodeToYsonString(result); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NTesting +} // namespace NYT + +//////////////////////////////////////////////////////////////////////////////// + +template <> +void Out<NYT::NTesting::TOwningYaMRRow>(IOutputStream& out, const NYT::NTesting::TOwningYaMRRow& row); + +//////////////////////////////////////////////////////////////////////////////// + +// for UNITTEST() +#define ASSERT_SERIALIZABLES_EQUAL(a, b) \ + UNIT_ASSERT_EQUAL_C(a, b, NYT::NTesting::ToYson(a) << " != " << NYT::NTesting::ToYson(b)) + +#define ASSERT_SERIALIZABLES_UNEQUAL(a, b) \ + UNIT_ASSERT_UNEQUAL_C(a, b, NYT::NTesting::ToYson(a) << " == " << NYT::NTesting::ToYson(b)) + +// for GTEST() +#define ASSERT_SERIALIZABLES_EQ(a, b) \ + ASSERT_EQ(a, b) << NYT::NTesting::ToYson(a) << " != " << NYT::NTesting::ToYson(b) + +#define ASSERT_SERIALIZABLES_NE(a, b) \ + ASSERT_NE(a, b) << NYT::NTesting::ToYson(a) << " == " << NYT::NTesting::ToYson(b) |
