|
|
@ -9,7 +9,7 @@ using namespace fielddb; |
|
|
|
// 测试中read/write都表示带索引的读写
|
|
|
|
|
|
|
|
//读写有索引数据的并发
|
|
|
|
TEST(TestReadWrite, Parallel) { |
|
|
|
TEST(TestReadPut, Parallel) { |
|
|
|
fielddb::DestroyDB("testdb2.1",Options()); |
|
|
|
FieldDB *db = new FieldDB(); |
|
|
|
|
|
|
@ -52,7 +52,7 @@ TEST(TestReadWrite, Parallel) { |
|
|
|
} |
|
|
|
|
|
|
|
//创建索引与写有该索引数据的并发
|
|
|
|
TEST(TestWriteCreatei, Parallel) { |
|
|
|
TEST(TestPutCreatei, Parallel) { |
|
|
|
fielddb::DestroyDB("testdb2.2",Options()); |
|
|
|
FieldDB *db = new FieldDB(); |
|
|
|
|
|
|
@ -242,6 +242,59 @@ TEST(TestPutDelete, Parallel) { |
|
|
|
delete db; |
|
|
|
} |
|
|
|
|
|
|
|
//write和其他功能的并发(大杂烩
|
|
|
|
TEST(TestWrite, Parallel) { |
|
|
|
fielddb::DestroyDB("testdb2.6",Options()); |
|
|
|
FieldDB *db = new FieldDB(); |
|
|
|
|
|
|
|
if(OpenDB("testdb2.6", &db).ok() == false) { |
|
|
|
std::cerr << "open db failed" << std::endl; |
|
|
|
abort(); |
|
|
|
} |
|
|
|
|
|
|
|
// ClearDB(db);
|
|
|
|
shanghaiKeys.clear(); |
|
|
|
age20Keys.clear(); |
|
|
|
db->CreateIndexOnField("address"); |
|
|
|
InsertFieldData(db, 2); //先填点数据,让创建索引的时间久一点
|
|
|
|
int thread_num_ = 5; |
|
|
|
std::vector<std::thread> threads(thread_num_); |
|
|
|
threads[0] = std::thread([db](){db->CreateIndexOnField("age");}); |
|
|
|
threads[1] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; //开始创建了再并发的写
|
|
|
|
} |
|
|
|
InsertFieldData(db);}); |
|
|
|
threads[2] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
WriteFieldData(db, 1);}); |
|
|
|
threads[3] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
DeleteFieldData(db, 0);}); |
|
|
|
threads[4] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
db->DeleteIndex("age");}); |
|
|
|
|
|
|
|
for (auto& t : threads) { |
|
|
|
if (t.joinable()) { |
|
|
|
t.join(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//检查
|
|
|
|
checkDataInKVAndIndex(db); |
|
|
|
ASSERT_EQ(db->GetIndexStatus("age"), NotExist); //删除索引的请求应该被pend在创建之上
|
|
|
|
//删掉最后一个线程,可以测试创建age索引时并发的写入能不能保持age的一致性
|
|
|
|
//checkDataInKVAndIndex(db, "age");
|
|
|
|
delete db; |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
// All tests currently run with the same read-only file limits.
|
|
|
|
testing::InitGoogleTest(&argc, argv); |
|
|
|