From 636cd3c714605456cbdff17d54f843c08d13ca77 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Mon, 14 Dec 2015 13:36:32 -0800 Subject: [PATCH] Clean up listener_test (reuse db_test_util) Summary: Reuse db_test_util in listener_test Test Plan: make listener_test -j64 && ./listener_test USE_CLANG=1 make listener_test -j64 && ./listener_test Reviewers: yhchiang, rven, kradhakrishnan, anthony Reviewed By: anthony Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D51939 --- Makefile | 2 +- db/listener_test.cc | 133 +++++--------------------------------------- 2 files changed, 14 insertions(+), 121 deletions(-) diff --git a/Makefile b/Makefile index c64ea3668..396b8e201 100644 --- a/Makefile +++ b/Makefile @@ -934,7 +934,7 @@ cuckoo_table_reader_test: table/cuckoo_table_reader_test.o $(LIBOBJECTS) $(TESTH cuckoo_table_db_test: db/cuckoo_table_db_test.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) -listener_test: db/listener_test.o $(LIBOBJECTS) $(TESTHARNESS) +listener_test: db/listener_test.o db/db_test_util.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) thread_list_test: util/thread_list_test.o $(LIBOBJECTS) $(TESTHARNESS) diff --git a/db/listener_test.cc b/db/listener_test.cc index ae911e7d1..b2825dff8 100644 --- a/db/listener_test.cc +++ b/db/listener_test.cc @@ -4,6 +4,7 @@ // of patent rights can be found in the PATENTS file in the same directory. #include "db/db_impl.h" +#include "db/db_test_util.h" #include "db/dbformat.h" #include "db/filename.h" #include "db/version_set.h" @@ -37,119 +38,11 @@ namespace rocksdb { -class EventListenerTest : public testing::Test { +class EventListenerTest : public DBTestBase { public: - EventListenerTest() { - dbname_ = test::TmpDir() + "/listener_test"; - EXPECT_OK(DestroyDB(dbname_, Options())); - db_ = nullptr; - Reopen(); - } - - ~EventListenerTest() { - Close(); - Options options; - options.db_paths.emplace_back(dbname_, 0); - options.db_paths.emplace_back(dbname_ + "_2", 0); - options.db_paths.emplace_back(dbname_ + "_3", 0); - options.db_paths.emplace_back(dbname_ + "_4", 0); - EXPECT_OK(DestroyDB(dbname_, options)); - } - - void CreateColumnFamilies(const std::vector& cfs, - const ColumnFamilyOptions* options = nullptr) { - ColumnFamilyOptions cf_opts; - cf_opts = ColumnFamilyOptions(Options()); - size_t cfi = handles_.size(); - handles_.resize(cfi + cfs.size()); - for (auto cf : cfs) { - ASSERT_OK(db_->CreateColumnFamily(cf_opts, cf, &handles_[cfi++])); - } - } - - void Close() { - for (auto h : handles_) { - delete h; - } - handles_.clear(); - delete db_; - db_ = nullptr; - } - - void ReopenWithColumnFamilies(const std::vector& cfs, - const Options* options = nullptr) { - ASSERT_OK(TryReopenWithColumnFamilies(cfs, options)); - } - - Status TryReopenWithColumnFamilies(const std::vector& cfs, - const Options* options = nullptr) { - Close(); - Options opts = (options == nullptr) ? Options() : *options; - std::vector v_opts(cfs.size(), &opts); - return TryReopenWithColumnFamilies(cfs, v_opts); - } - - Status TryReopenWithColumnFamilies( - const std::vector& cfs, - const std::vector& options) { - Close(); - EXPECT_EQ(cfs.size(), options.size()); - std::vector column_families; - for (size_t i = 0; i < cfs.size(); ++i) { - column_families.push_back(ColumnFamilyDescriptor(cfs[i], *options[i])); - } - DBOptions db_opts = DBOptions(*options[0]); - return DB::Open(db_opts, dbname_, column_families, &handles_, &db_); - } - - Status TryReopen(Options* options = nullptr) { - Close(); - Options opts; - if (options != nullptr) { - opts = *options; - } else { - opts.create_if_missing = true; - } - - return DB::Open(opts, dbname_, &db_); - } - - void Reopen(Options* options = nullptr) { - ASSERT_OK(TryReopen(options)); - } - - void CreateAndReopenWithCF(const std::vector& cfs, - const Options* options = nullptr) { - CreateColumnFamilies(cfs, options); - std::vector cfs_plus_default = cfs; - cfs_plus_default.insert(cfs_plus_default.begin(), kDefaultColumnFamilyName); - ReopenWithColumnFamilies(cfs_plus_default, options); - } - - DBImpl* dbfull() { - return reinterpret_cast(db_); - } - - Status Put(int cf, const Slice& k, const Slice& v, - WriteOptions wo = WriteOptions()) { - return db_->Put(wo, handles_[cf], k, v); - } - - Status Flush(size_t cf = 0) { - FlushOptions opt = FlushOptions(); - opt.wait = true; - if (cf == 0) { - return db_->Flush(opt); - } else { - return db_->Flush(opt, handles_[cf]); - } - } + EventListenerTest() : DBTestBase("listener_test") {} const size_t k110KB = 110 << 10; - - DB* db_; - std::string dbname_; - std::vector handles_; }; struct TestPropertiesCollector : public rocksdb::TablePropertiesCollector { @@ -238,7 +131,7 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) { std::vector cf_names = { "pikachu", "ilya", "muromec", "dobrynia", "nikitich", "alyosha", "popovich"}; - CreateAndReopenWithCF(cf_names, &options); + CreateAndReopenWithCF(cf_names, options); ASSERT_OK(Put(1, "pikachu", std::string(90000, 'p'))); ASSERT_OK(Put(2, "ilya", std::string(90000, 'i'))); ASSERT_OK(Put(3, "muromec", std::string(90000, 'm'))); @@ -246,12 +139,12 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) { ASSERT_OK(Put(5, "nikitich", std::string(90000, 'n'))); ASSERT_OK(Put(6, "alyosha", std::string(90000, 'a'))); ASSERT_OK(Put(7, "popovich", std::string(90000, 'p'))); - for (size_t i = 1; i < 8; ++i) { + for (int i = 1; i < 8; ++i) { ASSERT_OK(Flush(i)); - const Slice kStart = "a"; - const Slice kEnd = "z"; + const Slice kRangeStart = "a"; + const Slice kRangeEnd = "z"; ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), handles_[i], - &kStart, &kEnd)); + &kRangeStart, &kRangeEnd)); dbfull()->TEST_WaitForFlushMemTable(); dbfull()->TEST_WaitForCompact(); } @@ -349,7 +242,7 @@ TEST_F(EventListenerTest, OnSingleDBFlushTest) { "nikitich", "alyosha", "popovich"}; options.table_properties_collector_factories.push_back( std::make_shared()); - CreateAndReopenWithCF(cf_names, &options); + CreateAndReopenWithCF(cf_names, options); ASSERT_OK(Put(1, "pikachu", std::string(90000, 'p'))); ASSERT_OK(Put(2, "ilya", std::string(90000, 'i'))); @@ -358,7 +251,7 @@ TEST_F(EventListenerTest, OnSingleDBFlushTest) { ASSERT_OK(Put(5, "nikitich", std::string(90000, 'n'))); ASSERT_OK(Put(6, "alyosha", std::string(90000, 'a'))); ASSERT_OK(Put(7, "popovich", std::string(90000, 'p'))); - for (size_t i = 1; i < 8; ++i) { + for (int i = 1; i < 8; ++i) { ASSERT_OK(Flush(i)); dbfull()->TEST_WaitForFlushMemTable(); ASSERT_EQ(listener->flushed_dbs_.size(), i); @@ -385,7 +278,7 @@ TEST_F(EventListenerTest, MultiCF) { std::vector cf_names = { "pikachu", "ilya", "muromec", "dobrynia", "nikitich", "alyosha", "popovich"}; - CreateAndReopenWithCF(cf_names, &options); + CreateAndReopenWithCF(cf_names, options); ASSERT_OK(Put(1, "pikachu", std::string(90000, 'p'))); ASSERT_OK(Put(2, "ilya", std::string(90000, 'i'))); @@ -394,7 +287,7 @@ TEST_F(EventListenerTest, MultiCF) { ASSERT_OK(Put(5, "nikitich", std::string(90000, 'n'))); ASSERT_OK(Put(6, "alyosha", std::string(90000, 'a'))); ASSERT_OK(Put(7, "popovich", std::string(90000, 'p'))); - for (size_t i = 1; i < 8; ++i) { + for (int i = 1; i < 8; ++i) { ASSERT_OK(Flush(i)); ASSERT_EQ(listener->flushed_dbs_.size(), i); ASSERT_EQ(listener->flushed_column_family_names_.size(), i); @@ -511,7 +404,7 @@ TEST_F(EventListenerTest, DisableBGCompaction) { options.table_properties_collector_factories.push_back( std::make_shared()); - CreateAndReopenWithCF({"pikachu"}, &options); + CreateAndReopenWithCF({"pikachu"}, options); ColumnFamilyMetaData cf_meta; db_->GetColumnFamilyMetaData(handles_[1], &cf_meta);