def test_xp_durable_send(self): xp = self.container.ex_manager.create_xp('an_xp') #self.addCleanup(xp.delete) xq = self.container.ex_manager.create_xn_queue('no_matter', xp) self.addCleanup(xq.delete) xq.bind('one') pub = Publisher(to_name=xp.create_route('one')) pub.publish('test') pub.close() try: url = self.container.ex_manager._get_management_url("queues", "%2f", xq.queue, "get") res = self.container.ex_manager._make_management_call(url, use_ems=False, method='post', data=json.dumps({'count':1, 'requeue':True,'encoding':'auto'})) self.assertEquals(len(res), 1) self.assertIn('properties', res[0]) self.assertIn('delivery_mode', res[0]['properties']) self.assertEquals(2, res[0]['properties']['delivery_mode']) except Exception, e: # Rabbit 3.x does not support this command anymore apparently. self.assertIn('Method Not Allowed', e.message)
class TestPublisher(PyonTestCase): def setUp(self): self._node = Mock(spec=NodeB) self._pub = Publisher(node=self._node, to_name="testpub") self._ch = Mock(spec=SendChannel) self._node.channel.return_value = self._ch def test_publish(self): self.assertEquals(self._node.channel.call_count, 0) self._pub.publish("pub") self._node.channel.assert_called_once_with(self._pub.channel_type) self.assertEquals(self._ch.send.call_count, 1) self._pub.publish("pub2") self._node.channel.assert_called_once_with(self._pub.channel_type) self.assertEquals(self._ch.send.call_count, 2) def test_publish_with_new_name(self): self.assertEquals(self._node.channel.call_count, 0) self._pub.publish(sentinel.msg, to_name=sentinel.to_name) self.assertEquals(self._ch.send.call_count, 1) self._pub.publish(sentinel.msg, to_name=sentinel.to_name) self.assertEquals(self._ch.send.call_count, 2) def test_close(self): self._pub.publish(sentinel.msg) self._pub._pub_ep.close = Mock() self._pub.close() self._pub._pub_ep.close.assert_called_once_with()
def test_xp_durable_send(self): xp = self.container.ex_manager.create_xp('an_xp') #self.addCleanup(xp.delete) xq = self.container.ex_manager.create_xn_queue('no_matter', xp) self.addCleanup(xq.delete) xq.bind('one') pub = Publisher(to_name=xp.create_route('one')) pub.publish('test') pub.close() url = self.container.ex_manager._get_management_url( "queues", "%2f", xq.queue, "get") res = self.container.ex_manager._make_management_call(url, use_ems=False, method='post', data=json.dumps({ 'count': 1, 'requeue': True, 'encoding': 'auto' })) self.assertEquals(len(res), 1) self.assertIn('properties', res[0]) self.assertIn('delivery_mode', res[0]['properties']) self.assertEquals(2, res[0]['properties']['delivery_mode'])
class TestPublisher(PyonTestCase): def setUp(self): self._node = Mock(spec=NodeB) self._pub = Publisher(node=self._node, to_name="testpub") self._ch = Mock(spec=SendChannel) self._node.channel.return_value = self._ch def test_publish(self): self.assertEquals(self._node.channel.call_count, 0) self._pub.publish("pub") self._node.channel.assert_called_once_with(self._pub.channel_type) self.assertEquals(self._ch.send.call_count, 1) self._pub.publish("pub2") self._node.channel.assert_called_once_with(self._pub.channel_type) self.assertEquals(self._ch.send.call_count, 2) def test_publish_with_new_name(self): self.assertEquals(self._node.channel.call_count, 0) self._pub.publish(sentinel.msg, to_name=sentinel.to_name) self.assertEquals(self._ch.send.call_count, 1) self._pub.publish(sentinel.msg, to_name=sentinel.to_name) self.assertEquals(self._ch.send.call_count, 2) def test_close(self): self._pub.publish(sentinel.msg) self._pub._pub_ep.close = Mock() self._pub.close() self._pub._pub_ep.close.assert_called_once_with()
class AsyncResultPublisher(object): """ Class that helps sending async results. """ def __init__(self, process=None, wait_name=None): self.process = process if not wait_name.startswith("asyncresult_"): raise BadRequest("Not a valid wait_name") self.wait_name = wait_name if self.process: self.pub = ProcessPublisher(process=self.process, to_name=wait_name) else: self.pub = Publisher(to_name=wait_name) def publish_result(self, request_id, result): async_res = AsyncResultMsg(result=result, request_id=request_id, ts=get_ion_ts()) self.pub.publish(async_res) self.pub.close() def publish_error(self, request_id, error, error_code): async_res = AsyncResultMsg(result=error, request_id=request_id, ts=get_ion_ts(), status=error_code) self.pub.publish(async_res) self.pub.close()