You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/11/08 16:04:05 UTC

qpid-proton git commit: PROTON-1064: [ruby] New Container with native ruby IO

Repository: qpid-proton
Updated Branches:
  refs/heads/master 3904225c7 -> 4856b6e18


PROTON-1064: [ruby] New Container with native ruby IO

Minor doc correction, modify Container initialize parameters to match C++.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4856b6e1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4856b6e1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4856b6e1

Branch: refs/heads/master
Commit: 4856b6e1816ad3be4dc9fb06289701a1835aa7a9
Parents: 3904225
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Nov 8 11:02:35 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Nov 8 11:02:35 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/container.rb   | 27 +++++++++++----------
 proton-c/bindings/ruby/lib/core/listener.rb    |  5 +++-
 proton-c/bindings/ruby/tests/test_container.rb | 22 ++++++++---------
 3 files changed, 29 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4856b6e1/proton-c/bindings/ruby/lib/core/container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/container.rb b/proton-c/bindings/ruby/lib/core/container.rb
index 29df51b..6e14d11 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -22,7 +22,6 @@ require 'set'
 require_relative 'listener'
 
 module Qpid::Proton
-
   # An AMQP container manages a set of {Connection}s which contain {#Sender} and
   # {#Receiver} links to transfer messages.
   #
@@ -49,20 +48,22 @@ module Qpid::Proton
 
     # Create a new Container
     #
-    # @param opts [Hash] Options
-    # @option opts [String] :id A unique ID for this container. Defaults to a random UUID.
-    # @option opts [MessagingHandler] :handler Default handler for connections
+    # @param handler [MessagingHandler] Optional default handler for connections
     #   that do not have their own handler (see {#connect} and {#listen})
     #
-    #   @note In a multi-threaded, multi-connection container the default
-    #   handler can be called concurrently for different connections. An
-    #   individual handler attached to a single connection is never called
-    #   concurrently, so that is the recommended approach for multi-threading.
-    def initialize(opts = {})
-      opts = { :handler => opts } unless opts.is_a? Hash # Allow handler as only parameter
-      opts = { :handler => opts } if opts.is_a? String   # Allow ID as only parameter option
-      @handler = opts[:handler]
-      @id = String.new(opts[:id] || SecureRandom.uuid).freeze
+    #   @note For multi-threaded code, it is recommended to use a separate
+    #   handler instance for every connection, as a shared global handler can be
+    #   called concurrently for every connection that uses it.
+    # @param id [String] A unique ID for this container. Defaults to a random UUID.
+    #
+    def initialize(handler = nil, id = nil)
+      # Allow ID as sole argument
+      (handler, id = nil, handler.to_str) if (id.nil? && handler.respond_to?(:to_str))
+      raise TypeError, "Expected MessagingHandler, got #{handler.class}" if handler && !handler.is_a?(Qpid::Proton::Handler::MessagingHandler)
+
+      # TODO aconway 2017-11-08: allow handlers, opts for backwards compat?
+      @handler = handler
+      @id = (id || SecureRandom.uuid).freeze
       @work = Queue.new
       @work.push self           # Let the first #run thread select
       @wake = IO.pipe

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4856b6e1/proton-c/bindings/ruby/lib/core/listener.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/listener.rb b/proton-c/bindings/ruby/lib/core/listener.rb
index e5f5c0d..85dc976 100644
--- a/proton-c/bindings/ruby/lib/core/listener.rb
+++ b/proton-c/bindings/ruby/lib/core/listener.rb
@@ -20,7 +20,10 @@
 module Qpid::Proton
   # A listener for incoming connections.
   #
-  # Create with {Container#listen} or  {Container#listen_with}
+  # Create with {Container#listen} or  {Container#listen_io}.
+  # To control the handler and connection options applied to incoming connections,
+  # pass a {ListenerHandler} on creation.
+  #
   class Listener
     # The listener's container
     attr_reader :container

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4856b6e1/proton-c/bindings/ruby/tests/test_container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_container.rb b/proton-c/bindings/ruby/tests/test_container.rb
index 41fa133..51b1760 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -28,8 +28,8 @@ Disposition = Qpid::Proton::Disposition
 # Container that listens on a random port
 class TestContainer < Container
 
