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


Python EndpointUnit.spawn_listener方法代码示例

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


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

示例1: TestEndpointUnit

# 需要导入模块: from pyon.net.endpoint import EndpointUnit [as 别名]
# 或者: from pyon.net.endpoint.EndpointUnit import spawn_listener [as 别名]
class TestEndpointUnit(PyonTestCase):
    def setUp(self):
        self._endpoint_unit = EndpointUnit()

    def test_attach_channel(self):
        ch = Mock(spec=BaseChannel)
        self._endpoint_unit.attach_channel(ch)

        self.assertTrue(self._endpoint_unit.channel is not None)
        self.assertEquals(self._endpoint_unit.channel, ch)

    @patch("pyon.net.endpoint.get_ion_ts", Mock(return_value=sentinel.ts))
    def test_send(self):

        # need a channel to send on
        self.assertRaises(AttributeError, self._endpoint_unit.send, "fake")

        ch = Mock(spec=SendChannel)
        self._endpoint_unit.attach_channel(ch)

        self._endpoint_unit.send("hi", {"header": "value"})
        ch.send.assert_called_once_with("hi", {"header": "value", "ts": sentinel.ts})

    def test_close(self):
        ch = Mock(spec=BaseChannel)
        self._endpoint_unit.attach_channel(ch)
        self._endpoint_unit.close()
        ch.close.assert_called_once_with()

    def test_spawn_listener(self):
        def recv():
            ar = event.AsyncResult()
            ar.wait()

        ch = Mock(spec=BidirClientChannel)
        ch.recv.side_effect = recv
        self._endpoint_unit.attach_channel(ch)

        self._endpoint_unit.spawn_listener()

        self._endpoint_unit.close()
        self.assertTrue(self._endpoint_unit._recv_greenlet.ready())

    def test_build_header(self):
        head = self._endpoint_unit._build_header({"fake": "content"})
        self.assertTrue(isinstance(head, dict))

    def test_build_payload(self):
        fakemsg = {"fake": "content"}
        msg = self._endpoint_unit._build_payload(fakemsg)
        self.assertEquals(msg, fakemsg)

    def test_build_msg(self):
        fakemsg = {"fake": "content"}
        msg = self._endpoint_unit._build_msg(fakemsg)

    #        self.assertTrue(isinstance(msg, dict))
    #        self.assertTrue(msg.has_key('header'))
    #        self.assertTrue(msg.has_key('payload'))
    #        self.assertTrue(isinstance(msg['header'], dict))
    #        self.assertEquals(fakemsg, msg['payload'])

    def test__message_received(self):
        self._endpoint_unit._build_invocation = Mock()
        self._endpoint_unit._intercept_msg_in = Mock()
        self._endpoint_unit.message_received = Mock()
        self._endpoint_unit.message_received.return_value = sentinel.msg_return

        retval = self._endpoint_unit._message_received(sentinel.msg, sentinel.headers)

        self.assertEquals(retval, sentinel.msg_return)

        self._endpoint_unit._build_invocation.assert_called_once_with(
            path=Invocation.PATH_IN, message=sentinel.msg, headers=sentinel.headers
        )
        self.assertTrue(self._endpoint_unit._intercept_msg_in.called)
        self.assertTrue(self._endpoint_unit.message_received.called)
开发者ID:ooici-dm,项目名称:pyon,代码行数:79,代码来源:test_endpoint.py

示例2: TestEndpointUnit

# 需要导入模块: from pyon.net.endpoint import EndpointUnit [as 别名]
# 或者: from pyon.net.endpoint.EndpointUnit import spawn_listener [as 别名]
class TestEndpointUnit(PyonTestCase):

    def setUp(self):
        self._endpoint_unit = EndpointUnit()

    def test_attach_channel(self):
        ch = Mock(spec=BaseChannel)
        self._endpoint_unit.attach_channel(ch)

        self.assertTrue(self._endpoint_unit.channel is not None)
        self.assertEquals(self._endpoint_unit.channel, ch)

    def test_send(self):

        # need a channel to send on
        self.assertRaises(AttributeError, self._endpoint_unit.send, "fake")

        ch = Mock(spec=SendChannel)
        self._endpoint_unit.attach_channel(ch)

        self._endpoint_unit.send("hi", {'header':'value'})
        ch.send.assert_called_once_with('hi', {'header':'value'})

    def test_close(self):
        ch = Mock(spec=BaseChannel)
        self._endpoint_unit.attach_channel(ch)
        self._endpoint_unit.close()
        ch.close.assert_called_once_with()

    def test_spawn_listener(self):
        ch = Mock(spec=BidirClientChannel)
        self._endpoint_unit.attach_channel(ch)

        self._endpoint_unit.spawn_listener()

        self._endpoint_unit.close()
        self.assertTrue(self._endpoint_unit._recv_greenlet.ready())

    def test_build_header(self):
        head = self._endpoint_unit._build_header({'fake': 'content'})
        self.assertTrue(isinstance(head, dict))

    def test_build_payload(self):
        fakemsg = {'fake':'content'}
        msg = self._endpoint_unit._build_payload(fakemsg)
        self.assertEquals(msg, fakemsg)

    def test_build_msg(self):
        fakemsg = {'fake':'content'}
        msg = self._endpoint_unit._build_msg(fakemsg)
#        self.assertTrue(isinstance(msg, dict))
#        self.assertTrue(msg.has_key('header'))
#        self.assertTrue(msg.has_key('payload'))
#        self.assertTrue(isinstance(msg['header'], dict))
#        self.assertEquals(fakemsg, msg['payload'])

    def test__message_received(self):
        self._endpoint_unit._build_invocation = Mock()
        self._endpoint_unit._intercept_msg_in = Mock()
        self._endpoint_unit.message_received  = Mock()
        self._endpoint_unit.message_received.return_value = sentinel.msg_return


        retval = self._endpoint_unit._message_received(sentinel.msg, sentinel.headers)

        self.assertEquals(retval, sentinel.msg_return)

        self._endpoint_unit._build_invocation.assert_called_once_with(path=Invocation.PATH_IN,
                                                                      message=sentinel.msg,
                                                                      headers=sentinel.headers)
        self.assertTrue(self._endpoint_unit._intercept_msg_in.called)
        self.assertTrue(self._endpoint_unit.message_received.called)
开发者ID:blazetopher,项目名称:pyon,代码行数:74,代码来源:test_endpoint.py


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