db_with_timestamp_test_util.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2011-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. //
  6. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. #include "db/db_with_timestamp_test_util.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. std::string DBBasicTestWithTimestampBase::Key1(uint64_t k) {
  12. std::string ret;
  13. PutFixed64(&ret, k);
  14. std::reverse(ret.begin(), ret.end());
  15. return ret;
  16. }
  17. std::string DBBasicTestWithTimestampBase::KeyWithPrefix(std::string prefix,
  18. uint64_t k) {
  19. std::string ret;
  20. PutFixed64(&ret, k);
  21. std::reverse(ret.begin(), ret.end());
  22. return prefix + ret;
  23. }
  24. std::vector<Slice> DBBasicTestWithTimestampBase::ConvertStrToSlice(
  25. std::vector<std::string>& strings) {
  26. std::vector<Slice> ret;
  27. for (const auto& s : strings) {
  28. ret.emplace_back(s);
  29. }
  30. return ret;
  31. }
  32. std::string DBBasicTestWithTimestampBase::Timestamp(uint64_t low,
  33. uint64_t high) {
  34. std::string ts;
  35. PutFixed64(&ts, low);
  36. PutFixed64(&ts, high);
  37. return ts;
  38. }
  39. void DBBasicTestWithTimestampBase::CheckIterUserEntry(
  40. const Iterator* it, const Slice& expected_key,
  41. ValueType expected_value_type, const Slice& expected_value,
  42. const Slice& expected_ts) const {
  43. ASSERT_TRUE(it->Valid());
  44. ASSERT_OK(it->status());
  45. ASSERT_EQ(expected_key, it->key());
  46. if (kTypeValue == expected_value_type) {
  47. ASSERT_EQ(expected_value, it->value());
  48. }
  49. ASSERT_EQ(expected_ts, it->timestamp());
  50. }
  51. void DBBasicTestWithTimestampBase::CheckIterEntry(
  52. const Iterator* it, const Slice& expected_ukey, SequenceNumber expected_seq,
  53. ValueType expected_val_type, const Slice& expected_value,
  54. const Slice& expected_ts) const {
  55. ASSERT_TRUE(it->Valid());
  56. ASSERT_OK(it->status());
  57. std::string ukey_and_ts;
  58. ukey_and_ts.assign(expected_ukey.data(), expected_ukey.size());
  59. ukey_and_ts.append(expected_ts.data(), expected_ts.size());
  60. ParsedInternalKey parsed_ikey;
  61. ASSERT_OK(ParseInternalKey(it->key(), &parsed_ikey, true /* log_err_key */));
  62. ASSERT_EQ(ukey_and_ts, parsed_ikey.user_key);
  63. ASSERT_EQ(expected_val_type, parsed_ikey.type);
  64. ASSERT_EQ(expected_seq, parsed_ikey.sequence);
  65. if (expected_val_type == kTypeValue) {
  66. ASSERT_EQ(expected_value, it->value());
  67. }
  68. ASSERT_EQ(expected_ts, it->timestamp());
  69. }
  70. void DBBasicTestWithTimestampBase::CheckIterEntry(
  71. const Iterator* it, const Slice& expected_ukey, ValueType expected_val_type,
  72. const Slice& expected_value, const Slice& expected_ts) const {
  73. ASSERT_TRUE(it->Valid());
  74. ASSERT_OK(it->status());
  75. std::string ukey_and_ts;
  76. ukey_and_ts.assign(expected_ukey.data(), expected_ukey.size());
  77. ukey_and_ts.append(expected_ts.data(), expected_ts.size());
  78. ParsedInternalKey parsed_ikey;
  79. ASSERT_OK(ParseInternalKey(it->key(), &parsed_ikey, true /* log_err_key */));
  80. ASSERT_EQ(expected_val_type, parsed_ikey.type);
  81. ASSERT_EQ(Slice(ukey_and_ts), parsed_ikey.user_key);
  82. if (expected_val_type == kTypeValue) {
  83. ASSERT_EQ(expected_value, it->value());
  84. }
  85. ASSERT_EQ(expected_ts, it->timestamp());
  86. }
  87. } // namespace ROCKSDB_NAMESPACE