summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/freshness_checker_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/freshness_checker_test.cpp')
-rw-r--r--src/mongo/db/repl/freshness_checker_test.cpp284
1 files changed, 166 insertions, 118 deletions
diff --git a/src/mongo/db/repl/freshness_checker_test.cpp b/src/mongo/db/repl/freshness_checker_test.cpp
index 45fde9ef816..2d0917254ec 100644
--- a/src/mongo/db/repl/freshness_checker_test.cpp
+++ b/src/mongo/db/repl/freshness_checker_test.cpp
@@ -121,9 +121,13 @@ const BSONObj makeFreshRequest(const ReplicaSetConfig& rsConfig,
int selfIndex) {
const MemberConfig& myConfig = rsConfig.getMemberAt(selfIndex);
return BSON("replSetFresh" << 1 << "set" << rsConfig.getReplSetName() << "opTime"
- << Date_t::fromMillisSinceEpoch(lastOpTimeApplied.asLL()) << "who"
- << myConfig.getHostAndPort().toString() << "cfgver"
- << rsConfig.getConfigVersion() << "id" << myConfig.getId());
+ << Date_t::fromMillisSinceEpoch(lastOpTimeApplied.asLL())
+ << "who"
+ << myConfig.getHostAndPort().toString()
+ << "cfgver"
+ << rsConfig.getConfigVersion()
+ << "id"
+ << myConfig.getId());
}
// This is necessary because the run method must be scheduled in the Replication Executor
@@ -159,7 +163,9 @@ TEST_F(FreshnessCheckerTest, TwoNodes) {
// Two nodes, we are node h1. We are freshest, but we tie with h2.
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -177,16 +183,19 @@ TEST_F(FreshnessCheckerTest, TwoNodes) {
ASSERT_EQUALS("admin", noi->getRequest().dbname);
ASSERT_EQUALS(freshRequest, noi->getRequest().cmdObj);
ASSERT_EQUALS(HostAndPort("h1"), noi->getRequest().target);
- _net->scheduleResponse(noi,
- startDate + Milliseconds(10),
- ResponseStatus(RemoteCommandResponse(
- BSON("ok" << 1 << "id" << 2 << "set"
- << "rs0"
- << "who"
- << "h1"
- << "cfgver" << 1 << "opTime" << Date_t()),
- BSONObj(),
- Milliseconds(8))));
+ _net->scheduleResponse(
+ noi,
+ startDate + Milliseconds(10),
+ ResponseStatus(RemoteCommandResponse(BSON("ok" << 1 << "id" << 2 << "set"
+ << "rs0"
+ << "who"
+ << "h1"
+ << "cfgver"
+ << 1
+ << "opTime"
+ << Date_t()),
+ BSONObj(),
+ Milliseconds(8))));
}
_net->runUntil(startDate + Milliseconds(10));
_net->exitNetwork();
@@ -199,7 +208,9 @@ TEST_F(FreshnessCheckerTest, ShuttingDown) {
// Two nodes, we are node h1. Shutdown happens while we're scheduling remote commands.
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -222,7 +233,9 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshest) {
startCapturingLogMessages();
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -248,8 +261,12 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshest) {
<< "rs0"
<< "who"
<< "h1"
- << "cfgver" << 1 << "fresher" << true
- << "opTime" << Date_t()),
+ << "cfgver"
+ << 1
+ << "fresher"
+ << true
+ << "opTime"
+ << Date_t()),
BSONObj(),
Milliseconds(8))));
}
@@ -268,7 +285,9 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestOpTime) {
startCapturingLogMessages();
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -295,7 +314,9 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestOpTime) {
<< "rs0"
<< "who"
<< "h1"
- << "cfgver" << 1 << "opTime"
+ << "cfgver"
+ << 1
+ << "opTime"
<< Date_t::fromMillisSinceEpoch(Timestamp(10, 0).asLL())),
BSONObj(),
Milliseconds(8))));
@@ -314,7 +335,9 @@ TEST_F(FreshnessCheckerTest, ElectWrongTypeInFreshnessResponse) {
startCapturingLogMessages();
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -340,7 +363,10 @@ TEST_F(FreshnessCheckerTest, ElectWrongTypeInFreshnessResponse) {
<< "rs0"
<< "who"
<< "h1"
- << "cfgver" << 1 << "opTime" << 3),
+ << "cfgver"
+ << 1
+ << "opTime"
+ << 3),
BSONObj(),
Milliseconds(8))));
}
@@ -353,9 +379,8 @@ TEST_F(FreshnessCheckerTest, ElectWrongTypeInFreshnessResponse) {
ASSERT_EQUALS(shouldAbortElection(), FreshnessChecker::FresherNodeFound);
ASSERT_EQUALS(1,
- countLogLinesContaining(
- "wrong type for opTime argument in replSetFresh "
- "response: int"));
+ countLogLinesContaining("wrong type for opTime argument in replSetFresh "
+ "response: int"));
}
TEST_F(FreshnessCheckerTest, ElectVetoed) {
@@ -363,7 +388,9 @@ TEST_F(FreshnessCheckerTest, ElectVetoed) {
startCapturingLogMessages();
ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "h0")
<< BSON("_id" << 2 << "host"
@@ -390,9 +417,14 @@ TEST_F(FreshnessCheckerTest, ElectVetoed) {
<< "rs0"
<< "who"
<< "h1"
- << "cfgver" << 1 << "veto" << true << "errmsg"
+ << "cfgver"
+ << 1
+ << "veto"
+ << true
+ << "errmsg"
<< "I'd rather you didn't"
- << "opTime" << Date_t::fromMillisSinceEpoch(Timestamp(0, 0).asLL())),
+ << "opTime"
+ << Date_t::fromMillisSinceEpoch(Timestamp(0, 0).asLL())),
BSONObj(),
Milliseconds(8))));
}
@@ -405,9 +437,8 @@ TEST_F(FreshnessCheckerTest, ElectVetoed) {
ASSERT_EQUALS(shouldAbortElection(), FreshnessChecker::FresherNodeFound);
ASSERT_EQUALS(1,
- countLogLinesContaining(
- "not electing self, h1:27017 would veto with "
- "'I'd rather you didn't'"));
+ countLogLinesContaining("not electing self, h1:27017 would veto with "
+ "'I'd rather you didn't'"));
}
int findIdForMember(const ReplicaSetConfig& rsConfig, const HostAndPort& host) {
@@ -419,18 +450,21 @@ int findIdForMember(const ReplicaSetConfig& rsConfig, const HostAndPort& host) {
TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestManyNodes) {
// one other responds as fresher than us
startCapturingLogMessages();
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = ++config.membersBegin(); mem != config.membersEnd();
@@ -475,18 +509,21 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestManyNodes) {
TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestOpTimeManyNodes) {
// one other responds with a later optime than ours
startCapturingLogMessages();
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = config.membersBegin(); mem != config.membersEnd();
@@ -545,18 +582,21 @@ TEST_F(FreshnessCheckerTest, ElectNotElectingSelfWeAreNotFreshestOpTimeManyNodes
TEST_F(FreshnessCheckerTest, ElectWrongTypeInFreshnessResponseManyNodes) {
// one other responds with "opTime" field of non-Date value, causing not freshest
startCapturingLogMessages();
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = ++config.membersBegin(); mem != config.membersEnd();
@@ -597,26 +637,28 @@ TEST_F(FreshnessCheckerTest, ElectWrongTypeInFreshnessResponseManyNodes) {
stopCapturingLogMessages();
ASSERT_EQUALS(shouldAbortElection(), FreshnessChecker::FresherNodeFound);
ASSERT_EQUALS(1,
- countLogLinesContaining(
- "wrong type for opTime argument in replSetFresh "
- "response: int"));
+ countLogLinesContaining("wrong type for opTime argument in replSetFresh "
+ "response: int"));
}
TEST_F(FreshnessCheckerTest, ElectVetoedManyNodes) {
// one other responds with veto
startCapturingLogMessages();
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = ++config.membersBegin(); mem != config.membersEnd();
@@ -657,26 +699,28 @@ TEST_F(FreshnessCheckerTest, ElectVetoedManyNodes) {
stopCapturingLogMessages();
ASSERT_EQUALS(shouldAbortElection(), FreshnessChecker::FresherNodeFound);
ASSERT_EQUALS(1,
- countLogLinesContaining(
- "not electing self, h1:27017 would veto with "
- "'I'd rather you didn't'"));
+ countLogLinesContaining("not electing self, h1:27017 would veto with "
+ "'I'd rather you didn't'"));
}
TEST_F(FreshnessCheckerTest, ElectVetoedAndTiedFreshnessManyNodes) {
// one other responds with veto and another responds with tie
startCapturingLogMessages();
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = config.membersBegin(); mem != config.membersEnd();
@@ -726,9 +770,8 @@ TEST_F(FreshnessCheckerTest, ElectVetoedAndTiedFreshnessManyNodes) {
_net->runUntil(startDate + Milliseconds(10));
ASSERT_EQUALS(startDate + Milliseconds(10), _net->now());
ASSERT_EQUALS(0,
- countLogLinesContaining(
- "not electing self, h4:27017 would veto with '"
- "errmsg: \"I'd rather you didn't\"'"));
+ countLogLinesContaining("not electing self, h4:27017 would veto with '"
+ "errmsg: \"I'd rather you didn't\"'"));
_net->runUntil(startDate + Milliseconds(20));
ASSERT_EQUALS(startDate + Milliseconds(20), _net->now());
_net->exitNetwork();
@@ -736,24 +779,26 @@ TEST_F(FreshnessCheckerTest, ElectVetoedAndTiedFreshnessManyNodes) {
stopCapturingLogMessages();
ASSERT_EQUALS(shouldAbortElection(), FreshnessChecker::FresherNodeFound);
ASSERT_EQUALS(1,
- countLogLinesContaining(
- "not electing self, h4:27017 would veto with "
- "'I'd rather you didn't'"));
+ countLogLinesContaining("not electing self, h4:27017 would veto with "
+ "'I'd rather you didn't'"));
}
TEST_F(FreshnessCheckerTest, ElectManyNodesNotAllRespond) {
- ReplicaSetConfig config =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h0")
- << BSON("_id" << 2 << "host"
- << "h1") << BSON("_id" << 3 << "host"
- << "h2")
- << BSON("_id" << 4 << "host"
- << "h3") << BSON("_id" << 5 << "host"
- << "h4"))));
+ ReplicaSetConfig config = assertMakeRSConfig(BSON("_id"
+ << "rs0"
+ << "version"
+ << 1
+ << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h0")
+ << BSON("_id" << 2 << "host"
+ << "h1")
+ << BSON("_id" << 3 << "host"
+ << "h2")
+ << BSON("_id" << 4 << "host"
+ << "h3")
+ << BSON("_id" << 5 << "host"
+ << "h4"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = ++config.membersBegin(); mem != config.membersEnd();
@@ -806,12 +851,15 @@ public:
ReplicaSetConfig config;
config.initialize(BSON("_id"
<< "rs0"
- << "version" << 1 << "members"
+ << "version"
+ << 1
+ << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "host0")
<< BSON("_id" << 1 << "host"
- << "host1") << BSON("_id" << 2 << "host"
- << "host2"))));
+ << "host1")
+ << BSON("_id" << 2 << "host"
+ << "host2"))));
std::vector<HostAndPort> hosts;
for (ReplicaSetConfig::MemberIterator mem = ++config.membersBegin();