10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

86 行
2.3 KiB

#include "gtest/gtest.h"
// #include "leveldb/env.h"
// #include "leveldb/db.h"
#include "fielddb/field_db.h"
#include "test/helper.cc"
#include <thread>
#include <csignal>
#include <exception>
using namespace fielddb;
// std::atomic<bool> thread_has_error(false);
// void signalHandler(int signum) {
// // 捕捉段错误
// }
TEST(TestNormalRecover, Recover) {
fielddb::DestroyDB("testdb3.1",Options());
FieldDB *db = new FieldDB();
if(OpenDB("testdb3.1", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
db->CreateIndexOnField("address");
db->CreateIndexOnField("age");
InsertFieldData(db);
bool allowNotFound = false;
GetFieldData(db, allowNotFound);
findKeysByCityIndex(db, true);
findKeysByAgeIndex(db, true);
delete db;
db = new FieldDB();
if(OpenDB("testdb3.1", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
//仍然能读到之前写入的数据和索引
GetFieldData(db, allowNotFound);
findKeysByCityIndex(db, true);
findKeysByAgeIndex(db, true);
}
// TEST(TestParalPutRecover, Recover) {
// signal(SIGSEGV, signalHandler);
// fielddb::DestroyDB("testdb3.2",Options());
// FieldDB *db = new FieldDB();
// if(OpenDB("testdb3.2", &db).ok() == false) {
// std::cerr << "open db failed" << std::endl;
// abort();
// }
// db->CreateIndexOnField("address");
// db->CreateIndexOnField("age");
// shanghaiKeys.clear();
// age20Keys.clear();
// int thread_num_ = 2;
// std::vector<std::thread> threads(thread_num_);
// threads[0] = std::thread([db](){
// InsertFieldData(db);
// });
// threads[1] = std::thread([db](){
// InsertOneField(db);
// delete db;
// });
// if (threads[1].joinable()) {
// threads[1].join();
// }
// db = new FieldDB();
// if(OpenDB("testdb3.2", &db).ok() == false) {
// std::cerr << "open db failed" << std::endl;
// abort();
// }
// GetOneField(db);
// checkDataInKVAndIndex(db);
// }
int main(int argc, char** argv) {
// All tests currently run with the same read-only file limits.
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}