YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/docdb_test_base.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_DOCDB_DOCDB_TEST_BASE_H
15
#define YB_DOCDB_DOCDB_TEST_BASE_H
16
17
#include <string>
18
#include <vector>
19
20
#include "yb/rocksdb/db.h"
21
22
#include "yb/docdb/docdb_test_util.h"
23
#include "yb/docdb/key_bytes.h"
24
#include "yb/util/test_macros.h"
25
#include "yb/util/test_util.h"
26
27
namespace yb {
28
namespace docdb {
29
30
class DocDBTestBase : public YBTest, public DocDBRocksDBFixture {
31
 public:
32
  DocDBTestBase();
33
  ~DocDBTestBase() override;
34
  void SetUp() override;
35
  void TearDown() override;
36
37
 protected:
38
39
  // Captures a "logical snapshot" of the underlying RocksDB database. By "logical snapshot" we mean
40
  // a straightforward copy of all key/values stored, not a RocksDB-level snapshot. This is an easy
41
  // way to go back to an old state of RocksDB in tests so we can make some more changes and take
42
  // on a different path.
43
  void CaptureLogicalSnapshot();
44
45
  // Clears the internal vector of logical RocksDB snapshots. The next snapshot to be captured will
46
  // again have the index 0.
47
  void ClearLogicalSnapshots();
48
49
  // Restore the state of RocksDB to the previously taken "logical snapshot" with the given index.
50
  //
51
  // @param snapshot_index The snapshot index to restore the state to RocksDB to, with the first
52
  //                       snapshot having index 0.
53
  void RestoreToRocksDBLogicalSnapshot(size_t snapshot_index);
54
55
0
  void RestoreToLastLogicalRocksDBSnapshot() {
56
0
    RestoreToRocksDBLogicalSnapshot(logical_snapshots_.size() - 1);
57
0
  }
58
59
0
  size_t num_logical_snapshots() { return logical_snapshots_.size(); }
60
61
0
  const std::vector<LogicalRocksDBDebugSnapshot>& logical_snapshots() {
62
0
    return logical_snapshots_;
63
0
  }
64
65
 private:
66
  std::vector<LogicalRocksDBDebugSnapshot> logical_snapshots_;
67
};
68
69
}  // namespace docdb
70
}  // namespace yb
71
72
#endif  // YB_DOCDB_DOCDB_TEST_BASE_H