]>
git.proxmox.com Git - ceph.git/blob - 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).
6 #include "test_utils.h"
8 namespace ROCKSDB_NAMESPACE
{
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;
17 std::shared_ptr
<ColumnBase
> CreateTestColumn(int8_t mask
,
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
));
27 return std::shared_ptr
<Column
>(
28 new Column(mask
, index
, timestamp
, sizeof(kData
), kData
));
32 std::tuple
<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask
,
35 return std::make_tuple(mask
, index
, timestamp
);
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
),
45 last_modified_time
= std::max(last_modified_time
, c
-> Timestamp());
46 columns
.push_back(std::move(c
));
48 return RowValue(std::move(columns
), last_modified_time
);
51 RowValue
CreateRowTombstone(int64_t timestamp
) {
52 return RowValue(ToSeconds(timestamp
), timestamp
);
55 void VerifyRowValueColumns(
56 std::vector
<std::shared_ptr
<ColumnBase
>> &columns
,
57 std::size_t index_of_vector
,
59 int8_t expected_index
,
60 int64_t expected_timestamp
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());
67 int64_t ToMicroSeconds(int64_t seconds
) {
68 return seconds
* (int64_t)1000000;
71 int32_t ToSeconds(int64_t microseconds
) {
72 return (int32_t)(microseconds
/ (int64_t)1000000);
75 } // namespace ROCKSDB_NAMESPACE