summaryrefslogtreecommitdiff
path: root/qpid/cpp/bindings/qmf/tests/python_agent.py
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-10-20 15:22:19 +0000
committerTed Ross <tross@apache.org>2009-10-20 15:22:19 +0000
commit2d85ecb5af412f5026ca79aaf8ada830d83dfe87 (patch)
tree37dc15c210d5256d214566fde481cbff996ac452 /qpid/cpp/bindings/qmf/tests/python_agent.py
parent1503ab35e3eb29f59b2f8431cf41c9f74ce1689c (diff)
downloadqpid-python-2d85ecb5af412f5026ca79aaf8ada830d83dfe87.tar.gz
QPID-2126 - Sync the python QMF bindings to the current Ruby QMF bindings implementation
Applied patch from Ken Giusti git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@827686 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/bindings/qmf/tests/python_agent.py')
-rw-r--r--qpid/cpp/bindings/qmf/tests/python_agent.py133
1 files changed, 85 insertions, 48 deletions
diff --git a/qpid/cpp/bindings/qmf/tests/python_agent.py b/qpid/cpp/bindings/qmf/tests/python_agent.py
index d4373d3bb8..c80f54c9fc 100644
--- a/qpid/cpp/bindings/qmf/tests/python_agent.py
+++ b/qpid/cpp/bindings/qmf/tests/python_agent.py
@@ -30,40 +30,40 @@ class Model:
self.parent_class = qmf.SchemaObjectClass("org.apache.qpid.qmf", "parent")
self.parent_class.add_property(qmf.SchemaProperty("name", qmf.TYPE_SSTR, {"index":True}))
self.parent_class.add_property(qmf.SchemaProperty("state", qmf.TYPE_SSTR))
-
+
self.parent_class.add_property(qmf.SchemaProperty("uint64val", qmf.TYPE_UINT64))
self.parent_class.add_property(qmf.SchemaProperty("uint32val", qmf.TYPE_UINT32))
self.parent_class.add_property(qmf.SchemaProperty("uint16val", qmf.TYPE_UINT16))
self.parent_class.add_property(qmf.SchemaProperty("uint8val", qmf.TYPE_UINT8))
-
+
self.parent_class.add_property(qmf.SchemaProperty("int64val", qmf.TYPE_INT64))
self.parent_class.add_property(qmf.SchemaProperty("int32val", qmf.TYPE_INT32))
self.parent_class.add_property(qmf.SchemaProperty("int16val", qmf.TYPE_INT16))
self.parent_class.add_property(qmf.SchemaProperty("int8val", qmf.TYPE_INT8))
-
+
self.parent_class.add_statistic(qmf.SchemaStatistic("queryCount", qmf.TYPE_UINT32, {"unit":"query", "desc":"Query count"}))
-
+
_method = qmf.SchemaMethod("echo", {"desc":"Check responsiveness of the agent object"})
_method.add_argument(qmf.SchemaArgument("sequence", qmf.TYPE_UINT32, {"dir":qmf.DIR_IN_OUT}))
self.parent_class.add_method(_method)
-
+
_method = qmf.SchemaMethod("set_numerics", {"desc":"Set the numeric values in the object"})
_method.add_argument(qmf.SchemaArgument("test", qmf.TYPE_SSTR, {"dir":qmf.DIR_IN}))
self.parent_class.add_method(_method)
-
+
_method = qmf.SchemaMethod("create_child", {"desc":"Create a new child object"})
_method.add_argument(qmf.SchemaArgument("child_name", qmf.TYPE_LSTR, {"dir":qmf.DIR_IN}))
_method.add_argument(qmf.SchemaArgument("child_ref", qmf.TYPE_REF, {"dir":qmf.DIR_OUT}))
self.parent_class.add_method(_method)
-
+
_method = qmf.SchemaMethod("probe_userid", {"desc":"Return the user-id for this method call"})
_method.add_argument(qmf.SchemaArgument("userid", qmf.TYPE_SSTR, {"dir":qmf.DIR_OUT}))
self.parent_class.add_method(_method)
self.child_class = qmf.SchemaObjectClass("org.apache.qpid.qmf", "child")
self.child_class.add_property(qmf.SchemaProperty("name", qmf.TYPE_SSTR, {"index":True}))
-
-
+
+
def register(self, agent):
agent.register_class(self.parent_class)
agent.register_class(self.child_class)
@@ -71,7 +71,13 @@ class Model:
class App(qmf.AgentHandler):
+ '''
+ Object that handles events received by the Agent.
+ '''
def get_query(self, context, query, userId):
+ '''
+ Respond to a Query request from a console.
+ '''
#print "Query: user=%s context=%d class=%s" % (userId, context, query.class_name())
#if query.object_id():
# print query.object_id().object_num_low()
@@ -84,108 +90,139 @@ class App(qmf.AgentHandler):
def method_call(self, context, name, object_id, args, userId):
- # puts "Method: user=#{userId} context=#{context} method=#{name} object_num=#{object_id.object_num_low if object_id} args=#{args}"
- # oid = self._agent.alloc_object_id(2)
- # args['child_ref'] = oid
- # self._child = qmf.QmfObject(self._model.child_class)
- # self._child.set_attr("name", args.by_key("child_name"))
- # self._child.set_object_id(oid)
- # self._agent.method_response(context, 0, "OK", args)
+ '''
+ Invoke a method call requested by the console.
+ '''
+ #print "Method: name=%s user=%s context=%d object_id=%s args=%s" % (name, userId, context, object_id, args)
if name == "echo":
self._agent.method_response(context, 0, "OK", args)
-
+
elif name == "set_numerics":
_retCode = 0
_retText = "OK"
-
+
if args['test'] == "big":
+ #
+ # note the alternate forms for setting object attributes:
+ #
self._parent.set_attr("uint64val", 0x9494949449494949)
- self._parent.set_attr("uint32val", 0xa5a55a5a)
+ self._parent.uint32val = 0xa5a55a5a
self._parent.set_attr("uint16val", 0xb66b)
- self._parent.set_attr("uint8val", 0xc7)
-
- self._parent.set_attr("int64val", 1000000000000000000)
+ self._parent["uint8val"] = 0xc7
+
+ self._parent.int64val = 1000000000000000000
self._parent.set_attr("int32val", 1000000000)
- self._parent.set_attr("int16val", 10000)
+ self._parent["int16val"] = 10000
self._parent.set_attr("int8val", 100)
-
- elif args['test'] == "small":
+
+ ## Test the __getattr__ implementation:
+ ## @todo: remove once python_client implements this
+ ## form of property access
+ assert self._parent["uint8val"] == 0xc7
+ assert self._parent.uint64val == 0x9494949449494949
+ assert self._parent.queryCount >= 0
+
+ # note the alternative argument access syntax:
+ elif args.test == "small":
self._parent.set_attr("uint64val", 4)
self._parent.set_attr("uint32val", 5)
self._parent.set_attr("uint16val", 6)
self._parent.set_attr("uint8val", 7)
-
+
self._parent.set_attr("int64val", 8)
self._parent.set_attr("int32val", 9)
self._parent.set_attr("int16val", 10)
self._parent.set_attr("int8val", 11)
-
+
elif args['test'] == "negative":
self._parent.set_attr("uint64val", 0)
self._parent.set_attr("uint32val", 0)
self._parent.set_attr("uint16val", 0)
self._parent.set_attr("uint8val", 0)
-
+
self._parent.set_attr("int64val", -10000000000)
self._parent.set_attr("int32val", -100000)
self._parent.set_attr("int16val", -1000)
self._parent.set_attr("int8val", -100)
-
+
else:
_retCode = 1
_retText = "Invalid argument value for test"
-
+
self._agent.method_response(context, _retCode, _retText, args)
-
+
elif name == "create_child":
+ #
+ # Instantiate an object based on the Child Schema Class
+ #
_oid = self._agent.alloc_object_id(2)
args['child_ref'] = _oid
- self._child = qmf.QmfObject(self._model.child_class)
+ self._child = qmf.AgentObject(self._model.child_class)
self._child.set_attr("name", args["child_name"])
self._child.set_object_id(_oid)
self._agent.method_response(context, 0, "OK", args)
-
+
elif name == "probe_userid":
args['userid'] = userId
self._agent.method_response(context, 0, "OK", args)
-
+
else:
self._agent.method_response(context, 1, "Unimplemented Method: %s" % name, args)
-
-
+
+
def main(self):
+ '''
+ Agent application's main processing loop.
+ '''
+ # Connect to the broker
self._settings = qmf.ConnectionSettings()
+ self._settings.sendUserId = True
if len(sys.argv) > 1:
- self._settings.set_attr("host", sys.argv[1])
+ self._settings.host = str(sys.argv[1])
if len(sys.argv) > 2:
- self._settings.set_attr("port", int(sys.argv[2]))
+ self._settings.port = int(sys.argv[2])
self._connection = qmf.Connection(self._settings)
+
+ # Instantiate an Agent to serve me queries and method calls
self._agent = qmf.Agent(self)
-
+
+ # Dynamically define the parent and child schemas, then
+ # register them with the agent
self._model = Model()
self._model.register(self._agent)
-
+
+ # Tell the agent about our connection to the broker
self._agent.set_connection(self._connection)
-
- self._parent = qmf.QmfObject(self._model.parent_class)
+
+ # Instantiate and populate an instance of the Parent
+ # Schema Object
+ self._parent = qmf.AgentObject(self._model.parent_class)
+
+ ## @todo how do we force a test failure?
+ # verify the properties() and statistics() object methods:
+ assert len(self._parent.properties()) == 10
+ assert len(self._parent.statistics()) == 1
+
self._parent.set_attr("name", "Parent One")
self._parent.set_attr("state", "OPERATIONAL")
-
+
self._parent.set_attr("uint64val", 0)
self._parent.set_attr("uint32val", 0)
self._parent.set_attr("uint16val", 0)
self._parent.set_attr("uint8val", 0)
-
+
self._parent.set_attr("int64val", 0)
self._parent.set_attr("int32val", 0)
self._parent.set_attr("int16val", 0)
self._parent.set_attr("int8val", 0)
-
+
self._parent_oid = self._agent.alloc_object_id(1)
self._parent.set_object_id(self._parent_oid)
-
- while True: # there may be a better way, but
- time.sleep(1000) # I'm a python noob...
+
+ # Now wait for events arriving on the connection
+ # to the broker...
+ while True:
+ time.sleep(1000)