summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yt/yt/client/chaos_client/replication_card.cpp36
-rw-r--r--yt/yt/client/chaos_client/replication_card.h2
-rw-r--r--yt/yt/client/unittests/replication_card_ut.cpp98
-rw-r--r--yt/yt/client/unittests/ya.make1
4 files changed, 137 insertions, 0 deletions
diff --git a/yt/yt/client/chaos_client/replication_card.cpp b/yt/yt/client/chaos_client/replication_card.cpp
index ec61deb64dd..a4235d64552 100644
--- a/yt/yt/client/chaos_client/replication_card.cpp
+++ b/yt/yt/client/chaos_client/replication_card.cpp
@@ -61,6 +61,36 @@ void FormatProgressWithProjection(
builder->AppendChar(']');
}
+DEFINE_BIT_ENUM_WITH_UNDERLYING_TYPE(EReplicationCardOptionsBits, uint8_t,
+ ((None)(0))
+ ((IncludeCoordinators)(1 << 0))
+ ((IncludeProgress)(1 << 1))
+ ((IncludeHistory)(1 << 2))
+ ((IncludeReplicatedTableOptions)(1 << 3))
+);
+
+EReplicationCardOptionsBits ToBitMask(const TReplicationCardFetchOptions& options)
+{
+ auto mask = EReplicationCardOptionsBits::None;
+ if (options.IncludeCoordinators) {
+ mask |= EReplicationCardOptionsBits::IncludeCoordinators;
+ }
+
+ if (options.IncludeProgress) {
+ mask |= EReplicationCardOptionsBits::IncludeProgress;
+ }
+
+ if (options.IncludeHistory) {
+ mask |= EReplicationCardOptionsBits::IncludeHistory;
+ }
+
+ if (options.IncludeReplicatedTableOptions) {
+ mask |= EReplicationCardOptionsBits::IncludeReplicatedTableOptions;
+ }
+
+ return mask;
+}
+
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
@@ -86,6 +116,12 @@ TString ToString(const TReplicationCardFetchOptions& options)
return ToStringViaBuilder(options);
}
+bool TReplicationCardFetchOptions::Contains(const TReplicationCardFetchOptions& other) const
+{
+ auto selfMask = NDetail::ToBitMask(*this);
+ return (selfMask | NDetail::ToBitMask(other)) == selfMask;
+}
+
////////////////////////////////////////////////////////////////////////////////
void FormatValue(
diff --git a/yt/yt/client/chaos_client/replication_card.h b/yt/yt/client/chaos_client/replication_card.h
index 58a2cc8f0cd..62daba4e145 100644
--- a/yt/yt/client/chaos_client/replication_card.h
+++ b/yt/yt/client/chaos_client/replication_card.h
@@ -91,6 +91,8 @@ struct TReplicationCardFetchOptions
operator size_t() const;
bool operator == (const TReplicationCardFetchOptions& other) const = default;
+
+ bool Contains(const TReplicationCardFetchOptions& other) const;
};
void FormatValue(TStringBuilderBase* builder, const TReplicationCardFetchOptions& options, TStringBuf /*spec*/);
diff --git a/yt/yt/client/unittests/replication_card_ut.cpp b/yt/yt/client/unittests/replication_card_ut.cpp
new file mode 100644
index 00000000000..92bc3a52ebb
--- /dev/null
+++ b/yt/yt/client/unittests/replication_card_ut.cpp
@@ -0,0 +1,98 @@
+#include <yt/yt/client/chaos_client/replication_card.h>
+
+#include <yt/yt/core/test_framework/framework.h>
+
+namespace NYT::NChaosClient {
+namespace {
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TReplicationCardFetchOptionsTest
+ : public ::testing::Test
+ , public ::testing::WithParamInterface<std::tuple<
+ TReplicationCardFetchOptions,
+ TReplicationCardFetchOptions,
+ bool>>
+{ };
+
+TEST_P(TReplicationCardFetchOptionsTest, Contains)
+{
+ const auto& params = GetParam();
+ auto self = std::get<0>(params);
+ auto& other = std::get<1>(params);
+ auto expected = std::get<2>(params);
+
+
+ EXPECT_EQ(self.Contains(other), expected)
+ << "progress: " << std::get<0>(params) << std::endl
+ << "update: " << std::get<1>(params) << std::endl
+ << "expected: " << std::get<2>(params) << std::endl
+ << "actual: " << self.Contains(other) << std::endl;
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ TReplicationCardFetchOptionsTest,
+ TReplicationCardFetchOptionsTest,
+ ::testing::Values(
+ std::tuple(
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = true,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = true
+ },
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = false,
+ .IncludeProgress = false,
+ .IncludeHistory = false,
+ .IncludeReplicatedTableOptions = false
+ },
+ true),
+ std::tuple(
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = true,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = true
+ },
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = true,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = true
+ },
+ true),
+ std::tuple(
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = true,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = true
+ },
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = false,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = false
+ },
+ true),
+ std::tuple(
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = true,
+ .IncludeProgress = false,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = false
+ },
+ TReplicationCardFetchOptions {
+ .IncludeCoordinators = false,
+ .IncludeProgress = true,
+ .IncludeHistory = true,
+ .IncludeReplicatedTableOptions = false
+ },
+ false)
+));
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace
+} // namespace NYT::NChaosClient
diff --git a/yt/yt/client/unittests/ya.make b/yt/yt/client/unittests/ya.make
index bf1a29f0697..f5111fca971 100644
--- a/yt/yt/client/unittests/ya.make
+++ b/yt/yt/client/unittests/ya.make
@@ -26,6 +26,7 @@ SRCS(
node_directory_ut.cpp
query_builder_ut.cpp
read_limit_ut.cpp
+ replication_card_ut.cpp
replication_progress_ut.cpp
row_ut.cpp
schema_ut.cpp