コード例 #1
0
    def test_connection_close_handles_raise_on_write(self):
        connection = Connection('127.0.0.1',
                                'guest',
                                'guest',
                                timeout=0.1,
                                lazy=True)
        connection.set_state(connection.OPEN)
        io = IO(connection.parameters, [])
        io.socket = Mock(name='socket', spec=socket.socket)
        connection._io = io

        # Create some fake channels.
        for index in range(10):
            connection._channels[index + 1] = FakeChannel(FakeChannel.OPEN)

        def raise_on_write(_):
            raise AMQPConnectionError('travis-ci')

        connection._channel0._write_frame = raise_on_write

        self.assertFalse(connection.is_closed)

        connection.close()

        # Make sure all the fake channels were closed as well.
        for index in range(10):
            self.assertTrue(connection._channels[index + 1].is_closed)

        self.assertTrue(connection.is_closed)
コード例 #2
0
    def test_connection_close_when_already_closed(self):
        connection = Connection('127.0.0.1',
                                'guest',
                                'guest',
                                timeout=0.1,
                                lazy=True)
        connection.set_state(connection.OPEN)
        io = IO(connection.parameters, [])
        io.socket = Mock(name='socket', spec=socket.socket)
        connection._io = io

        connection.set_state(connection.CLOSED)

        # Create some fake channels.
        for index in range(10):
            connection._channels[index + 1] = FakeChannel(FakeChannel.OPEN)

        def state_set(state):
            self.assertEqual(state, connection.CLOSED)

        connection.set_state = state_set

        self.assertTrue(connection.is_closed)

        connection.close()

        # Make sure all the fake channels were closed as well.
        for index in range(10):
            self.assertTrue(connection._channels[index + 1].is_closed)

        self.assertTrue(connection.is_closed)
コード例 #3
0
    def test_connection_close(self):
        connection = Connection('127.0.0.1',
                                'guest',
                                'guest',
                                timeout=0.1,
                                lazy=True)
        connection.set_state(connection.OPEN)
        io = IO(connection.parameters, [])
        io.socket = Mock(name='socket', spec=socket.socket)
        connection._io = io

        # Create some fake channels.
        for index in range(10):
            connection._channels[index + 1] = FakeChannel(FakeChannel.OPEN)

        def on_write(frame_out):
            self.assertIsInstance(frame_out, specification.Connection.Close)
            connection._channel0._close_connection_ok()

        connection._channel0._write_frame = on_write

        self.assertFalse(connection.is_closed)

        connection.close()

        # Make sure all the fake channels were closed as well.
        for index in range(10):
            self.assertTrue(connection._channels[index + 1].is_closed)

        self.assertTrue(connection.is_closed)
コード例 #4
0
    def test_connection_close_channels(self):
        connection = Connection('127.0.0.1', 'guest', 'guest', timeout=0.1,
                                lazy=True)
        connection._channels[0] = FakeChannel()
        connection._channels[1] = FakeChannel()
        connection._channels[2] = FakeChannel(FakeChannel.CLOSED)

        self.assertTrue(connection._channels[0].is_open)
        self.assertTrue(connection._channels[1].is_open)
        self.assertTrue(connection._channels[2].is_closed)

        connection._close_remaining_channels()

        self.assertTrue(connection._channels[0].is_closed)
        self.assertTrue(connection._channels[1].is_closed)
        self.assertTrue(connection._channels[2].is_closed)
コード例 #5
0
    def test_message_ack(self):
        delivery_tag = 123456
        message = Message.create(body='', channel=FakeChannel())
        message._method = {'delivery_tag': delivery_tag}

        message.ack()
        result = message.channel.result.pop(0)
        self.assertEqual(result[0], delivery_tag)
        self.assertEqual(result[1], False)
コード例 #6
0
    def test_message_delivery_tag_is_none(self):
        message = Message.create(body='', channel=FakeChannel())
        message._method = {'delivery_tag': None}

        self.assertIsNone(message.delivery_tag)
コード例 #7
0
    def test_message_delivery_tag(self):
        message = Message.create(body='', channel=FakeChannel())
        message._method = {'delivery_tag': 5}

        self.assertEqual(message.delivery_tag, 5)
コード例 #8
0
    def test_message_redelivered_is_none(self):
        message = Message.create(body='', channel=FakeChannel())
        message._method = {'redelivered': None}

        self.assertIsNone(message.redelivered)
コード例 #9
0
    def test_message_not_redelivered(self):
        message = Message.create(body='', channel=FakeChannel())
        message._method = {'redelivered': False}

        self.assertFalse(message.redelivered)