Sessions to manage db open state
All checks were successful
Main LMDBAL workflow / Test LMDBAL with qt5 (push) Successful in 1m16s
Main LMDBAL workflow / Test LMDBAL with qt6 (push) Successful in 1m39s
Main LMDBAL workflow / Builds documentation (push) Successful in 46s
Main LMDBAL workflow / Deploys documentation (push) Successful in 7s

This commit is contained in:
Blue 2025-05-06 00:22:03 +03:00
parent 3701fb92a1
commit f9902bc0b1
Signed by: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 342 additions and 124 deletions

View file

@ -4,6 +4,7 @@
#include "base.h"
#include "storage.h"
#include "session.h"
class StorageTransactionsTest : public testing::Test {
protected:
@ -39,18 +40,19 @@ protected:
db->addStorage<std::string, float>("table2");
}
db->open();
session = db->open();
db->drop();
}
static void TearDownTestSuite() {
db->close();
session.close();
db->removeDirectory();
delete db;
db = nullptr;
}
static LMDBAL::Base* db;
static LMDBAL::Session session;
LMDBAL::Storage<int16_t, int64_t>* t1;
LMDBAL::Storage<std::string, float>* t2;
@ -58,9 +60,10 @@ protected:
LMDBAL::Base* StorageTransactionsTest::db = nullptr;
LMDBAL::Session StorageTransactionsTest::session;
TEST_F(StorageTransactionsTest, Adding) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
EXPECT_EQ(t1->count(), 0);
EXPECT_EQ(t2->count(), 0);
@ -90,7 +93,7 @@ TEST_F(StorageTransactionsTest, Adding) {
}
TEST_F(StorageTransactionsTest, Aborting) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::SizeType s1 = t1->count();
LMDBAL::SizeType s2 = t2->count();
@ -114,7 +117,7 @@ TEST_F(StorageTransactionsTest, Aborting) {
}
TEST_F(StorageTransactionsTest, Reading) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::Transaction txn = db->beginReadOnlyTransaction();
@ -132,7 +135,7 @@ TEST_F(StorageTransactionsTest, Reading) {
}
TEST_F(StorageTransactionsTest, ConcurentReading) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::SizeType size = t1->count();
LMDBAL::WriteTransaction txn = db->beginTransaction();
@ -167,7 +170,7 @@ TEST_F(StorageTransactionsTest, ConcurentReading) {
}
TEST_F(StorageTransactionsTest, ConcurentModification) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
//if you start one writable transaction after another
//in a single thread like so:
@ -230,7 +233,7 @@ TEST_F(StorageTransactionsTest, ConcurentModification) {
}
TEST_F(StorageTransactionsTest, RAIIResourceFree) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
int pid = fork();
if (pid == 0) { // I am the child
@ -286,8 +289,8 @@ TEST_F(StorageTransactionsTest, TransactionTerminationOnClose) {
EXPECT_EQ(t1->getRecord(543, txn), 229);
EXPECT_EQ(t1->checkRecord(543), false);
db->close();
db->open();
session.close();
session = db->open();
EXPECT_EQ(txn.isActive(), false);
EXPECT_THROW(t1->getRecord(543, txn), LMDBAL::TransactionTerminated);