mock_block_based_table.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2019-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. #pragma once
  6. #include <memory>
  7. #include "rocksdb/filter_policy.h"
  8. #include "table/block_based/block_based_table_reader.h"
  9. #include "table/block_based/filter_policy_internal.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. namespace mock {
  12. class MockBlockBasedTable : public BlockBasedTable {
  13. public:
  14. explicit MockBlockBasedTable(Rep* rep)
  15. : BlockBasedTable(rep, nullptr /* block_cache_tracer */) {}
  16. };
  17. class MockBlockBasedTableTester {
  18. static constexpr int kMockLevel = 0;
  19. public:
  20. Options options_;
  21. ImmutableOptions ioptions_;
  22. EnvOptions env_options_;
  23. BlockBasedTableOptions table_options_;
  24. InternalKeyComparator icomp_;
  25. std::unique_ptr<BlockBasedTable> table_;
  26. explicit MockBlockBasedTableTester(const FilterPolicy* filter_policy)
  27. : MockBlockBasedTableTester(
  28. std::shared_ptr<const FilterPolicy>(filter_policy)){};
  29. explicit MockBlockBasedTableTester(
  30. std::shared_ptr<const FilterPolicy> filter_policy)
  31. : ioptions_(options_),
  32. env_options_(options_),
  33. icomp_(options_.comparator) {
  34. table_options_.filter_policy = std::move(filter_policy);
  35. constexpr bool skip_filters = false;
  36. constexpr bool immortal_table = false;
  37. table_.reset(new MockBlockBasedTable(new BlockBasedTable::Rep(
  38. ioptions_, env_options_, table_options_, icomp_, skip_filters,
  39. 12345 /*file_size*/, kMockLevel, immortal_table)));
  40. }
  41. FilterBitsBuilder* GetBuilder() const {
  42. FilterBuildingContext context(table_options_);
  43. context.column_family_name = "mock_cf";
  44. context.compaction_style = ioptions_.compaction_style;
  45. context.level_at_creation = kMockLevel;
  46. context.info_log = ioptions_.logger;
  47. return BloomFilterPolicy::GetBuilderFromContext(context);
  48. }
  49. };
  50. } // namespace mock
  51. } // namespace ROCKSDB_NAMESPACE