예제 #1
0
    def test_close_connection_stream_should_be_release_from_pool(self):
        """[ConnectionPoolTestCase] - Release connection from pool when stream is closed"""

        pool = ConnectionPool('localhost',
                              27027,
                              dbname='test',
                              maxconnections=10)

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

        def release(conn):
            conn.should.be.equal(connection)
            _release(conn)
            self.stop()

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

        _release = pool.release
        pool.release = release
        connection._stream.close()

        self.wait()

        pool._connections.should.be.equal(0)
        pool._idle_connections.should.have.length_of(10)
예제 #2
0
    def test_get_connection(self):
        """[ConnectionPoolTestCase] - Can get a connection"""
        pool = ConnectionPool('localhost', 27027, dbname='test')
        pool.connection(self.stop)
        conn = self.wait()

        conn.should.be.a('mongotor.connection.Connection')
예제 #3
0
    def test_get_connection(self):
        """[ConnectionPoolTestCase] - Can get a connection"""
        pool = ConnectionPool('localhost', 27027, dbname='test')
        pool.connection(self.stop)
        conn = self.wait()

        conn.should.be.a('mongotor.connection.Connection')
예제 #4
0
    def test_raise_too_many_connection_when_maxconnection_is_reached(self):
        """[ConnectionPoolTestCase] - Raise TooManyConnections connection when maxconnections is reached"""

        pool = ConnectionPool('localhost', 27027, dbname='test', maxconnections=10)

        connections = []
        for i in xrange(10):
            pool.connection(self.stop)
            connections.append(self.wait())

        pool.connection(self.stop)
        self.wait.when.called_with().should.throw(TooManyConnections)
예제 #5
0
    def test_wait_for_connection_when_maxconnection_is_reached(self):
        """[ConnectionPoolTestCase] - Wait for a connection when maxconnections is reached"""

        pool = ConnectionPool('localhost', 27027, dbname='test', maxconnections=1)

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

        pool.connection(self.stop)

        conn1.close()
        conn2 = self.wait()

        conn1.should.be.a('mongotor.connection.Connection')
        conn2.should.be.a('mongotor.connection.Connection')
        pool._connections.should.be.equal(1)
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
    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)
예제 #9
0
    def test_close_connection_stream_should_be_release_from_pool(self):
        """[ConnectionPoolTestCase] - Release connection from pool when stream is closed"""

        pool = ConnectionPool('localhost', 27027, dbname='test', maxconnections=10)

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

        def release(conn):
            conn.should.be.equal(connection)
            _release(conn)
            self.stop()

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

        _release = pool.release
        pool.release = release
        connection._stream.close()

        self.wait()

        pool._connections.should.be.equal(0)
        pool._idle_connections.should.have.length_of(10)
예제 #10
0
    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)
예제 #11
0
파일: node.py 프로젝트: jibanli/mongotor
    def __init__(self, host, port, database, pool_kargs=None):
        if not pool_kargs:
            pool_kargs = {}

        assert isinstance(host, (str, unicode))
        assert isinstance(port, int)

        self.host = host
        self.port = port
        self.database = database
        self.pool_kargs = pool_kargs

        self.is_primary = False
        self.is_secondary = False
        self.available = False
        self.initialized = False

        self.pool = ConnectionPool(self.host, self.port, self.database.dbname,
                                   **self.pool_kargs)
예제 #12
0
    def test_raise_too_many_connection_when_maxconnection_is_reached(self):
        """[ConnectionPoolTestCase] - Raise TooManyConnections connection when maxconnections is reached"""

        pool = ConnectionPool('localhost',
                              27027,
                              dbname='test',
                              maxconnections=10)

        connections = []
        for i in xrange(10):
            pool.connection(self.stop)
            connections.append(self.wait())

        pool.connection(self.stop)
        self.wait.when.called_with().should.throw(TooManyConnections)
예제 #13
0
    def test_wait_for_connection_when_maxconnection_is_reached(self):
        """[ConnectionPoolTestCase] - Wait for a connection when maxconnections is reached"""

        pool = ConnectionPool(["localhost:27017"],
                              dbname='test',
                              maxconnections=1)

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

        pool.connection(self.stop)

        conn1.close()
        conn2 = self.wait()

        conn1.should.be.a('mongotor.connection.Connection')
        conn2.should.be.a('mongotor.connection.Connection')
        pool._connections.should.be.equal(1)
예제 #14
0
    def init(self, addresses, dbname, **kwargs):
        self._addresses = addresses
        self._dbname = dbname

        self._pool = ConnectionPool(addresses, dbname, **kwargs)