summaryrefslogtreecommitdiff
path: root/cpp/bindings/qmf
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-09-21 16:24:38 +0000
committerTed Ross <tross@apache.org>2009-09-21 16:24:38 +0000
commit4c9e6b30e9410cb32367be87ca9bbf941df750dc (patch)
treeb64a637ec4e4edf0c5240d0cfcc9b006f42b486c /cpp/bindings/qmf
parenta5283e144f9107e3e735379ddd68d8d29e9fdb53 (diff)
downloadqpid-python-4c9e6b30e9410cb32367be87ca9bbf941df750dc.tar.gz
Added Ruby test infrastructure and Console tests in Ruby
Fixed issues identified by the new tests: - Improper formatting of object-id in get-query - Remote (non-broker-resident) agents not visible to the console - object.update() and object.merge() not implemented git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@817312 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/bindings/qmf')
-rw-r--r--cpp/bindings/qmf/ruby/qmf.rb19
-rwxr-xr-xcpp/bindings/qmf/tests/ruby_console_test.rb137
-rwxr-xr-xcpp/bindings/qmf/tests/run_interop_tests10
-rw-r--r--cpp/bindings/qmf/tests/test_base.rb64
4 files changed, 224 insertions, 6 deletions
diff --git a/cpp/bindings/qmf/ruby/qmf.rb b/cpp/bindings/qmf/ruby/qmf.rb
index 4a4c863521..cba9759135 100644
--- a/cpp/bindings/qmf/ruby/qmf.rb
+++ b/cpp/bindings/qmf/ruby/qmf.rb
@@ -402,13 +402,18 @@ module Qmf
end
def update()
+ raise "No linkage to broker" unless @broker
+ newer = @broker.console.get_objects(Query.new(:object_id => object_id))
+ raise "Expected exactly one update for this object" unless newer.size == 1
+ mergeUpdate(newer[0])
end
def mergeUpdate(newObject)
+ @impl.merge(newObject.impl)
end
def deleted?()
- @delete_time > 0
+ @impl.isDeleted
end
def index()
@@ -523,7 +528,11 @@ module Qmf
@impl.getException
end
- def arguments
+ def text
+ exception.asString
+ end
+
+ def args
Arguments.new(@impl.getArgs)
end
end
@@ -542,13 +551,13 @@ module Qmf
if kwargs.include?(:key)
@impl = Qmfengine::Query.new(kwargs[:key])
elsif kwargs.include?(:object_id)
- @impl = Qmfengine::Query.new(kwargs[:object_id])
+ @impl = Qmfengine::Query.new(kwargs[:object_id].impl)
else
package = kwargs[:package] if kwargs.include?(:package)
if kwargs.include?(:class)
@impl = Qmfengine::Query.new(kwargs[:class], package)
else
- raise ArgumentError, "Invalid arguments, use :key or :class[,:package]"
+ raise ArgumentError, "Invalid arguments, use :key, :object_id or :class[,:package]"
end
end
end
@@ -930,7 +939,7 @@ module Qmf
class Broker < ConnectionHandler
include MonitorMixin
- attr_reader :impl, :conn
+ attr_reader :impl, :conn, :console
def initialize(console, conn)
super()
diff --git a/cpp/bindings/qmf/tests/ruby_console_test.rb b/cpp/bindings/qmf/tests/ruby_console_test.rb
new file mode 100755
index 0000000000..7779d2c70c
--- /dev/null
+++ b/cpp/bindings/qmf/tests/ruby_console_test.rb
@@ -0,0 +1,137 @@
+#!/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
+ agents = []
+ count = 0
+ while agents.size == 0
+ agents = @qmfc.get_objects(Qmf::Query.new(:class => "agent"))
+ sleep(1)
+ count += 1
+ fail("Timed out waiting for remote agent") if count > 10
+ end
+
+ agentList = @qmfc.get_agents
+ assert_equal(agentList.size, 2, "Number of agents reported by Console")
+ end
+
+ def test_B_basic_method_invocation
+ parents = @qmfc.get_objects(Qmf::Query.new(:class => "parent"))
+ assert_equal(parents.size, 1, "Number of 'parent' objects")
+ parent = parents[0]
+ 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
+ parents = @qmfc.get_objects(Qmf::Query.new(:class =>"parent"))
+ assert_equal(parents.size, 1, "Number of parent objects")
+ parent = parents[0]
+
+ 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
+ parents = @qmfc.get_objects(Qmf::Query.new(:class =>"parent"))
+ assert_equal(parents.size, 1, "Number of parent objects")
+ parent = parents[0]
+
+ 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
+ parents = @qmfc.get_objects(Qmf::Query.new(:class =>"parent"))
+ assert_equal(parents.size, 1, "Number of parent objects")
+ parent = parents[0]
+
+ 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_D_userid_for_method
+ parents = @qmfc.get_objects(Qmf::Query.new(:class => "parent"))
+ assert_equal(parents.size, 1, "Number of parent objects")
+ parent = parents[0]
+
+ result = parent.probe_userid
+ assert_equal(result.status, 0, "Method Response Status")
+ assert_equal(result.args["userid"], "guest")
+ end
+
+end
+
+app = ConsoleTest.new
+
+
+
diff --git a/cpp/bindings/qmf/tests/run_interop_tests b/cpp/bindings/qmf/tests/run_interop_tests
index 01d7221ac6..b5545d736d 100755
--- a/cpp/bindings/qmf/tests/run_interop_tests
+++ b/cpp/bindings/qmf/tests/run_interop_tests
@@ -88,11 +88,19 @@ if test -d ${PYTHON_DIR} ; then
echo " Ruby agent started at pid $AGENT_PID"
${PYTHON_DIR}/qpid-python-test -m python_console -b localhost:$BROKER_PORT $@
RETCODE=$?
- stop_ruby_agent
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
fi
# Also against the Pure-Python console:
diff --git a/cpp/bindings/qmf/tests/test_base.rb b/cpp/bindings/qmf/tests/test_base.rb
new file mode 100644
index 0000000000..18bf4c2649
--- /dev/null
+++ b/cpp/bindings/qmf/tests/test_base.rb
@@ -0,0 +1,64 @@
+#!/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
+ @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)
+ @qmfc = Qmf::Console.new
+
+ @broker = @qmfc.add_connection(@connection)
+ @broker.waitForStable
+
+ tests = []
+ methods.each do |m|
+ name = m.to_s
+ tests << name if name[0..4] == "test_"
+ end
+
+ tests.sort.each do |t|
+ begin
+ print "#{t}..."
+ $stdout.flush
+ send(t)
+ puts " Pass"
+ rescue
+ puts " Fail: #{$!}"
+ end
+ end
+
+ @qmfc.del_connection(@broker)
+ 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 fail(text)
+ raise text
+ end
+end