summaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/tests
diff options
context:
space:
mode:
authormax42 <[email protected]>2023-07-29 00:02:16 +0300
committermax42 <[email protected]>2023-07-29 00:02:16 +0300
commit73b89de71748a21e102d27b9f3ed1bf658766cb5 (patch)
tree188bbd2d622fa91cdcbb1b6d6d77fbc84a0646f5 /yt/cpp/mapreduce/tests
parent528e321bcc2a2b67b53aeba58c3bd88305a141ee (diff)
YT-19210: expose YQL shared library for YT.
After this, a new target libyqlplugin.so appears. in open-source cmake build. Diff in open-source YDB repo looks like the following: https://paste.yandex-team.ru/f302bdb4-7ef2-4362-91c7-6ca45f329264
Diffstat (limited to 'yt/cpp/mapreduce/tests')
-rw-r--r--yt/cpp/mapreduce/tests/yt_unittest_lib/yt_unittest_lib.h194
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)