RAII transactions
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s

This commit is contained in:
Blue 2023-10-17 18:06:11 -03:00
parent a9aa6b549f
commit de741eda21
Signed by: blue
GPG key ID: 9B203B252A63EE38
22 changed files with 689 additions and 222 deletions

View file

@ -64,7 +64,7 @@ TEST_F(CacheTransactionsTest, Adding) {
EXPECT_EQ(c1->count(), 0);
EXPECT_EQ(c2->count(), 0);
LMDBAL::TransactionID txn = db->beginTransaction();
LMDBAL::WriteTransaction txn = db->beginTransaction();
c1->addRecord(5, 13, txn);
c1->addRecord(-53, 782, txn);
c1->addRecord(5892, -37829, txn);
@ -76,7 +76,7 @@ TEST_F(CacheTransactionsTest, Adding) {
EXPECT_EQ(c1->count(), 0);
EXPECT_EQ(c2->count(), 0);
db->commitTransaction(txn);
txn.commit();
EXPECT_EQ(c1->count(), 3);
EXPECT_EQ(c1->getRecord(5), 13);
@ -95,7 +95,7 @@ TEST_F(CacheTransactionsTest, Aborting) {
LMDBAL::SizeType s1 = c1->count();
LMDBAL::SizeType s2 = c2->count();
LMDBAL::TransactionID txn = db->beginTransaction();
LMDBAL::WriteTransaction txn = db->beginTransaction();
c1->addRecord(18, 40, txn);
c1->addRecord(85, -4, txn);
c1->addRecord(-5, -3, txn);
@ -107,7 +107,7 @@ TEST_F(CacheTransactionsTest, Aborting) {
EXPECT_EQ(c1->count(), s1);
EXPECT_EQ(c2->count(), s2);
db->abortTransaction(txn);
txn.abort();
EXPECT_EQ(c1->count(), s1);
EXPECT_EQ(c2->count(), s2);
@ -116,7 +116,7 @@ TEST_F(CacheTransactionsTest, Aborting) {
TEST_F(CacheTransactionsTest, Reading) {
EXPECT_EQ(db->ready(), true);
LMDBAL::TransactionID txn = db->beginReadOnlyTransaction();
LMDBAL::Transaction txn = db->beginReadOnlyTransaction();
EXPECT_EQ(c1->count(txn), 3);
EXPECT_EQ(c1->getRecord(5, txn), 13);
@ -128,14 +128,14 @@ TEST_F(CacheTransactionsTest, Reading) {
EXPECT_FLOAT_EQ(c2->getRecord("decallence", txn), 8532.48);
EXPECT_FLOAT_EQ(c2->getRecord("prevent recovery", txn), -64.64);
db->abortTransaction(txn);
txn.terminate();
}
TEST_F(CacheTransactionsTest, ConcurentReading) {
EXPECT_EQ(db->ready(), true);
LMDBAL::SizeType size = c1->count();
LMDBAL::TransactionID txn = db->beginTransaction();
LMDBAL::WriteTransaction txn = db->beginTransaction();
EXPECT_EQ(c1->getRecord(5, txn), 13);
EXPECT_EQ(c1->getRecord(5), 13);
@ -160,7 +160,7 @@ TEST_F(CacheTransactionsTest, ConcurentReading) {
EXPECT_EQ(c1->count(txn), 1);
EXPECT_EQ(c1->count(), size);
db->commitTransaction(txn);
txn.commit();
EXPECT_FALSE(c1->checkRecord(5));
EXPECT_EQ(c1->count(), 1);
@ -183,7 +183,7 @@ TEST_F(CacheTransactionsTest, 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(c1->getRecord(5, txn2), 812);
@ -198,13 +198,13 @@ TEST_F(CacheTransactionsTest, ConcurentModification) {
EXPECT_EQ(c1->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);
@ -219,7 +219,7 @@ TEST_F(CacheTransactionsTest, ConcurentModification) {
EXPECT_FALSE(c1->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