You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2013/07/31 23:03:38 UTC

svn commit: r1509030 - in /qpid/proton/trunk: examples/messenger/ruby/recv.rb examples/messenger/ruby/send.rb proton-c/bindings/ruby/ChangeLog proton-c/bindings/ruby/lib/qpid_proton/message.rb proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb

Author: mcpierce
Date: Wed Jul 31 21:03:38 2013
New Revision: 1509030

URL: http://svn.apache.org/r1509030
Log:
PROTON-379: Added annotations property to Ruby Message class.

Added Rspec tests to verify. Also updated the send.rb and recv.rb
examples to use annotations.

Modified:
    qpid/proton/trunk/examples/messenger/ruby/recv.rb
    qpid/proton/trunk/examples/messenger/ruby/send.rb
    qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb
    qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb

Modified: qpid/proton/trunk/examples/messenger/ruby/recv.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/ruby/recv.rb?rev=1509030&r1=1509029&r2=1509030&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/ruby/recv.rb (original)
+++ qpid/proton/trunk/examples/messenger/ruby/recv.rb Wed Jul 31 21:03:38 2013
@@ -75,6 +75,7 @@ loop do
     puts "Content: #{body}"
     puts "Properties: #{msg.properties}"
     puts "Instructions: #{msg.instructions}"
+    puts "Annotations: #{msg.annotations}"
   end
 end
 

Modified: qpid/proton/trunk/examples/messenger/ruby/send.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/ruby/send.rb?rev=1509030&r1=1509029&r2=1509030&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/ruby/send.rb (original)
+++ qpid/proton/trunk/examples/messenger/ruby/send.rb Wed Jul 31 21:03:38 2013
@@ -50,6 +50,9 @@ messages.each do |message|
   msg.instructions["fold"] = "yes"
   msg.instructions["spindle"] = "no"
   msg.instructions["mutilate"] = "no"
+  msg.annotations["version"] = 1.0
+  msg.annotations["pill"] = :RED
+
   begin
     messenger.put(msg)
   rescue Qpid::Proton::ProtonError => error

Modified: qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog?rev=1509030&r1=1509029&r2=1509030&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog Wed Jul 31 21:03:38 2013
@@ -9,6 +9,7 @@ version 0.5:
 	* Hashes are now automatically encoded into Data objects.
 	* Fixed encoding Time objects.
 	* Added instructions field to Qpid::Proton::Message.
+	* Added annotations field to Qpid::Proton::Message.
 	* Fixed encoding Symbol objects.
 
 version 0.4:

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb?rev=1509030&r1=1509029&r2=1509030&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb Wed Jul 31 21:03:38 2013
@@ -52,6 +52,11 @@ module Qpid
         if insts.next
           @instructions = insts.type.get(insts)
         end
+        @annotations = nil
+        annts = Qpid::Proton::Data.new(Cproton::pn_message_annotations(@impl))
+        if annts.next
+          @annotations = annts.type.get(annts)
+        end
       end
 
       # Encodes the message.
@@ -80,6 +85,12 @@ module Qpid
           mapping = Qpid::Proton::Mapping.for_class(@instructions.class)
           mapping.put(insts, @instructions)
         end
+        annts = Qpid::Proton::Data.new(Cproton::pn_message_annotations(@impl))
+        annts.clear
+        if !@annotations.nil?
+          mapping = Qpid::Proton::Mapping.for_class(@annotations.class)
+          mapping.put(annts, @annotations)
+        end
       end
 
       # Creates a new +Message+ instance.
@@ -88,6 +99,7 @@ module Qpid
         ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
         @properties = {}
         @instructions = {}
+        @annotations = {}
       end
 
       # Invoked by garbage collection to clean up resources used
@@ -508,7 +520,7 @@ module Qpid
         @properties[name] = value
       end
 
-      # Retrieves the vaue for the specified property name. If not found, then
+      # Retrieves the value for the specified property name. If not found, then
       # it returns nil.
       #
       def [](name)
@@ -533,6 +545,18 @@ module Qpid
         @instructions = instr.nil? ? nil : instr.clone
       end
 
+      # Returns the annotations for this message.
+      #
+      def annotations
+        @annotations
+      end
+
+      # Assigns annotations to this message.
+      #
+      def annotations=(annotations)
+        @annotations = annotations.nil? ? nil : annotations.clone
+      end
+
       private
 
       def check(err) # :nodoc:

Modified: qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb?rev=1509030&r1=1509029&r2=1509030&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb Wed Jul 31 21:03:38 2013
@@ -525,6 +525,65 @@ module Qpid
         @message.instructions.should be_nil
       end
 
+      it "has annotations" do
+        @message.should respond_to(:annotations)
+        @message.should respond_to(:annotations=)
+      end
+
+      it "can set an annotation" do
+        name = random_hash(32)
+        value = random_hash(256)
+
+        @message.annotations[name] = value
+        @message.annotations[name].should eq(value)
+      end
+
+      it "can update an annotation" do
+        name = random_hash(32)
+        value = random_hash(256)
+
+        @message.annotations[name] = value
+        @message.annotations[name].should eq(value)
+
+        value = random_hash(128)
+
+        @message.annotations[name] = value
+        @message.annotations[name].should eq(value)
+      end
+
+      it "can delete an annotation" do
+        name = random_hash(32)
+        value = random_hash(256)
+
+        @message.annotations[name] = value
+        @message.annotations[name].should eq(value)
+
+        @message.annotations[name] = nil
+        @message.annotations[name].should be_nil
+      end
+
+      it "can replace all annotations" do
+        values = random_hash(rand(128) + 1)
+
+        @message.annotations = values
+        @message.annotations.should eq values
+
+        values = random_hash(rand(64) + 1)
+
+        @message.annotations = values
+        @message.annotations.should eq values
+      end
+
+      it "can delete the set of annotations" do
+        values = random_hash(rand(128) + 1)
+
+        @message.annotations = values
+        @message.annotations.should eq values
+
+        @message.annotations = nil
+        @message.annotations.should be_nil
+      end
+
     end
 
   end



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