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