コード例 #1
0
ファイル: test_pool.py プロジェクト: jibanli/mongotor
    def test_maxusage_in_pool_connections(self):
        """[ConnectionPoolTestCase] - test maxusage in connections"""
        pool = ConnectionPool('localhost',
                              27027,
                              dbname='test',
                              maxconnections=1,
                              maxusage=299)

        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': ObjectId()})

        for i in xrange(300):
            pool.connection(self.stop)
            connection = self.wait()

            connection.send_message_with_response(message_test,
                                                  callback=self.stop)
            self.wait()

        pool.connection(self.stop)
        new_connection = self.wait()

        new_connection.usage.should.be.equal(0)
        new_connection.should_not.be.equal(connection)
        new_connection.send_message_with_response(message_test,
                                                  callback=self.stop)

        self.wait()

        new_connection.usage.should.be.equal(1)
コード例 #2
0
ファイル: test_pool.py プロジェクト: jibanli/mongotor
    def test_load_in_pool_connections(self):
        """[ConnectionPoolTestCase] - test load in connections"""
        pool = ConnectionPool('localhost',
                              27027,
                              dbname='test',
                              maxconnections=10,
                              maxusage=29)

        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': ObjectId()})

        for i in xrange(300):
            pool.connection(self.stop)
            connection = self.wait()

            connection.send_message_with_response(message_test,
                                                  callback=self.stop)
            self.wait()

        pool._idle_connections.should.have.length_of(0)

        for i in xrange(300):
            pool.connection(self.stop)
            connection = self.wait()

            connection.send_message_with_response(message_test,
                                                  callback=self.stop)
            self.wait()

        pool._idle_connections.should.have.length_of(0)
コード例 #3
0
ファイル: cursor.py プロジェクト: sansa1839/mongotor
    def find(self, callback=None):
        message_query = message.query(self._query_options(), self._collection_name,
            self._skip, self._limit, self._query_spec(), self._fields)

        if self._connection:
            response, error = yield gen.Task(self._connection.send_message, message_query)
        else:
            response, error = yield gen.Task(self._database.send_message, message_query,
                read_preference=self._read_preference)

        # close cursor
        if response and response.get('cursor_id'):
            cursor_id = response['cursor_id']

            if self._connection:
                self._connection.send_message(message.kill_cursors([cursor_id]), callback=None)
            else:
                self._database.send_message(message.kill_cursors([cursor_id]),
                    callback=None)

        if error:
            callback((None, error))
        else:
            if self._limit == -1 and len(response['data']) == 1:
                callback((response['data'][0], None))
            else:
                callback((response['data'], None))
コード例 #4
0
ファイル: test_connection.py プロジェクト: Arion-Dsh/mongotor
    def test_raises_error_when_cant_unpack_response(self, fake_helpers):
        """[ConnectionTestCase] - Returns DatabaseError when can't unpack response from mongo"""

        fake_helpers.provides('_unpack_response') \
            .raises(DatabaseError('database error'))

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        self.conn.send_message(message_test, with_last_error=True, callback=self.stop)

        self.wait.when.called_with().throw(DatabaseError, 'database error')
コード例 #5
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_raises_error_when_cant_unpack_response(self, fake_helpers):
        """[ConnectionTestCase] - Returns DatabaseError when can't unpack response from mongo"""

        fake_helpers.provides("_unpack_response").raises(DatabaseError("database error"))

        object_id = ObjectId()
        message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        response.should.be.none
        error.should.be.a("mongotor.errors.DatabaseError")
コード例 #6
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_send_test_message_to_mongo(self):
        """[ConnectionTestCase] - Send message to test driver connection"""

        object_id = ObjectId()
        message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        result = response["data"][0]

        result["oid"].should.be(object_id)
        result["ok"].should.be(1.0)
        result["str"].should.be(str(object_id))
コード例 #7
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_return_integrity_error_when_mongo_return_err(self, fake_helpers):
        """[ConnectionTestCase] - Returns IntegrityError when mongo return a message with err"""

        fake_helpers.expects("_unpack_response").returns({"data": [{"err": "shouldBeError", "code": 1000}]})

        object_id = ObjectId()
        message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        error.should.be.a("mongotor.errors.IntegrityError")
        error.msg.should.be.equal("shouldBeError")
        error.code.should.be.equal(1000)
