2017-06-16 21:12:52 +00:00
|
|
|
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2022-10-24 23:38:09 +00:00
|
|
|
|
2019-05-30 18:21:38 +00:00
|
|
|
#include "test_util/testharness.h"
|
2017-07-21 21:42:32 +00:00
|
|
|
#include "utilities/cassandra/format.h"
|
|
|
|
#include "utilities/cassandra/test_utils.h"
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-06-16 21:12:52 +00:00
|
|
|
namespace cassandra {
|
|
|
|
|
2020-06-02 20:54:03 +00:00
|
|
|
class RowValueMergeTest : public testing::Test {};
|
|
|
|
|
2017-06-16 21:12:52 +00:00
|
|
|
TEST(RowValueMergeTest, Merge) {
|
|
|
|
std::vector<RowValue> row_values;
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kTombstone, 0, 5),
|
|
|
|
CreateTestColumnSpec(kColumn, 1, 8),
|
|
|
|
CreateTestColumnSpec(kExpiringColumn, 2, 5),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kColumn, 0, 2),
|
|
|
|
CreateTestColumnSpec(kExpiringColumn, 1, 5),
|
|
|
|
CreateTestColumnSpec(kTombstone, 2, 7),
|
|
|
|
CreateTestColumnSpec(kExpiringColumn, 7, 17),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kExpiringColumn, 0, 6),
|
|
|
|
CreateTestColumnSpec(kTombstone, 1, 5),
|
|
|
|
CreateTestColumnSpec(kColumn, 2, 4),
|
|
|
|
CreateTestColumnSpec(kTombstone, 11, 11),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
RowValue merged = RowValue::Merge(std::move(row_values));
|
|
|
|
EXPECT_FALSE(merged.IsTombstone());
|
2020-06-02 20:54:03 +00:00
|
|
|
EXPECT_EQ(merged.get_columns().size(), 5);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 0, kExpiringColumn, 0, 6);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 1, kColumn, 1, 8);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 2, kTombstone, 2, 7);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 3, kExpiringColumn, 7, 17);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 4, kTombstone, 11, 11);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RowValueMergeTest, MergeWithRowTombstone) {
|
|
|
|
std::vector<RowValue> row_values;
|
|
|
|
|
|
|
|
// A row tombstone.
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateRowTombstone(11));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
// This row's timestamp is smaller than tombstone.
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kColumn, 0, 5),
|
|
|
|
CreateTestColumnSpec(kColumn, 1, 6),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
// Some of the column's row is smaller, some is larger.
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kColumn, 2, 10),
|
|
|
|
CreateTestColumnSpec(kColumn, 3, 12),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
// All of the column's rows are larger than tombstone.
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateTestRowValue({
|
2017-12-14 19:57:11 +00:00
|
|
|
CreateTestColumnSpec(kColumn, 4, 13),
|
|
|
|
CreateTestColumnSpec(kColumn, 5, 14),
|
2022-10-24 23:38:09 +00:00
|
|
|
}));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
RowValue merged = RowValue::Merge(std::move(row_values));
|
|
|
|
EXPECT_FALSE(merged.IsTombstone());
|
2020-06-02 20:54:03 +00:00
|
|
|
EXPECT_EQ(merged.get_columns().size(), 3);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 0, kColumn, 3, 12);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 1, kColumn, 4, 13);
|
|
|
|
VerifyRowValueColumns(merged.get_columns(), 2, kColumn, 5, 14);
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
// If the tombstone's timestamp is the latest, then it returns a
|
|
|
|
// row tombstone.
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateRowTombstone(15));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
row_values.push_back(CreateRowTombstone(17));
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
merged = RowValue::Merge(std::move(row_values));
|
|
|
|
EXPECT_TRUE(merged.IsTombstone());
|
|
|
|
EXPECT_EQ(merged.LastModifiedTime(), 17);
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
} // namespace cassandra
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2022-10-18 07:35:35 +00:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2017-06-16 21:12:52 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|