|
@ -1,11 +1,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
#include "leveldb/env.h"
|
|
|
#include "leveldb/env.h"
|
|
|
#include "leveldb/db.h"
|
|
|
#include "leveldb/db.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace leveldb; |
|
|
using namespace leveldb; |
|
|
|
|
|
|
|
|
constexpr int value_size = 2048; |
|
|
constexpr int value_size = 2048; |
|
@ -20,7 +16,7 @@ Status OpenDB(std::string dbName, DB **db) { |
|
|
void InsertData(DB *db, uint64_t ttl/* second */) { |
|
|
void InsertData(DB *db, uint64_t ttl/* second */) { |
|
|
WriteOptions writeOptions; |
|
|
WriteOptions writeOptions; |
|
|
int key_num = data_size / value_size; |
|
|
int key_num = data_size / value_size; |
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
|
|
|
|
|
srand(0); |
|
|
|
|
|
|
|
|
for (int i = 0; i < key_num; i++) { |
|
|
for (int i = 0; i < key_num; i++) { |
|
|
int key_ = rand() % key_num+1; |
|
|
int key_ = rand() % key_num+1; |
|
@ -35,7 +31,7 @@ void GetData(DB *db, int size = (1 << 30)) { |
|
|
int key_num = data_size / value_size; |
|
|
int key_num = data_size / value_size; |
|
|
|
|
|
|
|
|
// 点查
|
|
|
// 点查
|
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
|
|
|
|
|
srand(0); |
|
|
for (int i = 0; i < 100; i++) { |
|
|
for (int i = 0; i < 100; i++) { |
|
|
int key_ = rand() % key_num+1; |
|
|
int key_ = rand() % key_num+1; |
|
|
std::string key = std::to_string(key_); |
|
|
std::string key = std::to_string(key_); |
|
@ -58,7 +54,7 @@ TEST(TestTTL, ReadTTL) { |
|
|
ReadOptions readOptions; |
|
|
ReadOptions readOptions; |
|
|
Status status; |
|
|
Status status; |
|
|
int key_num = data_size / value_size; |
|
|
int key_num = data_size / value_size; |
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
|
|
|
|
|
srand(0); |
|
|
for (int i = 0; i < 100; i++) { |
|
|
for (int i = 0; i < 100; i++) { |
|
|
int key_ = rand() % key_num+1; |
|
|
int key_ = rand() % key_num+1; |
|
|
std::string key = std::to_string(key_); |
|
|
std::string key = std::to_string(key_); |
|
@ -99,9 +95,9 @@ TEST(TestTTL, CompactionTTL) { |
|
|
|
|
|
|
|
|
db->CompactRange(nullptr, nullptr); |
|
|
db->CompactRange(nullptr, nullptr); |
|
|
|
|
|
|
|
|
// leveldb::Range ranges[1];
|
|
|
|
|
|
|
|
|
// leveldb::Range ranges[1];
|
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
// uint64_t sizes[1];
|
|
|
|
|
|
|
|
|
// uint64_t sizes[1];
|
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
ASSERT_EQ(sizes[0], 0); |
|
|
ASSERT_EQ(sizes[0], 0); |
|
|
} |
|
|
} |
|
@ -111,4 +107,4 @@ int main(int argc, char** argv) { |
|
|
// All tests currently run with the same read-only file limits.
|
|
|
// All tests currently run with the same read-only file limits.
|
|
|
testing::InitGoogleTest(&argc, argv); |
|
|
testing::InitGoogleTest(&argc, argv); |
|
|
return RUN_ALL_TESTS(); |
|
|
return RUN_ALL_TESTS(); |
|
|
} |
|
|
|
|
|
|
|
|
} |