]>
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
, int8_t index
,
19 if ((mask
& ColumnTypeMask::DELETION_MASK
) != 0) {
20 return std::shared_ptr
<Tombstone
>(
21 new Tombstone(mask
, index
, ToSeconds(timestamp
), timestamp
));
22 } else if ((mask
& ColumnTypeMask::EXPIRATION_MASK
) != 0) {
23 return std::shared_ptr
<ExpiringColumn
>(new ExpiringColumn(
24 mask
, index
, timestamp
, sizeof(kExpiringData
), kExpiringData
, kTtl
));
26 return std::shared_ptr
<Column
>(
27 new Column(mask
, index
, timestamp
, sizeof(kData
), kData
));
31 std::tuple
<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask
,
34 return std::make_tuple(mask
, index
, timestamp
);
37 RowValue
CreateTestRowValue(
38 std::vector
<std::tuple
<int8_t, int8_t, int64_t>> column_specs
) {
39 std::vector
<std::shared_ptr
<ColumnBase
>> columns
;
40 int64_t last_modified_time
= 0;
41 for (auto spec
: column_specs
) {
42 auto c
= CreateTestColumn(std::get
<0>(spec
), std::get
<1>(spec
),
44 last_modified_time
= std::max(last_modified_time
, c
->Timestamp());
45 columns
.push_back(std::move(c
));
47 return RowValue(std::move(columns
), last_modified_time
);
50 RowValue
CreateRowTombstone(int64_t timestamp
) {
51 return RowValue(ToSeconds(timestamp
), timestamp
);
54 void VerifyRowValueColumns(
55 const std::vector
<std::shared_ptr
<ColumnBase
>> &columns
,
56 std::size_t index_of_vector
, int8_t expected_mask
, int8_t expected_index
,
57 int64_t expected_timestamp
) {
58 EXPECT_EQ(expected_timestamp
, columns
[index_of_vector
]->Timestamp());
59 EXPECT_EQ(expected_mask
, columns
[index_of_vector
]->Mask());
60 EXPECT_EQ(expected_index
, columns
[index_of_vector
]->Index());
63 int64_t ToMicroSeconds(int64_t seconds
) { return seconds
* (int64_t)1000000; }
65 int32_t ToSeconds(int64_t microseconds
) {
66 return (int32_t)(microseconds
/ (int64_t)1000000);
68 } // namespace cassandra
69 } // namespace ROCKSDB_NAMESPACE