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


Python ExchangeManager.stop方法代码示例

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


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

示例1: TestExchangeManager

# 需要导入模块: from pyon.ion.exchange import ExchangeManager [as 别名]
# 或者: from pyon.ion.exchange.ExchangeManager import stop [as 别名]
class TestExchangeManager(PyonTestCase):

    def setUp(self):
        self.container = Mock()
        self.ex_manager = ExchangeManager(self.container)
        self.ex_manager.get_transport = Mock()

    def test_verify_service(self, mockmessaging):
        PyonTestCase.test_verify_service(self)

    @patch.dict('pyon.ion.exchange.CFG', container=_make_container_cfg())
    def test_start_with_no_connections(self, mockmessaging):
        self.assertRaises(ExchangeManagerError, self.ex_manager.start)

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp':dict_amqp, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(primary='amqp'))
    def test_start_with_one_connection(self, mockmessaging):
        mockmessaging.make_node.return_value = (Mock(), Mock())     # node, ioloop
        self.ex_manager.start()

        mockmessaging.make_node.assert_called_once_with(dict_amqp, 'primary', 0)
        self.assertIn('primary', self.ex_manager._nodes)
        self.assertIn('primary', self.ex_manager._ioloops)
        self.assertEquals(self.ex_manager._nodes['primary'], mockmessaging.make_node.return_value[0])
        self.assertEquals(self.ex_manager._ioloops['primary'], mockmessaging.make_node.return_value[1])

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp':dict_amqp, 'amqp_again':dict_amqp_again, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(primary='amqp', secondary='amqp_again'))
    def test_start_with_multi_connections(self, mockmessaging):
        mockmessaging.make_node.return_value = (Mock(), Mock())     # node, ioloop
        self.ex_manager.start()

        mockmessaging.make_node.assert_calls(call(dict_amqp, 'primary', 0), call(dict_amqp_again, 'secondary', 0))

        self.assertIn('primary', self.ex_manager._nodes)
        self.assertIn('primary', self.ex_manager._ioloops)
        self.assertEquals(self.ex_manager._nodes['primary'], mockmessaging.make_node.return_value[0])
        self.assertEquals(self.ex_manager._ioloops['primary'], mockmessaging.make_node.return_value[1])

        self.assertIn('secondary', self.ex_manager._nodes)
        self.assertIn('secondary', self.ex_manager._ioloops)
        self.assertEquals(self.ex_manager._nodes['secondary'], mockmessaging.make_node.return_value[0])
        self.assertEquals(self.ex_manager._ioloops['secondary'], mockmessaging.make_node.return_value[1])

    @patch.dict('pyon.ion.exchange.CFG', server={}, container=_make_container_cfg(primary='idontexist'))
    def test_start_with_non_existing_connection_in_server(self, mockmessaging):
        mockmessaging.make_node.return_value = (Mock(), Mock())     # node, ioloop

        self.assertRaises(ExchangeManagerError, self.ex_manager.start)
        self.assertFalse(mockmessaging.make_node.called)

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp':dict_amqp, 'amqp_fail':dict_amqp_fail, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(primary='amqp', secondary='amqp_fail'))
    def test_start_with_working_and_failing_connection(self, mockmessaging):

        # set up return values - first is amqp (Working) second is amqp_fail (not working)
        nodemock = Mock()
        nodemock.running = False
        iomock = Mock()
        def ret_vals(conf, name, timeout):
            if name == 'secondary':
                return (nodemock, iomock)
            return (Mock(), Mock())

        mockmessaging.make_node.side_effect = ret_vals

        self.ex_manager.start()

        self.assertEquals(len(self.ex_manager._nodes), 1)
        iomock.kill.assert_called_once_with()

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp_fail':dict_amqp_fail, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(primary='amqp_fail'))
    def test_start_with_only_failing_connections(self, mockmessaging):
        nodemock = Mock()
        nodemock.running = False
        iomock = Mock()

        mockmessaging.make_node.return_value = (nodemock, iomock)

        self.assertRaises(ExchangeManagerError, self.ex_manager.start)
        iomock.kill.assert_called_once_with()

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp':dict_amqp, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(primary='amqp'))
    def test_start_stop(self, mockmessaging):
        nodemock = Mock()
        iomock = Mock()
        mockmessaging.make_node.return_value = (nodemock, iomock)

        self.ex_manager.start()
        self.ex_manager.stop()

        nodemock.stop_node.assert_called_once_with()
        iomock.kill.assert_called_once_with()

    def test_default_node_no_connections(self, mockmessaging):
        self.assertIsNone(self.ex_manager.default_node)

    @patch.dict('pyon.ion.exchange.CFG', server={'amqp_not_default':dict_amqp_not_default, 'postgresql':CFG.server.postgresql}, container=_make_container_cfg(secondary='amqp_not_default'))
    def test_default_node_no_default_name(self, mockmessaging):
        nodemock = Mock()
        mockmessaging.make_node.return_value = (nodemock, Mock())     # node, ioloop

        self.ex_manager.start()
#.........这里部分代码省略.........
开发者ID:j2project,项目名称:pyon,代码行数:103,代码来源:test_exchange.py


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