diff options
author | Dan Smith <danms@us.ibm.com> | 2013-05-19 14:13:59 -0700 |
---|---|---|
committer | Dan Smith <danms@us.ibm.com> | 2013-05-21 06:40:51 -0700 |
commit | 93ee6e3bfb280bfe5b5f6617c5d89c65cc54028d (patch) | |
tree | 7dd9d7485b729bf1fa613c3b877912a2be729750 /tests/unit/rpc/test_proxy.py | |
parent | df7ea8308363235afba503f8562341bd2e3dce4f (diff) | |
download | oslo-93ee6e3bfb280bfe5b5f6617c5d89c65cc54028d.tar.gz oslo-93ee6e3bfb280bfe5b5f6617c5d89c65cc54028d.tar.xz oslo-93ee6e3bfb280bfe5b5f6617c5d89c65cc54028d.zip |
Add generic serialization support
This adds a generic serialization model that the RpcProxy and
RpcDispatcher will use to serialize and deserialize arguments
and return values. The base definition is provided, as well
as a default NoOpSerializer which performs no special
action (retaining the existing behavior).
Related to blueprint rpc-object-serialization
Change-Id: I0a33baddee3e28dfc47100eb3216b679558b0bdd
Diffstat (limited to 'tests/unit/rpc/test_proxy.py')
-rw-r--r-- | tests/unit/rpc/test_proxy.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/rpc/test_proxy.py b/tests/unit/rpc/test_proxy.py index f05964b..9427cbe 100644 --- a/tests/unit/rpc/test_proxy.py +++ b/tests/unit/rpc/test_proxy.py @@ -19,6 +19,7 @@ Unit Tests for rpc.proxy """ import copy +import mox import six @@ -27,11 +28,20 @@ from openstack.common import lockutils from openstack.common import rpc from openstack.common.rpc import common as rpc_common from openstack.common.rpc import proxy +from openstack.common.rpc import serializer as rpc_serializer from tests import utils class RpcProxyTestCase(utils.BaseTestCase): + def setUp(self): + super(RpcProxyTestCase, self).setUp() + self.mox = mox.Mox() + + def cleanUp(self): + super(RpcProxyTestCase, self).cleanUp() + self.mox.VerifyAll() + def _test_rpc_method(self, rpc_method, has_timeout=False, has_retval=False, server_params=None, supports_topic_override=True): topic = 'fake_topic' @@ -174,3 +184,28 @@ class RpcProxyTestCase(utils.BaseTestCase): expected = {'method': 'test_method', 'namespace': 'meow', 'args': {'a': 1, 'b': 2}} self.assertEqual(msg, expected) + + def test_serializer(self): + ctxt = context.RequestContext('fake', 'fake') + serializer = rpc_serializer.NoOpSerializer() + + self.mox.StubOutWithMock(serializer, 'serialize_entity') + self.mox.StubOutWithMock(serializer, 'deserialize_entity') + self.mox.StubOutWithMock(rpc, 'call') + + serializer.serialize_entity(ctxt, 1).AndReturn(1) + serializer.serialize_entity(ctxt, 2).AndReturn(2) + rpc.call(ctxt, 'fake', + {'args': {'a': 1, 'b': 2}, + 'namespace': None, + 'method': 'foo', + 'version': '1.0'}, + None).AndReturn('foo') + serializer.deserialize_entity(ctxt, 'foo').AndReturn('worked!') + + self.mox.ReplayAll() + + rpc_proxy = proxy.RpcProxy('fake', '1.0', serializer=serializer) + msg = rpc_proxy.make_msg('foo', a=1, b=2) + result = rpc_proxy.call(ctxt, msg) + self.assertEqual(result, 'worked!') |