From 6dcdd23dd37ef12c87e71cf59ef01cd82432efe0 Mon Sep 17 00:00:00 2001 From: Mark Benvenuto Date: Sat, 28 May 2016 17:55:12 -0400 Subject: SERVER-23971 Clang-Format code --- .../db/repl/topology_coordinator_impl_v1_test.cpp | 1456 +++++++++++++------- 1 file changed, 959 insertions(+), 497 deletions(-) (limited to 'src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp') diff --git a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp index 826905a860a..9e04bf8942d 100644 --- a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp @@ -255,12 +255,15 @@ TEST_F(TopoCoordTest, NodeReturnsSecondaryWithMostRecentDataAsSyncSource) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -320,26 +323,41 @@ TEST_F(TopoCoordTest, NodeReturnsSecondaryWithMostRecentDataAsSyncSource) { TEST_F(TopoCoordTest, NodeReturnsClosestValidSyncSourceAsSyncSource) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself") << BSON("_id" << 10 << "host" << "h1") << BSON("_id" << 20 << "host" << "h2" - << "buildIndexes" << false << "priority" << 0) + << "buildIndexes" + << false + << "priority" + << 0) << BSON("_id" << 30 << "host" << "h3" - << "hidden" << true << "priority" << 0 << "votes" - << 0) << BSON("_id" << 40 << "host" - << "h4" - << "arbiterOnly" << true) + << "hidden" + << true + << "priority" + << 0 + << "votes" + << 0) + << BSON("_id" << 40 << "host" + << "h4" + << "arbiterOnly" + << true) << BSON("_id" << 50 << "host" << "h5" - << "slaveDelay" << 1 << "priority" << 0) + << "slaveDelay" + << 1 + << "priority" + << 0) << BSON("_id" << 60 << "host" - << "h6") << BSON("_id" << 70 << "host" - << "hprimary"))), + << "h6") + << BSON("_id" << 70 << "host" + << "hprimary"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -471,13 +489,17 @@ TEST_F(TopoCoordTest, NodeReturnsClosestValidSyncSourceAsSyncSource) { TEST_F(TopoCoordTest, ChooseOnlyPrimaryAsSyncSourceWhenChainingIsDisallowed) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "settings" << BSON("chainingAllowed" << false) + << "version" + << 1 + << "settings" + << BSON("chainingAllowed" << false) << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -523,12 +545,11 @@ TEST_F(TopoCoordTest, ChooseOnlyPrimaryAsSyncSourceWhenChainingIsDisallowed) { } TEST_F(TopoCoordTest, ChooseOnlyVotersAsSyncSourceWhenNodeIsAVoter) { - updateConfig(fromjson( - "{_id:'rs0', version:1, members:[" - "{_id:10, host:'hself'}, " - "{_id:20, host:'h2', votes:0, priority:0}, " - "{_id:30, host:'h3'} " - "]}"), + updateConfig(fromjson("{_id:'rs0', version:1, members:[" + "{_id:10, host:'hself'}, " + "{_id:20, host:'h2', votes:0, priority:0}, " + "{_id:30, host:'h3'} " + "]}"), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -561,12 +582,15 @@ TEST_F(TopoCoordTest, ChooseOnlyVotersAsSyncSourceWhenNodeIsAVoter) { TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -608,12 +632,15 @@ TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimary) { TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourceIsForciblySet) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -651,12 +678,15 @@ TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourc TEST_F(TopoCoordTest, NodeDoesNotChooseBlacklistedSyncSourceUntilBlacklistingExpires) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -700,13 +730,17 @@ TEST_F(TopoCoordTest, NodeDoesNotChooseBlacklistedSyncSourceUntilBlacklistingExp TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimaryIsBlacklistedAndChainingIsDisallowed) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "settings" << BSON("chainingAllowed" << false) + << "version" + << 1 + << "settings" + << BSON("chainingAllowed" << false) << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -751,12 +785,15 @@ TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimaryIsBlacklistedAndChainingIsDis TEST_F(TopoCoordTest, NodeChangesToRecoveringWhenOnlyUnauthorizedNodesAreUp) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -815,18 +852,22 @@ TEST_F(TopoCoordTest, NodeChangesToRecoveringWhenOnlyUnauthorizedNodesAreUp) { TEST_F(TopoCoordTest, NodeDoesNotActOnHeartbeatsWhenAbsentFromConfig) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "h1") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), -1); ASSERT_NO_ACTION(heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(Timestamp(1, 0), 0), - Milliseconds(300)).getAction()); + Milliseconds(300)) + .getAction()); } TEST_F(TopoCoordTest, NodeReturnsNotSecondaryWhenSyncFromIsRunPriorToHavingAConfig) { @@ -853,10 +894,13 @@ TEST_F(TopoCoordTest, NodeReturnsNotSecondaryWhenSyncFromIsRunAgainstArbiter) { // Test trying to sync from another node when we are an arbiter updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 1 << "host" << "h1"))), 0); @@ -875,21 +919,29 @@ TEST_F(TopoCoordTest, NodeReturnsNotSecondaryWhenSyncFromIsRunAgainstPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); // Try to sync while PRIMARY @@ -912,21 +964,29 @@ TEST_F(TopoCoordTest, NodeReturnsNodeNotFoundWhenSyncFromRequestsANodeNotInConfi updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -945,21 +1005,29 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsSelf) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -978,21 +1046,29 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1012,21 +1088,29 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsAnIndexNonbui updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1046,21 +1130,29 @@ TEST_F(TopoCoordTest, NodeReturnsHostUnreachableWhenSyncFromRequestsADownNode) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1081,21 +1173,29 @@ TEST_F(TopoCoordTest, ChooseRequestedNodeWhenSyncFromRequestsAStaleNode) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1120,21 +1220,29 @@ TEST_F(TopoCoordTest, ChooseRequestedNodeWhenSyncFromRequestsAValidNode) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1160,21 +1268,29 @@ TEST_F(TopoCoordTest, updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1199,21 +1315,29 @@ TEST_F(TopoCoordTest, NodeReturnsUnauthorizedWhenSyncFromRequestsANodeWeAreNotAu updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1234,12 +1358,11 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenAskedToSyncFromANonVoterAsAVo BSONObjBuilder response; // Test trying to sync from another node - updateConfig(fromjson( - "{_id:'rs0', version:1, members:[" - "{_id:0, host:'self'}," - "{_id:1, host:'h1'}," - "{_id:2, host:'h2', votes:0, priority:0}" - "]}"), + updateConfig(fromjson("{_id:'rs0', version:1, members:[" + "{_id:0, host:'self'}," + "{_id:1, host:'h1'}," + "{_id:2, host:'h2', votes:0, priority:0}" + "]}"), 0); getTopoCoord().prepareSyncFromResponse(HostAndPort("h2"), ourOpTime, &response, &result); @@ -1258,21 +1381,29 @@ TEST_F(TopoCoordTest, updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" << 0 << "buildIndexes" << false) + << "priority" + << 0 + << "buildIndexes" + << false) << BSON("_id" << 3 << "host" - << "h3") << BSON("_id" << 4 << "host" - << "h4") + << "h3") + << BSON("_id" << 4 << "host" + << "h4") << BSON("_id" << 5 << "host" - << "h5") << BSON("_id" << 6 << "host" - << "h6"))), + << "h5") + << BSON("_id" << 6 << "host" + << "h6"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1329,17 +1460,17 @@ TEST_F(TopoCoordTest, ReplSetGetStatus) { hb.setAppliedOpTime(oplogProgress); StatusWith hbResponseGood = StatusWith(hb); - updateConfig( - BSON("_id" << setName << "version" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "test0:1234") - << BSON("_id" << 1 << "host" - << "test1:1234") << BSON("_id" << 2 << "host" - << "test2:1234") - << BSON("_id" << 3 << "host" - << "test3:1234"))), - 3, - startupTime + Milliseconds(1)); + updateConfig(BSON("_id" << setName << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "test0:1234") + << BSON("_id" << 1 << "host" + << "test1:1234") + << BSON("_id" << 2 << "host" + << "test2:1234") + << BSON("_id" << 3 << "host" + << "test3:1234"))), + 3, + startupTime + Milliseconds(1)); // Now that the replica set is setup, put the members into the states we want them in. HostAndPort member = HostAndPort("test0:1234"); @@ -1468,15 +1599,15 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidReplicaSetConfigInResponseToGetStatusWhe OpTime oplogProgress(Timestamp(3, 4), 0); std::string setName = "mySet"; - updateConfig( - BSON("_id" << setName << "version" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "test0:1234") - << BSON("_id" << 1 << "host" - << "test1:1234") << BSON("_id" << 2 << "host" - << "test2:1234"))), - -1, // This one is not part of the replica set. - startupTime + Milliseconds(1)); + updateConfig(BSON("_id" << setName << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "test0:1234") + << BSON("_id" << 1 << "host" + << "test1:1234") + << BSON("_id" << 2 << "host" + << "test2:1234"))), + -1, // This one is not part of the replica set. + startupTime + Milliseconds(1)); BSONObjBuilder statusBuilder; Status resultStatus(ErrorCodes::InternalError, "prepareStatusResponse didn't set result"); @@ -1497,11 +1628,10 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidReplicaSetConfigInResponseToGetStatusWhe TEST_F(TopoCoordTest, HeartbeatFrequencyShouldBeHalfElectionTimeoutWhenArbiter) { // This tests that arbiters issue heartbeats at electionTimeout/2 frequencies TopoCoordTest::setUp(); - updateConfig(fromjson( - "{_id:'mySet', version:1, protocolVersion:1, members:[" - "{_id:1, host:'node1:12345', arbiterOnly:true}, " - "{_id:2, host:'node2:12345'}], " - "settings:{heartbeatIntervalMillis:10, electionTimeoutMillis:5000}}"), + updateConfig(fromjson("{_id:'mySet', version:1, protocolVersion:1, members:[" + "{_id:1, host:'node1:12345', arbiterOnly:true}, " + "{_id:2, host:'node2:12345'}], " + "settings:{heartbeatIntervalMillis:10, electionTimeoutMillis:5000}}"), 0); HostAndPort target("host2", 27017); Date_t requestDate = now(); @@ -1523,12 +1653,16 @@ public: TopoCoordTest::setUp(); updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3")) << "settings" + << "h2") + << BSON("_id" << 30 << "host" + << "h3")) + << "settings" << BSON("protocolVersion" << 1)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -1558,9 +1692,8 @@ TEST_F(PrepareHeartbeatResponseV1Test, ASSERT(result.reason().find("repl set names do not match")) << "Actual string was \"" << result.reason() << '"'; ASSERT_EQUALS(1, - countLogLinesContaining( - "replSet set names do not match, ours: rs0; remote " - "node's: rs1")); + countLogLinesContaining("replSet set names do not match, ours: rs0; remote " + "node's: rs1")); // only protocolVersion should be set in this failure case ASSERT_EQUALS("", response.getReplicaSetName()); } @@ -1570,11 +1703,15 @@ TEST_F(PrepareHeartbeatResponseV1Test, // reconfig self out of set updateConfig(BSON("_id" << "rs0" - << "version" << 3 << "members" << BSON_ARRAY(BSON("_id" << 20 << "host" - << "h2") - << BSON("_id" << 30 << "host" - << "h3")) - << "settings" << BSON("protocolVersion" << 1)), + << "version" + << 3 + << "members" + << BSON_ARRAY(BSON("_id" << 20 << "host" + << "h2") + << BSON("_id" << 30 << "host" + << "h3")) + << "settings" + << BSON("protocolVersion" << 1)), -1); ReplSetHeartbeatArgsV1 args; args.setSetName("rs0"); @@ -1764,8 +1901,11 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" - << "hself"))), + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "hself"))), 0); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1782,10 +1922,13 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { ReplicaSetConfig cfg; cfg.initialize(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself" - << "priority" << 0)))); + << "priority" + << 0)))); getTopoCoord().updateConfig(cfg, 0, now()++, OpTime()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1798,8 +1941,11 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" - << "hself"))), + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "hself"))), 0); ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); } @@ -1810,10 +1956,13 @@ TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNod ReplicaSetConfig cfg; cfg.initialize(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself" - << "priority" << 0)))); + << "priority" + << 0)))); getTopoCoord().updateConfig(cfg, 0, now()++, OpTime()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1831,7 +1980,9 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { // config to be absent from the set updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -1842,16 +1993,18 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); // reconfig to add to set - updateConfig( - BSON("_id" - << "rs0" - << "version" << 2 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017"))), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017"))), + 0); // having been added to the config, we should no longer be REMOVED and should enter STARTUP2 ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1860,23 +2013,27 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); - updateConfig( - BSON("_id" - << "rs0" - << "version" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017"))), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017"))), + 0); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // reconfig to remove self updateConfig(BSON("_id" << "rs0" - << "version" << 2 << "members" + << "version" + << 2 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -1892,8 +2049,11 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017"))), + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017"))), 0); ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1908,7 +2068,9 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima // reconfig to remove self updateConfig(BSON("_id" << "rs0" - << "version" << 2 << "members" + << "version" + << 2 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -1924,8 +2086,11 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017"))), + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017"))), 0); ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -1938,17 +2103,20 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // now lose primary due to loss of electability - updateConfig( - BSON("_id" - << "rs0" - << "version" << 2 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017" - << "priority" << 0) - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017"))), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017" + << "priority" + << 0) + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017"))), + 0); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } @@ -1958,8 +2126,11 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017"))), + << "version" + << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017"))), 0); ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); @@ -1974,38 +2145,45 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta // Now reconfig in ways that leave us electable and ensure we are still the primary. // Add hosts - updateConfig( - BSON("_id" - << "rs0" - << "version" << 2 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017"))), - 0, - Date_t::fromMillisSinceEpoch(-1), - OpTime(Timestamp(10, 0), 0)); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017"))), + 0, + Date_t::fromMillisSinceEpoch(-1), + OpTime(Timestamp(10, 0), 0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // Change priorities and tags - updateConfig( - BSON("_id" - << "rs0" - << "version" << 2 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017" - << "priority" << 10) - << BSON("_id" << 1 << "host" - << "host2:27017" - << "priority" << 5 << "tags" << BSON("dc" - << "NA" - << "rack" - << "rack1")))), - 0, - Date_t::fromMillisSinceEpoch(-1), - OpTime(Timestamp(10, 0), 0)); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017" + << "priority" + << 10) + << BSON("_id" << 1 << "host" + << "host2:27017" + << "priority" + << 5 + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rack1")))), + 0, + Date_t::fromMillisSinceEpoch(-1), + OpTime(Timestamp(10, 0), 0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); } @@ -2013,7 +2191,9 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" @@ -2025,16 +2205,18 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // reconfig and stay secondary - updateConfig( - BSON("_id" - << "rs0" - << "version" << 2 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017"))), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017"))), + 0); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } @@ -2042,12 +2224,15 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { TEST_F(TopoCoordTest, ShouldNotStandForElectionWhileAwareOfPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2059,12 +2244,15 @@ TEST_F(TopoCoordTest, ShouldNotStandForElectionWhileAwareOfPrimary) { TEST_F(TopoCoordTest, ShouldStandForElectionDespiteNotCloseEnoughToLastOptime) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2076,12 +2264,15 @@ TEST_F(TopoCoordTest, ShouldStandForElectionDespiteNotCloseEnoughToLastOptime) { TEST_F(TopoCoordTest, VoteForMyselfFailsWhileNotCandidate) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); ASSERT_FALSE(getTopoCoord().voteForMyself(now()++)); @@ -2090,13 +2281,17 @@ TEST_F(TopoCoordTest, VoteForMyselfFailsWhileNotCandidate) { TEST_F(TopoCoordTest, NodeReturnsArbiterWhenGetMemberStateRunsAgainstArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); ASSERT_EQUALS(MemberState::RS_ARBITER, getTopoCoord().getMemberState().s); } @@ -2111,20 +2306,28 @@ TEST_F(TopoCoordTest, ShouldNotStandForElectionWhileRemovedFromTheConfig) { TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; OpTime lastAppliedOpTime; @@ -2134,11 +2337,17 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { ASSERT_TRUE(response.getVoteGranted()); ReplSetRequestVotesArgs args2; - args2.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 1LL << "configVersion" << 1LL - << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + args2.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response2; // different candidate same term, should be a problem @@ -2150,12 +2359,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatTerm) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2163,8 +2375,14 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << true << "term" << 1LL - << "candidateIndex" << 0LL << "configVersion" << 1LL + << "dryRun" + << true + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2176,12 +2394,19 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT // second dry run fine ReplSetRequestVotesArgs args2; - args2.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "dryRun" << true << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + args2.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "dryRun" + << true + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response2; getTopoCoord().processReplSetRequestVotes(args2, &response2, lastAppliedOpTime); @@ -2190,12 +2415,19 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT // real request fine ReplSetRequestVotesArgs args3; - args3.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "dryRun" << false << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + args3.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "dryRun" + << false + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response3; getTopoCoord().processReplSetRequestVotes(args3, &response3, lastAppliedOpTime); @@ -2204,12 +2436,19 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT // dry post real, fails ReplSetRequestVotesArgs args4; - args4.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "dryRun" << false << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + args4.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "dryRun" + << false + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response4; getTopoCoord().processReplSetRequestVotes(args4, &response4, lastAppliedOpTime); @@ -2220,12 +2459,15 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2233,8 +2475,14 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << false << "term" << 1LL - << "candidateIndex" << 0LL << "configVersion" << 1LL + << "dryRun" + << false + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2246,12 +2494,19 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { // dry post real, fails ReplSetRequestVotesArgs args2; - args2.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "dryRun" << false << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + args2.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "dryRun" + << false + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response2; getTopoCoord().processReplSetRequestVotes(args2, &response2, lastAppliedOpTime); @@ -2262,12 +2517,15 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2275,8 +2533,13 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "wrongName" - << "term" << 1LL << "candidateIndex" << 0LL - << "configVersion" << 1LL << "lastCommittedOp" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; OpTime lastAppliedOpTime; @@ -2289,12 +2552,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2302,8 +2568,13 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" << 1LL << "candidateIndex" << 1LL - << "configVersion" << 0LL << "lastCommittedOp" + << "term" + << 1LL + << "candidateIndex" + << 1LL + << "configVersion" + << 0LL + << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; OpTime lastAppliedOpTime; @@ -2316,12 +2587,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2333,8 +2607,13 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" << 1LL << "candidateIndex" << 1LL - << "configVersion" << 1LL << "lastCommittedOp" + << "term" + << 1LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL + << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; OpTime lastAppliedOpTime; @@ -2348,12 +2627,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -2362,8 +2644,13 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" << 3LL << "candidateIndex" << 1LL - << "configVersion" << 1LL << "lastCommittedOp" + << "term" + << 3LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL + << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; OpTime lastAppliedOpTime2 = {Timestamp(20, 0), 0}; @@ -2376,12 +2663,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); // set term to 1 @@ -2389,12 +2679,17 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { getTopoCoord().updateTerm(1, now())); // and make sure we voted in term 1 ReplSetRequestVotesArgs argsForRealVote; - argsForRealVote.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL << "configVersion" - << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + argsForRealVote.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse responseForRealVote; OpTime lastAppliedOpTime; @@ -2408,8 +2703,14 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "wrongName" - << "dryRun" << true << "term" << 2LL - << "candidateIndex" << 0LL << "configVersion" << 1LL + << "dryRun" + << true + << "term" + << 2LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2423,12 +2724,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); // set term to 1 @@ -2436,12 +2740,17 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { getTopoCoord().updateTerm(1, now())); // and make sure we voted in term 1 ReplSetRequestVotesArgs argsForRealVote; - argsForRealVote.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL << "configVersion" - << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + argsForRealVote.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse responseForRealVote; OpTime lastAppliedOpTime; @@ -2455,8 +2764,14 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << true << "term" << 2LL - << "candidateIndex" << 1LL << "configVersion" << 0LL + << "dryRun" + << true + << "term" + << 2LL + << "candidateIndex" + << 1LL + << "configVersion" + << 0LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2470,12 +2785,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); // set term to 1 @@ -2483,12 +2801,17 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { getTopoCoord().updateTerm(1, now())); // and make sure we voted in term 1 ReplSetRequestVotesArgs argsForRealVote; - argsForRealVote.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL << "configVersion" - << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + argsForRealVote.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse responseForRealVote; OpTime lastAppliedOpTime; @@ -2501,8 +2824,14 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << true << "term" << 0LL - << "candidateIndex" << 1LL << "configVersion" << 1LL + << "dryRun" + << true + << "term" + << 0LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2516,12 +2845,15 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); // set term to 1 @@ -2529,12 +2861,17 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { getTopoCoord().updateTerm(1, now())); // and make sure we voted in term 1 ReplSetRequestVotesArgs argsForRealVote; - argsForRealVote.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL << "configVersion" - << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + argsForRealVote.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse responseForRealVote; OpTime lastAppliedOpTime; @@ -2548,8 +2885,14 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << true << "term" << 1LL - << "candidateIndex" << 1LL << "configVersion" << 1LL + << "dryRun" + << true + << "term" + << 1LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2563,12 +2906,15 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" << 1 << "members" + << "version" + << 1 + << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); // set term to 1 @@ -2576,12 +2922,17 @@ TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { getTopoCoord().updateTerm(1, now())); // and make sure we voted in term 1 ReplSetRequestVotesArgs argsForRealVote; - argsForRealVote.initialize(BSON("replSetRequestVotes" - << 1 << "setName" - << "rs0" - << "term" << 1LL << "candidateIndex" << 0LL << "configVersion" - << 1LL << "lastCommittedOp" - << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); + argsForRealVote.initialize( + BSON("replSetRequestVotes" << 1 << "setName" + << "rs0" + << "term" + << 1LL + << "candidateIndex" + << 0LL + << "configVersion" + << 1LL + << "lastCommittedOp" + << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse responseForRealVote; OpTime lastAppliedOpTime; @@ -2595,8 +2946,14 @@ TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" << true << "term" << 3LL - << "candidateIndex" << 1LL << "configVersion" << 1LL + << "dryRun" + << true + << "term" + << 3LL + << "candidateIndex" + << 1LL + << "configVersion" + << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))); ReplSetRequestVotesResponse response; @@ -2618,13 +2975,19 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedIfCSRSButHaveNoReadCommittedSuppor updateConfig(BSON("_id" << "rs0" - << "protocolVersion" << 1 << "version" << 1 << "configsvr" << true + << "protocolVersion" + << 1 + << "version" + << 1 + << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); } @@ -2639,13 +3002,19 @@ TEST_F(TopoCoordTest, NodeBecomesSecondaryAsNormalWhenReadCommittedSupportedAndC updateConfig(BSON("_id" << "rs0" - << "protocolVersion" << 1 << "version" << 1 << "configsvr" << true + << "protocolVersion" + << 1 + << "version" + << 1 + << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" - << "h2") << BSON("_id" << 30 << "host" - << "h3"))), + << "h2") + << BSON("_id" << 30 << "host" + << "h3"))), 0); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -2657,17 +3026,22 @@ class HeartbeatResponseTestV1 : public TopoCoordTest { public: virtual void setUp() { TopoCoordTest::setUp(); - updateConfig( - BSON("_id" - << "rs0" - << "version" << 5 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017")) - << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 5 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017")) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), + 0); } }; @@ -2683,15 +3057,23 @@ TEST_F(HeartbeatResponseTestV1, updateConfig(BSON("_id" << "rs0" - << "version" << 7 << "members" + << "version" + << 7 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself" - << "buildIndexes" << false << "priority" << 0) + << "buildIndexes" + << false + << "priority" + << 0) << BSON("_id" << 1 << "host" << "host2") << BSON("_id" << 2 << "host" << "host3" - << "buildIndexes" << false << "priority" << 0))), + << "buildIndexes" + << false + << "priority" + << 0))), 0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -3017,11 +3399,15 @@ TEST_F(HeartbeatResponseTestV1, ReconfigNodeRemovedBetweenHeartbeatRequestAndRep updateConfig(BSON("_id" << "rs0" - << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017")) - << "protocolVersion" << 1), + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017")) + << "protocolVersion" + << 1), 0); ReplSetHeartbeatResponse hb; @@ -3066,11 +3452,15 @@ TEST_F(HeartbeatResponseTestV1, ReconfigBetweenHeartbeatRequestAndRepsonse) { updateConfig(BSON("_id" << "rs0" - << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 2 << "host" - << "host3:27017")) - << "protocolVersion" << 1), + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 2 << "host" + << "host3:27017")) + << "protocolVersion" + << 1), 0); ReplSetHeartbeatResponse hb; @@ -3131,14 +3521,20 @@ TEST_F(HeartbeatResponseTestV1, ScheduleAPriorityTakeoverWhenElectableAndReceiveHeartbeatFromLowerPriorityPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" << 5 << "members" + << "version" + << 5 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" << 2) + << "priority" + << 2) << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 6 << "host" - << "host7:27017")) - << "protocolVersion" << 1 << "settings" + << "host2:27017") + << BSON("_id" << 6 << "host" + << "host7:27017")) + << "protocolVersion" + << 1 + << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -3162,15 +3558,21 @@ TEST_F(HeartbeatResponseTestV1, TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataTermPreventsPriorityTakeover) { updateConfig(BSON("_id" << "rs0" - << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host0:27017" - << "priority" << 2) - << BSON("_id" << 1 << "host" - << "host1:27017" - << "priority" << 3) - << BSON("_id" << 2 << "host" - << "host2:27017")) - << "settings" << BSON("heartbeatTimeoutSecs" << 5)), + << "version" + << 5 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0:27017" + << "priority" + << 2) + << BSON("_id" << 1 << "host" + << "host1:27017" + << "priority" + << 3) + << BSON("_id" << 2 << "host" + << "host2:27017")) + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -3223,26 +3625,43 @@ TEST_F(HeartbeatResponseTestV1, ScheduleElectionIfAMajorityOfVotersIsVisibleEvenThoughATrueMajorityIsNot) { updateConfig(BSON("_id" << "rs0" - << "version" << 5 << "members" + << "version" + << 5 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "votes" << 0 << "priority" << 0) + << "votes" + << 0 + << "priority" + << 0) << BSON("_id" << 3 << "host" << "host4:27017" - << "votes" << 0 << "priority" << 0) + << "votes" + << 0 + << "priority" + << 0) << BSON("_id" << 4 << "host" << "host5:27017" - << "votes" << 0 << "priority" << 0) + << "votes" + << 0 + << "priority" + << 0) << BSON("_id" << 5 << "host" << "host6:27017" - << "votes" << 0 << "priority" << 0) + << "votes" + << 0 + << "priority" + << 0) << BSON("_id" << 6 << "host" - << "host7:27017")) << "protocolVersion" << 1 - << "settings" << BSON("heartbeatTimeoutSecs" << 5)), + << "host7:27017")) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -3323,14 +3742,19 @@ TEST_F(HeartbeatResponseTestV1, NodeDoesNotStandForElectionWhenPrimaryIsMarkedDownViaHeartbeatButWeAreAnArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" << 5 << "members" + << "version" + << 5 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "arbiterOnly" << true) + << "arbiterOnly" + << true) << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017")) - << "protocolVersion" << 1), + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017")) + << "protocolVersion" + << 1), 0); OpTime election = OpTime(Timestamp(400, 0), 0); @@ -3455,14 +3879,19 @@ TEST_F(HeartbeatResponseTestV1, updateConfig(BSON("_id" << "rs0" - << "version" << 5 << "members" + << "version" + << 5 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" << 0) + << "priority" + << 0) << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017")) - << "protocolVersion" << 1), + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017")) + << "protocolVersion" + << 1), 0); OpTime election = OpTime(Timestamp(400, 0), 0); @@ -3553,18 +3982,24 @@ TEST_F(HeartbeatResponseTestV1, // In this test, the Topology coordinator sees a PRIMARY ("host2") and then sees a higher // priority and stale node ("host3"). It responds with NoAction, as it should in all // multiprimary states in PV1. - updateConfig( - BSON("_id" - << "rs0" - << "version" << 6 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017" - << "priority" << 3)) - << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 6 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017" + << "priority" + << 3)) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), + 0); setSelfMemberState(MemberState::RS_SECONDARY); OpTime election = OpTime(Timestamp(1000, 0), 0); @@ -3585,18 +4020,24 @@ TEST_F(HeartbeatResponseTestV1, // In this test, the Topology coordinator becomes PRIMARY and then sees a higher priority // and stale node ("host3"). It responds with NoAction, as it should in all // multiprimary states in PV1. - updateConfig( - BSON("_id" - << "rs0" - << "version" << 6 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017" - << "priority" << 3)) - << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 6 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017" + << "priority" + << 3)) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), + 0); OpTime election = OpTime(Timestamp(1000, 0), 0); OpTime staleTime = OpTime(); @@ -3614,18 +4055,24 @@ TEST_F(HeartbeatResponseTestV1, // In this test, the Topology coordinator becomes PRIMARY and then sees a higher priority // and equally fresh node ("host3"). It responds with NoAction, as it should in all // multiprimary states in PV1. - updateConfig( - BSON("_id" - << "rs0" - << "version" << 6 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017" - << "priority" << 3)) - << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 6 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017" + << "priority" + << 3)) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), + 0); OpTime election = OpTime(Timestamp(1000, 0), 0); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); @@ -3644,18 +4091,24 @@ TEST_F(HeartbeatResponseTestV1, // In this test, the Topology coordinator sees a PRIMARY ("host2") and then sees a higher // priority and similarly fresh node ("host3"). It responds with NoAction, as it should // in all multiprimary states in PV1. - updateConfig( - BSON("_id" - << "rs0" - << "version" << 6 << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host1:27017") - << BSON("_id" << 1 << "host" - << "host2:27017") << BSON("_id" << 2 << "host" - << "host3:27017" - << "priority" << 3)) - << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), - 0); + updateConfig(BSON("_id" + << "rs0" + << "version" + << 6 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host1:27017") + << BSON("_id" << 1 << "host" + << "host2:27017") + << BSON("_id" << 2 << "host" + << "host3:27017" + << "priority" + << 3)) + << "protocolVersion" + << 1 + << "settings" + << BSON("heartbeatTimeoutSecs" << 5)), + 0); setSelfMemberState(MemberState::RS_SECONDARY); OpTime election = OpTime(); @@ -3811,15 +4264,21 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberDoesNo updateConfig(BSON("_id" << "rs0" - << "version" << 6 << "members" + << "version" + << 6 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "host2") << BSON("_id" << 2 << "host" << "host3" - << "buildIndexes" << false << "priority" << 0)) - << "protocolVersion" << 1), + << "buildIndexes" + << false + << "priority" + << 0)) + << "protocolVersion" + << 1), 0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -4184,14 +4643,18 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataSameConfig) { ReplicaSetConfig originalConfig; originalConfig.initialize(BSON("_id" << "rs0" - << "version" << 5 << "members" + << "version" + << 5 + << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" << 1 << "settings" + << "protocolVersion" + << 1 + << "settings" << BSON("heartbeatTimeoutSecs" << 5))); ReplSetHeartbeatResponse sameConfigResponse; @@ -4212,9 +4675,8 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataSameConfig) { stopCapturingLogMessages(); ASSERT_NO_ACTION(action.getAction()); ASSERT_EQUALS(1, - countLogLinesContaining( - "Config from heartbeat response was " - "same as ours.")); + countLogLinesContaining("Config from heartbeat response was " + "same as ours.")); } TEST_F(HeartbeatResponseHighVerbosityTestV1, -- cgit v1.2.1