PROTON-1790: [ruby] Link name not generated
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/de8df025 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/de8df025 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/de8df025 Branch: refs/heads/master Commit: de8df0252ea66630d953ad9ba8d8c80f5983a9e3 Parents: c553d3d Author: Alan Conway <[email protected]> Authored: Tue Mar 20 17:10:30 2018 -0400 Committer: Alan Conway <[email protected]> Committed: Wed Mar 21 09:13:14 2018 -0400 ---------------------------------------------------------------------- proton-c/bindings/ruby/lib/core/session.rb | 10 ++-- proton-c/bindings/ruby/lib/core/terminus.rb | 6 +++ proton-c/bindings/ruby/tests/test_container.rb | 51 +++++++++++++++++---- proton-c/bindings/ruby/tests/test_tools.rb | 18 +++++--- 4 files changed, 64 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/de8df025/proton-c/bindings/ruby/lib/core/session.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/core/session.rb b/proton-c/bindings/ruby/lib/core/session.rb index 5508fd9..91dabcf 100644 --- a/proton-c/bindings/ruby/lib/core/session.rb +++ b/proton-c/bindings/ruby/lib/core/session.rb @@ -114,16 +114,14 @@ module Qpid::Proton # @param opts [Hash] receiver options, see {Receiver#open} # @return [Receiver] def open_receiver(opts=nil) - name = opts[:name] rescue connection.link_name - Receiver.new(Cproton.pn_receiver(@impl, name)).open(opts) + Receiver.new(Cproton.pn_receiver(@impl, link_name(opts))).open(opts) end # Create and open a {Sender} link, see {#open} # @param opts [Hash] sender options, see {Sender#open} # @return [Sender] def open_sender(opts=nil) - name = opts[:name] rescue connection.link_name - Sender.new(Cproton.pn_sender(@impl, name)).open(opts) + Sender.new(Cproton.pn_sender(@impl, link_name(opts))).open(opts) end # Get the links on this Session. @@ -150,6 +148,10 @@ module Qpid::Proton private + def link_name(opts) + (opts.respond_to?(:to_hash) && opts[:name]) || connection.link_name + end + def _local_condition Cproton.pn_session_condition(@impl) end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/de8df025/proton-c/bindings/ruby/lib/core/terminus.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/core/terminus.rb b/proton-c/bindings/ruby/lib/core/terminus.rb index ffa1e7d..a7a8af0 100644 --- a/proton-c/bindings/ruby/lib/core/terminus.rb +++ b/proton-c/bindings/ruby/lib/core/terminus.rb @@ -243,6 +243,12 @@ module Qpid::Proton end end + def inspect() + "\#<#{self.class}: address=#{address.inspect} dynamic?=#{dynamic?.inspect}>" + end + + def to_s() inspect; end + can_raise_error([:type=, :address=, :durability=, :expiry_policy=, :timeout=, :dynamic=, :distribution_mode=, :copy], :error_class => Qpid::Proton::LinkError) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/de8df025/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 29cf985..b35e24f 100644 --- a/proton-c/bindings/ruby/tests/test_container.rb +++ b/proton-c/bindings/ruby/tests/test_container.rb @@ -65,8 +65,7 @@ class ContainerTest < MiniTest::Test c = ServerContainer.new(__method__, {:handler => receive_handler}) c.connect(c.url, {:handler => send_handler}).open_sender({:name => "testlink"}) - send_handler.wait - c.wait + c.run assert send_handler.accepted assert_equal "testlink", receive_handler.link.name @@ -160,9 +159,8 @@ class ContainerTest < MiniTest::Test def test_connection_options # Note: user, password and sasl_xxx options are tested by ContainerSASLTest below server_handler = Class.new(ExceptionMessagingHandler) do - def initialize() @connection = Queue.new; end def on_connection_open(c) - @connection << c + @connection = c c.open({ :virtual_host => "server.to.client", :properties => { :server => :client }, @@ -191,10 +189,9 @@ class ContainerTest < MiniTest::Test :max_frame_size => 4096, :container_id => "bowl" }) - server = server_handler.connection.pop - cont.wait + cont.run - c = server + c = server_handler.connection assert_equal "client.to.server", c.virtual_host assert_equal({ :foo => :bar, :str => "str" }, c.properties) assert_equal([:c1], c.offered_capabilities) @@ -215,6 +212,39 @@ class ContainerTest < MiniTest::Test assert_equal 100, c.max_sessions end + def test_link_options + server_handler = Class.new(ExceptionMessagingHandler) do + def initialize() @links = []; end + attr_reader :links + def on_sender_open(l) @links << l; end + def on_receiver_open(l) @links << l; end + end.new + + client_handler = Class.new(ExceptionMessagingHandler) do + def on_connection_open(c) + @links = []; + @links << c.open_sender("s1") + @links << c.open_sender({:name => "s2-n", :target => "s2-t", :source => "s2-s"}) + @links << c.open_receiver("r1") + @links << c.open_receiver({:name => "r2-n", :target => "r2-t", :source => "r2-s"}) + c.close + end + attr_reader :links + end.new + + cont = ServerContainer.new(__method__, {:handler => server_handler }, 1) + cont.connect(cont.url, :handler => client_handler) + cont.run + + expect = ["test_link_options/1", "s2-n", "test_link_options/2", "r2-n"] + assert_equal expect, server_handler.links.map(&:name) + assert_equal expect, client_handler.links.map(&:name) + + expect = [[nil,"s1"], ["s2-s","s2-t"], ["r1",nil], ["r2-s","r2-t"]] + assert_equal expect, server_handler.links.map { |l| [l.remote_source.address, l.remote_target.address] } + assert_equal expect, client_handler.links.map { |l| [l.source.address, l.target.address] } + end + # Test for time out on connecting to an unresponsive server def test_idle_timeout_server_no_open s = TCPServer.new(0) @@ -228,7 +258,7 @@ class ContainerTest < MiniTest::Test # Test for time out on unresponsive client def test_idle_timeout_client - server = ServerContainer.new("#{__method__}.server", {:idle_timeout => 0.1}) + server = ServerContainerThread.new("#{__method__}.server", {:idle_timeout => 0.1}) client_handler = Class.new(ExceptionMessagingHandler) do def initialize() @ready, @block = Queue.new, Queue.new; end attr_reader :ready, :block @@ -237,11 +267,12 @@ class ContainerTest < MiniTest::Test @block.pop # Block the client so the server will time it out end end.new + client = Container.new(nil, "#{__method__}.client") client.connect(server.url, {:handler => client_handler}) client_thread = Thread.new { client.run } client_handler.ready.pop # Wait till the client has connected - server.wait # Exits when the connection closes from idle-timeout + server.join # Exits when the connection closes from idle-timeout client_handler.block.push nil # Unblock the client ex = assert_raises(Qpid::Proton::Condition) { client_thread.join } assert_match(/resource-limit-exceeded/, ex.to_s) @@ -250,7 +281,7 @@ class ContainerTest < MiniTest::Test # Make sure we stop and clean up if an aborted connection causes a handler to raise. # https://issues.apache.org/jira/browse/PROTON-1791 def test_handler_raise - cont = ServerContainer.new(__method__) + cont = ServerContainer.new(__method__, {}, 0) # Don't auto-close the listener client_handler = Class.new(MessagingHandler) do # TestException is < Exception so not handled by default rescue clause def on_connection_open(c) raise TestException.new("Bad Dog"); end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/de8df025/proton-c/bindings/ruby/tests/test_tools.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/tests/test_tools.rb b/proton-c/bindings/ruby/tests/test_tools.rb index a4110d4..911669b 100644 --- a/proton-c/bindings/ruby/tests/test_tools.rb +++ b/proton-c/bindings/ruby/tests/test_tools.rb @@ -147,23 +147,27 @@ DriverPair = Struct.new(:client, :server) do end end -# Container that listens on a random port and runs itself +# Container that listens on a random port class ServerContainer < Qpid::Proton::Container include Qpid::Proton - def initialize(id=nil, listener_opts=nil, n=0) + def initialize(id=nil, listener_opts=nil, n=1) super id @listener = listen_io(TCPServer.open(0), ListenOnceHandler.new(listener_opts, n)) - @thread = Thread.new { run } end attr_reader :listener def port() @listener.port; end def url() "amqp://:#{port}"; end - - # NOTE: the test must have already waited for some events to happen before - # calling this, otherwise the listener can close before it opens and nothing happens - def wait() @listener.close; @thread.join; end end +class ServerContainerThread < ServerContainer + def initialize(id=nil, listener_opts=nil, n=1) + super + @thread = Thread.new { run } + end + + attr_reader :thread + def join() @thread.join; end +end --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
