From 8a547d6d7f06a9dbe7c77bf3d0cd31b40552fcb9 Mon Sep 17 00:00:00 2001 From: alexfisher <1823748191@qq.com> Date: Sat, 4 Jan 2025 19:23:57 +0800 Subject: [PATCH] fix a tiny test bug --- YCSB-cpp | 2 +- test/test.cpp | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/YCSB-cpp b/YCSB-cpp index d78c626..3f60b05 160000 --- a/YCSB-cpp +++ b/YCSB-cpp @@ -1 +1 @@ -Subproject commit d78c62696691f5d745aa58ed8008e3f38632c2a4 +Subproject commit 3f60b05ba0c07487731daa1b629e709f08e5bd78 diff --git a/test/test.cpp b/test/test.cpp index 6bd5e39..2b678af 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -5,7 +5,7 @@ #include "db/filename.h" #include using namespace leveldb; -std::string dbName="valuelog_test"; +const std::string dbName="valuelog_test"; Status OpenDB(DB **db,Options options=Options(),bool destroy_old_db=true) { @@ -20,7 +20,7 @@ void Corrupt(FileType filetype, int offset, int bytes_to_corrupt,std::string dbn // Pick file to corrupt std::vector filenames; auto env_=Env::Default(); - assert(env_->GetChildren(dbname_, &filenames).ok()); + ASSERT_TRUE(env_->GetChildren(dbname_, &filenames).ok()); uint64_t number; FileType type; std::string fname; @@ -88,12 +88,10 @@ bool CompareFieldArray(const FieldArray &a, const FieldArray &b) { bool CompareKey(const std::vector a, std::vector b) { if (a.size() != b.size()){ - assert(0); return false; } for (size_t i = 0; i < a.size(); ++i) { if (a[i] != b[i]){ - assert(0); return false; } } @@ -496,6 +494,21 @@ TEST(Test, garbage_collect_test) { db->CompactRange(nullptr,nullptr);//create garbage db->TEST_GarbageCollect(); + for(int i=0;i<50000;i++){ + std::string key=std::to_string(i); + std::string value; + Status s=db->Get(readOptions,key,&value); + assert(s.ok()); + ASSERT_TRUE(values[i]==value); + } + for(int i=0;i<50000;i++){//make all remaining valuelog worthless, so they will be GC + std::string key=std::to_string(i); + std::string value; + for(int j=0;j<1001;j++){ + value+=std::to_string(i); + } + db->Put(writeOptions,key,value); + } db->CompactRange(nullptr,nullptr);//update version std::vector new_filenames; @@ -510,13 +523,6 @@ TEST(Test, garbage_collect_test) { ASSERT_TRUE(oldest_new_valuelog_id<1000); ASSERT_TRUE(oldest_new_valuelog_id>oldest_valuelog_id);//at least one valuelog file should be deleted - for(int i=0;i<50000;i++){ - std::string key=std::to_string(i); - std::string value; - Status s=db->Get(readOptions,key,&value); - assert(s.ok()); - ASSERT_TRUE(values[i]==value); - } delete db; }