23241e76b9
Summary: This diff contains step 1: - Remove clog exposure from tx::engine - Reduce and cleanup tx::Engine API All current functionality is kept, but the API is reduced. This is very desirable because every function in tx::Engine will need to be considered and implemented in both Master and Worker situations. The less we have, the better. Next step is exactly that: seeing how each of these functions behaves in a distributed system and implementing accordingly. Reviewers: dgleich, mislav.bradac, buda Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1008
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "gtest/gtest.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "transactions/engine.hpp"
|
|
#include "transactions/transaction.hpp"
|
|
|
|
TEST(Engine, GcSnapshot) {
|
|
tx::Engine engine;
|
|
ASSERT_EQ(engine.GcSnapshot(), tx::Snapshot({1}));
|
|
|
|
std::vector<tx::Transaction *> transactions;
|
|
// create transactions and check the GC snapshot
|
|
for (int i = 0; i < 5; ++i) {
|
|
transactions.push_back(engine.Begin());
|
|
EXPECT_EQ(engine.GcSnapshot(), tx::Snapshot({1}));
|
|
}
|
|
|
|
// commit transactions in the middle, expect
|
|
// the GcSnapshot did not change
|
|
transactions[1]->Commit();
|
|
EXPECT_EQ(engine.GcSnapshot(), tx::Snapshot({1}));
|
|
transactions[2]->Commit();
|
|
EXPECT_EQ(engine.GcSnapshot(), tx::Snapshot({1}));
|
|
|
|
// have the first three transactions committed
|
|
transactions[0]->Commit();
|
|
EXPECT_EQ(engine.GcSnapshot(), tx::Snapshot({1, 2, 3, 4}));
|
|
|
|
// commit all
|
|
transactions[3]->Commit();
|
|
transactions[4]->Commit();
|
|
EXPECT_EQ(engine.GcSnapshot(), tx::Snapshot({6}));
|
|
}
|
|
|
|
TEST(Engine, Advance) {
|
|
tx::Engine engine;
|
|
|
|
auto t0 = engine.Begin();
|
|
auto t1 = engine.Begin();
|
|
EXPECT_EQ(t0->cid(), 1);
|
|
engine.Advance(t0->id_);
|
|
EXPECT_EQ(t0->cid(), 2);
|
|
engine.Advance(t0->id_);
|
|
EXPECT_EQ(t0->cid(), 3);
|
|
EXPECT_EQ(t1->cid(), 1);
|
|
}
|