]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/util_merge_operators_test.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 #include "test_util/testharness.h"
7 #include "test_util/testutil.h"
8 #include "utilities/merge_operators.h"
10 namespace ROCKSDB_NAMESPACE
{
12 class UtilMergeOperatorTest
: public testing::Test
{
14 UtilMergeOperatorTest() {}
16 std::string
FullMergeV2(std::string existing_value
,
17 std::vector
<std::string
> operands
,
18 std::string key
= "") {
20 Slice
result_operand(nullptr, 0);
22 Slice
existing_value_slice(existing_value
);
23 std::vector
<Slice
> operands_slice(operands
.begin(), operands
.end());
25 const MergeOperator::MergeOperationInput
merge_in(
26 key
, &existing_value_slice
, operands_slice
, nullptr);
27 MergeOperator::MergeOperationOutput
merge_out(result
, result_operand
);
28 merge_operator_
->FullMergeV2(merge_in
, &merge_out
);
30 if (result_operand
.data()) {
31 result
.assign(result_operand
.data(), result_operand
.size());
36 std::string
FullMergeV2(std::vector
<std::string
> operands
,
37 std::string key
= "") {
39 Slice
result_operand(nullptr, 0);
41 std::vector
<Slice
> operands_slice(operands
.begin(), operands
.end());
43 const MergeOperator::MergeOperationInput
merge_in(key
, nullptr,
44 operands_slice
, nullptr);
45 MergeOperator::MergeOperationOutput
merge_out(result
, result_operand
);
46 merge_operator_
->FullMergeV2(merge_in
, &merge_out
);
48 if (result_operand
.data()) {
49 result
.assign(result_operand
.data(), result_operand
.size());
54 std::string
PartialMerge(std::string left
, std::string right
,
55 std::string key
= "") {
58 merge_operator_
->PartialMerge(key
, left
, right
, &result
, nullptr);
62 std::string
PartialMergeMulti(std::deque
<std::string
> operands
,
63 std::string key
= "") {
65 std::deque
<Slice
> operands_slice(operands
.begin(), operands
.end());
67 merge_operator_
->PartialMergeMulti(key
, operands_slice
, &result
, nullptr);
72 std::shared_ptr
<MergeOperator
> merge_operator_
;
75 TEST_F(UtilMergeOperatorTest
, MaxMergeOperator
) {
76 merge_operator_
= MergeOperators::CreateMaxOperator();
78 EXPECT_EQ("B", FullMergeV2("B", {"A"}));
79 EXPECT_EQ("B", FullMergeV2("A", {"B"}));
80 EXPECT_EQ("", FullMergeV2({"", "", ""}));
81 EXPECT_EQ("A", FullMergeV2({"A"}));
82 EXPECT_EQ("ABC", FullMergeV2({"ABC"}));
83 EXPECT_EQ("Z", FullMergeV2({"ABC", "Z", "C", "AXX"}));
84 EXPECT_EQ("ZZZ", FullMergeV2({"ABC", "CC", "Z", "ZZZ"}));
85 EXPECT_EQ("a", FullMergeV2("a", {"ABC", "CC", "Z", "ZZZ"}));
87 EXPECT_EQ("z", PartialMergeMulti({"a", "z", "efqfqwgwew", "aaz", "hhhhh"}));
89 EXPECT_EQ("b", PartialMerge("a", "b"));
90 EXPECT_EQ("z", PartialMerge("z", "azzz"));
91 EXPECT_EQ("a", PartialMerge("a", ""));
94 } // namespace ROCKSDB_NAMESPACE
96 int main(int argc
, char** argv
) {
97 ::testing::InitGoogleTest(&argc
, argv
);
98 return RUN_ALL_TESTS();