浏览代码

modify new test

main
李畅 3 周前
父节点
当前提交
d6199efe75
共有 1 个文件被更改,包括 48 次插入38 次删除
  1. +48
    -38
      test/ttl_test.cc

+ 48
- 38
test/ttl_test.cc 查看文件

@ -40,41 +40,41 @@ void GetData(DB *db, int size = (1 << 30)) {
}
}
TEST(TestTTL, ReadTTL) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
uint64_t ttl = 20;
InsertData(db, ttl);
ReadOptions readOptions;
Status status;
int key_num = data_size / value_size;
srand(0);
for (int i = 0; i < 100; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
std::string value;
status = db->Get(readOptions, key, &value);
ASSERT_TRUE(status.ok());
}
Env::Default()->SleepForMicroseconds(ttl * 1000000);
for (int i = 0; i < 100; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
std::string value;
status = db->Get(readOptions, key, &value);
ASSERT_FALSE(status.ok());
}
delete db;
}
// TEST(TestTTL, ReadTTL) {
// DB *db;
// if(OpenDB("testdb", &db).ok() == false) {
// std::cerr << "open db failed" << std::endl;
// abort();
// }
// uint64_t ttl = 20;
// InsertData(db, ttl);
// ReadOptions readOptions;
// Status status;
// int key_num = data_size / value_size;
// srand(0);
// for (int i = 0; i < 100; i++) {
// int key_ = rand() % key_num+1;
// std::string key = std::to_string(key_);
// std::string value;
// status = db->Get(readOptions, key, &value);
// ASSERT_TRUE(status.ok());
// }
// Env::Default()->SleepForMicroseconds(ttl * 1000000);
// for (int i = 0; i < 100; i++) {
// int key_ = rand() % key_num+1;
// std::string key = std::to_string(key_);
// std::string value;
// status = db->Get(readOptions, key, &value);
// ASSERT_FALSE(status.ok());
// }
// delete db;
// }
TEST(TestTTL, CompactionTTL) {
DB *db;
@ -124,11 +124,21 @@ TEST(TestTTL, LastLevelCompaction) {
db->GetApproximateSizes(ranges, 1, sizes);
ASSERT_GT(sizes[0], 0);
std::string last_level_file_num;
int last_level_file_num;
std::string file_num;
std::string last_level = "2";
db->GetProperty("leveldb.num-files-at-level" + last_level, &last_level_file_num);
for (int level = 0; level < 7; level++){
db->GetProperty("leveldb.num-files-at-level" + std::to_string(level), &file_num);
if (std::atoi(file_num.c_str()) > 0){
last_level = std::to_string(level);
last_level_file_num = std::atoi(file_num.c_str());
}
else{
break;
}
}
std::cout << "File nums in last level: " << last_level_file_num << std::endl;
ASSERT_GT(std::atoi(last_level_file_num.c_str()), 0);
ASSERT_GT(last_level_file_num, 0);
Env::Default()->SleepForMicroseconds(ttl * 1000000);

正在加载...
取消
保存