2017-07-28 20:55:19 +00:00
|
|
|
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
|
|
|
// 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 "test_utils.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-06-16 21:12:52 +00:00
|
|
|
namespace cassandra {
|
|
|
|
const char kData[] = {'d', 'a', 't', 'a'};
|
|
|
|
const char kExpiringData[] = {'e', 'd', 'a', 't', 'a'};
|
2017-07-21 21:42:32 +00:00
|
|
|
const int32_t kTtl = 86400;
|
2017-06-16 21:12:52 +00:00
|
|
|
const int8_t kColumn = 0;
|
|
|
|
const int8_t kTombstone = 1;
|
|
|
|
const int8_t kExpiringColumn = 2;
|
|
|
|
|
2017-07-21 21:42:32 +00:00
|
|
|
std::shared_ptr<ColumnBase> CreateTestColumn(int8_t mask,
|
2017-06-16 21:12:52 +00:00
|
|
|
int8_t index,
|
|
|
|
int64_t timestamp) {
|
|
|
|
if ((mask & ColumnTypeMask::DELETION_MASK) != 0) {
|
2017-08-31 17:10:47 +00:00
|
|
|
return std::shared_ptr<Tombstone>(
|
|
|
|
new Tombstone(mask, index, ToSeconds(timestamp), timestamp));
|
2017-06-16 21:12:52 +00:00
|
|
|
} else if ((mask & ColumnTypeMask::EXPIRATION_MASK) != 0) {
|
2017-07-21 21:42:32 +00:00
|
|
|
return std::shared_ptr<ExpiringColumn>(new ExpiringColumn(
|
2017-06-16 21:12:52 +00:00
|
|
|
mask, index, timestamp, sizeof(kExpiringData), kExpiringData, kTtl));
|
|
|
|
} else {
|
2017-07-21 21:42:32 +00:00
|
|
|
return std::shared_ptr<Column>(
|
2017-06-16 21:12:52 +00:00
|
|
|
new Column(mask, index, timestamp, sizeof(kData), kData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:57:11 +00:00
|
|
|
std::tuple<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask,
|
|
|
|
int8_t index,
|
|
|
|
int64_t timestamp) {
|
|
|
|
return std::make_tuple(mask, index, timestamp);
|
|
|
|
}
|
|
|
|
|
2017-06-16 21:12:52 +00:00
|
|
|
RowValue CreateTestRowValue(
|
|
|
|
std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs) {
|
2017-07-21 21:42:32 +00:00
|
|
|
std::vector<std::shared_ptr<ColumnBase>> columns;
|
2017-06-16 21:12:52 +00:00
|
|
|
int64_t last_modified_time = 0;
|
|
|
|
for (auto spec: column_specs) {
|
|
|
|
auto c = CreateTestColumn(std::get<0>(spec), std::get<1>(spec),
|
|
|
|
std::get<2>(spec));
|
|
|
|
last_modified_time = std::max(last_modified_time, c -> Timestamp());
|
|
|
|
columns.push_back(std::move(c));
|
|
|
|
}
|
|
|
|
return RowValue(std::move(columns), last_modified_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
RowValue CreateRowTombstone(int64_t timestamp) {
|
2017-08-31 17:10:47 +00:00
|
|
|
return RowValue(ToSeconds(timestamp), timestamp);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyRowValueColumns(
|
2020-06-02 20:54:03 +00:00
|
|
|
const std::vector<std::shared_ptr<ColumnBase>> &columns,
|
|
|
|
std::size_t index_of_vector, int8_t expected_mask, int8_t expected_index,
|
|
|
|
int64_t expected_timestamp) {
|
2017-06-16 21:12:52 +00:00
|
|
|
EXPECT_EQ(expected_timestamp, columns[index_of_vector]->Timestamp());
|
|
|
|
EXPECT_EQ(expected_mask, columns[index_of_vector]->Mask());
|
|
|
|
EXPECT_EQ(expected_index, columns[index_of_vector]->Index());
|
|
|
|
}
|
|
|
|
|
2017-07-21 21:42:32 +00:00
|
|
|
int64_t ToMicroSeconds(int64_t seconds) {
|
|
|
|
return seconds * (int64_t)1000000;
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:10:47 +00:00
|
|
|
int32_t ToSeconds(int64_t microseconds) {
|
|
|
|
return (int32_t)(microseconds / (int64_t)1000000);
|
|
|
|
}
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|