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
|
@ -24,6 +24,7 @@ protected:
|
|||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
transaction.terminate();
|
||||
db->close();
|
||||
db->removeDirectory();
|
||||
delete db;
|
||||
|
@ -35,7 +36,7 @@ protected:
|
|||
static LMDBAL::Base* db;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* cursor;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* emptyCursor;
|
||||
static LMDBAL::TransactionID transaction;
|
||||
static LMDBAL::Transaction transaction;
|
||||
|
||||
LMDBAL::Cache<uint64_t, std::string>* cache;
|
||||
LMDBAL::Cache<uint64_t, std::string>* emptyCache;
|
||||
|
@ -44,7 +45,7 @@ protected:
|
|||
LMDBAL::Base* CacheCursorTest::db = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* CacheCursorTest::cursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* CacheCursorTest::emptyCursor = nullptr;
|
||||
LMDBAL::TransactionID CacheCursorTest::transaction = nullptr;
|
||||
LMDBAL::Transaction CacheCursorTest::transaction;
|
||||
|
||||
static const std::map<uint64_t, std::string> data({
|
||||
{245665783, "bothering nerds"},
|
||||
|
@ -288,7 +289,7 @@ TEST_F(CacheCursorTest, CurrentPublic) {
|
|||
}
|
||||
|
||||
TEST_F(CacheCursorTest, CornerCases) {
|
||||
db->abortTransaction(transaction);
|
||||
transaction.terminate();
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown);
|
||||
cursor->close();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -331,7 +331,7 @@ TEST_F(DuplicatesTest, Changing) {
|
|||
}
|
||||
|
||||
TEST_F(DuplicatesTest, GettingAllRecords) {
|
||||
LMDBAL::TransactionID txn = db->beginReadOnlyTransaction();
|
||||
LMDBAL::Transaction txn = db->beginReadOnlyTransaction();
|
||||
bool cycle;
|
||||
LMDBAL::SizeType iterations;
|
||||
|
||||
|
@ -462,6 +462,5 @@ TEST_F(DuplicatesTest, GettingAllRecords) {
|
|||
EXPECT_NE(iterations, 0);
|
||||
EXPECT_NE(k4.size(), 0);
|
||||
|
||||
|
||||
db->abortTransaction(txn);
|
||||
txn.terminate();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ protected:
|
|||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
transaction.terminate();
|
||||
db->close();
|
||||
db->removeDirectory();
|
||||
delete db;
|
||||
|
@ -34,7 +35,7 @@ protected:
|
|||
static LMDBAL::Base* db;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* cursor;
|
||||
static LMDBAL::Cursor<uint64_t, std::string>* emptyCursor;
|
||||
static LMDBAL::TransactionID transaction;
|
||||
static LMDBAL::Transaction transaction;
|
||||
|
||||
LMDBAL::Storage<uint64_t, std::string>* table;
|
||||
LMDBAL::Storage<uint64_t, std::string>* emptyTable;
|
||||
|
@ -43,7 +44,7 @@ protected:
|
|||
LMDBAL::Base* StorageCursorTest::db = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::cursor = nullptr;
|
||||
LMDBAL::Cursor<uint64_t, std::string>* StorageCursorTest::emptyCursor = nullptr;
|
||||
LMDBAL::TransactionID StorageCursorTest::transaction = nullptr;
|
||||
LMDBAL::Transaction StorageCursorTest::transaction = LMDBAL::Transaction();
|
||||
|
||||
static const std::map<uint64_t, std::string> data({
|
||||
{245665783, "bothering nerds"},
|
||||
|
@ -265,7 +266,7 @@ TEST_F(StorageCursorTest, CurrentPublic) {
|
|||
}
|
||||
|
||||
TEST_F(StorageCursorTest, CornerCases) {
|
||||
db->abortTransaction(transaction);
|
||||
transaction.terminate();
|
||||
EXPECT_THROW(cursor->current(), LMDBAL::Unknown);
|
||||
cursor->close();
|
||||
|
||||
|
|
|
@ -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