RAII transactions
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
This commit is contained in:
parent
a9aa6b549f
commit
de741eda21
22 changed files with 689 additions and 222 deletions
|
@ -64,7 +64,7 @@ TEST_F(StorageTransactionsTest, Adding) {
|
|||
EXPECT_EQ(t1->count(), 0);
|
||||
EXPECT_EQ(t2->count(), 0);
|
||||
|
||||
LMDBAL::TransactionID txn = db->beginTransaction();
|
||||
LMDBAL::WriteTransaction txn = db->beginTransaction();
|
||||
t1->addRecord(5, 13, txn);
|
||||
t1->addRecord(-53, 782, txn);
|
||||
t1->addRecord(5892, -37829, txn);
|
||||
|
@ -76,7 +76,7 @@ TEST_F(StorageTransactionsTest, Adding) {
|
|||
EXPECT_EQ(t1->count(), 0);
|
||||
EXPECT_EQ(t2->count(), 0);
|
||||
|
||||
db->commitTransaction(txn);
|
||||
txn.commit();
|
||||
|
||||
EXPECT_EQ(t1->count(), 3);
|
||||
EXPECT_EQ(t1->getRecord(5), 13);
|
||||
|
@ -95,7 +95,7 @@ TEST_F(StorageTransactionsTest, Aborting) {
|
|||
LMDBAL::SizeType s1 = t1->count();
|
||||
LMDBAL::SizeType s2 = t2->count();
|
||||
|
||||
LMDBAL::TransactionID txn = db->beginTransaction();
|
||||
LMDBAL::WriteTransaction txn = db->beginTransaction();
|
||||
t1->addRecord(18, 40, txn);
|
||||
t1->addRecord(85, -4, txn);
|
||||
t1->addRecord(-5, -3, txn);
|
||||
|
@ -107,7 +107,7 @@ TEST_F(StorageTransactionsTest, Aborting) {
|
|||
EXPECT_EQ(t1->count(), s1);
|
||||
EXPECT_EQ(t2->count(), s2);
|
||||
|
||||
db->abortTransaction(txn);
|
||||
txn.abort();
|
||||
|
||||
EXPECT_EQ(t1->count(), s1);
|
||||
EXPECT_EQ(t2->count(), s2);
|
||||
|
@ -116,7 +116,7 @@ TEST_F(StorageTransactionsTest, Aborting) {
|
|||
TEST_F(StorageTransactionsTest, Reading) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
|
||||
LMDBAL::TransactionID txn = db->beginReadOnlyTransaction();
|
||||
LMDBAL::Transaction txn = db->beginReadOnlyTransaction();
|
||||
|
||||
EXPECT_EQ(t1->count(txn), 3);
|
||||
EXPECT_EQ(t1->getRecord(5, txn), 13);
|
||||
|
@ -128,14 +128,14 @@ TEST_F(StorageTransactionsTest, Reading) {
|
|||
EXPECT_FLOAT_EQ(t2->getRecord("decallence", txn), 8532.48);
|
||||
EXPECT_FLOAT_EQ(t2->getRecord("prevent recovery", txn), -64.64);
|
||||
|
||||
db->abortTransaction(txn);
|
||||
txn.terminate();
|
||||
}
|
||||
|
||||
TEST_F(StorageTransactionsTest, ConcurentReading) {
|
||||
EXPECT_EQ(db->ready(), true);
|
||||
|
||||
LMDBAL::SizeType size = t1->count();
|
||||
LMDBAL::TransactionID txn = db->beginTransaction();
|
||||
LMDBAL::WriteTransaction txn = db->beginTransaction();
|
||||
EXPECT_EQ(t1->getRecord(5, txn), 13);
|
||||
EXPECT_EQ(t1->getRecord(5), 13);
|
||||
|
||||
|
@ -160,7 +160,7 @@ TEST_F(StorageTransactionsTest, ConcurentReading) {
|
|||
EXPECT_EQ(t1->count(txn), 1);
|
||||
EXPECT_EQ(t1->count(), size);
|
||||
|
||||
db->commitTransaction(txn);
|
||||
txn.commit();
|
||||
|
||||
EXPECT_FALSE(t1->checkRecord(5));
|
||||
EXPECT_EQ(t1->count(), 1);
|
||||
|
@ -182,7 +182,7 @@ TEST_F(StorageTransactionsTest, ConcurentModification) {
|
|||
int pid = fork();
|
||||
if (pid == 0) { // I am the child
|
||||
std::cout << "beggining second transaction" << std::endl;
|
||||
LMDBAL::TransactionID txn2 = db->beginTransaction(); //<--- this is where the execution should pause
|
||||
LMDBAL::WriteTransaction txn2 = db->beginTransaction(); //<--- this is where the execution should pause
|
||||
//and wait for the first transaction to get finished
|
||||
std::cout << "checking result of the first transaction value" << std::endl;
|
||||
EXPECT_EQ(t1->getRecord(5, txn2), 812);
|
||||
|
@ -197,13 +197,13 @@ TEST_F(StorageTransactionsTest, ConcurentModification) {
|
|||
EXPECT_EQ(t1->getRecord(5), 812);
|
||||
|
||||
std::cout << "commiting second transaction" << std::endl;
|
||||
db->commitTransaction(txn2);
|
||||
txn2.commit();
|
||||
|
||||
std::cout << "quitting child thread" << std::endl;
|
||||
exit(testing::Test::HasFailure());
|
||||
} else { // I am the parent
|
||||
std::cout << "beggining first transaction" << std::endl;
|
||||
LMDBAL::TransactionID txn1 = db->beginTransaction();
|
||||
LMDBAL::WriteTransaction txn1 = db->beginTransaction();
|
||||
|
||||
std::cout << "putting parent thread to sleep for 5 ms" << std::endl;
|
||||
usleep(5);
|
||||
|
@ -218,7 +218,7 @@ TEST_F(StorageTransactionsTest, ConcurentModification) {
|
|||
EXPECT_FALSE(t1->checkRecord(5));
|
||||
|
||||
std::cout << "commiting first transaction" << std::endl;
|
||||
db->commitTransaction(txn1);
|
||||
txn1.commit();
|
||||
|
||||
std::cout << "waiting for the other thread to finish" << std::endl;
|
||||
ASSERT_EQ(0, waitForChildFork(pid)); //child process should have no problems
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue