4fa44c3edd
Summary: `ReplicationLog` had a classic off-by-one bug. The `valid_prefix` variable wasn't set properly. This diff also includes a poor man's version of a HA client. This client assumes that all the HA instances run on a single machine and that the corresponding Bold endpoints have open ports ranging from `7687` to `7687 + num_machines - 1`. This should make it easeir to test certain things, ie. disk usage, P25. This test revealed the bug with `ReplicationLog` Reviewers: ipaljak Reviewed By: ipaljak Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1813
67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "raft/replication_log.hpp"
|
|
|
|
using namespace tx;
|
|
|
|
TEST(ReplicationLog, ActiveReplicated) {
|
|
raft::ReplicationLog rlog;
|
|
const tx::TransactionId tx_id = 10;
|
|
|
|
EXPECT_FALSE(rlog.is_replicated(tx_id));
|
|
EXPECT_FALSE(rlog.is_active(tx_id));
|
|
|
|
rlog.set_active(tx_id);
|
|
|
|
EXPECT_FALSE(rlog.is_replicated(tx_id));
|
|
EXPECT_TRUE(rlog.is_active(tx_id));
|
|
|
|
rlog.set_replicated(tx_id);
|
|
|
|
EXPECT_TRUE(rlog.is_replicated(tx_id));
|
|
EXPECT_FALSE(rlog.is_active(tx_id));
|
|
}
|
|
|
|
TEST(ReplicationLog, GarbageCollect) {
|
|
raft::ReplicationLog rlog;
|
|
|
|
auto set_active = [&rlog](tx::TransactionId tx_id) {
|
|
rlog.set_active(tx_id);
|
|
EXPECT_TRUE(rlog.is_active(tx_id));
|
|
};
|
|
|
|
auto set_replicated = [&rlog](tx::TransactionId tx_id) {
|
|
rlog.set_replicated(tx_id);
|
|
EXPECT_TRUE(rlog.is_replicated(tx_id));
|
|
EXPECT_FALSE(rlog.is_active(tx_id));
|
|
};
|
|
|
|
const int n = raft::ReplicationLog::kBitsetBlockSize;
|
|
|
|
for (int i = 1; i < 3 * n; ++i) {
|
|
set_active(i);
|
|
}
|
|
|
|
for (int i = 1; i < 2 * n; ++i) {
|
|
set_replicated(i);
|
|
}
|
|
|
|
rlog.garbage_collect_older(n);
|
|
|
|
for (int i = 1; i < n; ++i) {
|
|
EXPECT_FALSE(rlog.is_active(i));
|
|
EXPECT_FALSE(rlog.is_replicated(i));
|
|
}
|
|
|
|
for (int i = n; i < 2 * n; ++i) {
|
|
EXPECT_FALSE(rlog.is_active(i));
|
|
EXPECT_TRUE(rlog.is_replicated(i));
|
|
}
|
|
|
|
for (int i = 2 * n; i < 3 * n; ++i) {
|
|
EXPECT_TRUE(rlog.is_active(i));
|
|
EXPECT_FALSE(rlog.is_replicated(i));
|
|
}
|
|
}
|