def test_listen_exception_in_handling(self): # make a listen loop that will return one message (to blow up in processing) chmock = MagicMock(spec=ListenChannel) chmock.accept.return_value = Mock() chmock.accept.return_value.recv = Mock(return_value=(sentinel.msg, sentinel.headers, sentinel.delivery_tag)) chmock.accept.return_value._recv_queue.qsize.return_value = 1 nodemock = Mock(spec=NodeB) nodemock.channel.return_value = chmock recv_name = NameTrio(sentinel.ex, sentinel.queue) ep = ListeningBaseEndpoint(node=nodemock, from_name=recv_name) # make msg received error out! ep.create_endpoint = Mock(return_value=Mock(spec=EndpointUnit)) ep.create_endpoint.return_value._message_received.side_effect = TestError ep.create_endpoint.return_value.intercept_in.return_value = (sentinel.msg, sentinel.headers) self.assertRaises(TestError, ep.listen) chmock.setup_listener.assert_called_once_with(recv_name, binding=sentinel.queue) chmock.start_consume.assert_called_once_with() chmock.accept.assert_called_once_with(n=1, timeout=None) chmock.accept.return_value.recv.assert_called_once_with() ep.create_endpoint.assert_called_once_with(existing_channel=chmock.accept.return_value)
def test_get_stats(self): ep = ListeningBaseEndpoint() ep._chan = Mock(spec=ListenChannel) ep.get_stats() ep._chan.get_stats.assert_called_once_with()
def _setup_listener(self, name, binding=None): """ Override Subscriber - we may have specified a queue name. XXX BASECLASS SEEMS WRONG """ ListeningBaseEndpoint._setup_listener(self, name, binding=binding)
def test__create_channel_sets_transport_kwarg(self): # if send_name is a transport, it makes sure that kwarg is passed in to node's channel (and therefore the channel) class FakeSendName(NameTrio, BaseTransport): pass fn = FakeSendName() ep = ListeningBaseEndpoint(node=Mock(spec=NodeB), from_name=fn) ch = ep._create_channel() self.assertIn('transport', ep.node.channel.call_args[1]) self.assertIn(fn, ep.node.channel.call_args[1].itervalues())
def test_listen(self): # make a listen loop that will exit right away chmock = Mock(spec=ListenChannel) chmock.accept.side_effect = ChannelClosedError nodemock = Mock(spec=NodeB) nodemock.channel.return_value = chmock ep = ListeningBaseEndpoint(node=nodemock, from_name=NameTrio(sentinel.ex, sentinel.queue)) ep.listen() chmock.setup_listener.assert_called_once_with(ep._recv_name, binding=sentinel.queue)
def test_listen_with_base_transport_for_name(self): # make a listen loop that will exit right away chmock = Mock(spec=ListenChannel) chmock.accept.side_effect = ChannelClosedError nodemock = Mock(spec=NodeB) nodemock.channel.return_value = chmock class FakeRecvName(BaseTransport, NameTrio): pass recv_name = FakeRecvName() recv_name.setup_listener = Mock() ep = ListeningBaseEndpoint(node=nodemock, from_name=recv_name) ep.listen(binding=sentinel.binding) self.assertTrue(ep.get_ready_event().is_set()) self.assertIn('transport', nodemock.channel.call_args[1]) self.assertIn(recv_name, nodemock.channel.call_args[1].itervalues())
def test_get_stats(self): ep = ListeningBaseEndpoint(node=self.container.node) gl = spawn(ep.listen, binding="test_get_stats") ep.get_ready_event().wait(timeout=5) gs_res = ep.get_stats() self.assertEquals(gs_res, (0, 1)) # num of messages, num listeners ep.close() gl.join(timeout=5)
def test_get_stats_multiple_on_named_queue(self): ep1 = ListeningBaseEndpoint(node=self.container.node, from_name="test_get_stats_multi") gl1 = spawn(ep1.listen) ep2 = ListeningBaseEndpoint(node=self.container.node, from_name="test_get_stats_multi") gl2 = spawn(ep2.listen) ep1.get_ready_event().wait(timeout=5) ep2.get_ready_event().wait(timeout=5) gs_res1 = ep1.get_stats() self.assertEquals(gs_res1, (0, 2)) # num of messages, num listeners gs_res2 = ep2.get_stats() self.assertEquals(gs_res2, (0, 2)) # num of messages, num listeners ep1.close() ep2.close() gl1.join(timeout=5) gl2.join(timeout=5)
def test_close(self): ep = ListeningBaseEndpoint(node=Mock(soec=NodeB)) ep._chan = Mock() ep.close() ep._chan.close.assert_called_once_with()
def test_get_ready_event(self): ep = ListeningBaseEndpoint(node=Mock(spec=NodeB)) self.assertEquals(ep.get_ready_event(), ep._ready_event)
def test_get_stats_no_channel(self): ep = ListeningBaseEndpoint() self.assertRaises(EndpointError, ep.get_stats)