diff options
author | Ted Ross <tross@apache.org> | 2009-09-22 20:11:30 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2009-09-22 20:11:30 +0000 |
commit | 642183fb8a6eb1a8adc71acfd2117bfcbdba3546 (patch) | |
tree | 20defcf1758c4e8673cd1c9d49cac9eac480a4b1 | |
parent | df826cf6ab76c434904811eb38c2258c278d7872 (diff) | |
download | qpid-python-642183fb8a6eb1a8adc71acfd2117bfcbdba3546.tar.gz |
QMF updates:
- Added "sendUserId" option (defaults to true) to QMF connection settings
- Implemented the user-id function using "negotiatedSettings" from qpid::client::Connection
- Fixed a sign-extension bug in Value
- Added tests for all of the above
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@817813 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | cpp/bindings/qmf/tests/agent_ruby.rb | 29 | ||||
-rwxr-xr-x | cpp/bindings/qmf/tests/ruby_console_test.rb | 60 | ||||
-rw-r--r-- | cpp/src/qmf/ConnectionSettingsImpl.cpp | 6 | ||||
-rw-r--r-- | cpp/src/qmf/ConnectionSettingsImpl.h | 2 | ||||
-rw-r--r-- | cpp/src/qmf/ResilientConnection.cpp | 15 | ||||
-rw-r--r-- | cpp/src/qmf/ValueImpl.cpp | 4 |
6 files changed, 100 insertions, 16 deletions
diff --git a/cpp/bindings/qmf/tests/agent_ruby.rb b/cpp/bindings/qmf/tests/agent_ruby.rb index 2f0869ad73..426a284e7d 100755 --- a/cpp/bindings/qmf/tests/agent_ruby.rb +++ b/cpp/bindings/qmf/tests/agent_ruby.rb @@ -40,6 +40,9 @@ class Model @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_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") @@ -50,6 +53,14 @@ class Model method.add_argument(Qmf::SchemaArgument.new("test", Qmf::TYPE_SSTR, :dir => Qmf::DIR_IN)) @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)) @@ -84,12 +95,13 @@ class App < Qmf::AgentHandler def method_call(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}" + retCode = 0 + retText = "OK" + if name == "echo" @agent.method_response(context, 0, "OK", args) elsif name == "set_numerics" - retCode = 0 - retText = "OK" if args['test'] == "big" @parent.uint64val = 0x9494949449494949 @@ -129,7 +141,11 @@ class App < Qmf::AgentHandler retText = "Invalid argument value for test" end - @agent.method_response(context, retCode, retText, args) + elsif name == "set_short_string" + @parent.sstrval = args['value'] + + elsif name == "set_long_string" + @parent.lstrval = args['value'] elsif name == "create_child" oid = @agent.alloc_object_id(2) @@ -137,15 +153,16 @@ class App < Qmf::AgentHandler @child = Qmf::AgentObject.new(@model.child_class) @child.name = args.by_key("child_name") @child.set_object_id(oid) - @agent.method_response(context, 0, "OK", args) elsif name == "probe_userid" args['userid'] = userId - @agent.method_response(context, 0, "OK", args) else - @agent.method_response(context, 1, "Unimplemented Method: #{name}", args) + retCode = 1 + retText = "Unimplemented Method: #{name}" end + + @agent.method_response(context, retCode, retText, args) end def main diff --git a/cpp/bindings/qmf/tests/ruby_console_test.rb b/cpp/bindings/qmf/tests/ruby_console_test.rb index a5d37ba71f..6c6547efbb 100755 --- a/cpp/bindings/qmf/tests/ruby_console_test.rb +++ b/cpp/bindings/qmf/tests/ruby_console_test.rb @@ -97,7 +97,7 @@ class ConsoleTest < ConsoleTestBase assert_equal(parent.int8val, 11) end - def _test_C_basic_types_numeric_negative + 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] @@ -119,14 +119,68 @@ class ConsoleTest < ConsoleTestBase assert_equal(parent.int8val, -100) end - def _test_D_userid_for_method + def test_C_basic_types_string_short + parents = @qmfc.get_objects(Qmf::Query.new(:class =>"parent")) + assert_equal(parents.size, 1, "Number of parent objects") + parent = parents[0] + + 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_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 + parents = @qmfc.get_objects(Qmf::Query.new(:class =>"parent")) + assert_equal(parents.size, 1, "Number of parent objects") + parent = parents[0] + + 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 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") + assert_equal(result.args.userid, "anonymous") end end diff --git a/cpp/src/qmf/ConnectionSettingsImpl.cpp b/cpp/src/qmf/ConnectionSettingsImpl.cpp index fa0257aeba..63ce53b751 100644 --- a/cpp/src/qmf/ConnectionSettingsImpl.cpp +++ b/cpp/src/qmf/ConnectionSettingsImpl.cpp @@ -43,14 +43,15 @@ const string attrMaxSsf("maxSsf"); const string attrRetryDelayMin("retryDelayMin"); const string attrRetryDelayMax("retryDelayMax"); const string attrRetryDelayFactor("retryDelayFactor"); +const string attrSendUserId("sendUserId"); ConnectionSettingsImpl::ConnectionSettingsImpl() : - retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2) + retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2), sendUserId(true) { } ConnectionSettingsImpl::ConnectionSettingsImpl(const string& /*url*/) : - retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2) + retryDelayMin(1), retryDelayMax(64), retryDelayFactor(2), sendUserId(true) { // TODO: Parse the URL } @@ -77,6 +78,7 @@ void ConnectionSettingsImpl::setAttr(const string& key, const Value& value) else if (key == attrRetryDelayMin) retryDelayMin = value.asUint(); else if (key == attrRetryDelayMax) retryDelayMax = value.asUint(); else if (key == attrRetryDelayFactor) retryDelayFactor = value.asUint(); + else if (key == attrSendUserId) sendUserId = value.asBool(); } Value ConnectionSettingsImpl::getAttr(const string& key) const diff --git a/cpp/src/qmf/ConnectionSettingsImpl.h b/cpp/src/qmf/ConnectionSettingsImpl.h index 4e34cfe870..e73715460a 100644 --- a/cpp/src/qmf/ConnectionSettingsImpl.h +++ b/cpp/src/qmf/ConnectionSettingsImpl.h @@ -34,6 +34,7 @@ namespace qmf { int retryDelayMin; int retryDelayMax; int retryDelayFactor; + bool sendUserId; public: ConnectionSettingsImpl(); @@ -52,6 +53,7 @@ namespace qmf { const qpid::client::ConnectionSettings& getClientSettings() const; void getRetrySettings(int* delayMin, int* delayMax, int* delayFactor) const; + bool getSendUserId() const { return sendUserId; } }; } diff --git a/cpp/src/qmf/ResilientConnection.cpp b/cpp/src/qmf/ResilientConnection.cpp index be7837b829..b3735657af 100644 --- a/cpp/src/qmf/ResilientConnection.cpp +++ b/cpp/src/qmf/ResilientConnection.cpp @@ -65,13 +65,12 @@ namespace qmf { client::Connection& connection; client::Session session; client::SubscriptionManager* subscriptions; + string userId; void* userContext; vector<string> dests; qpid::sys::Thread thread; - RCSession(ResilientConnectionImpl& ci, const string& n, client::Connection& c, void* uc) : - connImpl(ci), name(n), connection(c), session(connection.newSession(name)), - subscriptions(new client::SubscriptionManager(session)), userContext(uc), thread(*this) {} + RCSession(ResilientConnectionImpl& ci, const string& n, client::Connection& c, void* uc); ~RCSession(); void received(client::Message& msg); void run(); @@ -135,6 +134,14 @@ ResilientConnectionEvent ResilientConnectionEventImpl::copy() return item; } +RCSession::RCSession(ResilientConnectionImpl& ci, const string& n, client::Connection& c, void* uc) : + connImpl(ci), name(n), connection(c), session(connection.newSession(name)), + subscriptions(new client::SubscriptionManager(session)), userContext(uc), thread(*this) +{ + const qpid::client::ConnectionSettings& operSettings = connection.getNegotiatedSettings(); + userId = operSettings.username; +} + RCSession::~RCSession() { subscriptions->stop(); @@ -254,6 +261,8 @@ void ResilientConnectionImpl::sendMessage(SessionHandle handle, qmf::Message& me string data(message.body, message.length); msg.getDeliveryProperties().setRoutingKey(message.routingKey); msg.getMessageProperties().setReplyTo(qpid::framing::ReplyTo(message.replyExchange, message.replyKey)); + if (settings.impl->getSendUserId()) + msg.getMessageProperties().setUserId(sess->userId); msg.setData(data); try { diff --git a/cpp/src/qmf/ValueImpl.cpp b/cpp/src/qmf/ValueImpl.cpp index 652b99cae9..f13e1a231e 100644 --- a/cpp/src/qmf/ValueImpl.cpp +++ b/cpp/src/qmf/ValueImpl.cpp @@ -42,8 +42,8 @@ ValueImpl::ValueImpl(Typecode t, Buffer& buf) : typecode(t) case TYPE_BOOL : value.boolVal = (buf.getOctet() != 0); break; case TYPE_FLOAT : value.floatVal = buf.getFloat(); break; case TYPE_DOUBLE : value.doubleVal = buf.getDouble(); break; - case TYPE_INT8 : value.s32 = (int32_t) buf.getOctet(); break; - case TYPE_INT16 : value.s32 = (int32_t) buf.getShort(); break; + case TYPE_INT8 : value.s32 = (int32_t) ((int8_t) buf.getOctet()); break; + case TYPE_INT16 : value.s32 = (int32_t) ((int16_t) buf.getShort()); break; case TYPE_INT32 : value.s32 = (int32_t) buf.getLong(); break; case TYPE_INT64 : value.s64 = buf.getLongLong(); break; case TYPE_UUID : buf.getBin128(value.uuidVal); break; |