~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/dbtests/mock/mock_dbclient_connection.h

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*    Copyright 2012 10gen Inc.
 
2
 *
 
3
 *    Licensed under the Apache License, Version 2.0 (the "License");
 
4
 *    you may not use this file except in compliance with the License.
 
5
 *    You may obtain a copy of the License at
 
6
 *
 
7
 *    http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
9
 *    Unless required by applicable law or agreed to in writing, software
 
10
 *    distributed under the License is distributed on an "AS IS" BASIS,
 
11
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
 *    See the License for the specific language governing permissions and
 
13
 *    limitations under the License.
 
14
 */
 
15
 
 
16
#pragma once
 
17
 
 
18
#include <boost/shared_ptr.hpp>
 
19
#include <string>
 
20
#include <vector>
 
21
 
 
22
#include "mongo/client/dbclientinterface.h"
 
23
#include "mongo/dbtests/mock/mock_remote_db_server.h"
 
24
 
 
25
namespace mongo {
 
26
    /**
 
27
     * A simple class for mocking mongo::DBClientConnection.
 
28
     *
 
29
     * Also check out sample usage in dbtests/mock_dbclient_conn_test.cpp
 
30
     */
 
31
    class MockDBClientConnection : public mongo::DBClientConnection {
 
32
    public:
 
33
        /**
 
34
         * Create a mock connection to a mock server.
 
35
         *
 
36
         * @param remoteServer the remote server to connect to. The caller is
 
37
         *     responsible for making sure that the life of remoteServer is
 
38
         *     longer than this connection.
 
39
         * @param autoReconnect will automatically re-establish connection the
 
40
         *     next time an operation is requested when the last operation caused
 
41
         *     this connection to fall into a failed state.
 
42
         */
 
43
        MockDBClientConnection(MockRemoteDBServer* remoteServer, bool autoReconnect = false);
 
44
        virtual ~MockDBClientConnection();
 
45
 
 
46
        //
 
47
        // DBClientBase methods
 
48
        //
 
49
 
 
50
        bool connect(const char* hostName, std::string& errmsg);
 
51
 
 
52
        inline bool connect(const HostAndPort& host, std::string& errmsg) {
 
53
            return connect(host.toString().c_str(), errmsg);
 
54
        }
 
55
 
 
56
        bool runCommand(const std::string& dbname, const mongo::BSONObj& cmdObj,
 
57
                mongo::BSONObj &info, int options = 0);
 
58
 
 
59
        std::auto_ptr<mongo::DBClientCursor> query(const std::string &ns,
 
60
                mongo::Query query = mongo::Query(),
 
61
                int nToReturn = 0,
 
62
                int nToSkip = 0,
 
63
                const mongo::BSONObj* fieldsToReturn = 0,
 
64
                int queryOptions = 0,
 
65
                int batchSize = 0);
 
66
 
 
67
        uint64_t getSockCreationMicroSec() const;
 
68
 
 
69
        virtual void insert(const string& ns, BSONObj obj, int flags = 0);
 
70
 
 
71
        virtual void insert(const string& ns, const vector<BSONObj>& objList, int flags = 0);
 
72
 
 
73
        virtual void remove(const string& ns, Query query, bool justOne = false);
 
74
 
 
75
        virtual void remove(const string& ns, Query query, int flags = 0);
 
76
 
 
77
        //
 
78
        // Getters
 
79
        //
 
80
 
 
81
        mongo::ConnectionString::ConnectionType type() const;
 
82
        bool isFailed() const;
 
83
        double getSoTimeout() const;
 
84
        std::string getServerAddress() const;
 
85
        std::string toString();
 
86
 
 
87
        //
 
88
        // Unsupported methods (defined to get rid of virtual function was hidden error)
 
89
        //
 
90
        unsigned long long query(boost::function<void(const mongo::BSONObj&)> f,
 
91
                const std::string& ns, mongo::Query query,
 
92
                const mongo::BSONObj* fieldsToReturn = 0, int queryOptions = 0);
 
93
 
 
94
        unsigned long long query(boost::function<void(mongo::DBClientCursorBatchIterator&)> f,
 
95
                const std::string& ns, mongo::Query query,
 
96
                const mongo::BSONObj* fieldsToReturn = 0,
 
97
                int queryOptions = 0);
 
98
 
 
99
        //
 
100
        // Unsupported methods (these are pure virtuals in the base class)
 
101
        //
 
102
 
 
103
        void killCursor(long long cursorID);
 
104
        bool callRead(mongo::Message& toSend , mongo::Message& response);
 
105
        bool call(mongo::Message& toSend, mongo::Message& response, bool assertOk = true,
 
106
                std::string* actualServer = 0);
 
107
        void say(mongo::Message& toSend, bool isRetry = false, std::string* actualServer = 0);
 
108
        void sayPiggyBack(mongo::Message& toSend);
 
109
        bool lazySupported() const;
 
110
 
 
111
    private:
 
112
        void checkConnection();
 
113
 
 
114
        MockRemoteDBServer::InstanceID _remoteServerInstanceID;
 
115
        MockRemoteDBServer* _remoteServer;
 
116
        bool _isFailed;
 
117
        uint64_t _sockCreationTime;
 
118
        bool _autoReconnect;
 
119
    };
 
120
}