test_utils.cc 2.7 KB

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