test_utils.cc 2.6 KB

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