コード例 #8
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_send_test_message_to_mongo(self):
        """[ConnectionTestCase] - Send message to test driver connection"""

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
コード例 #9
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_raises_error_when_cant_unpack_response(self, fake_helpers):
        """[ConnectionTestCase] - Returns DatabaseError when can't unpack response from mongo"""

        fake_helpers.provides('_unpack_response') \
            .raises(DatabaseError('database error'))

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        response.should.be.none
        error.should.be.a('mongotor.errors.DatabaseError')
コード例 #10
0
ファイル: test_connection.py プロジェクト: sansa1839/mongotor
    def test_send_test_message_to_mongo(self):
        """[ConnectionTestCase] - Send message to test driver connection"""

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
コード例 #11
0
    def test_raises_error_when_cant_unpack_response(self, fake_helpers):
        """[ConnectionTestCase] - Returns DatabaseError when can't unpack response from mongo"""

        fake_helpers.provides('_unpack_response') \
            .raises(DatabaseError('database error'))

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': object_id})

        self.conn.send_message(message_test,
                               with_last_error=True,
                               callback=self.stop)

        self.wait.when.called_with().throw(DatabaseError, 'database error')
コード例 #12
0
ファイル: test_database.py プロジェクト: sansa1839/mongotor
    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.connect(["localhost:27027", "localhost:27028"], dbname="test")

        object_id = ObjectId()
        message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})

        Database().send_message(message_test, callback=self.stop)
        response, error = self.wait()

        result = response["data"][0]

        result["oid"].should.be(object_id)
        result["ok"].should.be(1.0)
        result["str"].should.be(str(object_id))
コード例 #13
0
ファイル: test_connection.py プロジェクト: pauloalem/mongotor
    def test_return_integrity_error_when_mongo_return_err(self, fake_helpers):
        """[ConnectionTestCase] - Returns IntegrityError when mongo return a message with err"""

        fake_helpers.expects('_unpack_response') \
            .returns({'data': [{'err': 'shouldBeError', 'code': 1000}]})

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        error.should.be.a('mongotor.errors.IntegrityError')
        error.msg.should.be.equal('shouldBeError')
        error.code.should.be.equal(1000)
コード例 #14
0
ファイル: test_connection.py プロジェクト: sansa1839/mongotor
    def test_return_integrity_error_when_mongo_return_err(self, fake_helpers):
        """[ConnectionTestCase] - Returns IntegrityError when mongo return a message with err"""

        fake_helpers.expects('_unpack_response') \
            .returns({'data': [{'err': 'shouldBeError', 'code': 1000}]})

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        self.conn.send_message(message_test, callback=self.stop)
        response, error = self.wait()

        error.should.be.a('mongotor.errors.IntegrityError')
        error.msg.should.be.equal('shouldBeError')
        error.code.should.be.equal(1000)
コード例 #15
0
ファイル: test_pool.py プロジェクト: Arion-Dsh/mongotor
    def test_load_two_in_pool_connections(self):
        """[ConnectionPoolTestCase] - test load two in connections"""
        pool = ConnectionPool('localhost', 27027, dbname='test', maxconnections=10, maxusage=29)

        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': ObjectId()})

        for i in xrange(30000):
            pool.connection(self.stop)
            connection = self.wait()

            connection.send_message_with_response(message_test, callback=self.stop)
            self.wait()

        pool._idle_connections.should.have.length_of(0)
        pool._connections.should.be.equal(0)
コード例 #16
0
ファイル: test_database.py プロジェクト: pauloalem/mongotor
    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.connect(["localhost:27017"], dbname='test')

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        Database().send_message(message_test, self.stop)
        response, error = self.wait()

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
コード例 #17
0
    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.init(["localhost:27027", "localhost:27028"], dbname='test')

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
                                     {'driverOIDTest': object_id})

        Database().send_message(message_test, callback=self.stop)
        response, _ = self.wait()
        response = helpers._unpack_response(response)

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
コード例 #18
0
ファイル: test_database.py プロジェクト: Arion-Dsh/mongotor
    def test_send_test_message(self):
        """[DatabaseTestCase] - Send a test message to database"""

        Database.init(["localhost:27027", "localhost:27028"], dbname='test')

        object_id = ObjectId()
        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': object_id})

        Database().send_message(message_test, callback=self.stop)
        response, _ = self.wait()
        response = helpers._unpack_response(response)

        result = response['data'][0]

        result['oid'].should.be(object_id)
        result['ok'].should.be(1.0)
        result['str'].should.be(str(object_id))
