1
// mockdbclient.h - mocked out client for testing.
4
* Copyright (C) 2008 10gen Inc.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License, version 3,
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
15
* You should have received a copy of the GNU Affero General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "../client/dbclient.h"
22
#include "../db/commands.h"
24
class MockDBClientConnection : public DBClientConnection {
26
MockDBClientConnection() : connect_() {}
28
BSONObj findOne(const string &ns, Query query, const BSONObj *fieldsToReturn = 0, int queryOptions = 0) {
32
bool connect(const string &serverHostname, string& errmsg) {
36
bool isMaster(bool& isMaster, BSONObj *info=0) {
39
void one( const BSONObj &one ) {
42
void connect( bool val ) {
45
void setIsMaster( bool val ) {
54
class DirectDBClientConnection : public DBClientConnection {
56
struct ConnectionCallback {
57
virtual ~ConnectionCallback() {}
58
virtual void beforeCommand() {}
59
virtual void afterCommand() {}
61
DirectDBClientConnection( ReplPair *rp, ConnectionCallback *cc = 0 ) :
65
virtual BSONObj findOne(const string &ns, Query query, const BSONObj *fieldsToReturn = 0, int queryOptions = 0) {
66
if ( cc_ ) cc_->beforeCommand();
67
SetGlobalReplPair s( rp_ );
68
BSONObjBuilder result;
69
result.append( "ok", Command::runAgainstRegistered( "admin.$cmd", query.obj, result ) ? 1.0 : 0.0 );
70
if ( cc_ ) cc_->afterCommand();
73
virtual bool connect( const string &serverHostname, string& errmsg ) {
78
ConnectionCallback *cc_;
79
class SetGlobalReplPair {
81
SetGlobalReplPair( ReplPair *rp ) {
85
~SetGlobalReplPair() {