diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/dbtests/mock/mock_replica_set.h | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/dbtests/mock/mock_replica_set.h')
-rw-r--r-- | src/mongo/dbtests/mock/mock_replica_set.h | 195 |
1 files changed, 97 insertions, 98 deletions
diff --git a/src/mongo/dbtests/mock/mock_replica_set.h b/src/mongo/dbtests/mock/mock_replica_set.h index 9c394c97648..c3f22c3cb97 100644 --- a/src/mongo/dbtests/mock/mock_replica_set.h +++ b/src/mongo/dbtests/mock/mock_replica_set.h @@ -36,106 +36,105 @@ #include <vector> namespace mongo { +/** + * This is a helper class for managing a replica set consisting of + * MockRemoteDBServer instances. + * + * Note: Be sure to call ScopedDbConnection::clearPool() after every test + * when doing tests that involves the ReplicaSetMonitor. This is because + * it uses ScopedDbConnection which means you can have a residue connections + * that was created from previous tests and can cause a seg fault if the + * MockRemoteDBServer instances were already destroyed. + * + * Warning: Not thread-safe + */ +class MockReplicaSet { +public: + /** + * Creates a mock replica set and automatically mocks the isMaster + * and replSetGetStatus commands based on the default replica set + * configuration. + * + * @param setName The name for this replica set + * @param nodes The initial number of nodes for this replica set + */ + MockReplicaSet(const std::string& setName, size_t nodes); + ~MockReplicaSet(); + + // + // getters + // + + std::string getSetName() const; + std::string getConnectionString() const; + std::vector<HostAndPort> getHosts() const; + repl::ReplicaSetConfig getReplConfig() const; + std::string getPrimary() const; + std::vector<std::string> getSecondaries() const; + + /** + * Sets the configuration for this replica sets. This also has a side effect + * of mocking the ismaster and replSetGetStatus command responses based on + * the new config. + * + * Note: does not automatically select a new primary. Can be done manually by + * calling setPrimary. + */ + void setConfig(const repl::ReplicaSetConfig& newConfig); + + void setPrimary(const std::string& hostAndPort); + + /** + * @return pointer to the mocked remote server with the given hostName. + * NULL if host doesn't exists. + */ + MockRemoteDBServer* getNode(const std::string& hostAndPort); + + /** + * Kills a node belonging to this set. + * + * @param hostName the name of the replica node to kill. + */ + void kill(const std::string& hostAndPort); + /** - * This is a helper class for managing a replica set consisting of - * MockRemoteDBServer instances. + * Kills a set of host belonging to this set. * - * Note: Be sure to call ScopedDbConnection::clearPool() after every test - * when doing tests that involves the ReplicaSetMonitor. This is because - * it uses ScopedDbConnection which means you can have a residue connections - * that was created from previous tests and can cause a seg fault if the - * MockRemoteDBServer instances were already destroyed. + * @param hostList the list of host names of the servers to kill. + */ + void kill(const std::vector<std::string>& hostList); + + /** + * Reboots a node. * - * Warning: Not thread-safe + * @param hostName the name of the host to reboot. + */ + void restore(const std::string& hostName); + +private: + typedef std::map<std::string, MockRemoteDBServer*> ReplNodeMap; + + /** + * Mocks the ismaster command based on the information on the current + * replica set configuration. */ - class MockReplicaSet { - public: - - /** - * Creates a mock replica set and automatically mocks the isMaster - * and replSetGetStatus commands based on the default replica set - * configuration. - * - * @param setName The name for this replica set - * @param nodes The initial number of nodes for this replica set - */ - MockReplicaSet(const std::string& setName, size_t nodes); - ~MockReplicaSet(); - - // - // getters - // - - std::string getSetName() const; - std::string getConnectionString() const; - std::vector<HostAndPort> getHosts() const; - repl::ReplicaSetConfig getReplConfig() const; - std::string getPrimary() const; - std::vector<std::string> getSecondaries() const; - - /** - * Sets the configuration for this replica sets. This also has a side effect - * of mocking the ismaster and replSetGetStatus command responses based on - * the new config. - * - * Note: does not automatically select a new primary. Can be done manually by - * calling setPrimary. - */ - void setConfig(const repl::ReplicaSetConfig& newConfig); - - void setPrimary(const std::string& hostAndPort); - - /** - * @return pointer to the mocked remote server with the given hostName. - * NULL if host doesn't exists. - */ - MockRemoteDBServer* getNode(const std::string& hostAndPort); - - /** - * Kills a node belonging to this set. - * - * @param hostName the name of the replica node to kill. - */ - void kill(const std::string& hostAndPort); - - /** - * Kills a set of host belonging to this set. - * - * @param hostList the list of host names of the servers to kill. - */ - void kill(const std::vector<std::string>& hostList); - - /** - * Reboots a node. - * - * @param hostName the name of the host to reboot. - */ - void restore(const std::string& hostName); - - private: - typedef std::map<std::string, MockRemoteDBServer*> ReplNodeMap; - - /** - * Mocks the ismaster command based on the information on the current - * replica set configuration. - */ - void mockIsMasterCmd(); - - /** - * Mocks the replSetGetStatus command based on the current states of the - * mocked servers. - */ - void mockReplSetGetStatusCmd(); - - /** - * @return the replica set state of the given host - */ - int getState(const std::string& hostAndPort) const; - - const std::string _setName; - ReplNodeMap _nodeMap; - repl::ReplicaSetConfig _replConfig; - - std::string _primaryHost; - }; + void mockIsMasterCmd(); + + /** + * Mocks the replSetGetStatus command based on the current states of the + * mocked servers. + */ + void mockReplSetGetStatusCmd(); + + /** + * @return the replica set state of the given host + */ + int getState(const std::string& hostAndPort) const; + + const std::string _setName; + ReplNodeMap _nodeMap; + repl::ReplicaSetConfig _replConfig; + + std::string _primaryHost; +}; } |