コード例 #19
0
ファイル: cursor.py プロジェクト: pauloalem/mongotor
    def find(self, skip=0, limit=0, sort=None, callback=None):
        self._ordering = sort

        message_query = message.query(self._query_options(), self._collection_name,
            skip, limit, self._query_spec(), self._fields)

        response, error = yield gen.Task(Database().send_message, message_query)

        # close cursor
        if response and response.get('cursor_id'):
            cursor_id = response['cursor_id']
            Database().send_message(message.kill_cursors([cursor_id]), callback=None)

        if error:
            callback((None, error))
        else:
            if limit == -1 and len(response['data']) == 1:
                callback((response['data'][0], None))
            else:
                callback((response['data'], None))
コード例 #20
0
ファイル: cursor.py プロジェクト: abdelouahabb/mongotor
    def find(self, callback=None):
        message_query = message.query(self._query_options(), self._collection_name,
            self._skip, self._limit, self._query_spec(), self._fields)

        if not self._connection:
            node = self._database.get_node(self._read_preference)
            connection = yield gen.Task(node.connection)
        else:
            connection = self._connection

        response, _ = yield gen.Task(connection.send_message_with_response, message_query)
        response = helpers._unpack_response(response)

        # close cursor
        if response and response.get('cursor_id'):
            cursor_id = response['cursor_id']

            connection.send_message(message.kill_cursors([cursor_id]), callback=None)

        if self._limit == -1 and len(response['data']) == 1:
            callback((response['data'][0], None))
        else:
            callback((response['data'], None))
コード例 #21
0
ファイル: cursor.py プロジェクト: pauloalem/mongotor
    def find(self, skip=0, limit=0, sort=None, callback=None):
        self._ordering = sort

        message_query = message.query(self._query_options(),
                                      self._collection_name, skip, limit,
                                      self._query_spec(), self._fields)

        response, error = yield gen.Task(Database().send_message,
                                         message_query)

        # close cursor
        if response and response.get('cursor_id'):
            cursor_id = response['cursor_id']
            Database().send_message(message.kill_cursors([cursor_id]),
                                    callback=None)

        if error:
            callback((None, error))
        else:
            if limit == -1 and len(response['data']) == 1:
                callback((response['data'][0], None))
            else:
                callback((response['data'], None))
コード例 #22
0
    def find(self, callback=None):
        message_query = message.query(self._query_options(), self._collection_name,
            self._skip, self._limit, self._query_spec(), self._fields)

        if not self._connection:
            node = yield gen.Task(self._database.get_node, self._read_preference)
            connection = yield gen.Task(node.connection)
        else:
            connection = self._connection

        response, _ = yield gen.Task(connection.send_message_with_response, message_query)
        response = helpers._unpack_response(response)

        # close cursor
        if response and response.get('cursor_id'):
            cursor_id = response['cursor_id']

            connection.send_message(message.kill_cursors([cursor_id]), callback=None)

        if self._limit == -1 and len(response['data']) == 1:
            callback((response['data'][0], None))
        else:
            callback((response['data'], None))
コード例 #23
0
ファイル: test_pool.py プロジェクト: Arion-Dsh/mongotor
    def test_maxusage_in_pool_connections(self):
        """[ConnectionPoolTestCase] - test maxusage in connections"""
        pool = ConnectionPool('localhost', 27027, dbname='test', maxconnections=1, maxusage=299)

        message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
            {'driverOIDTest': ObjectId()})

        for i in xrange(300):
            pool.connection(self.stop)
            connection = self.wait()

            connection.send_message_with_response(message_test, callback=self.stop)
            self.wait()

        pool.connection(self.stop)
        new_connection = self.wait()

        new_connection.usage.should.be.equal(0)
        new_connection.should_not.be.equal(connection)
        new_connection.send_message_with_response(message_test, callback=self.stop)

        self.wait()

        new_connection.usage.should.be.equal(1)