virtual DBClientConnection *newClientConnection() const { MockDBClientConnection * c = new MockDBClientConnection(); c->connect( connect_ ); c->one( one_ ); return c; }
mongol::DBClientBase* MockConnRegistry::MockConnHook::connect(const ConnectionString& connString, std::string& errmsg, double socketTimeout) { const string hostName(connString.toString()); MockDBClientConnection* conn = _registry->connect(hostName); if (!conn->connect(hostName.c_str(), errmsg)) { // Assumption: connect never throws, so no leak. delete conn; // mimic ConnectionString::connect for MASTER type connection to return NULL // if the destination is unreachable. return NULL; } return conn; }
void run() { ReplPair rp( "a", "b" ); MockDBClientConnection cc; cc.one( res( 0, 0 ) ); rp.negotiate( &cc, "dummy" ); ASSERT( rp.state == ReplPair::State_Confused ); rp.state = ReplPair::State_Negotiating; cc.one( res( 1, 2 ) ); rp.negotiate( &cc, "dummy" ); ASSERT( rp.state == ReplPair::State_Negotiating ); cc.one( res( 1, ReplPair::State_Slave ) ); rp.negotiate( &cc, "dummy" ); ASSERT( rp.state == ReplPair::State_Slave ); cc.one( res( 1, ReplPair::State_Master ) ); rp.negotiate( &cc, "dummy" ); ASSERT( rp.state == ReplPair::State_Master ); }