qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcpie...@apache.org
Subject svn commit: r1576357 - in /qpid/trunk/qpid/cpp/bindings/qpid/ruby: examples/ lib/qpid_messaging/ spec/ spec/qpid_messaging/
Date Tue, 11 Mar 2014 14:12:04 GMT
Author: mcpierce
Date: Tue Mar 11 14:12:03 2014
New Revision: 1576357

URL: http://svn.apache.org/r1576357
Log:
QPID-5622: Expose {get,set}ContentObject in Ruby bindings.

Added the feature and updated the rspec tests and examples to use
content_object for retrieving data.

Modified:
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/client.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/drain.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/server.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/spout.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb
    qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/client.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/client.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/client.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/client.rb Tue Mar 11 14:12:03 2014
@@ -40,7 +40,7 @@ if __FILE__ == $0
     request.reply_to = response_queue
     sender.send request
     response = receiver.fetch
-    puts "#{request.content} -> #{response.content}"
+    puts "#{request.content_object} -> #{response.content_object}"
   end
 
   connection.close

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/drain.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/drain.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/drain.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/drain.rb Tue Mar 11 14:12:03 2014
@@ -93,11 +93,11 @@ begin
     message = receiver.fetch(options[:timeout])
     print "Message(properties="
     render_map message.properties
-    print ", content="
-    if message.content_type == "amqp/map"
-      print "'#{render_map message.content}')"
+    print ", content_object="
+    if message.content_object == "amqp/map"
+      print "'#{render_map message.content_object}')"
     else
-      print "'#{message.content}'"
+      print "'#{message.content_object}'"
     end
     print ")\n"
     session.acknowledge message

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb Tue Mar 11 14:12:03 2014
@@ -41,7 +41,7 @@ if __FILE__ == $0
 
   # Now receive the message
   message = receiver.fetch Qpid::Messaging::Duration::SECOND
-  puts "#{message.content}"
+  puts "#{message.content_object}"
   session.acknowledge
 
   connection.close

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb Tue Mar 11 14:12:03 2014
@@ -44,7 +44,7 @@ begin
   receiver = session.create_receiver address
 
   message = receiver.fetch
-  content = message.content
+  content = message.content_object
 
   print "content-type:#{message.content_type}"
   print "{"

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb Tue Mar 11 14:12:03 2014
@@ -23,7 +23,7 @@ require 'qpid_messaging'
 
 broker  = ARGV[0] || "amqp:tcp:127.0.0.1:5672"
 address = ARGV[1] || "message_queue; {create: always}"
-options = ARGV[2] || []
+options = ARGV[2] || {}
 
 connection = Qpid::Messaging::Connection.new :url => broker, :options => options
 connection.open
@@ -34,18 +34,19 @@ begin
   message = Qpid::Messaging::Message.new
 
   content = {
-    :id      => 987654321,
+    "id"     => 987654321,
     :name    => "Widget",
     :percent => 0.99,
     :colors  => ["red", "green", "blue"]
   }
 
-  message.content = content
+  message.content_object = content
 
   sender.send message
 
 rescue Exception => error
   puts "Exception: #{error.message}"
+  puts error.backtrace
 end
 
 connection.close

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/server.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/server.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/server.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/server.rb Tue Mar 11 14:12:03 2014
@@ -36,12 +36,12 @@ if __FILE__ == $0
 
     if !address.nil?
       sender = session.create_sender address
-      response = Qpid::Messaging::Message.new :content => request.content.upcase
+      response = Qpid::Messaging::Message.new :content => request.content_object.upcase
       sender.send response
-      puts "Processed request: #{request.content} -> #{response.content}"
+      puts "Processed request: #{request.content_object} -> #{response.content_object}"
       session.acknowledge
     else
-      puts "Error: no reply address specified for request: #{request.content}"
+      puts "Error: no reply address specified for request: #{request.content_object}"
       session.reject request
     end
   end

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/spout.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/spout.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/spout.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/examples/spout.rb Tue Mar 11 14:12:03 2014
@@ -137,12 +137,12 @@ options[:properties].each_key {|key| mes
 
 (1..options[:count]).each do |count|
   if !options[:mapped].keys.empty?
-    message.content = options[:mapped]
+    message.content_object = options[:mapped]
   elsif options[:content]
-    message.content = options[:content]
+    message.content_object = options[:content]
   end
   message.durable = options[:durable]
-  message.content = options[:content] unless options[:content].nil?
+  message.content_object = options[:content] unless options[:content].nil?
   message.properties["spout-id"] = "#{count}"
   message.reply_to = options[:replyto] unless options[:replyto].nil? || options[:replyto].empty?
   sender.send message

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb Tue Mar 11 14:12:03
2014
@@ -39,9 +39,8 @@ module Qpid
       def initialize(args = {})
         @message_impl = (args[:impl] if args[:impl]) || nil
         @message_impl = Cqpid::Message.new if @message_impl.nil?
-        @content = nil
         args = {} if args.nil?
-        self.content = args[:content] if args[:content]
+        self.content_object = args[:content] if args[:content]
       end
 
       def message_impl # :nodoc:
@@ -345,6 +344,29 @@ module Qpid
       # Returns the content's size in bytes.
       def content_size; @message_impl.getContentSize; end
 
+      # Sets the message content.
+      #
+      # ==== Options
+      #
+      # * +content+ - the content
+      #
+      # ==== Examples
+      #
+      #   # set a simple content for a message
+      #   msg.content_object = "This is a simple message."
+      #   # sets content that is automatically encoded
+      #   msg.content_object = {:foo => :bar}
+      #
+      def content_object=(content)
+        @message_impl.setContentObject(Qpid::Messaging.stringify(content))
+      end
+
+      # Returns the content of the +Message+.
+      #
+      def content_object
+        @message_impl.getContentObject()
+      end
+
     end
 
   end

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb Tue Mar 11
14:12:03 2014
@@ -64,6 +64,36 @@ module Qpid
         content.should == "My content"
       end
 
+      it "should store and retrieve string content properly" do
+        content = random_string(64)
+
+        @message.content_object = content
+        @message.content_object.should == content
+      end
+
+      it "should store and retrieve numeric content properly" do
+        content = rand(65536)
+
+        @message.content_object = content
+        @message.content_object.should == content
+      end
+
+      it "should store and retrieve map content properly" do
+        content = {}
+        (1..rand(128)).each { content["#{random_string(64)}"] = "#{random_string(64)}" }
+
+        @message.content = content
+        @message.content.should eq content
+      end
+
+      it "should store and retrieve list content properly" do
+        content = []
+        (1..rand(128)).each { content << "#{random_string(64)}" }
+
+        @message.content = content
+        @message.content.should eq content
+      end
+
       it "should properly encode a map when created" do
         message = Qpid::Messaging::Message.new :content => {"foo" => "bar"}
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb?rev=1576357&r1=1576356&r2=1576357&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb Tue Mar 11 14:12:03 2014
@@ -18,3 +18,9 @@
 #
 
 require 'qpid_messaging'
+
+# Generates a random string of the specified length
+def random_string(length = 8)
+  (0...length).map{65.+(rand(25)).chr}.join
+end
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message