From 457bcfde028c37e01a087e631bb87ea49b5a5f98 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Mon, 7 Oct 2019 17:47:19 -0700 Subject: [PATCH] Let TestEnv and FaultInjectEnv use Env of choice (#5886) Summary: Instead of hard coding Env::Default in TestEnv and a few other places, use the DBTestBase::env_ that has been deduced from the constructor. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5886 Test Plan: ``` make check ``` Differential Revision: D17773029 Pulled By: riversand963 fbshipit-source-id: 7ce4e5175a487e9d281ea2c3aae3c41bffd44629 --- db/db_basic_test.cc | 49 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/db/db_basic_test.cc b/db/db_basic_test.cc index 23f7d44511..b3bd681b2d 100644 --- a/db/db_basic_test.cc +++ b/db/db_basic_test.cc @@ -913,30 +913,30 @@ TEST_F(DBBasicTest, MmapAndBufferOptions) { class TestEnv : public EnvWrapper { public: - explicit TestEnv() : EnvWrapper(Env::Default()), - close_count(0) { } + explicit TestEnv(Env* base_env) : EnvWrapper(base_env), close_count(0) {} - class TestLogger : public Logger { - public: - using Logger::Logv; - TestLogger(TestEnv *env_ptr) : Logger() { env = env_ptr; } - ~TestLogger() override { - if (!closed_) { - CloseHelper(); - } - } - void Logv(const char* /*format*/, va_list /*ap*/) override{}; + class TestLogger : public Logger { + public: + using Logger::Logv; + explicit TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; } + ~TestLogger() override { + if (!closed_) { + CloseHelper(); + } + } + void Logv(const char* /*format*/, va_list /*ap*/) override {} - protected: - Status CloseImpl() override { return CloseHelper(); } + protected: + Status CloseImpl() override { return CloseHelper(); } - private: - Status CloseHelper() { - env->CloseCountInc();; - return Status::IOError(); - } - TestEnv *env; - }; + private: + Status CloseHelper() { + env->CloseCountInc(); + ; + return Status::IOError(); + } + TestEnv* env; + }; void CloseCountInc() { close_count++; } @@ -958,7 +958,8 @@ TEST_F(DBBasicTest, DBClose) { ASSERT_OK(DestroyDB(dbname, options)); DB* db = nullptr; - TestEnv* env = new TestEnv(); + TestEnv* env = new TestEnv(env_); + std::unique_ptr local_env_guard(env); options.create_if_missing = true; options.env = env; Status s = DB::Open(options, dbname, &db); @@ -992,13 +993,11 @@ TEST_F(DBBasicTest, DBClose) { ASSERT_EQ(env->GetCloseCount(), 2); options.info_log.reset(); ASSERT_EQ(env->GetCloseCount(), 3); - - delete options.env; } TEST_F(DBBasicTest, DBCloseFlushError) { std::unique_ptr fault_injection_env( - new FaultInjectionTestEnv(Env::Default())); + new FaultInjectionTestEnv(env_)); Options options = GetDefaultOptions(); options.create_if_missing = true; options.manual_wal_flush = true;