diff options
Diffstat (limited to 'src/mongo/dbtests/config_server_fixture.h')
-rw-r--r-- | src/mongo/dbtests/config_server_fixture.h | 156 |
1 files changed, 77 insertions, 79 deletions
diff --git a/src/mongo/dbtests/config_server_fixture.h b/src/mongo/dbtests/config_server_fixture.h index e5e21cc787e..d06ac0c4026 100644 --- a/src/mongo/dbtests/config_server_fixture.h +++ b/src/mongo/dbtests/config_server_fixture.h @@ -37,91 +37,89 @@ namespace mongo { - class CustomDirectClient: public DBDirectClient { - public: - CustomDirectClient(OperationContext* txn) : DBDirectClient(txn) { - setWireVersions(minWireVersion, maxWireVersion); - } - - virtual ConnectionString::ConnectionType type() const { - return ConnectionString::CUSTOM; - } - - virtual bool recv( Message& m ) { - // This is tailored to act as a dummy response for write commands. - - BufBuilder bb; - bb.skip(sizeof(QueryResult::Value)); - - BSONObj cmdResult(BSON("ok" << 1)); - - bb.appendBuf(cmdResult.objdata(), cmdResult.objsize()); - - QueryResult::View qr = bb.buf(); - bb.decouple(); - qr.setResultFlagsToOk(); - qr.msgdata().setLen(bb.len()); - qr.msgdata().setOperation(opReply); - qr.setCursorId(0); - qr.setStartingFrom(0); - qr.setNReturned(1); - m.setData(qr.view2ptr(), true); - - return true; - } - }; - - class CustomConnectHook : public ConnectionString::ConnectionHook { - public: - CustomConnectHook(OperationContext* txn) : _txn(txn) { } - - virtual DBClientBase* connect(const ConnectionString& connStr, - std::string& errmsg, - double socketTimeout) - { - // Note - must be new, since it gets owned elsewhere - return new CustomDirectClient(_txn); - } - - private: - OperationContext* const _txn; - }; +class CustomDirectClient : public DBDirectClient { +public: + CustomDirectClient(OperationContext* txn) : DBDirectClient(txn) { + setWireVersions(minWireVersion, maxWireVersion); + } + + virtual ConnectionString::ConnectionType type() const { + return ConnectionString::CUSTOM; + } + + virtual bool recv(Message& m) { + // This is tailored to act as a dummy response for write commands. + + BufBuilder bb; + bb.skip(sizeof(QueryResult::Value)); + + BSONObj cmdResult(BSON("ok" << 1)); + + bb.appendBuf(cmdResult.objdata(), cmdResult.objsize()); + + QueryResult::View qr = bb.buf(); + bb.decouple(); + qr.setResultFlagsToOk(); + qr.msgdata().setLen(bb.len()); + qr.msgdata().setOperation(opReply); + qr.setCursorId(0); + qr.setStartingFrom(0); + qr.setNReturned(1); + m.setData(qr.view2ptr(), true); + + return true; + } +}; + +class CustomConnectHook : public ConnectionString::ConnectionHook { +public: + CustomConnectHook(OperationContext* txn) : _txn(txn) {} + + virtual DBClientBase* connect(const ConnectionString& connStr, + std::string& errmsg, + double socketTimeout) { + // Note - must be new, since it gets owned elsewhere + return new CustomDirectClient(_txn); + } + +private: + OperationContext* const _txn; +}; + +/** + * Fixture for testing complicated operations against a "virtual" config server. + * + * Use this if your test requires complex commands and writing to many collections, + * otherwise a unit test in the mock framework may be a better option. + */ +class ConfigServerFixture : public mongo::unittest::Test { +public: + ConfigServerFixture(); /** - * Fixture for testing complicated operations against a "virtual" config server. - * - * Use this if your test requires complex commands and writing to many collections, - * otherwise a unit test in the mock framework may be a better option. + * Returns a uniform shard name to use throughout the tests. */ - class ConfigServerFixture: public mongo::unittest::Test { - public: - ConfigServerFixture(); - - /** - * Returns a uniform shard name to use throughout the tests. - */ - static std::string shardName(); + static std::string shardName(); - /** - * Clears all data on the server - */ - void clearServer(); - - void clearVersion(); + /** + * Clears all data on the server + */ + void clearServer(); - /** - * Dumps the contents of the config server to the log. - */ - void dumpServer(); + void clearVersion(); - protected: - OperationContextImpl _txn; - CustomDirectClient _client; - CustomConnectHook* _connectHook; + /** + * Dumps the contents of the config server to the log. + */ + void dumpServer(); - private: - virtual void setUp(); - virtual void tearDown(); - }; +protected: + OperationContextImpl _txn; + CustomDirectClient _client; + CustomConnectHook* _connectHook; +private: + virtual void setUp(); + virtual void tearDown(); +}; } |