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


Python QueueService.list_queues方法代码示例

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


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

示例1: QueueStorageHandlerTest

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import list_queues [as 别名]
class QueueStorageHandlerTest(_TestCase):

    def setUp(self):
        self.service = QueueService(account_name=ACCOUNT_NAME,
                                    account_key=ACCOUNT_KEY,
                                    is_emulated=_EMULATED)
        # ensure that there's no message on the queue before each test
        queues = set()
        for cfg in LOGGING['handlers'].values():
            if 'queue' in cfg:
                queues.add(cfg['queue'])
        for queue in self.service.list_queues():
            if queue.name in queues:
                self.service.clear_messages(queue.name)

    def test_logging(self):
        # get the logger for the test
        logger_name = 'queue'
        logger = logging.getLogger(logger_name)
        handler_name = _get_handler_name(logger_name)

        # perform logging
        log_text = 'logging test'
        logger.info(log_text)

        # confirm that the massage has correct log text
        queue = _get_handler_config_value(handler_name, 'queue')
        messages = iter(self.service.get_messages(queue))
        message = next(messages)
        text_expected = "INFO %s" % log_text
        if _get_handler_config_value(handler_name, 'base64_encoding'):
            text_expected = _base64_encode(text_expected)
        self.assertEqual(message.content, text_expected)

        # confirm that there's no more message in the queue
        with self.assertRaises(StopIteration):
            next(messages)

    def test_message_ttl(self):
        # get the logger for the test
        logger_name = 'message_ttl'
        logger = logging.getLogger(logger_name)
        handler_name = _get_handler_name(logger_name)

        # perform logging
        log_text = 'time-to-live test'
        logger.info(log_text)

        # confirm that the new message is visible till the ttl expires
        queue = _get_handler_config_value(handler_name, 'queue')
        messages = iter(self.service.get_messages(queue))
        message = next(messages)
        text_expected = 'INFO %s' % log_text
        if _get_handler_config_value(handler_name, 'base64_encoding'):
            text_expected = _base64_encode(text_expected)
        self.assertEqual(message.content, text_expected)

        # confirm that there's no more message in the queue
        with self.assertRaises(StopIteration):
            next(messages)

        # confirm that the new message is invisible after the ttl expires
        ttl = _get_handler_config_value(handler_name, 'message_ttl')
        time.sleep(int(ttl)+5)
        messages = iter(self.service.get_messages(queue))
        with self.assertRaises(StopIteration):
            next(messages)

    def test_visibility_timeout(self):
        # get the logger for the test
        logger_name = 'visibility_timeout'
        logger = logging.getLogger(logger_name)
        handler_name = _get_handler_name(logger_name)

        # perform logging
        log_text = 'visibility test'
        logger.info(log_text)

        # confirm that the new message is invisible till the timeout expires
        queue = _get_handler_config_value(handler_name, 'queue')
        messages = iter(self.service.get_messages(queue))
        with self.assertRaises(StopIteration):
            next(messages)

        # confirm that the new message is visible after the timeout expires
        timeout = _get_handler_config_value(handler_name, 'visibility_timeout')
        time.sleep(int(timeout)+5)
        messages = iter(self.service.get_messages(queue))
        message = next(messages)
        text_expected = 'INFO %s' % log_text
        if _get_handler_config_value(handler_name, 'base64_encoding'):
            text_expected = _base64_encode(text_expected)
        self.assertEqual(message.content, text_expected)

        # confirm that there's no more message in the queue
        with self.assertRaises(StopIteration):
            next(messages)

    def test_base64_encoding(self):
        # get the logger for the test
#.........这里部分代码省略.........
开发者ID:michiya,项目名称:azure-storage-logging,代码行数:103,代码来源:tests.py


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