def _test_cast(self, fanout, server_params=None): self.mock_connection = self.mox.CreateMock(self.orig_connection) self.mock_session = self.mox.CreateMock(self.orig_session) self.mock_sender = self.mox.CreateMock(self.orig_sender) self.mock_connection.opened().AndReturn(False) self.mock_connection.open() self.mock_connection.session().AndReturn(self.mock_session) if fanout: expected_address = ( 'impl_qpid_test_fanout ; ' '{"node": {"x-declare": {"auto-delete": true, ' '"durable": false, "type": "fanout"}, ' '"type": "topic"}, "create": "always"}') else: expected_address = ( 'openstack/impl_qpid_test ; {"node": {"x-declare": ' '{"auto-delete": true, "durable": false}, "type": "topic"}, ' '"create": "always"}') self.mock_session.sender(expected_address).AndReturn(self.mock_sender) self.mock_sender.send(mox.IgnoreArg()) if not server_params: # This is a pooled connection, so instead of closing it, it # gets reset, which is just creating a new session on the # connection. self.mock_session.close() self.mock_connection.session().AndReturn(self.mock_session) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") args = [FLAGS, ctx, "impl_qpid_test", {"method": "test_method", "args": {}}] if server_params: args.insert(2, server_params) if fanout: method = impl_qpid.fanout_cast_to_server else: method = impl_qpid.cast_to_server else: if fanout: method = impl_qpid.fanout_cast else: method = impl_qpid.cast method(*args) finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()
def _test_call_with_timeout(self, timeout, expect_failure): self._test_call_mock_common() if not expect_failure: self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "result": "foo", "failure": False, "ending": False })) self.mock_session.acknowledge(mox.IgnoreArg()) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "failure": False, "ending": True })) self.mock_session.acknowledge(mox.IgnoreArg()) # Normally the iterconsume() runs indefinitely, but we have to stop it # here otherwise, the test won't end self.mock_session.next_receiver(timeout=None).AndRaise(StopIteration) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") method = impl_qpid.call if expect_failure: try: res = method(self.FLAGS, ctx, "impl_qpid_test", { "method": "test_method", "args": {} }, timeout) self.fail('Expected a timeout exception') except rpc_common.Timeout: # Good, this is expected! pass else: res = method(self.FLAGS, ctx, "impl_qpid_test", { "method": "test_method", "args": {} }, timeout) self.assertEqual(res, "foo") finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()
def _test_call_with_timeout(self, timeout, expect_failure): self._test_call_mock_common() if not expect_failure: self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn(qpid.messaging.Message( {"_msg_id": self.uuid4.hex, "result": "foo", "failure": False, "ending": False})) self.mock_session.acknowledge(mox.IgnoreArg()) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn(qpid.messaging.Message( {"_msg_id": self.uuid4.hex, "failure": False, "ending": True})) self.mock_session.acknowledge(mox.IgnoreArg()) # Normally the iterconsume() runs indefinitely, but we have to stop it # here otherwise, the test won't end self.mock_session.next_receiver(timeout=None).AndRaise(StopIteration) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") method = impl_qpid.call if expect_failure: try: res = method(self.FLAGS, ctx, "impl_qpid_test", {"method": "test_method", "args": {}}, timeout) self.fail('Expected a timeout exception') except rpc_common.Timeout: # Good, this is expected! pass else: res = method(self.FLAGS, ctx, "impl_qpid_test", {"method": "test_method", "args": {}}, timeout) self.assertEqual(res, "foo") finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()
def _test_call(self, multi, reply_proxy_exc): self._test_call_mock_common() if reply_proxy_exc: self.mock_session.next_receiver(timeout=None).AndRaise( Exception('unexpected exception')) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn(qpid.messaging.Message( {"_msg_id": self.uuid4.hex, "result": "foo", "failure": False, "ending": False})) self.mock_session.acknowledge(mox.IgnoreArg()) if multi: self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({"_msg_id": self.uuid4.hex, "result": "bar", "failure": False, "ending": False})) self.mock_session.acknowledge(mox.IgnoreArg()) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({"_msg_id": self.uuid4.hex, "result": "baz", "failure": False, "ending": False})) self.mock_session.acknowledge(mox.IgnoreArg()) if reply_proxy_exc: self.mock_session.next_receiver(timeout=None).AndRaise( Exception('unexpected exception')) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn(qpid.messaging.Message( {"_msg_id": self.uuid4.hex, "failure": False, "ending": True})) self.mock_session.acknowledge(mox.IgnoreArg()) # Normally the iterconsume() runs indefinitely, but we have to stop it # here otherwise, the test won't end self.mock_session.next_receiver(timeout=None).AndRaise(StopIteration) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") if multi: method = impl_qpid.multicall else: method = impl_qpid.call res = method(self.FLAGS, ctx, "impl_qpid_test", {"method": "test_method", "args": {}}) if multi: self.assertEqual(list(res), ["foo", "bar", "baz"]) else: self.assertEqual(res, "foo") finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()
def _test_call(self, multi, reply_proxy_exc): self._test_call_mock_common() if reply_proxy_exc: self.mock_session.next_receiver(timeout=None).AndRaise( Exception('unexpected exception')) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "result": "foo", "failure": False, "ending": False })) self.mock_session.acknowledge(mox.IgnoreArg()) if multi: self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "result": "bar", "failure": False, "ending": False })) self.mock_session.acknowledge(mox.IgnoreArg()) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "result": "baz", "failure": False, "ending": False })) self.mock_session.acknowledge(mox.IgnoreArg()) if reply_proxy_exc: self.mock_session.next_receiver(timeout=None).AndRaise( Exception('unexpected exception')) self.mock_session.next_receiver(timeout=None).AndReturn( self.mock_receiver) self.mock_receiver.fetch().AndReturn( qpid.messaging.Message({ "_msg_id": self.uuid4.hex, "failure": False, "ending": True })) self.mock_session.acknowledge(mox.IgnoreArg()) # Normally the iterconsume() runs indefinitely, but we have to stop it # here otherwise, the test won't end self.mock_session.next_receiver(timeout=None).AndRaise(StopIteration) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") if multi: method = impl_qpid.multicall else: method = impl_qpid.call res = method(self.FLAGS, ctx, "impl_qpid_test", { "method": "test_method", "args": {} }) if multi: self.assertEqual(list(res), ["foo", "bar", "baz"]) else: self.assertEqual(res, "foo") finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()
def _test_cast(self, fanout, server_params=None, topology_version=1): self.config(qpid_topology_version=topology_version) self.mock_connection = self.mox.CreateMock(self.orig_connection) self.mock_session = self.mox.CreateMock(self.orig_session) self.mock_sender = self.mox.CreateMock(self.orig_sender) self.mock_connection.opened().AndReturn(False) self.mock_connection.open() self.mock_connection.session().AndReturn(self.mock_session) if fanout: if topology_version == 1: expected_address = ( 'impl_qpid_test_fanout ; ' '{"node": {"x-declare": {"auto-delete": true, ' '"durable": false, "type": "fanout"}, ' '"type": "topic"}, "create": "always"}') elif topology_version == 2: expected_address = 'amq.topic/fanout/impl_qpid_test' else: if topology_version == 1: expected_address = ( 'openstack/impl_qpid_test ; {"node": {"x-declare": ' '{"auto-delete": true, "durable": false}, ' '"type": "topic"}, "create": "always"}') elif topology_version == 2: expected_address = 'amq.topic/topic/openstack/impl_qpid_test' self.mock_session.sender(expected_address).AndReturn(self.mock_sender) self.mock_sender.send(mox.IgnoreArg()) if not server_params: # This is a pooled connection, so instead of closing it, it # gets reset, which is just creating a new session on the # connection. self.mock_session.close() self.mock_connection.session().AndReturn(self.mock_session) self.mock_connection.close() self.mox.ReplayAll() try: ctx = context.RequestContext("user", "project") args = [ self.FLAGS, ctx, "impl_qpid_test", { "method": "test_method", "args": {} } ] if server_params: args.insert(2, server_params) if fanout: method = impl_qpid.fanout_cast_to_server else: method = impl_qpid.cast_to_server else: if fanout: method = impl_qpid.fanout_cast else: method = impl_qpid.cast method(*args) finally: impl_qpid.cleanup() self.uuid4 = uuid.uuid4()