]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/env/mock_env.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / env / mock_env.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
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#pragma once
10
11#include <atomic>
12#include <map>
13#include <string>
14#include <vector>
15#include "rocksdb/env.h"
16#include "rocksdb/status.h"
17#include "port/port.h"
18#include "util/mutexlock.h"
19
f67539c2 20namespace ROCKSDB_NAMESPACE {
7c673cae
FG
21
22class MemFile;
23class MockEnv : public EnvWrapper {
24 public:
25 explicit MockEnv(Env* base_env);
26
27 virtual ~MockEnv();
28
29 // Partial implementation of the Env interface.
30 virtual Status NewSequentialFile(const std::string& fname,
494da23a 31 std::unique_ptr<SequentialFile>* result,
7c673cae
FG
32 const EnvOptions& soptions) override;
33
34 virtual Status NewRandomAccessFile(const std::string& fname,
494da23a 35 std::unique_ptr<RandomAccessFile>* result,
7c673cae
FG
36 const EnvOptions& soptions) override;
37
38 virtual Status NewRandomRWFile(const std::string& fname,
494da23a 39 std::unique_ptr<RandomRWFile>* result,
7c673cae
FG
40 const EnvOptions& options) override;
41
42 virtual Status ReuseWritableFile(const std::string& fname,
43 const std::string& old_fname,
494da23a 44 std::unique_ptr<WritableFile>* result,
7c673cae
FG
45 const EnvOptions& options) override;
46
47 virtual Status NewWritableFile(const std::string& fname,
494da23a 48 std::unique_ptr<WritableFile>* result,
7c673cae
FG
49 const EnvOptions& env_options) override;
50
51 virtual Status NewDirectory(const std::string& name,
494da23a 52 std::unique_ptr<Directory>* result) override;
7c673cae
FG
53
54 virtual Status FileExists(const std::string& fname) override;
55
56 virtual Status GetChildren(const std::string& dir,
57 std::vector<std::string>* result) override;
58
59 void DeleteFileInternal(const std::string& fname);
60
61 virtual Status DeleteFile(const std::string& fname) override;
62
11fdf7f2
TL
63 virtual Status Truncate(const std::string& fname, size_t size) override;
64
7c673cae
FG
65 virtual Status CreateDir(const std::string& dirname) override;
66
67 virtual Status CreateDirIfMissing(const std::string& dirname) override;
68
69 virtual Status DeleteDir(const std::string& dirname) override;
70
71 virtual Status GetFileSize(const std::string& fname,
72 uint64_t* file_size) override;
73
74 virtual Status GetFileModificationTime(const std::string& fname,
75 uint64_t* time) override;
76
77 virtual Status RenameFile(const std::string& src,
78 const std::string& target) override;
79
80 virtual Status LinkFile(const std::string& src,
81 const std::string& target) override;
82
83 virtual Status NewLogger(const std::string& fname,
494da23a 84 std::shared_ptr<Logger>* result) override;
7c673cae
FG
85
86 virtual Status LockFile(const std::string& fname, FileLock** flock) override;
87
88 virtual Status UnlockFile(FileLock* flock) override;
89
90 virtual Status GetTestDirectory(std::string* path) override;
91
92 // Results of these can be affected by FakeSleepForMicroseconds()
93 virtual Status GetCurrentTime(int64_t* unix_time) override;
94 virtual uint64_t NowMicros() override;
95 virtual uint64_t NowNanos() override;
96
7c673cae
FG
97 Status CorruptBuffer(const std::string& fname);
98
99 // Doesn't really sleep, just affects output of GetCurrentTime(), NowMicros()
100 // and NowNanos()
101 void FakeSleepForMicroseconds(int64_t micros);
102
103 private:
104 std::string NormalizePath(const std::string path);
105
106 // Map from filenames to MemFile objects, representing a simple file system.
107 typedef std::map<std::string, MemFile*> FileSystem;
108 port::Mutex mutex_;
109 FileSystem file_map_; // Protected by mutex_.
110
111 std::atomic<int64_t> fake_sleep_micros_;
112};
113
f67539c2 114} // namespace ROCKSDB_NAMESPACE