2017-06-02 15:19:23 +08:00
|
|
|
#include "mvcc_find_update_common.hpp"
|
|
|
|
|
|
|
|
#undef T2_FIND
|
|
|
|
#define T2_FIND version_list.find(*t2)
|
|
|
|
|
|
|
|
#undef EXPECT_CRE
|
|
|
|
#undef EXPECT_EXP
|
|
|
|
#define EXPECT_CRE(record, transaction, command) \
|
2017-09-27 20:45:50 +08:00
|
|
|
EXPECT_EQ(record->tx().cre, id##transaction); \
|
|
|
|
EXPECT_EQ(record->cmd().cre, command)
|
2017-06-02 15:19:23 +08:00
|
|
|
#define EXPECT_EXP(record, transaction, command) \
|
2017-09-27 20:45:50 +08:00
|
|
|
EXPECT_EQ(record->tx().exp, id##transaction); \
|
|
|
|
EXPECT_EQ(record->cmd().exp, command)
|
2017-06-02 15:19:23 +08:00
|
|
|
|
|
|
|
// IMPORTANT: look definiton of EXPECT_CRE and EXPECT_EXP macros in
|
|
|
|
// tests/mvcc_find_update_common.hpp. Numbers in those macros represent
|
|
|
|
// transaction ids when transactions where created.
|
|
|
|
|
|
|
|
TEST_F(Mvcc, UpdateNotAdvanceUpdate) {
|
|
|
|
T2_UPDATE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
|
|
|
auto v2_2 = version_list.update(*t2);
|
|
|
|
EXPECT_NXT(v2, v1);
|
|
|
|
EXPECT_EQ(v2, v2_2);
|
|
|
|
EXPECT_CRE(v2, 2, 1);
|
|
|
|
EXPECT_EXP(v2, 0, 0);
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, UpdateNotAdvanceRemove) {
|
|
|
|
T2_UPDATE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_NXT(v2, v1);
|
|
|
|
EXPECT_CRE(v2, 2, 1);
|
|
|
|
EXPECT_EXP(v2, 0, 0);
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, RemoveNotAdvanceUpdate) {
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
|
|
|
T2_UPDATE;
|
|
|
|
EXPECT_NXT(v2, v1);
|
|
|
|
EXPECT_CRE(v2, 2, 1);
|
|
|
|
EXPECT_EXP(v2, 0, 0);
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, RemoveNotAdvanceRemove) {
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, UpdateAdvanceUpdate) {
|
|
|
|
T2_UPDATE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
2017-06-12 16:21:19 +08:00
|
|
|
engine.Advance(t2->id_);
|
2017-06-02 15:19:23 +08:00
|
|
|
EXPECT_EQ(T2_FIND, v2);
|
|
|
|
auto v2_2 = version_list.update(*t2);
|
|
|
|
EXPECT_NXT(v2, v1);
|
|
|
|
EXPECT_NXT(v2_2, v2);
|
|
|
|
EXPECT_CRE(v2, 2, 1);
|
|
|
|
EXPECT_EXP(v2, 2, 2);
|
|
|
|
EXPECT_CRE(v2_2, 2, 2);
|
|
|
|
EXPECT_EXP(v2_2, 0, 0);
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, UpdateAdvanceRemove) {
|
|
|
|
T2_UPDATE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
2017-06-12 16:21:19 +08:00
|
|
|
engine.Advance(t2->id_);
|
2017-06-02 15:19:23 +08:00
|
|
|
EXPECT_EQ(T2_FIND, v2);
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_NXT(v2, v1);
|
|
|
|
EXPECT_CRE(v2, 2, 1);
|
|
|
|
EXPECT_EXP(v2, 2, 2);
|
|
|
|
EXPECT_CRE(v1, 1, 1);
|
|
|
|
EXPECT_EXP(v1, 2, 1);
|
|
|
|
EXPECT_SIZE(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, RemoveAdvanceUpdate) {
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
2017-06-12 16:21:19 +08:00
|
|
|
engine.Advance(t2->id_);
|
2017-06-02 15:19:23 +08:00
|
|
|
EXPECT_EQ(T2_FIND, nullptr);
|
|
|
|
EXPECT_DEATH(T2_UPDATE, ".*nullptr.*");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(Mvcc, RemoveAdvanceRemove) {
|
|
|
|
T2_REMOVE;
|
|
|
|
EXPECT_EQ(T2_FIND, v1);
|
2017-06-12 16:21:19 +08:00
|
|
|
engine.Advance(t2->id_);
|
2017-06-02 15:19:23 +08:00
|
|
|
EXPECT_EQ(T2_FIND, nullptr);
|
2017-10-18 22:03:06 +08:00
|
|
|
EXPECT_FALSE(T2_FIND);
|
2017-06-02 15:19:23 +08:00
|
|
|
}
|
2017-10-16 22:24:47 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|