-  def initialize(opts = {}, lopts = {})
-    super opts
+  def initialize(handler, lopts = {}, id=nil)
+    super handler, id
     @server = TCPServer.open(0)
     @listener = listen_io(@server, ListenOnceHandler.new(lopts))
   end
@@ -69,7 +69,7 @@ class ContainerTest < Minitest::Test
       end
     end.new
 
-    c = TestContainer.new({:id => __method__.to_s, :handler => rh})
+    c = TestContainer.new(rh, {}, "test_simple")
     c.connect(c.url, {:handler => sh}).open_sender({:name => "testlink"})
     c.run
 
@@ -85,8 +85,8 @@ class ContainerTest < Minitest::Test
   end
 
   def test_auto_stop
-    c1 = Container.new "#{__method__}1"
-    c2 = Container.new "#{__method__}2"
+    c1 = Container.new
+    c2 = Container.new
 
     # A listener and a connection
     t1 = 3.times.collect { Thread.new { c1.run } }
@@ -104,7 +104,7 @@ class ContainerTest < Minitest::Test
   end
 
   def test_auto_stop_listener_only
-    c1 = Container.new "#{__method__}1"
+    c1 = Container.new
     # Listener only, external close
     t1 = Thread.new { c1.run }
     l = c1.listen_io(TCPServer.new(0))
@@ -113,7 +113,7 @@ class ContainerTest < Minitest::Test
   end
 
   def test_stop
-    c = Container.new __method__
+    c = Container.new
     c.auto_stop = false
     l = c.listen_io(TCPServer.new(0))
     c.connect("amqp://:#{l.to_io.addr[1]}")
@@ -211,7 +211,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
 
   def test_sasl_anonymous()
     s = SASLHandler.new("amqp://",  {:sasl_allowed_mechs => "ANONYMOUS"})
-    TestContainer.new({:id => __method__.to_s, :handler => s}, {:sasl_allowed_mechs => "ANONYMOUS"}).run
+    TestContainer.new(s, {:sasl_allowed_mechs => "ANONYMOUS"}).run
     assert_nil(s.connections[0].user)
   end
 
@@ -220,7 +220,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
     # Use default realm with URL, should authenticate with "default_password"
     opts = {:sasl_allowed_mechs => "PLAIN", :sasl_allow_insecure_mechs => true}
     s = SASLHandler.new("amqp://user:default_password@",  opts)
-    TestContainer.new({:id => __method__.to_s, :handler => s}, opts).run
+    TestContainer.new(s, opts).run
     assert_equal(2, s.connections.size)
     assert_equal("user", s.auth_user)
   end
@@ -231,7 +231,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
     opts = {:sasl_allowed_mechs => "PLAIN",:sasl_allow_insecure_mechs => true,
             :user => 'user', :password => 'default_password' }
     s = SASLHandler.new("amqp://", opts)
-    TestContainer.new({:id => __method__.to_s, :handler => s}, {:sasl_allowed_mechs => "PLAIN",:sasl_allow_insecure_mechs => true}).run
+    TestContainer.new(s, {:sasl_allowed_mechs => "PLAIN",:sasl_allow_insecure_mechs => true}).run
     assert_equal(2, s.connections.size)
     assert_equal("user", s.auth_user)
   end
@@ -240,7 +240,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
   def test_disallow_insecure()
     # Don't set allow_insecure_mechs, but try to use PLAIN
     s = SASLHandler.new("amqp://user:password@", {:sasl_allowed_mechs => "PLAIN", :sasl_allow_insecure_mechs => true})
-    e = assert_raises(TestError) { TestContainer.new({:id => __method__.to_s, :handler => s}, {:sasl_allowed_mechs => "PLAIN"}).run }
+    e = assert_raises(TestError) { TestContainer.new(s, {:sasl_allowed_mechs => "PLAIN"}).run }
     assert_match(/PN_TRANSPORT_ERROR.*unauthorized-access/, e.to_s)
   end
 end


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