@@ -47,20 +47,19 @@ using std::vector;
4747
4848namespace mongo {
4949
50- MockRemoteDBServer::CircularBSONIterator::CircularBSONIterator (const vector<BSONObj>& replyVector) {
51- for (std::vector<mongo::BSONObj>::const_iterator iter = replyVector.begin ();
52- iter != replyVector.end ();
53- ++iter) {
54- _replyObjs.push_back (iter->copy ());
50+ MockRemoteDBServer::CircularBSONIterator::CircularBSONIterator (
51+ const vector<StatusWith<BSONObj>>& replyVector) {
52+ for (auto iter = replyVector.begin (); iter != replyVector.end (); ++iter) {
53+ _replyObjs.push_back (iter->isOK () ? StatusWith (iter->getValue ().copy ()) : *iter);
5554 }
5655
5756 _iter = _replyObjs.begin ();
5857}
5958
60- BSONObj MockRemoteDBServer::CircularBSONIterator::next () {
59+ StatusWith< BSONObj> MockRemoteDBServer::CircularBSONIterator::next () {
6160 verify (_iter != _replyObjs.end ());
6261
63- BSONObj reply = _iter->copy ();
62+ StatusWith< BSONObj> reply = _iter->isOK () ? StatusWith (_iter-> getValue (). copy ()) : *_iter ;
6463 ++_iter;
6564
6665 if (_iter == _replyObjs.end ()) {
@@ -109,14 +108,15 @@ bool MockRemoteDBServer::isRunning() const {
109108 return _isRunning;
110109}
111110
112- void MockRemoteDBServer::setCommandReply (const string& cmdName, const mongo::BSONObj& replyObj) {
113- vector<BSONObj> replySequence;
111+ void MockRemoteDBServer::setCommandReply (const string& cmdName,
112+ const StatusWith<mongo::BSONObj>& replyObj) {
113+ vector<StatusWith<BSONObj>> replySequence;
114114 replySequence.push_back (replyObj);
115115 setCommandReply (cmdName, replySequence);
116116}
117117
118118void MockRemoteDBServer::setCommandReply (const string& cmdName,
119- const vector<BSONObj>& replySequence) {
119+ const vector<StatusWith< BSONObj> >& replySequence) {
120120 scoped_spinlock sLock (_lock);
121121 _cmdMap[cmdName].reset (new CircularBSONIterator (replySequence));
122122}
@@ -146,16 +146,15 @@ rpc::UniqueReply MockRemoteDBServer::runCommand(InstanceID id, const OpMsgReques
146146 checkIfUp (id);
147147 std::string cmdName = request.getCommandName ().toString ();
148148
149- BSONObj reply;
150- {
149+ StatusWith<BSONObj> reply ([this , &cmdName] {
151150 scoped_spinlock lk (_lock);
152151
153152 uassert (ErrorCodes::IllegalOperation,
154153 str::stream () << " no reply for command: " << cmdName,
155154 _cmdMap.count (cmdName));
156155
157- reply = _cmdMap[cmdName]->next ();
158- }
156+ return _cmdMap[cmdName]->next ();
157+ }());
159158
160159 if (_delayMilliSec > 0 ) {
161160 mongo::sleepmillis (_delayMilliSec);
0 commit comments