Ver código fonte

针对合并测到新的bug

ld
augurier 3 semanas atrás
pai
commit
c38d2b733e
1 arquivos alterados com 48 adições e 5 exclusões
  1. +48
    -5
      test/ttl_test.cc

+ 48
- 5
test/ttl_test.cc Ver arquivo

@ -17,15 +17,15 @@ Status OpenDB(std::string dbName, DB **db) {
return DB::Open(options, dbName, db);
}
void InsertData(DB *db, uint64_t ttl/* second */) {
void InsertData(DB *db, uint64_t ttl/* second */, int vsize = 0) {
WriteOptions writeOptions;
int key_num = data_size / value_size;
srand(static_cast<unsigned int>(time(0)));
srand(0);
for (int i = 0; i < key_num; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
std::string value(value_size, 'a');
std::string value(value_size + vsize, 'a');
db->Put(writeOptions, std::to_string(i+1), value, ttl);
// db->Put(writeOptions, key, value, ttl);
}
@ -36,7 +36,7 @@ void GetData(DB *db, int size = (1 << 30)) {
int key_num = data_size / value_size;
// 点查
srand(static_cast<unsigned int>(time(0)));
srand(0);
for (int i = 0; i < 100; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
@ -60,7 +60,7 @@ TEST(TestTTL, ReadTTL) {
ReadOptions readOptions;
Status status;
int key_num = data_size / value_size;
srand(static_cast<unsigned int>(time(0)));
srand(0);
for (int i = 0; i < 100; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
@ -83,6 +83,49 @@ TEST(TestTTL, ReadTTL) {
delete db;
}
TEST(TestTTL, GetEarlierData) {
DestroyDB("testdb",Options());
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
uint64_t ttl1 = 3;
uint64_t ttl2 = 5;
uint64_t extra_size = 1;
InsertData(db, ttl2);
InsertData(db, ttl1, extra_size); //后一个数据长度变化一下
//都没过期先找到后插的
Env::Default()->SleepForMicroseconds(1 * 1000000);
int key_num = data_size / value_size;
ReadOptions readOptions;
Status status;
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());
ASSERT_EQ(value.size(), value_size + extra_size);
}
//再找到前一次
Env::Default()->SleepForMicroseconds(3 * 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_TRUE(status.ok());
ASSERT_EQ(value.size(), value_size);
}
delete db;
}
TEST(TestTTL, CompactionTTL) {
DestroyDB("testdb",Options());
DB *db;

Carregando…
Cancelar
Salvar