Move ExternalSSTTestEnv to FileSystemWrapper (#11139)

Summary:
Migrate ExternalSSTTestEnv to FileSystemWrapper

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11139

Reviewed By: anand1976

Differential Revision: D42780180

Pulled By: akankshamahajan15

fbshipit-source-id: 9a4448c9fe5186b518235fe11e1a34dcad897cdd
oxigraph-8.1.1
akankshamahajan 2 years ago committed by Facebook GitHub Bot
parent 4720ba4391
commit 79e57a39a3
  1. 31
      db/external_sst_file_test.cc

@ -3,8 +3,8 @@
// COPYING file in the root directory) and Apache 2.0 License // COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
#include <functional> #include <functional>
#include <memory>
#include "db/db_test_util.h" #include "db/db_test_util.h"
#include "db/dbformat.h" #include "db/dbformat.h"
@ -22,18 +22,19 @@
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
// A test environment that can be configured to fail the Link operation. // A test environment that can be configured to fail the Link operation.
class ExternalSSTTestEnv : public EnvWrapper { class ExternalSSTTestFS : public FileSystemWrapper {
public: public:
ExternalSSTTestEnv(Env* t, bool fail_link) ExternalSSTTestFS(const std::shared_ptr<FileSystem>& t, bool fail_link)
: EnvWrapper(t), fail_link_(fail_link) {} : FileSystemWrapper(t), fail_link_(fail_link) {}
static const char* kClassName() { return "ExternalSSTTestEnv"; } static const char* kClassName() { return "ExternalSSTTestFS"; }
const char* Name() const override { return kClassName(); } const char* Name() const override { return kClassName(); }
Status LinkFile(const std::string& s, const std::string& t) override { IOStatus LinkFile(const std::string& s, const std::string& t,
const IOOptions& options, IODebugContext* dbg) override {
if (fail_link_) { if (fail_link_) {
return Status::NotSupported("Link failed"); return IOStatus::NotSupported("Link failed");
} }
return target()->LinkFile(s, t); return target()->LinkFile(s, t, options, dbg);
} }
void set_fail_link(bool fail_link) { fail_link_ = fail_link; } void set_fail_link(bool fail_link) { fail_link_ = fail_link; }
@ -67,24 +68,24 @@ class ExternSSTFileLinkFailFallbackTest
: public ExternalSSTFileTestBase, : public ExternalSSTFileTestBase,
public ::testing::WithParamInterface<std::tuple<bool, bool>> { public ::testing::WithParamInterface<std::tuple<bool, bool>> {
public: public:
ExternSSTFileLinkFailFallbackTest() ExternSSTFileLinkFailFallbackTest() {
: test_env_(new ExternalSSTTestEnv(env_, true)) { fs_ = std::make_shared<ExternalSSTTestFS>(env_->GetFileSystem(), true);
test_env_.reset(new CompositeEnvWrapper(env_, fs_));
options_ = CurrentOptions(); options_ = CurrentOptions();
options_.disable_auto_compactions = true; options_.disable_auto_compactions = true;
options_.env = test_env_; options_.env = test_env_.get();
} }
void TearDown() override { void TearDown() override {
delete db_; delete db_;
db_ = nullptr; db_ = nullptr;
ASSERT_OK(DestroyDB(dbname_, options_)); ASSERT_OK(DestroyDB(dbname_, options_));
delete test_env_;
test_env_ = nullptr;
} }
protected: protected:
Options options_; Options options_;
ExternalSSTTestEnv* test_env_; std::shared_ptr<ExternalSSTTestFS> fs_;
std::unique_ptr<Env> test_env_;
}; };
class ExternalSSTFileTest class ExternalSSTFileTest
@ -1995,7 +1996,7 @@ TEST_F(ExternalSSTFileTest, FileWithCFInfo) {
TEST_P(ExternSSTFileLinkFailFallbackTest, LinkFailFallBackExternalSst) { TEST_P(ExternSSTFileLinkFailFallbackTest, LinkFailFallBackExternalSst) {
const bool fail_link = std::get<0>(GetParam()); const bool fail_link = std::get<0>(GetParam());
const bool failed_move_fall_back_to_copy = std::get<1>(GetParam()); const bool failed_move_fall_back_to_copy = std::get<1>(GetParam());
test_env_->set_fail_link(fail_link); fs_->set_fail_link(fail_link);
const EnvOptions env_options; const EnvOptions env_options;
DestroyAndReopen(options_); DestroyAndReopen(options_);
const int kNumKeys = 10000; const int kNumKeys = 10000;

Loading…
Cancel
Save