diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
commit | 66765100f4257159622cefe57bed50125a5ad017 (patch) | |
tree | a88ee23bb194eb91f0ebb2d9b23ff423e3ea8e37 /qpid/cpp/bindings/qmf/tests | |
parent | 1aeaa7b16e5ce54f10c901d75c4d40f9f88b9db6 (diff) | |
parent | 88b98b2f4152ef59a671fad55a0d08338b6b78ca (diff) | |
download | qpid-python-rajith_jms_client.tar.gz |
Creating a branch for experimenting with some ideas for JMS client.rajith_jms_client
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/rajith_jms_client@1128369 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/bindings/qmf/tests')
-rw-r--r-- | qpid/cpp/bindings/qmf/tests/Makefile.am | 27 | ||||
-rwxr-xr-x | qpid/cpp/bindings/qmf/tests/agent_ruby.rb | 279 | ||||
-rw-r--r-- | qpid/cpp/bindings/qmf/tests/python_agent.py | 326 | ||||
-rwxr-xr-x | qpid/cpp/bindings/qmf/tests/python_console.py | 311 | ||||
-rwxr-xr-x | qpid/cpp/bindings/qmf/tests/ruby_console.rb | 174 | ||||
-rwxr-xr-x | qpid/cpp/bindings/qmf/tests/ruby_console_test.rb | 397 | ||||
-rwxr-xr-x | qpid/cpp/bindings/qmf/tests/run_interop_tests | 135 | ||||
-rw-r--r-- | qpid/cpp/bindings/qmf/tests/test_base.rb | 82 |
8 files changed, 1731 insertions, 0 deletions
diff --git a/qpid/cpp/bindings/qmf/tests/Makefile.am b/qpid/cpp/bindings/qmf/tests/Makefile.am new file mode 100644 index 0000000000..182771e16b --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/Makefile.am @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +TESTS = run_interop_tests + +EXTRA_DIST = \ + agent_ruby.rb \ + python_agent.py \ + python_console.py \ + ruby_console.rb \ + run_interop_tests diff --git a/qpid/cpp/bindings/qmf/tests/agent_ruby.rb b/qpid/cpp/bindings/qmf/tests/agent_ruby.rb new file mode 100755 index 0000000000..5ee5e371d3 --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/agent_ruby.rb @@ -0,0 +1,279 @@ +#!/usr/bin/ruby + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'qmf' +require 'socket' + +class Model + attr_reader :parent_class, :child_class, :event_class + + def initialize + @parent_class = Qmf::SchemaObjectClass.new("org.apache.qpid.qmf", "parent") + @parent_class.add_property(Qmf::SchemaProperty.new("name", Qmf::TYPE_SSTR, :index => true)) + @parent_class.add_property(Qmf::SchemaProperty.new("state", Qmf::TYPE_SSTR)) + + @parent_class.add_property(Qmf::SchemaProperty.new("uint64val", Qmf::TYPE_UINT64)) + @parent_class.add_property(Qmf::SchemaProperty.new("uint32val", Qmf::TYPE_UINT32)) + @parent_class.add_property(Qmf::SchemaProperty.new("uint16val", Qmf::TYPE_UINT16)) + @parent_class.add_property(Qmf::SchemaProperty.new("uint8val", Qmf::TYPE_UINT8)) + + @parent_class.add_property(Qmf::SchemaProperty.new("int64val", Qmf::TYPE_INT64)) + @parent_class.add_property(Qmf::SchemaProperty.new("int32val", Qmf::TYPE_INT32)) + @parent_class.add_property(Qmf::SchemaProperty.new("int16val", Qmf::TYPE_INT16)) + @parent_class.add_property(Qmf::SchemaProperty.new("int8val", Qmf::TYPE_INT8)) + + @parent_class.add_property(Qmf::SchemaProperty.new("sstrval", Qmf::TYPE_SSTR)) + @parent_class.add_property(Qmf::SchemaProperty.new("lstrval", Qmf::TYPE_LSTR)) + + @parent_class.add_property(Qmf::SchemaProperty.new("mapval", Qmf::TYPE_MAP)) + @parent_class.add_property(Qmf::SchemaProperty.new("listval", Qmf::TYPE_LIST)) + + @parent_class.add_statistic(Qmf::SchemaStatistic.new("queryCount", Qmf::TYPE_UINT32, :unit => "query", :desc => "Query count")) + + method = Qmf::SchemaMethod.new("echo", :desc => "Check responsiveness of the agent object") + method.add_argument(Qmf::SchemaArgument.new("sequence", Qmf::TYPE_UINT32, :dir => Qmf::DIR_IN_OUT)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("set_numerics", :desc => "Set the numeric values in the object") + method.add_argument(Qmf::SchemaArgument.new("test", Qmf::TYPE_SSTR, :dir => Qmf::DIR_IN)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("test_map_list", :desc => "A method call that accepts map and list arguments.") + method.add_argument(Qmf::SchemaArgument.new("inMap", Qmf::TYPE_MAP, :dir => Qmf::DIR_IN)) + method.add_argument(Qmf::SchemaArgument.new("inList", Qmf::TYPE_LIST, :dir => Qmf::DIR_IN)) + method.add_argument(Qmf::SchemaArgument.new("outMap", Qmf::TYPE_MAP, :dir => Qmf::DIR_OUT)) + method.add_argument(Qmf::SchemaArgument.new("outList", Qmf::TYPE_LIST, :dir => Qmf::DIR_OUT)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("set_short_string", :desc => "Set the short string value in the object") + method.add_argument(Qmf::SchemaArgument.new("value", Qmf::TYPE_SSTR, :dir => Qmf::DIR_IN_OUT)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("set_long_string", :desc => "Set the long string value in the object") + method.add_argument(Qmf::SchemaArgument.new("value", Qmf::TYPE_LSTR, :dir => Qmf::DIR_IN_OUT)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("create_child", :desc => "Create a new child object") + method.add_argument(Qmf::SchemaArgument.new("child_name", Qmf::TYPE_LSTR, :dir => Qmf::DIR_IN)) + method.add_argument(Qmf::SchemaArgument.new("child_ref", Qmf::TYPE_REF, :dir => Qmf::DIR_OUT)) + @parent_class.add_method(method) + + method = Qmf::SchemaMethod.new("probe_userid", :desc => "Return the user-id for this method call") + method.add_argument(Qmf::SchemaArgument.new("userid", Qmf::TYPE_SSTR, :dir => Qmf::DIR_OUT)) + @parent_class.add_method(method) + + @child_class = Qmf::SchemaObjectClass.new("org.apache.qpid.qmf", "child") + @child_class.add_property(Qmf::SchemaProperty.new("name", Qmf::TYPE_SSTR, :index => true)) + + @event_class = Qmf::SchemaEventClass.new("org.apache.qpid.qmf", "test_event", Qmf::SEV_INFORM) + @event_class.add_argument(Qmf::SchemaArgument.new("uint32val", Qmf::TYPE_UINT32)) + @event_class.add_argument(Qmf::SchemaArgument.new("strval", Qmf::TYPE_LSTR)) + @event_class.add_argument(Qmf::SchemaArgument.new("mapval", Qmf::TYPE_MAP)) + @event_class.add_argument(Qmf::SchemaArgument.new("listval", Qmf::TYPE_LIST)) + end + + def register(agent) + agent.register_class(@parent_class) + agent.register_class(@child_class) + agent.register_class(@event_class) + end +end + + +class App < Qmf::AgentHandler + def get_query(context, query, userId) +# puts "Query: user=#{userId} context=#{context} class=#{query.class_name} object_num=#{query.object_id if query.object_id}" + if query.class_name == 'parent' + @agent.query_response(context, @parent) + elsif query.object_id == @parent_oid + @agent.query_response(context, @parent) + end + @agent.query_complete(context) + end + + def method_call(context, name, object_id, args, userId) +# puts "Method: user=#{userId} context=#{context} method=#{name} object_num=#{object_id if object_id} args=#{args}" + + retCode = 0 + retText = "OK" + + if name == "echo" + @agent.method_response(context, 0, "OK", args) + + elsif name == "test_map_list" + # build the output map from the input map, accessing each key, + # value to ensure they are encoded/decoded + outMap = {} + args['inMap'].each do |k,v| + outMap[k] = v + end + + # same deal for the output list + outList = [] + args['inList'].each do |v| + outList << v + end + + args['outMap'] = outMap + args['outList'] = outList + + elsif name == "set_numerics" + + if args['test'] == "big" + @parent.uint64val = 0x9494949449494949 + @parent.uint32val = 0xa5a55a5a + @parent.uint16val = 0xb66b + @parent.uint8val = 0xc7 + + @parent.int64val = 1000000000000000000 + @parent.int32val = 1000000000 + @parent.int16val = 10000 + @parent.int8val = 100 + + event = Qmf::QmfEvent.new(@model.event_class) + event.uint32val = @parent.uint32val + event.strval = "Unused" + event.mapval = @parent.mapval + event.listval = @parent.listval + @agent.raise_event(event) + + elsif args['test'] == "small" + @parent.uint64val = 4 + @parent.uint32val = 5 + @parent.uint16val = 6 + @parent.uint8val = 7 + + @parent.int64val = 8 + @parent.int32val = 9 + @parent.int16val = 10 + @parent.int8val = 11 + + event = Qmf::QmfEvent.new(@model.event_class) + event.uint32val = @parent.uint32val + event.strval = "Unused" + @agent.raise_event(event) + + elsif args['test'] == "negative" + @parent.uint64val = 0 + @parent.uint32val = 0 + @parent.uint16val = 0 + @parent.uint8val = 0 + + @parent.int64val = -10000000000 + @parent.int32val = -100000 + @parent.int16val = -1000 + @parent.int8val = -100 + + event = Qmf::QmfEvent.new(@model.event_class) + event.uint32val = @parent.uint32val + event.strval = "Unused" + @agent.raise_event(event) + + else + retCode = 1 + retText = "Invalid argument value for test" + end + + elsif name == "set_short_string" + @parent.sstrval = args['value'] + + event = Qmf::QmfEvent.new(@model.event_class) + event.uint32val = 0 + event.strval = @parent.sstrval + @agent.raise_event(event) + + elsif name == "set_long_string" + @parent.lstrval = args['value'] + + event = Qmf::QmfEvent.new(@model.event_class) + event.uint32val = 0 + event.strval = @parent.lstrval + @agent.raise_event(event) + + elsif name == "create_child" + oid = @agent.alloc_object_id(2) + args['child_ref'] = oid + @child = Qmf::AgentObject.new(@model.child_class) + @child.name = args.by_key("child_name") + @child.set_object_id(oid) + + elsif name == "probe_userid" + args['userid'] = userId + + else + retCode = 1 + retText = "Unimplemented Method: #{name}" + end + + @agent.method_response(context, retCode, retText, args) + end + + def main + @settings = Qmf::ConnectionSettings.new + @settings.set_attr("host", ARGV[0]) if ARGV.size > 0 + @settings.set_attr("port", ARGV[1].to_i) if ARGV.size > 1 + @connection = Qmf::Connection.new(@settings) + @agent = Qmf::Agent.new(self, "agent_test_label") + + @model = Model.new + @model.register(@agent) + + @agent.set_connection(@connection) + + @parent = Qmf::AgentObject.new(@model.parent_class) + @parent.name = "Parent One" + @parent.state = "OPERATIONAL" + + @parent.uint64val = 0 + @parent.uint32val = 0 + @parent.uint16val = 0 + @parent.uint8val = 0 + + @parent.int64val = 0 + @parent.int32val = 0 + @parent.int16val = 0 + @parent.int8val = 0 + + # a list containing a list that contains a map (so there!) + @parent.listval = ['a', 1, 'b', -2, + ['c', true, 3.1415, + {"hi" => 10, "lo" => 5, "neg" => -3}]] + + # a default map + @parent.mapval = {'aLong' => 9999999999, + 'aInt' => 54321, + 'aSigned' => -666, + 'aString' => "A String", + 'aFloat'=> 3.1415, + 'aMap' => {"first" => 1, "second" => 2}, + 'aList' => ['x', -1, 'y', 2]} + + @parent_oid = @agent.alloc_object_id(1) + @parent.set_object_id(@parent_oid) + + sleep + end +end + +app = App.new +app.main + + diff --git a/qpid/cpp/bindings/qmf/tests/python_agent.py b/qpid/cpp/bindings/qmf/tests/python_agent.py new file mode 100644 index 0000000000..28ba47e1bb --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/python_agent.py @@ -0,0 +1,326 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +import qmf +import sys +import time + + +class Model: + # attr_reader :parent_class, :child_class + def __init__(self): + 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_property(qmf.SchemaProperty("sstrval", qmf.TYPE_SSTR)) + self.parent_class.add_property(qmf.SchemaProperty("lstrval", qmf.TYPE_LSTR)) + + self.parent_class.add_property(qmf.SchemaProperty("mapval", qmf.TYPE_MAP)) + self.parent_class.add_property(qmf.SchemaProperty("listval", qmf.TYPE_LIST)) + + + 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("test_map_list", {"desc":"A method call that accepts map and list arguments."}) + _method.add_argument(qmf.SchemaArgument("inMap", qmf.TYPE_MAP, {"dir":qmf.DIR_IN})) + _method.add_argument(qmf.SchemaArgument("inList", qmf.TYPE_LIST, {"dir":qmf.DIR_IN})) + _method.add_argument(qmf.SchemaArgument("outMap", qmf.TYPE_MAP, {"dir":qmf.DIR_OUT})) + _method.add_argument(qmf.SchemaArgument("outList", qmf.TYPE_LIST, {"dir":qmf.DIR_OUT})) + self.parent_class.add_method(_method) + + _method = qmf.SchemaMethod("set_short_string", {"desc":"Set the short string value in the object"}) + _method.add_argument(qmf.SchemaArgument("value", qmf.TYPE_SSTR, {"dir":qmf.DIR_IN_OUT})) + self.parent_class.add_method(_method) + + _method = qmf.SchemaMethod("set_long_string", {"desc":"Set the long string value in the object"}) + _method.add_argument(qmf.SchemaArgument("value", qmf.TYPE_LSTR, {"dir":qmf.DIR_IN_OUT})) + 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})) + + self.event_class = qmf.SchemaEventClass("org.apache.qpid.qmf", "test_event", qmf.SEV_NOTICE) + self.event_class.add_argument(qmf.SchemaArgument("uint32val", qmf.TYPE_UINT32)) + self.event_class.add_argument(qmf.SchemaArgument("strval", qmf.TYPE_LSTR)) + self.event_class.add_argument(qmf.SchemaArgument("mapval", qmf.TYPE_MAP)) + self.event_class.add_argument(qmf.SchemaArgument("listval", qmf.TYPE_LIST)) + + def register(self, agent): + agent.register_class(self.parent_class) + agent.register_class(self.child_class) + agent.register_class(self.event_class) + + + +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() + self._parent.inc_attr("queryCount") + if query.class_name() == 'parent': + self._agent.query_response(context, self._parent) + elif query.object_id() == self._parent_oid: + self._agent.query_response(context, self._parent) + self._agent.query_complete(context) + + + def method_call(self, context, name, object_id, args, userId): + ''' + 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 == "test_map_list": + # build the output map from the input map, accessing each key, + # value to ensure they are encoded/decoded + outMap = {} + for key,value in args['inMap'].items(): + outMap[key] = value + + # same deal for the output list + outList = [] + for value in args['inList']: + outList.append(value) + + args['outMap'] = outMap + args['outList'] = outList + 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.uint32val = 0xa5a55a5a + self._parent.set_attr("uint16val", 0xb66b) + self._parent["uint8val"] = 0xc7 + + self._parent.int64val = 1000000000000000000 + self._parent.set_attr("int32val", 1000000000) + self._parent["int16val"] = 10000 + self._parent.set_attr("int8val", 100) + + event = qmf.QmfEvent(self._model.event_class) + event.uint32val = self._parent.get_attr("uint32val") + event.strval = "Unused" + event.mapval = self._parent.get_attr("mapval") + event.listval = self._parent["listval"] + + self._agent.raise_event(event) + + ## 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 + + # 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) + + event = qmf.QmfEvent(self._model.event_class) + event.uint32val = self._parent.uint32val + event.strval = "Unused" + self._agent.raise_event(event) + + 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) + + event = qmf.QmfEvent(self._model.event_class) + event.uint32val = self._parent.uint32val + event.strval = "Unused" + self._agent.raise_event(event) + + else: + _retCode = 1 + _retText = "Invalid argument value for test" + + self._agent.method_response(context, _retCode, _retText, args) + + elif name == "set_short_string": + self._parent.set_attr('sstrval', args['value']) + event = qmf.QmfEvent(self._model.event_class) + event.uint32val = 0 + event.strval = self._parent.sstrval + self._agent.raise_event(event) + + self._agent.method_response(context, 0, "OK", args) + + elif name == "set_long_string": + self._parent.set_attr('lstrval', args['value']) + event = qmf.QmfEvent(self._model.event_class) + event.uint32val = 0 + event.strval = self._parent.lstrval + self._agent.raise_event(event) + + self._agent.method_response(context, 0, "OK", 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.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.host = str(sys.argv[1]) + if len(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, "agent_test_label") + + # 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) + + # 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()) == 14 + 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) + + # a list containing a list that contains a map (so there!) + self._parent.set_attr("listval", ['a', 1, 'b', -2, + ['c', True, 3.1415, + {"hi": 10, "lo": 5, "neg": -3}]]) + # a default map + self._parent.set_attr("mapval", {'aLong' : long(9999999999), + 'aInt' : int(54321), + 'aSigned' : -666, + 'aString' : "A String", + 'aFloat' : 3.1415, + 'aMap' : {'first' : 1, + 'second': 2}, + 'aList' : ['x', -1, 'y', 2]}) + + + + self._parent_oid = self._agent.alloc_object_id(1) + self._parent.set_object_id(self._parent_oid) + + # Now wait for events arriving on the connection + # to the broker... + while True: + time.sleep(1000) + + + +app = App() +app.main() + diff --git a/qpid/cpp/bindings/qmf/tests/python_console.py b/qpid/cpp/bindings/qmf/tests/python_console.py new file mode 100755 index 0000000000..1cef824fb5 --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/python_console.py @@ -0,0 +1,311 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import sys +from qpid.testlib import TestBase010 +from qpid.datatypes import Message +from qpid.queue import Empty +from time import sleep +import qmf.console + +class QmfInteropTests(TestBase010): + + def test_A_agent_presence(self): + self.startQmf(); + qmf = self.qmf + + agents = [] + count = 0 + while len(agents) == 0: + agents = qmf.getObjects(_class="agent") + sleep(1) + count += 1 + if count > 10: + self.fail("Timed out waiting for remote agent") + + def test_B_basic_method_invocation(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + for seq in range(10): + result = parent.echo(seq, _timeout=5) + self.assertEqual(result.status, 0) + self.assertEqual(result.text, "OK") + self.assertEqual(result.sequence, seq) + + result = parent.set_numerics("bogus") + self.assertEqual(result.status, 1) + self.assertEqual(result.text, "Invalid argument value for test") + + def test_C_basic_types_numeric_big(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + result = parent.set_numerics("big") + self.assertEqual(result.status, 0) + self.assertEqual(result.text, "OK") + + parent.update() + + self.assertEqual(parent.uint64val, 0x9494949449494949) + self.assertEqual(parent.uint32val, 0xA5A55A5A) + self.assertEqual(parent.uint16val, 0xB66B) + self.assertEqual(parent.uint8val, 0xC7) + + self.assertEqual(parent.int64val, 1000000000000000000) + self.assertEqual(parent.int32val, 1000000000) + self.assertEqual(parent.int16val, 10000) + self.assertEqual(parent.int8val, 100) + + def test_C_basic_types_numeric_small(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + result = parent.set_numerics("small") + self.assertEqual(result.status, 0) + self.assertEqual(result.text, "OK") + + parent.update() + + self.assertEqual(parent.uint64val, 4) + self.assertEqual(parent.uint32val, 5) + self.assertEqual(parent.uint16val, 6) + self.assertEqual(parent.uint8val, 7) + + self.assertEqual(parent.int64val, 8) + self.assertEqual(parent.int32val, 9) + self.assertEqual(parent.int16val, 10) + self.assertEqual(parent.int8val, 11) + + def test_C_basic_types_numeric_negative(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + result = parent.set_numerics("negative") + self.assertEqual(result.status, 0) + self.assertEqual(result.text, "OK") + + parent.update() + + self.assertEqual(parent.uint64val, 0) + self.assertEqual(parent.uint32val, 0) + self.assertEqual(parent.uint16val, 0) + self.assertEqual(parent.uint8val, 0) + + self.assertEqual(parent.int64val, -10000000000) + self.assertEqual(parent.int32val, -100000) + self.assertEqual(parent.int16val, -1000) + self.assertEqual(parent.int8val, -100) + + def disabled_test_D_userid_for_method(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + result = parent.probe_userid() + self.assertEqual(result.status, 0) + self.assertEqual(result.userid, "guest") + + def test_D_get_by_object_id(self): + self.startQmf() + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + newList = qmf.getObjects(_objectId=parent.getObjectId()) + self.assertEqual(len(newList), 1) + + def test_E_filter_by_object_id(self): + self.startQmf() + qmf = self.qmf + + list = qmf.getObjects(_class="exchange", name="qpid.management") + self.assertEqual(len(list), 1, "No Management Exchange") + mgmt_exchange = list[0] + + bindings = qmf.getObjects(_class="binding", exchangeRef=mgmt_exchange.getObjectId()) + if len(bindings) == 0: + self.fail("No bindings found on management exchange") + + for binding in bindings: + self.assertEqual(binding.exchangeRef, mgmt_exchange.getObjectId()) + + def test_F_events(self): + class Handler(qmf.console.Console): + def __init__(self): + self.queue = [] + + def event(self, broker, event): + if event.getClassKey().getClassName() == "test_event": + self.queue.append(event) + + handler = Handler() + self.startQmf(handler) + + parents = self.qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + parent.set_numerics("big") + parent.set_numerics("small") + parent.set_numerics("negative") + parent.set_short_string("TEST") + parent.set_long_string("LONG_TEST") + parent.probe_userid() + + queue = handler.queue + self.assertEqual(len(queue), 5) + self.assertEqual(queue[0].arguments["uint32val"], 0xA5A55A5A) + self.assertEqual(queue[0].arguments["strval"], "Unused") + + # verify map and list event content. + # see agent for structure of listval and mapval + listval = queue[0].arguments["listval"] + self.assertTrue(isinstance(listval, list)) + self.assertEqual(len(listval), 5) + self.assertTrue(isinstance(listval[4], list)) + self.assertEqual(len(listval[4]), 4) + self.assertTrue(isinstance(listval[4][3], dict)) + self.assertEqual(listval[4][3]["hi"], 10) + self.assertEqual(listval[4][3]["lo"], 5) + self.assertEqual(listval[4][3]["neg"], -3) + + mapval = queue[0].arguments["mapval"] + self.assertTrue(isinstance(mapval, dict)) + self.assertEqual(len(mapval), 7) + self.assertEqual(mapval['aLong'], 9999999999) + self.assertEqual(mapval['aInt'], 54321) + self.assertEqual(mapval['aSigned'], -666) + self.assertEqual(mapval['aString'], "A String"), + self.assertEqual(mapval['aFloat'], 3.1415), + self.assertTrue(isinstance(mapval['aMap'], dict)) + self.assertEqual(len(mapval['aMap']), 2) + self.assertEqual(mapval['aMap']['second'], 2) + self.assertTrue(isinstance(mapval['aList'], list)) + self.assertEqual(len(mapval['aList']), 4) + self.assertEqual(mapval['aList'][1], -1) + + self.assertEqual(queue[1].arguments["uint32val"], 5) + self.assertEqual(queue[1].arguments["strval"], "Unused") + self.assertEqual(queue[2].arguments["uint32val"], 0) + self.assertEqual(queue[2].arguments["strval"], "Unused") + self.assertEqual(queue[3].arguments["uint32val"], 0) + self.assertEqual(queue[3].arguments["strval"], "TEST") + self.assertEqual(queue[4].arguments["uint32val"], 0) + self.assertEqual(queue[4].arguments["strval"], "LONG_TEST") + + + + def test_G_basic_map_list_data(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + # see agent for structure of listval + + self.assertTrue(isinstance(parent.listval, list)) + self.assertEqual(len(parent.listval), 5) + self.assertTrue(isinstance(parent.listval[4], list)) + self.assertEqual(len(parent.listval[4]), 4) + self.assertTrue(isinstance(parent.listval[4][3], dict)) + self.assertEqual(parent.listval[4][3]["hi"], 10) + self.assertEqual(parent.listval[4][3]["lo"], 5) + self.assertEqual(parent.listval[4][3]["neg"], -3) + + # see agent for structure of mapval + + self.assertTrue(isinstance(parent.mapval, dict)) + self.assertEqual(len(parent.mapval), 7) + self.assertEqual(parent.mapval['aLong'], 9999999999) + self.assertEqual(parent.mapval['aInt'], 54321) + self.assertEqual(parent.mapval['aSigned'], -666) + self.assertEqual(parent.mapval['aString'], "A String"), + self.assertEqual(parent.mapval['aFloat'], 3.1415), + self.assertTrue(isinstance(parent.mapval['aMap'], dict)) + self.assertEqual(len(parent.mapval['aMap']), 2) + self.assertEqual(parent.mapval['aMap']['second'], 2) + self.assertTrue(isinstance(parent.mapval['aList'], list)) + self.assertEqual(len(parent.mapval['aList']), 4) + self.assertEqual(parent.mapval['aList'][1], -1) + + def test_H_map_list_method_call(self): + self.startQmf(); + qmf = self.qmf + + parents = qmf.getObjects(_class="parent") + self.assertEqual(len(parents), 1) + parent = parents[0] + + inMap = {'aLong' : long(9999999999), + 'aInt' : int(54321), + 'aSigned' : -666, + 'aString' : "A String", + 'aFloat' : 3.1415, + 'aList' : ['x', -1, 'y', 2], + 'abool' : False} + inList = ['aString', long(1), -1, 2.7182, {'aMap': -8}, True] + + result = parent.test_map_list(inMap, inList) + self.assertEqual(result.status, 0) + self.assertEqual(result.text, "OK") + + # verify returned values + self.assertEqual(len(inMap), len(result.outArgs['outMap'])) + for key,value in result.outArgs['outMap'].items(): + self.assertEqual(inMap[key], value) + + self.assertEqual(len(inList), len(result.outArgs['outList'])) + for idx in range(len(inList)): + self.assertEqual(inList[idx], result.outArgs['outList'][idx]) + + + def getProperty(self, msg, name): + for h in msg.headers: + if hasattr(h, name): return getattr(h, name) + return None + + def getAppHeader(self, msg, name): + headers = self.getProperty(msg, "application_headers") + if headers: + return headers[name] + return None diff --git a/qpid/cpp/bindings/qmf/tests/ruby_console.rb b/qpid/cpp/bindings/qmf/tests/ruby_console.rb new file mode 100755 index 0000000000..31670312d6 --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/ruby_console.rb @@ -0,0 +1,174 @@ +#!/usr/bin/ruby + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'qmf' +require 'socket' + +class App < Qmf::ConsoleHandler + + def agent_added(agent) + puts "AgentAdded: label=#{agent.label} key=#{agent.key}" + end + + def agent_deleted(agent) + puts "AgentDeleted: #{agent.label}" + end + + def new_package(package) + puts "NewPackage: #{package}" + end + + def new_class(class_key) + puts "NewClass: #{class_key}" + end + + def object_update(object, hasProps, hasStats) + puts "ObjectUpdate: #{object.object_class.class_name} props=#{hasProps} stats=#{hasStats}" + puts " agent-key=#{object.object_id.agent_key}" + puts " package=#{object.object_class.package_name}" + end + + def event_received(event); end + + def agent_heartbeat(agent, timestamp) + puts "AgentHeartbeat: #{agent.label} time=#{timestamp/1000000000}" + end + + def method_response(resp); end + def broker_info(broker); end + + + def dump_schema + packages = @qmfc.packages + puts "----- Packages -----" + packages.each do |p| + puts p + puts " ----- Object Classes -----" + classes = @qmfc.classes(p) + classes.each do |c| + puts " #{c.name}" + + puts " ---- Properties ----" + props = c.properties + props.each do |prop| + puts " #{prop.name}" + end + + puts " ---- Statistics ----" + stats = c.statistics + stats.each do |stat| + puts " #{stat.name}" + end + + puts " ---- Methods ----" + methods = c.methods + methods.each do |method| + puts " #{method.name}" + puts " ---- Args ----" + args = method.arguments + args.each do |arg| + puts " #{arg.name}" + end + end + end + + puts " ----- Event Classes -----" + classes = @qmfc.classes(p, Qmf::CLASS_EVENT) + classes.each do |c| + puts " #{c.name}" + puts " ---- Args ----" + args = c.arguments + args.each do |arg| + puts " #{arg.name}" + end + end + end + puts "-----" + end + + def main + @settings = Qmf::ConnectionSettings.new + @settings.host = ARGV[0] if ARGV.size > 0 + @settings.port = ARGV[1].to_i if ARGV.size > 1 + @connection = Qmf::Connection.new(@settings) + @qmfc = Qmf::Console.new(self) + + @broker = @qmfc.add_connection(@connection) + @broker.wait_for_stable + + ##dump_schema + + agents = @qmfc.agents() + puts "---- Agents ----" + agents.each do |a| + puts " => #{a.label}" + end + puts "----" + + for idx in 0...20 + blist = @qmfc.objects(Qmf::Query.new(:class => "broker")) + puts "---- Brokers ----" + blist.each do |b| + puts " ---- Broker ----" + puts " systemRef: #{b.systemRef}" + puts " port : #{b.port}" + puts " uptime : #{b.uptime / 1000000000}" + puts " properties : #{b.properties}" + puts " statistics : #{b.statistics}" + + for rep in 0...1 + puts " Pinging..." + ret = b.echo(45, 'text string') + puts " status=#{ret.status} text=#{ret.exception.asString} seq=#{ret.args.sequence} body=#{ret.args.body}" + end + end + puts "----" + + elist = @qmfc.objects(:package => "org.apache.qpid.broker", :class => "exchange", 'durable' => true) + puts "---- Durable Exchanges ----" + elist.each do |e| + puts "Exchange: #{e.name}" + end + puts "----" + + qlist = @qmfc.objects(Qmf::Query.new(:package => "org.apache.qpid.broker", + :class => "queue")) + puts "---- Queues ----" + qlist.each do |q| + puts " ---- Queue ----" + puts " name : #{q.name}" + end + puts "----" + sleep(5) + end + + sleep(5) + puts "Deleting connection..." + @qmfc.del_connection(@broker) + puts " done" + sleep + end +end + +app = App.new +app.main + + diff --git a/qpid/cpp/bindings/qmf/tests/ruby_console_test.rb b/qpid/cpp/bindings/qmf/tests/ruby_console_test.rb new file mode 100755 index 0000000000..972d5977b8 --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/ruby_console_test.rb @@ -0,0 +1,397 @@ +#!/usr/bin/ruby + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'test_base' + +class ConsoleTest < ConsoleTestBase + + def test_A_agent_presence + assert(@connection.connected?, "Connection not connected") + + agents = [] + count = 0 + while agents.size == 0 + agents = @qmfc.objects(Qmf::Query.new(:class => "agent")) + sleep(1) + count += 1 + fail("Timed out waiting for remote agent") if count > 10 + end + + agentList = @qmfc.agents + assert_equal(agentList.size, 2, "Number of agents reported by Console") + end + + def test_A_connection_settings + begin + @settings.bogusAttribute = 25 + fail("Connection settings accepted bogus attribute") + rescue + end + end + + def test_B_basic_method_invocation + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of 'parent' objects") + for seq in 0...10 + result = parent.echo(seq) + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.text, "OK", "Method Response Text") + assert_equal(result.args.sequence, seq, "Echo Response Sequence") + end + + result = parent.set_numerics("bogus") + assert_equal(result.status, 1) + assert_equal(result.text, "Invalid argument value for test") + end + + def test_C_basic_types_numeric_big + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + result = parent.set_numerics("big") + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.text, "OK", "Method Response Text") + + parent.update + + assert_equal(parent.uint64val, 0x9494949449494949) + assert_equal(parent.uint32val, 0xA5A55A5A) + assert_equal(parent.uint16val, 0xB66B) + assert_equal(parent.uint8val, 0xC7) + + assert_equal(parent.int64val, 1000000000000000000) + assert_equal(parent.int32val, 1000000000) + assert_equal(parent.int16val, 10000) + assert_equal(parent.int8val, 100) + end + + def test_C_basic_types_numeric_small + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + result = parent.set_numerics("small") + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.text, "OK", "Method Response Text") + + parent.update + + assert_equal(parent.uint64val, 4) + assert_equal(parent.uint32val, 5) + assert_equal(parent.uint16val, 6) + assert_equal(parent.uint8val, 7) + + assert_equal(parent.int64val, 8) + assert_equal(parent.int32val, 9) + assert_equal(parent.int16val, 10) + assert_equal(parent.int8val, 11) + end + + def test_C_basic_types_numeric_negative + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + result = parent.set_numerics("negative") + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.text, "OK", "Method Response Text") + + parent.update + + assert_equal(parent.uint64val, 0) + assert_equal(parent.uint32val, 0) + assert_equal(parent.uint16val, 0) + assert_equal(parent.uint8val, 0) + + assert_equal(parent.int64val, -10000000000) + assert_equal(parent.int32val, -100000) + assert_equal(parent.int16val, -1000) + assert_equal(parent.int8val, -100) + end + + def test_C_basic_types_string_short + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + strings = [] + strings << "" + strings << "A" + strings << "BC" + strings << "DEF" + strings << "GHIJKLMNOPQRSTUVWXYZ" + big = "a" + for i in 0...254 + big << "X" + end + strings << big + + strings.each do |str| + result = parent.set_short_string(str) + assert_equal(result.status, 0, "Method Response Status") + compare = str + compare = compare[0..254] if compare.size > 255 + assert_equal(result.args.value, compare, "Value returned by method") + parent.update + assert_equal(parent.sstrval, compare, "Value stored in the object") + end + end + + def test_C_basic_types_string_long + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + strings = [] + strings << "" + strings << "A" + strings << "BC" + strings << "DEF" + strings << "GHIJKLMNOPQRSTUVWXYZ" + big = "a" + for i in 0...270 + big << "X" + end + strings << big + + strings.each do |str| + result = parent.set_long_string(str) + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.args.value, str, "Value returned by method") + parent.update + assert_equal(parent.lstrval, str, "Value stored in the object") + end + end + + def test_D_userid_for_method + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of parent objects") + + result = parent.probe_userid + assert_equal(result.status, 0, "Method Response Status") + assert_equal(result.args.userid, "anonymous") + end + + def test_D_get_by_object_id + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of parent objects") + + list = @qmfc.objects(:object_id => parent.object_id) + assert_equal(list.size, 1) + + bad_oid = Qmf::ObjectId.new + list = @qmfc.objects(:object_id => bad_oid) + assert_equal(list.size, 0) + + # TODO: test a bad_oid that has an agent-bank that is not associated with an attached agent. + + end + + def test_D_get_with_agent + agents = @qmfc.agents + agents.each do |agent| + if agent.label == "agent_test_label" + parent = @qmfc.object(:class => "parent", :agent => agent) + assert(parent, "Number of parent objects") + return + end + end + + fail("Didn't find a non-broker agent") + end + + def test_E_filter_by_object_id + mgmt_exchange = @qmfc.object(:class => "exchange", 'name' => "qpid.management") + assert(mgmt_exchange, "No Management Exchange") + + bindings = @qmfc.objects(:class => "binding", 'exchangeRef' => mgmt_exchange.object_id) + if bindings.size == 0 + fail("No bindings found on management exchange") + end + + bindings.each do |binding| + assert_equal(binding.exchangeRef, mgmt_exchange.object_id) + end + end + + + def test_F_events + + @event_list.clear + @store_events = :true + + parent = @qmfc.object(:class =>"parent") + assert(parent, "Number of parent objects") + + parent.set_numerics("big") + parent.set_numerics("small") + parent.set_numerics("negative") + parent.set_short_string("TEST") + parent.set_long_string("LONG_TEST") + parent.probe_userid() + + @store_events = :false + + assert_equal(@event_list.length, 5) + + assert_equal(@event_list[0].get_attr("uint32val"), 0xA5A55A5A) + assert_equal(@event_list[0].get_attr("strval"), "Unused") + + # verify map and list event content. + # see agent for structure of listval and mapval + + listval = @event_list[0].listval + assert(listval.class == Array) + assert_equal(listval.length, 5) + assert(listval[4].class == Array) + assert_equal(listval[4].length, 4) + assert(listval[4][3].class == Hash) + assert_equal(listval[4][3]["hi"], 10) + assert_equal(listval[4][3]["lo"], 5) + assert_equal(listval[4][3]["neg"], -3) + + mapval = @event_list[0].mapval + assert(mapval.class == Hash) + assert_equal(mapval.length, 7) + assert_equal(mapval['aLong'], 9999999999) + assert_equal(mapval['aInt'], 54321) + assert_equal(mapval['aSigned'], -666) + assert_equal(mapval['aString'], "A String") + assert_equal(mapval['aFloat'], 3.1415) + assert(mapval['aMap'].class == Hash) + assert_equal(mapval['aMap'].length, 2) + assert_equal(mapval['aMap']['second'], 2) + assert(mapval['aList'].class == Array) + assert_equal(mapval['aList'].length, 4) + assert_equal(mapval['aList'][1], -1) + + assert_equal(@event_list[1]["uint32val"], 5) + assert_equal(@event_list[1].get_attr("strval"), "Unused") + assert_equal(@event_list[2].get_attr("uint32val"), 0) + assert_equal(@event_list[2].get_attr("strval"), "Unused") + assert_equal(@event_list[3].get_attr("uint32val"), 0) + assert_equal(@event_list[3].get_attr("strval"), "TEST") + assert_equal(@event_list[4].get_attr("uint32val"), 0) + assert_equal(@event_list[4].get_attr("strval"), "LONG_TEST") + + @event_list.clear + + end + + def test_G_basic_map_list_data + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of 'parent' objects") + + # see agent for structure of listval + + assert(parent.listval.class == Array) + assert_equal(parent.listval.length, 5) + assert(parent.listval[4].class == Array) + assert_equal(parent.listval[4].length, 4) + assert(parent.listval[4][3].class == Hash) + assert_equal(parent.listval[4][3]["hi"], 10) + assert_equal(parent.listval[4][3]["lo"], 5) + assert_equal(parent.listval[4][3]["neg"], -3) + + # see agent for structure of mapval + + assert(parent.mapval.class == Hash) + assert_equal(parent.mapval.length, 7) + assert_equal(parent.mapval['aLong'], 9999999999) + assert_equal(parent.mapval['aInt'], 54321) + assert_equal(parent.mapval['aSigned'], -666) + assert_equal(parent.mapval['aString'], "A String") + assert_equal(parent.mapval['aFloat'], 3.1415) + assert(parent.mapval['aMap'].class == Hash) + assert_equal(parent.mapval['aMap'].length, 2) + assert_equal(parent.mapval['aMap']['second'], 2) + assert(parent.mapval['aList'].class == Array) + assert_equal(parent.mapval['aList'].length, 4) + assert_equal(parent.mapval['aList'][1], -1) + end + + def test_H_map_list_method_call + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of 'parent' objects") + + inMap = {'aLong' => 9999999999, + 'aInt' => 54321, + 'aSigned' => -666, + 'aString' => "A String", + 'aFloat' => 3.1415, + 'aList' => ['x', -1, 'y', 2], + 'abool' => false} + + inList = ['aString', 1, -1, 2.7182, {'aMap'=> -8}, true] + + result = parent.test_map_list(inMap, inList) + assert_equal(result.status, 0) + assert_equal(result.text, "OK") + + # verify returned values + assert_equal(inMap.length, result.args['outMap'].length) + result.args['outMap'].each do |k,v| + assert_equal(inMap[k], v) + end + + assert_equal(inList.length, result.args['outList'].length) + for idx in 0...inList.length + assert_equal(inList[idx], result.args['outList'][idx]) + end + end + + def test_H_map_list_method_call_big + parent = @qmfc.object(:class => "parent") + assert(parent, "Number of 'parent' objects") + + big_string = "" + segment = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + for idx in 1...1500 + big_string = big_string + segment + end + + inMap = {'aLong' => 9999999999, + 'aInt' => 54321, + 'aSigned' => -666, + 'aString' => big_string, + 'another' => big_string, + 'aFloat' => 3.1415, + 'aList' => ['x', -1, 'y', 2], + 'abool' => false} + + inList = ['aString', 1, -1, 2.7182, {'aMap'=> -8}, true] + + result = parent.test_map_list(inMap, inList) + assert_equal(result.status, 0) + assert_equal(result.text, "OK") + + # verify returned values + assert_equal(inMap.length, result.args['outMap'].length) + result.args['outMap'].each do |k,v| + assert_equal(inMap[k], v) + end + + assert_equal(inList.length, result.args['outList'].length) + for idx in 0...inList.length + assert_equal(inList[idx], result.args['outList'][idx]) + end + end + +end + +app = ConsoleTest.new + diff --git a/qpid/cpp/bindings/qmf/tests/run_interop_tests b/qpid/cpp/bindings/qmf/tests/run_interop_tests new file mode 100755 index 0000000000..83e7f2593b --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/run_interop_tests @@ -0,0 +1,135 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Run the qmf interoperability tests. +MY_DIR=`dirname \`which $0\`` +QPID_DIR=${MY_DIR}/../../../.. +BUILD_DIR=../../.. +PYTHON_DIR=${QPID_DIR}/python +QMF_DIR=${QPID_DIR}/extras/qmf +QMF_DIR_PY=${QMF_DIR}/src/py +BROKER_DIR=${BUILD_DIR}/src +API_DIR=${BUILD_DIR}/bindings/qmf +SPEC_DIR=${QPID_DIR}/specs + +RUBY_LIB_DIR=${API_DIR}/ruby/.libs +PYTHON_LIB_DIR=${API_DIR}/python/.libs + +trap stop_broker INT TERM QUIT + +start_broker() { + ${BROKER_DIR}/qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no > _qpidd.port + BROKER_PORT=`cat _qpidd.port` +} + +stop_broker() { + ${BROKER_DIR}/qpidd -q --port $BROKER_PORT + echo "Broker stopped" +} + +start_ruby_agent() { + ruby -I${MY_DIR}/../ruby -I${RUBY_LIB_DIR} ${MY_DIR}/agent_ruby.rb localhost $BROKER_PORT & + AGENT_PID=$! +} + +stop_ruby_agent() { + kill $AGENT_PID +} + +start_python_agent() { + PYTHONPATH="${MY_DIR}/../python:${API_DIR}/python:${PYTHON_LIB_DIR}" python ${MY_DIR}/python_agent.py localhost $BROKER_PORT & + PY_AGENT_PID=$! +} + +stop_python_agent() { + kill $PY_AGENT_PID +} + +TESTS_FAILED=0 + +if test -d ${PYTHON_DIR} ; then + start_broker + echo "Running qmf interop tests using broker on port $BROKER_PORT" + PYTHONPATH=${PYTHON_DIR}:${QMF_DIR_PY}:${MY_DIR} + export PYTHONPATH + + if test -d ${PYTHON_LIB_DIR} ; then + echo " Python Agent (external storage) vs. Pure-Python Console" + start_python_agent + echo " Python agent started at pid $PY_AGENT_PID" + ${PYTHON_DIR}/qpid-python-test -m python_console -b localhost:$BROKER_PORT $@ + RETCODE=$? + stop_python_agent + if test x$RETCODE != x0; then + echo "FAIL qmf interop tests (Python Agent)"; + TESTS_FAILED=1 + fi + fi + + if test -d ${RUBY_LIB_DIR} ; then + echo " Ruby Agent (external storage) vs. Pure-Python Console" + start_ruby_agent + echo " Ruby agent started at pid $AGENT_PID" + ${PYTHON_DIR}/qpid-python-test -m python_console -b localhost:$BROKER_PORT $@ + RETCODE=$? + if test x$RETCODE != x0; then + echo "FAIL qmf interop tests (Ruby Agent)"; + TESTS_FAILED=1 + fi + + echo " Ruby Agent (external storage) vs. Ruby Console" + ruby -I${MY_DIR} -I${MY_DIR}/../ruby -I${RUBY_LIB_DIR} ${MY_DIR}/ruby_console_test.rb localhost $BROKER_PORT $@ + RETCODE=$? + stop_ruby_agent + if test x$RETCODE != x0; then + echo "FAIL qmf interop tests (Ruby Console/Ruby Agent)"; + TESTS_FAILED=1 + fi + + if test -d ${PYTHON_LIB_DIR} ; then + echo " Python Agent (external storage) vs. Ruby Console" + start_python_agent + ruby -I${MY_DIR} -I${MY_DIR}/../ruby -I${RUBY_LIB_DIR} ${MY_DIR}/ruby_console_test.rb localhost $BROKER_PORT $@ + RETCODE=$? + stop_python_agent + if test x$RETCODE != x0; then + echo "FAIL qmf interop tests (Ruby Console/Python Agent)"; + TESTS_FAILED=1 + fi + fi + fi + + # Also against the Pure-Python console: + # Ruby agent (internal storage) + # Python agent (external and internal) + # C++ agent (external and internal) + # + # Other consoles against the same set of agents: + # Wrapped Python console + # Ruby console + # C++ console + + stop_broker + if test x$TESTS_FAILED != x0; then + echo "TEST FAILED!" + exit 1 + fi +fi diff --git a/qpid/cpp/bindings/qmf/tests/test_base.rb b/qpid/cpp/bindings/qmf/tests/test_base.rb new file mode 100644 index 0000000000..7d4609097c --- /dev/null +++ b/qpid/cpp/bindings/qmf/tests/test_base.rb @@ -0,0 +1,82 @@ +#!/usr/bin/ruby + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'qmf' +require 'socket' + +class ConsoleTestBase < Qmf::ConsoleHandler + def initialize + sleep(2) + @settings = Qmf::ConnectionSettings.new + @settings.host = ARGV[0] if ARGV.size > 0 + @settings.port = ARGV[1].to_i if ARGV.size > 1 + @connection = Qmf::Connection.new(@settings) + @qmfc = Qmf::Console.new(self) + + @broker = @qmfc.add_connection(@connection) + @broker.wait_for_stable + + @store_events = :false + @event_list = [] + + tests = [] + methods.each do |m| + name = m.to_s + tests << name if name[0..4] == "test_" + end + + failures = 0 + + tests.sort.each do |t| + begin + print "#{t}..." + $stdout.flush + send(t) + puts " Pass" + rescue + puts " Fail: #{$!}" + failures += 1 + end + end + + @qmfc.del_connection(@broker) + exit(1) if failures > 0 + end + + def assert_equal(left, right, in_text=nil) + text = " (#{in_text})" if in_text + raise "Assertion failed: #{left} != #{right}#{text}" unless left == right + end + + def assert(condition, in_text=nil) + text = " (#{in_text})" if in_text + raise "Assertion failed: #{condition} #{text}" unless condition + end + + def fail(text) + raise text + end + + def event_received(event) + @event_list << event if @store_events + end + +end |