Example #1
0
    def test_raises_interface_error_when_cant_reconnect(self):
        """[ConnectionTestCase] - Raises InterfaceError when connection was lost and autoreconnect is False"""

        self.conn = Connection(host="localhost",
                               port=27027,
                               autoreconnect=False)

        self.conn.close()

        self.conn.send_message.when.called_with('shouldBeMessage',
                                                callback=None).should.throw(
                                                    InterfaceError,
                                                    "connection is closed")
Example #2
0
    def config(self, callback=None):
        ismaster = SON([('ismaster', 1)])

        response = None
        try:
            try:
                connection = yield gen.Task(self.connection)
            except TooManyConnections:
                # create a connection on the fly if pool is full
                connection = Connection(host=self.host, port=self.port)
            response, error = yield gen.Task(self.database._command,
                                             ismaster,
                                             connection=connection)
            if not connection._pool:  # if connection is created on the fly
                connection.close()
        except InterfaceError, ie:
            logger.error(
                'oops, database node {host}:{port} is unavailable: {error}'.
                format(host=self.host, port=self.port, error=ie))
Example #3
0
 def setUp(self):
     super(ConnectionTestCase, self).setUp()
     self.conn = Connection(host="localhost", port=27027)
Example #4
0
 def setUp(self):
     super(ConnectionTestCase, self).setUp()
     self.conn = Connection(pool=FakeConnectionPool(),
                            host="localhost",
                            port=27017)
Example #5
0
 def _create_connection(self):
     log.debug('{0} creating new connection'.format(self))
     return Connection(host=self._host, port=self._port, pool=self,
                       autoreconnect=self._autoreconnect)
Example #6
0
 def _create_connection(self):
     host, port = self._addresses[0]
     return Connection(self, host, port, self._autoreconnnect)