Skip to content

Commit

Permalink
add test for tid_word compare
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Aug 27, 2024
1 parent 0886652 commit a074bff
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 15 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ else ()
"shutdown/*.cpp"
"sequence/*.cpp"
"storage/*.cpp"
"tid_word/*.cpp"
"transaction_options/*.cpp"
"tsurugi_issues/*.cpp"
"tx_id/*.cpp"
Expand Down
81 changes: 81 additions & 0 deletions test/tid_word/tid_word_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

#include "gtest/gtest.h"
#include "glog/logging.h"

#include "concurrency_control/include/tid.h"
#include "shirakami/interface.h"

namespace shirakami::testing {

using namespace shirakami;

class tid_word_test : public ::testing::Test { // NOLINT
public:
static void call_once_f() {
google::InitGoogleLogging("shirakami-test-tid_word-tid_word_test");
// FLAGS_stderrthreshold = 0;
}

void SetUp() override { std::call_once(init_google, call_once_f); }

void TearDown() override {}

private:
static inline std::once_flag init_google;
};

// moved from tx_id_test
TEST_F(tid_word_test, comp) {
tid_word ltid{0}, stid{0};
// short, ltx. epoch 1, tid0, by_short test
ltid.set_by_short(false);
stid.set_by_short(true);
ASSERT_GT(stid, ltid);
// common: tid 0, ltx: epoch 2, occ: epoch 1
ltid.set_epoch(2);
stid.set_epoch(1);
ASSERT_GT(ltid, stid);
// common: tid 0, ltx: epoch 1, occ: epoch 2
ltid.set_epoch(1);
stid.set_epoch(2);
ASSERT_GT(stid, ltid);
}

TEST_F(tid_word_test, epoch_is_stronger_than_tid) {
tid_word t1{}, t2{};
t1.set_epoch(1);
t1.set_tid(2);
t2.set_epoch(2);
t2.set_tid(1);
EXPECT_LT(t1, t2);
}

TEST_F(tid_word_test, epoch_keeps_ordered) {
// check epoch=1 < epoch=2 < epoch=4 < ...
tid_word t1{}, t2{};
t1.set_tid(0);
t2.set_tid(0);
for (epoch::epoch_t e = 1; e; e <<= 1) {
t1.set_epoch(e);
t2.set_epoch(e << 1);
if (t2.get_epoch() == 0) { break; }
ASSERT_LT(t1.get_epoch(), t2.get_epoch());
EXPECT_LT(t1, t2);
}
}

TEST_F(tid_word_test, tid_keeps_ordered) {
// check tid=1 < tid=2 < tid=4 < ...
tid_word t1{}, t2{};
t1.set_epoch(0);
t2.set_epoch(0);
for (uint64_t t = 1; t; t <<= 1) {
t1.set_tid(t);
t2.set_tid(t << 1);
if (t2.get_tid() == 0) { break; }
ASSERT_LT(t1.get_tid(), t2.get_tid());
EXPECT_LT(t1, t2);
}
}

} // namespace shirakami::testing
16 changes: 1 addition & 15 deletions test/tx_id/tx_id_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ TEST_F(tx_id_test, simple) { // NOLINT
ASSERT_EQ(Status::OK, leave(s1));
}

TEST_F(tx_id_test, comp) { // NOLINT
tid_word ltid{0}, stid{0};
// short, ltx. epoch 1, tid0, by_short test
ltid.set_by_short(false);
stid.set_by_short(true);
ASSERT_GT(stid, ltid);
// common: tid 0, ltx: epoch 2, occ: epoch 1
ltid.set_epoch(2);
stid.set_epoch(1);
ASSERT_GT(ltid, stid);
// common: tid 0, ltx: epoch 1, occ: epoch 2
ltid.set_epoch(1);
stid.set_epoch(2);
ASSERT_GT(stid, ltid);
}
// moved to tid_word_test

} // namespace shirakami::testing

0 comments on commit a074bff

Please sign in to comment.