qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darryl L. Pierce" <dpie...@redhat.com>
Subject [PATCH 07/11] Created the Receiver class and its unit tests.
Date Mon, 11 Jul 2011 12:43:13 GMT
From: "Darryl L. Pierce" <dpierce@redhat.com>

The class is packaged as follows:

Qpid::Messaging::Receiver
---
 qpid/cpp/bindings/qpid/ruby/lib/qpid.rb           |    1 +
 qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb  |  102 +++++++++
 qpid/cpp/bindings/qpid/ruby/test/test_receiver.rb |  238 +++++++++++++++++++++
 qpid/cpp/bindings/qpid/ruby/test/ts_bindings.rb   |    1 +
 4 files changed, 342 insertions(+), 0 deletions(-)
 create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
 create mode 100644 qpid/cpp/bindings/qpid/ruby/test/test_receiver.rb

diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb
index b72747d..3edb65c 100644
--- a/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb
+++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb
@@ -23,4 +23,5 @@ require 'qpid/address'
 require 'qpid/encoding'
 require 'qpid/message'
 require 'qpid/sender'
+require 'qpid/receiver'
 
diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
new file mode 100644
index 0000000..d498aa9
--- /dev/null
+++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
@@ -0,0 +1,102 @@
+#
+# 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 'cqpid'
+
+require 'qpid/duration'
+
+module Qpid
+
+  module Messaging
+
+    # Receiver defines a type for receiving messages.
+    class Receiver
+
+      def initialize(receiver_impl) # :nodoc:
+        @receiver_impl = receiver_impl
+      end
+
+      def receiver_impl # :nodoc:
+        @receiver_impl
+      end
+
+      # Retrieves a message from the receiver's local queue, or waits
+      # for up to the duration specified for one to become available.
+      def get(duration = Qpid::Messaging::Duration::FOREVER)
+        message_impl = @receiver_impl.get duration.duration_impl
+        create_message_wrapper message_impl unless message_impl.nil?
+      end
+
+      # Retrieves a message from the receiver's subscription, or waits
+      # for up to the duration specified for one to become available.
+      def fetch(duration = Qpid::Messaging::Duration::FOREVER)
+        message_impl = @receiver_impl.fetch duration.duration_impl
+        create_message_wrapper message_impl unless message_impl.nil?
+      end
+
+      # Sets the capacity.
+      #
+      # The capacity for a receiver determines the number of messages that
+      # can be held in the receiver before being fetched.
+      def capacity=(capacity); @receiver_impl.setCapacity capacity; end
+
+      # Returns the capacity.
+      def capacity; @receiver_impl.getCapacity; end
+
+      # Returns the number of available messages waiting to be fetched.
+      def available; @receiver_impl.getAvailable; end
+
+      # Returns the number of messages that have been received and acknowledged
+      # but whose acknowledgements have not been confirmed by the sender.
+      def unsettled; @receiver_impl.getUnsettled; end
+
+      # Cancels the reciever.
+      def close; @receiver_impl.close; end
+
+      # Returns whether the receiver is closed.
+      def closed?; @receiver_impl.isClosed; end
+
+      # Returns the name of the receiver
+      def name; @receiver_impl.getName; end
+
+      # Returns the Session for this receiver.
+      def session; Qpid::Messaging::Session.new(@receiver_impl.getSession); end
+
+      # Returns whether the underlying handle is valid.
+      def valid?; @receiver_impl.isValid; end
+
+      # Returns whether the underlying handle is null.
+      def null?; @receiver_impl.isNull; end
+
+      def swap receiver
+        @receiver_impl.swap receiver.receiver_impl
+      end
+
+      private
+
+      def create_message_wrapper message_impl
+        Qpid::Messaging::Message.new({}, message_impl)
+      end
+
+    end
+
+  end
+
+end
+
diff --git a/qpid/cpp/bindings/qpid/ruby/test/test_receiver.rb b/qpid/cpp/bindings/qpid/ruby/test/test_receiver.rb
new file mode 100644
index 0000000..61a4db1
--- /dev/null
+++ b/qpid/cpp/bindings/qpid/ruby/test/test_receiver.rb
@@ -0,0 +1,238 @@
+#
+# 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.
+#
+
+$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
+
+require 'test/unit'
+require 'flexmock/test_unit'
+
+require 'qpid/receiver'
+
+class TestReceiver < Test::Unit::TestCase
+
+  def setup
+    @session_impl = flexmock("session")
+
+    @Message_class = flexmock(Qpid::Messaging::Message)
+    @Messaging_module = flexmock(Qpid::Messaging)
+    @message_impl = flexmock("message_impl")
+    @message = flexmock("message")
+
+    @receiver_impl       = flexmock("receiver")
+    @other_receiver      = flexmock("other_receiver")
+    @other_receiver_impl = flexmock("other_receiver_impl")
+    @receiver            = Qpid::Messaging::Receiver.new @receiver_impl
+  end
+
+  def test_receiver_impl
+    assert_same @receiver_impl, @receiver.receiver_impl
+  end
+
+  def test_get
+    @receiver_impl.
+      should_receive(:get).
+      once.
+      with_any_args.
+      and_return(@message_impl)
+
+    result = @receiver.get
+
+    assert_not_nil result
+    assert_same @message_impl, result.message_impl
+  end
+
+  def test_get_with_duration
+    @receiver_impl.
+      should_receive(:get).
+      once.
+      with_any_args.
+      and_return(@message_impl)
+
+    result = @receiver.get Qpid::Messaging::Duration::MINUTE
+
+    assert_not_nil result
+    assert_same @message_impl, result.message_impl
+  end
+
+  def test_get_with_no_message_received
+    @receiver_impl.
+      should_receive(:get).
+      once.
+      with_any_args.
+      and_return(nil)
+
+    result = @receiver.get Qpid::Messaging::Duration::SECOND
+
+    assert_nil result
+  end
+
+  def test_fetch
+   @receiver_impl.
+      should_receive(:fetch).
+      once.
+      with_any_args.
+      and_return(@message_impl)
+
+    result = @receiver.fetch
+
+    assert_not_nil result
+    assert_same @message_impl, result.message_impl
+  end
+
+  def test_fetch_with_duration
+    @receiver_impl.
+      should_receive(:fetch).
+      once.
+      with_any_args.
+      and_return(@message_impl)
+
+    result = @receiver.fetch Qpid::Messaging::Duration::MINUTE
+
+    assert_not_nil result
+    assert_same @message_impl, result.message_impl
+  end
+
+  def test_fetch_with_no_message_received
+    @receiver_impl.
+      should_receive(:fetch).
+      once.
+      with_any_args.
+      and_return(nil)
+
+    result = @receiver.fetch Qpid::Messaging::Duration::SECOND
+
+    assert_nil result
+  end
+
+  def test_set_capacity
+    @receiver_impl.
+      should_receive(:setCapacity).
+      once.
+      with(15)
+
+    @receiver.capacity = 15
+  end
+
+  def test_get_capacity
+    @receiver_impl.
+      should_receive(:getCapacity).
+      once.
+      and_return(17)
+
+    assert_equal 17, @receiver.capacity
+  end
+
+  def test_get_available
+    @receiver_impl.
+      should_receive(:getAvailable).
+      once.
+      and_return(2)
+
+    assert_equal 2, @receiver.available
+  end
+
+  def test_get_unsettled
+    @receiver_impl.
+      should_receive(:getUnsettled).
+      once.
+      and_return(12)
+
+    assert_equal 12, @receiver.unsettled
+  end
+
+  def test_close
+    @receiver_impl.
+      should_receive(:close).
+      once
+
+    @receiver.close
+  end
+
+  def test_closed_when_open
+    @receiver_impl.
+      should_receive(:isClosed).
+      once.
+      and_return(false)
+
+    assert !@receiver.closed?
+  end
+
+  def test_closed
+    @receiver_impl.
+      should_receive(:isClosed).
+      once.
+      and_return(true)
+
+    assert @receiver.closed?
+  end
+
+  def test_get_name
+    @receiver_impl.
+      should_receive(:getName).
+      once.
+      and_return("my-queue")
+
+    assert_equal "my-queue", @receiver.name
+  end
+
+  def test_get_session
+    @receiver_impl.
+      should_receive(:getSession).
+      once.
+      and_return(@session_impl)
+
+    result = @receiver.session
+
+    assert_not_nil result
+    assert_same @session_impl, result.session_impl
+  end
+
+  def test_is_valid
+    @receiver_impl.
+      should_receive(:isValid).
+      once.
+      and_return(false)
+
+    assert !@receiver.valid?
+  end
+
+  def test_is_null
+    @receiver_impl.
+      should_receive(:isNull).
+      once.
+      and_return(true)
+
+    assert @receiver.null?
+  end
+
+  def test_swap
+    @other_receiver.
+      should_receive(:receiver_impl).
+      once.
+      and_return(@other_receiver_impl)
+    @receiver_impl.
+      should_receive(:swap).
+      once.
+      with(@other_receiver_impl)
+
+    @receiver.swap @other_receiver
+  end
+
+end
+
diff --git a/qpid/cpp/bindings/qpid/ruby/test/ts_bindings.rb b/qpid/cpp/bindings/qpid/ruby/test/ts_bindings.rb
index a58b10f..549e268 100644
--- a/qpid/cpp/bindings/qpid/ruby/test/ts_bindings.rb
+++ b/qpid/cpp/bindings/qpid/ruby/test/ts_bindings.rb
@@ -24,4 +24,5 @@ require 'test_encoding'
 require 'test_address'
 require 'test_message'
 require 'test_sender'
+require 'test_receiver'
 
-- 
1.7.6


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


Mime
View raw message