]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/cassandra/test_utils.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / utilities / cassandra / test_utils.cc
1 // Copyright (c) 2017-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).
5
6 #include "test_utils.h"
7
8 namespace ROCKSDB_NAMESPACE {
9 namespace cassandra {
10 const char kData[] = {'d', 'a', 't', 'a'};
11 const char kExpiringData[] = {'e', 'd', 'a', 't', 'a'};
12 const int32_t kTtl = 86400;
13 const int8_t kColumn = 0;
14 const int8_t kTombstone = 1;
15 const int8_t kExpiringColumn = 2;
16
17 std::shared_ptr<ColumnBase> CreateTestColumn(int8_t mask,
18 int8_t index,
19 int64_t timestamp) {
20 if ((mask & ColumnTypeMask::DELETION_MASK) != 0) {
21 return std::shared_ptr<Tombstone>(
22 new Tombstone(mask, index, ToSeconds(timestamp), timestamp));
23 } else if ((mask & ColumnTypeMask::EXPIRATION_MASK) != 0) {
24 return std::shared_ptr<ExpiringColumn>(new ExpiringColumn(
25 mask, index, timestamp, sizeof(kExpiringData), kExpiringData, kTtl));
26 } else {
27 return std::shared_ptr<Column>(
28 new Column(mask, index, timestamp, sizeof(kData), kData));
29 }
30 }
31
32 std::tuple<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask,
33 int8_t index,
34 int64_t timestamp) {
35 return std::make_tuple(mask, index, timestamp);
36 }
37
38 RowValue CreateTestRowValue(
39 std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs) {
40 std::vector<std::shared_ptr<ColumnBase>> columns;
41 int64_t last_modified_time = 0;
42 for (auto spec: column_specs) {
43 auto c = CreateTestColumn(std::get<0>(spec), std::get<1>(spec),
44 std::get<2>(spec));
45 last_modified_time = std::max(last_modified_time, c -> Timestamp());
46 columns.push_back(std::move(c));
47 }
48 return RowValue(std::move(columns), last_modified_time);
49 }
50
51 RowValue CreateRowTombstone(int64_t timestamp) {
52 return RowValue(ToSeconds(timestamp), timestamp);
53 }
54
55 void VerifyRowValueColumns(
56 std::vector<std::shared_ptr<ColumnBase>> &columns,
57 std::size_t index_of_vector,
58 int8_t expected_mask,
59 int8_t expected_index,
60 int64_t expected_timestamp
61 ) {
62 EXPECT_EQ(expected_timestamp, columns[index_of_vector]->Timestamp());
63 EXPECT_EQ(expected_mask, columns[index_of_vector]->Mask());
64 EXPECT_EQ(expected_index, columns[index_of_vector]->Index());
65 }
66
67 int64_t ToMicroSeconds(int64_t seconds) {
68 return seconds * (int64_t)1000000;
69 }
70
71 int32_t ToSeconds(int64_t microseconds) {
72 return (int32_t)(microseconds / (int64_t)1000000);
73 }
74 }
75 } // namespace ROCKSDB_NAMESPACE