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 "cache.h"
#include "session.h"
class CacheTransactionsTest : public testing::Test {
protected:
@ -39,18 +40,19 @@ protected:
db->addStorage<std::string, float>("cache2");
}
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::Cache<int16_t, int64_t>* c1;
LMDBAL::Cache<std::string, float>* c2;
@ -58,9 +60,10 @@ protected:
LMDBAL::Base* CacheTransactionsTest::db = nullptr;
LMDBAL::Session CacheTransactionsTest::session;
TEST_F(CacheTransactionsTest, Adding) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
EXPECT_EQ(c1->count(), 0);
EXPECT_EQ(c2->count(), 0);
@ -90,7 +93,7 @@ TEST_F(CacheTransactionsTest, Adding) {
}
TEST_F(CacheTransactionsTest, Aborting) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::SizeType s1 = c1->count();
LMDBAL::SizeType s2 = c2->count();
@ -114,7 +117,7 @@ TEST_F(CacheTransactionsTest, Aborting) {
}
TEST_F(CacheTransactionsTest, Reading) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::Transaction txn = db->beginReadOnlyTransaction();
@ -132,7 +135,7 @@ TEST_F(CacheTransactionsTest, Reading) {
}
TEST_F(CacheTransactionsTest, ConcurentReading) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
LMDBAL::SizeType size = c1->count();
LMDBAL::WriteTransaction txn = db->beginTransaction();
@ -168,7 +171,7 @@ TEST_F(CacheTransactionsTest, ConcurentReading) {
TEST_F(CacheTransactionsTest, 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:
@ -231,7 +234,7 @@ TEST_F(CacheTransactionsTest, ConcurentModification) {
}
TEST_F(CacheTransactionsTest, RAIIResourceFree) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(db->opened(), true);
int pid = fork();
if (pid == 0) { // I am the child
@ -287,8 +290,8 @@ TEST_F(CacheTransactionsTest, TransactionTerminationOnClose) {
EXPECT_EQ(c1->getRecord(578, txn), 4552);
EXPECT_EQ(c1->checkRecord(578), false);
db->close();
db->open();
session.close();
session = db->open();
EXPECT_EQ(txn.isActive(), false);
EXPECT_THROW(c1->getRecord(578, txn), LMDBAL::TransactionTerminated);