本文整理汇总了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)
示例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)