当前位置: 首页>>代码示例>>Python>>正文


Python Channel.build_inbound_messages方法代码示例

本文整理汇总了Python中amqpstorm.Channel.build_inbound_messages方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.build_inbound_messages方法的具体用法?Python Channel.build_inbound_messages怎么用?Python Channel.build_inbound_messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在amqpstorm.Channel的用法示例。


在下文中一共展示了Channel.build_inbound_messages方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_build_empty_inbound_messages

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
 def test_build_empty_inbound_messages(self):
     channel = Channel(0, FakeConnection(), 360)
     channel.set_state(Channel.OPEN)
     result = None
     for message in channel.build_inbound_messages(break_on_empty=True):
         result = message
     self.assertIsNone(result)
开发者ID:gaochunzy,项目名称:amqp-storm,代码行数:9,代码来源:channel_tests.py

示例2: test_channel_build_inbound_raises

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_inbound_raises(self, _):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)

        generator = channel.build_inbound_messages(break_on_empty=False)
        if hasattr(generator, 'next'):
            self.assertRaises(AMQPChannelError, generator.next)
        else:
            self.assertRaises(AMQPChannelError, generator.__next__)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:11,代码来源:channel_exception_tests.py

示例3: test_channel_build_empty_inbound_messages

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_empty_inbound_messages(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        generator = channel.build_inbound_messages(break_on_empty=True)

        if hasattr(generator, 'next'):
            self.assertRaises(StopIteration, generator.next)
        else:
            self.assertRaises(StopIteration, generator.__next__)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:11,代码来源:channel_message_handling_tests.py

示例4: test_build_inbound_messages

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_build_inbound_messages(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)

        message = b'Hello World!'
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        for message in channel.build_inbound_messages(break_on_empty=True):
            self.assertIsInstance(message, Message)
开发者ID:gaochunzy,项目名称:amqp-storm,代码行数:17,代码来源:channel_tests.py

示例5: test_channel_build_inbound_raises_in_loop

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_inbound_raises_in_loop(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)
        self.first = True

        def raise_after_one(**_):
            if not self.first:
                channel.exceptions.append(AMQPChannelError())
            self.first = False
            return None

        with mock.patch('amqpstorm.Channel._build_message',
                        side_effect=raise_after_one):
            generator = channel.build_inbound_messages(break_on_empty=False)
            if hasattr(generator, 'next'):
                self.assertRaises(AMQPChannelError, generator.next)
            else:
                self.assertRaises(AMQPChannelError, generator.__next__)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:20,代码来源:channel_exception_tests.py

示例6: test_channel_build_inbound_messages

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_inbound_messages(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        messages_consumed = 0
        for msg in channel.build_inbound_messages(break_on_empty=True):
            self.assertIsInstance(msg, Message)
            messages_consumed += 1

        self.assertEqual(messages_consumed, 1)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:21,代码来源:channel_message_handling_tests.py

示例7: test_channel_build_no_message_but_inbound_not_empty

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_no_message_but_inbound_not_empty(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(Channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        def add_content():
            channel._inbound.append(ContentHeader(body_size=message_len))
            channel._inbound.append(ContentBody(value=message))

        deliver = specification.Basic.Deliver()
        channel._inbound = [deliver]

        self.assertTrue(channel._inbound)

        threading.Timer(function=add_content, interval=0.2).start()

        for msg in channel.build_inbound_messages(break_on_empty=True):
            self.assertEqual(msg.body, message.decode('utf-8'))

        self.assertFalse(channel._inbound)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:24,代码来源:channel_message_handling_tests.py

示例8: test_channel_build_inbound_messages_without_break_on_empty

# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
    def test_channel_build_inbound_messages_without_break_on_empty(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        for _ in range(25):
            channel._inbound.append(deliver)
            channel._inbound.append(header)
            channel._inbound.append(body)

        messages_consumed = 0
        for msg in channel.build_inbound_messages(break_on_empty=False):
            messages_consumed += 1
            self.assertIsInstance(msg.body, str)
            self.assertEqual(msg.body.encode('utf-8'), message)
            if messages_consumed >= 10:
                channel.set_state(channel.CLOSED)
        self.assertEqual(messages_consumed, 10)
开发者ID:eandersson,项目名称:amqpstorm,代码行数:26,代码来源:channel_message_handling_tests.py


注:本文中的amqpstorm.Channel.build_inbound_messages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。