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/12/18 18:50:35 UTC
qpid-proton git commit: PROTON-1720: [ruby] Missing link options,
remove handler options
Repository: qpid-proton
Updated Branches:
refs/heads/master 055f3dc6b -> c5351a9d7
PROTON-1720: [ruby] Missing link options, remove handler options
- Filled in missing link options
- Removed all options from MessagingHandler:
- credit_window, auto_settle and auto_accept are now link options
- on_xxx_open/close can prevent an auto-response by raising StopAutoResponse
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c5351a9d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c5351a9d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c5351a9d
Branch: refs/heads/master
Commit: c5351a9d710e52086a09d571079e104895869cfd
Parents: 055f3dc
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Dec 18 13:41:15 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Mon Dec 18 13:49:02 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/connection.rb | 2 +-
proton-c/bindings/ruby/lib/core/exceptions.rb | 4 ++
proton-c/bindings/ruby/lib/core/link.rb | 2 +-
.../bindings/ruby/lib/core/messaging_handler.rb | 28 +++-------
proton-c/bindings/ruby/lib/core/receiver.rb | 33 +++++++++++
proton-c/bindings/ruby/lib/core/sender.rb | 26 ++++++++-
proton-c/bindings/ruby/lib/core/session.rb | 40 ++++----------
proton-c/bindings/ruby/lib/core/terminus.rb | 56 +++++++++++++++----
.../ruby/lib/handler/messaging_adapter.rb | 58 ++++++++++----------
proton-c/bindings/ruby/tests/test_container.rb | 3 +-
proton-c/bindings/ruby/tests/test_delivery.rb | 3 +-
.../ruby/tests/test_messaging_adapter.rb | 45 +++++++--------
12 files changed, 182 insertions(+), 118 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/connection.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection.rb b/proton-c/bindings/ruby/lib/core/connection.rb
index f9a80a7..e71e69b 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -132,7 +132,7 @@ module Qpid::Proton
Cproton.pn_connection_set_user(@impl, opts[:user]) if opts[:user]
Cproton.pn_connection_set_password(@impl, opts[:password]) if opts[:password]
Cproton.pn_connection_set_hostname(@impl, opts[:virtual_host]) if opts[:virtual_host]
- @link_prefix = opts[:link_prefix] || cid
+ @link_prefix = opts[:link_prefix] || cid
Codec::Data.from_object(Cproton.pn_connection_offered_capabilities(@impl),
Types.symbol_array(opts[:offered_capabilities]))
Codec::Data.from_object(Cproton.pn_connection_desired_capabilities(@impl),
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 66af5fc..1f74085 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -122,4 +122,8 @@ module Qpid::Proton
class AbortedError < ProtonError
end
+ # Raised to stop an automatic response to an endpoint open/close,
+ # so that the application can delay completing the open/close to a later time.
+ class StopAutoResponse < ProtonError
+ end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/link.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/link.rb b/proton-c/bindings/ruby/lib/core/link.rb
index 2e656c2..8b1525f 100644
--- a/proton-c/bindings/ruby/lib/core/link.rb
+++ b/proton-c/bindings/ruby/lib/core/link.rb
@@ -48,7 +48,7 @@ module Qpid::Proton
#
proton_caller :state
- # @deprecated use {Session#open_sender} and {#Session#open_receiver}
+ # @deprecated Use {Sender#open} or {Receiver#open}
proton_caller :open
# Close the local end of the link. The remote end may or may not be closed.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/messaging_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/messaging_handler.rb b/proton-c/bindings/ruby/lib/core/messaging_handler.rb
index b733d37..88392f9 100644
--- a/proton-c/bindings/ruby/lib/core/messaging_handler.rb
+++ b/proton-c/bindings/ruby/lib/core/messaging_handler.rb
@@ -1,4 +1,4 @@
-# Licensed to the Apache Software Foundation (ASF) under one
+ # 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
@@ -22,31 +22,17 @@ module Qpid::Proton
#
# Subclass the handler and provide the #on_xxx methods with your event-handling code.
#
+ # An AMQP endpoint (connection, session or link) must be opened and closed at
+ # each end. Normally proton responds automatically to an incoming
+ # open/close. You can prevent the automatic response by raising
+ # {StopAutoResponse} from +#on_xxx_open+ or +#on_xxx_close+. The application becomes responsible
+ # for calling +#open/#close+ at a later point.
+ #
class MessagingHandler
# @private
def proton_adapter_class() Handler::MessagingAdapter; end
- # Create a {MessagingHandler}
- # @option opts [Integer] :prefetch (10)
- # The number of messages to fetch in advance, 0 disables prefetch.
- # @option opts [Boolean] :auto_accept (true)
- # If true, incoming messages are accepted automatically after {#on_message}.
- # If false, the application can accept, reject or release the message
- # by calling methods on {Delivery} when the message has been processed.
- # @option opts [Boolean] :auto_settle (true) If true, outgoing
- # messages are settled automatically when the remote peer settles. If false,
- # the application must call {Delivery#settle} explicitly.
- # @option opts [Boolean] :auto_open (true)
- # If true, incoming connections are opened automatically.
- # If false, the application must call {Connection#open} to open incoming connections.
- # @option opts [Boolean] :auto_close (true)
- # If true, respond to a remote close automatically with a local close.
- # If false, the application must call {Connection#close} to finish closing connections.
- def initialize(opts={})
- @options = opts.clone
- end
-
# @return [Hash] handler options, see {#initialize}
attr_reader :options
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/receiver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/receiver.rb b/proton-c/bindings/ruby/lib/core/receiver.rb
index 791e891..649219f 100644
--- a/proton-c/bindings/ruby/lib/core/receiver.rb
+++ b/proton-c/bindings/ruby/lib/core/receiver.rb
@@ -29,6 +29,39 @@ module Qpid::Proton
# @private
include Util::Wrapper
+ # Open {Receiver} link
+ #
+ # @overload open_receiver(address)
+ # @param address [String] address of the source to receive from
+ # @overload open_receiver(opts)
+ # @param opts [Hash] Receiver options, see {Receiver#open}
+ # @option opts [Boolean] :credit_window automatically maintain this much credit
+ # for messages to be pre-fetched while the current message is processed.
+ # @option opts [Boolean] :auto_accept if true, deliveries that are not settled by
+ # the application in {MessagingHandler#on_message} are automatically accepted.
+ # @option opts [Integer] :credit_window (10) automatically replenish credits for flow control.
+ # @option opts [Boolean] :dynamic (false) dynamic property for source {Terminus#dynamic}
+ # @option opts [String,Hash] :source source address or source options, see {Terminus#apply}
+ # @option opts [String,Hash] :target target address or target options, see {Terminus#apply}
+ # @option opts [String] :name (generated) unique name for the link.
+ def open(opts=nil)
+ opts ||= {}
+ opts = { :source => opts } if opts.is_a? String
+ @credit_window = opts.fetch(:credit_window, 10)
+ @auto_accept = opts.fetch(:auto_accept, true)
+ source.apply(opts[:source])
+ target.apply(opts[:target])
+ source.dynamic = !!opts[:dynamic]
+ super()
+ self
+ end
+
+ # @return [Integer] credit window, see {#open}
+ attr_reader :credit_window
+
+ # @return [Boolean] auto_accept flag, see {#open}
+ attr_reader :auto_accept
+
# @!attribute drain
#
# The drain mode.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/core/sender.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/sender.rb b/proton-c/bindings/ruby/lib/core/sender.rb
index c1ba1f8..ff035cb 100644
--- a/proton-c/bindings/ruby/lib/core/sender.rb
+++ b/proton-c/bindings/ruby/lib/core/sender.rb
@@ -27,6 +27,30 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
+ # Open the {Sender} link
+ #
+ # @overload open_sender(address)
+ # @param address [String] address of the target to send to
+ # @overload open_sender(opts)
+ # @option opts [Boolean] :auto_settle (true) if true, automatically settle transfers
+ # @option opts [Boolean] :dynamic (false) dynamic property for source {Terminus#dynamic}
+ # @option opts [String,Hash] :source source address or source options, see {Terminus#apply}
+ # @option opts [String,Hash] :target target address or target options, see {Terminus#apply}
+ # @option opts [String] :name (generated) unique name for the link.
+ def open(opts=nil)
+ opts = { :target => opts } if opts.is_a? String
+ opts ||= {}
+ target.apply opts[:target]
+ source.apply opts[:source]
+ target.dynamic = !!opts[:dynamic]
+ @auto_settle = opts.fetch(:auto_settle, true)
+ super()
+ self
+ end
+
+ # @return [Boolean] auto_settle flag, see {#open}
+ attr_reader :auto_settle
+
# Hint to the remote receiver about the number of messages available.
# The receiver may use this to optimize credit flow, or may ignore it.
# @param n [Integer] The number of deliveries potentially available.
@@ -68,8 +92,6 @@ module Qpid::Proton
def initialize(*arg) super; @tag_count = 0; end
def next_tag() (@tag_count += 1).to_s(32); end
-
- # @private
can_raise_error :stream, :error_class => Qpid::Proton::LinkError
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/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 78e78a2..5508fd9 100644
--- a/proton-c/bindings/ruby/lib/core/session.rb
+++ b/proton-c/bindings/ruby/lib/core/session.rb
@@ -56,13 +56,7 @@ module Qpid::Proton
#
proton_caller :incoming_bytes
- # @!method open
- # Opens the session.
- #
- # Once this operaton has completed, the state flag is updated.
- #
- # @see LOCAL_ACTIVE
- #
+ # Open the session
proton_caller :open
# @!attribute [r] state
@@ -116,30 +110,20 @@ module Qpid::Proton
Receiver.new(Cproton.pn_receiver(@impl, name))
end
- # TODO aconway 2016-01-04: doc options or target param, move option handling to Link.
- def open_receiver(opts=nil)
- opts = { :source => opts } if opts.is_a? String
- opts ||= {}
- receiver = Receiver.new Cproton.pn_receiver(@impl, opts[:name] || connection.link_name)
- receiver.source.address ||= opts[:source]
- receiver.target.address ||= opts[:target]
- receiver.source.dynamic = true if opts[:dynamic]
- receiver.handler = opts[:handler] if !opts[:handler].nil?
- receiver.open
- return receiver
+ # Create and open a {Receiver} link, see {Receiver#open}
+ # @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)
end
- # TODO aconway 2016-01-04: doc opts or target param, connection and containers
+ # Create and open a {Sender} link, see {#open}
+ # @param opts [Hash] sender options, see {Sender#open}
+ # @return [Sender]
def open_sender(opts=nil)
- opts = { :target => opts } if opts.is_a? String
- opts ||= {}
- sender = Sender.new Cproton.pn_sender(@impl, opts[:name] || connection.link_name)
- sender.target.address ||= opts[:target]
- sender.source.address ||= opts[:source]
- sender.target.dynamic = true if opts[:dynamic]
- sender.handler = opts[:handler] if !opts[:handler].nil?
- sender.open
- return sender
+ name = opts[:name] rescue connection.link_name
+ Sender.new(Cproton.pn_sender(@impl, name)).open(opts)
end
# Get the links on this Session.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/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 d3181db..df7ca8e 100644
--- a/proton-c/bindings/ruby/lib/core/terminus.rb
+++ b/proton-c/bindings/ruby/lib/core/terminus.rb
@@ -29,6 +29,7 @@ module Qpid::Proton
# the Link.
#
class Terminus
+ include Util::Deprecation
# Indicates a non-existent source or target terminus.
UNSPECIFIED = Cproton::PN_UNSPECIFIED
@@ -85,7 +86,7 @@ module Qpid::Proton
#
proton_set_get :address
- # @!attribute durability
+ # @!attribute durability_mode
#
# @return [Integer] The durability mode of the terminus.
#
@@ -93,7 +94,11 @@ module Qpid::Proton
# @see CONFIGURATION
# @see DELIVERIES
#
- proton_set_get :durability
+ proton_forward :durability_mode, :get_durability
+ proton_forward :durability_mode=, :set_durability
+
+ deprecated_alias :durability, :durability_mode
+ deprecated_alias :durability=, :durability_mode=
# @!attribute expiry_policy
#
@@ -120,7 +125,7 @@ module Qpid::Proton
# @!attribute distribution_mode
#
- # @return [Integer] The distribution mode.
+ # @return [Integer] The distribution mode. Only relevant for a message source.
#
# @see DIST_MODE_UNSPECIFIED
# @see DIST_MODE_COPY
@@ -184,7 +189,8 @@ module Qpid::Proton
Codec::Data.new(Cproton.pn_terminus_outcomes(@impl))
end
- # Access and modify the AMQP filter set for the Terminus.
+ # Access and modify the AMQP filter set for a source terminus.
+ # Only relevant for a message source.
#
# This operation will return an instance of Data that is valid until the
# Terminus is freed due to its parent being freed. Any data contained in
@@ -199,12 +205,42 @@ module Qpid::Proton
Codec::Data.new(Cproton.pn_terminus_filter(@impl))
end
- # Copy another Terminus into this instance.
- #
- # @param source [Terminus] The source instance.
- #
- def copy(source)
- Cproton.pn_terminus_copy(@impl,source.impl)
+ # Replace the data in this Terminus with the contents of +other+
+ # @param other [Terminus] The other instance.
+ def replace(other)
+ Cproton.pn_terminus_copy(@impl, other.impl)
+ self
+ end
+ deprecated_alias :copy, :replace
+
+ # Apply options to this terminus.
+ # @option opts [String] :address the node address
+ # @option opts [Boolean] :dynamic (false)
+ # if true, request a new node with a unique address to be created. +:address+ is ignored.
+ # @option opts [Integer] :distribution_mode see {#distribution_mode}, only for source nodes
+ # @option opts [Integer] :durability_mode see {#durability_mode}
+ # @option opts [Integer] :timeout see {#timeout}
+ # @option opts [Integer] :expiry_policy see {#expiry_policy}
+ # @option opts [Hash] :filter see {#filter}, only for source nodes
+ # @option opts [Hash] :capabilities see {#capabilities}
+ def apply(opts=nil)
+ return unless opts
+ if opts.is_a? String # Shorthand for address
+ self.address = opts
+ else
+ opts.each_pair do |k,v|
+ case k
+ when :address then self.address = v
+ when :dynamic then self.dynamic = !!v
+ when :distribution_mode then self.distribution_mode = v
+ when :durability_mode then self.durability_mode = v
+ when :timeout then self.timeout = v
+ when :expiry_policy then self.expiry_policy = v
+ when :filter then self.filter = v
+ when :capabilities then self.capabilities = v
+ end
+ end
+ end
end
can_raise_error([:type=, :address=, :durability=, :expiry_policy=,
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/lib/handler/messaging_adapter.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/messaging_adapter.rb b/proton-c/bindings/ruby/lib/handler/messaging_adapter.rb
index 92dbba4..92f92e1 100644
--- a/proton-c/bindings/ruby/lib/handler/messaging_adapter.rb
+++ b/proton-c/bindings/ruby/lib/handler/messaging_adapter.rb
@@ -22,15 +22,6 @@ module Qpid::Proton
# Adapt raw proton events to {MessagingHandler} events.
class MessagingAdapter < Adapter
- def initialize handler
- super
- @opts = { :prefetch => 10, :auto_accept => true, :auto_settle => true,
- :auto_open => true, :auto_close => true }
- if handler.respond_to?(:options) && handler.options
- @opts.update(handler.options)
- handler.options.replace @opts
- end
- end
def delegate(method, *args)
forward(method, *args) or forward(:on_unhandled, method, *args)
@@ -39,8 +30,8 @@ module Qpid::Proton
def delegate_error(method, context)
unless forward(method, context) || forward(:on_error, context.condition)
forward(:on_unhandled, method, context)
- # By default close the whole connection on an un-handled error
- context.connection.close(context.condition) if @opts[:auto_close]
+ # Close the whole connection on an un-handled error
+ context.connection.close(context.condition)
end
end
@@ -51,14 +42,20 @@ module Qpid::Proton
def self.open_close(endpoint)
Module.new do
define_method(:"on_#{endpoint}_remote_open") do |event|
- delegate(:"on_#{endpoint}_open", event.context)
- event.context.open if @opts[:auto_open] && event.context.local_uninit?
+ begin
+ delegate(:"on_#{endpoint}_open", event.context)
+ event.context.open if event.context.local_uninit?
+ rescue StopAutoResponse
+ end
end
define_method(:"on_#{endpoint}_remote_close") do |event|
delegate_error(:"on_#{endpoint}_error", event.context) if event.context.condition
- delegate(:"on_#{endpoint}_close", event.context)
- event.context.close if @opts[:auto_close] && event.context.local_active?
+ begin
+ delegate(:"on_#{endpoint}_close", event.context)
+ event.context.close if event.context.local_active?
+ rescue StopAutoResponse
+ end
end
end
end
@@ -66,12 +63,17 @@ module Qpid::Proton
# Using modules so we can override to extend the behavior later in the handler.
[:connection, :session, :link].each { |endpoint| include open_close(endpoint) }
- def on_transport_error(event) delegate_error(:on_transport_error, event.context); end
- def on_transport_closed(event) delegate(:on_transport_close, event.context); end
+ def on_transport_error(event)
+ delegate_error(:on_transport_error, event.context)
+ end
+
+ def on_transport_closed(event)
+ delegate(:on_transport_close, event.context) rescue StopAutoResponse
+ end
# Add flow control for link opening events
- def on_link_local_open(event) add_credit(event.receiver); end
- def on_link_remote_open(event) super; add_credit(event.receiver); end
+ def on_link_local_open(event) add_credit(event); end
+ def on_link_remote_open(event) super; add_credit(event); end
def on_delivery(event)
@@ -80,12 +82,12 @@ module Qpid::Proton
if d.aborted?
delegate(:on_delivery_abort, d)
elsif d.complete?
- if d.link.local_closed? && @opts[:auto_accept]
+ if d.link.local_closed? && d.receiver.auto_accept
d.release # Auto release after close
else
begin
delegate(:on_message, d, d.message)
- d.accept if @opts[:auto_accept] && !d.settled?
+ d.accept if d.receiver.auto_accept && !d.settled?
rescue Reject
d.reject unless d.settled?
rescue Release
@@ -94,7 +96,7 @@ module Qpid::Proton
end
end
delegate(:on_delivery_settle, d) if d.settled?
- add_credit(event.receiver)
+ add_credit(event)
else # Outgoing message
t = event.tracker
case t.state
@@ -104,20 +106,20 @@ module Qpid::Proton
when Delivery::MODIFIED then delegate(:on_tracker_modify, t)
end
delegate(:on_tracker_settle, t) if t.settled?
- t.settle if @opts[:auto_settle]
+ t.settle if t.sender.auto_settle
end
end
def on_link_flow(event)
- add_credit(event.receiver)
+ add_credit(event)
sender = event.sender
delegate(:on_sendable, sender) if sender && sender.open? && sender.credit > 0
end
- def add_credit(r)
- prefetch = @opts[:prefetch]
- if r && r.open? && (r.drained == 0) && prefetch && (prefetch > r.credit)
- r.flow(prefetch - r.credit)
+ def add_credit(event)
+ return unless (r = event.receiver)
+ if r.open? && (r.drained == 0) && r.credit_window && (r.credit_window > r.credit)
+ r.flow(r.credit_window - r.credit)
end
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/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 82c34e2..f2ad1f1 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -164,7 +164,8 @@ class ContainerTest < Minitest::Test
# Note: user, password and sasl_xxx options are tested by ContainerSASLTest below
server_handler = Class.new(MessagingHandler) do
def on_error(e) raise e.inspect; end
- def on_connection_open(c) @connection = c
+ def on_connection_open(c)
+ @connection = c
c.open({
:virtual_host => "server.to.client",
:properties => { :server => :client },
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/tests/test_delivery.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_delivery.rb b/proton-c/bindings/ruby/tests/test_delivery.rb
index db15321..266ccd6 100644
--- a/proton-c/bindings/ruby/tests/test_delivery.rb
+++ b/proton-c/bindings/ruby/tests/test_delivery.rb
@@ -25,8 +25,7 @@ include Qpid::Proton
class TestDelivery < Minitest::Test
class NoAutoHandler < MessagingHandler
- @@options = {:auto_settle=>false, :auto_accept=>false}
- def options() @@options; end
+ def on_link_open(l) l.open({:auto_settle=>false, :auto_accept=>false}); end
end
class SendHandler < NoAutoHandler
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c5351a9d/proton-c/bindings/ruby/tests/test_messaging_adapter.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_messaging_adapter.rb b/proton-c/bindings/ruby/tests/test_messaging_adapter.rb
index 200b68c..5a2055b 100644
--- a/proton-c/bindings/ruby/tests/test_messaging_adapter.rb
+++ b/proton-c/bindings/ruby/tests/test_messaging_adapter.rb
@@ -45,14 +45,18 @@ class DriverPair
def clear() each { |x| x.handler.clear; } end
end
-class TestMessagingHandler < Minitest::Test
+class NoAutoOpenClose < RecordingHandler
+ def initialize() super; @endpoints = []; end
+ def on_connection_open(x) @connection = x; super; raise StopAutoResponse; end
+ def on_session_open(x) @session = x; super; raise StopAutoResponse; end
+ def on_link_open(x) @link = x; super; raise StopAutoResponse; end
+ def on_connection_close(x) super; raise StopAutoResponse; end
+ def on_session_close(x) super; raise StopAutoResponse; end
+ def on_link_close(x) super; raise StopAutoResponse; end
+ attr_reader :connection, :session, :link
+end
- def test_handler_defaults
- d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
- want = { :prefetch => 10, :auto_settle => true, :auto_accept => true, :auto_open => true, :auto_close => true }
- assert_equal want, d.client.handler.options
- assert_equal want, d.server.handler.options
- end
+class TestMessagingHandler < Minitest::Test
def test_auto_open_close
d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
@@ -66,9 +70,7 @@ class TestMessagingHandler < Minitest::Test
end
def test_no_auto_open_close
- opts = { :auto_close => false, :auto_open => false }
- d = DriverPair.new(RecordingHandler.new(opts), RecordingHandler.new(opts))
-
+ d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
d.client.connection.open; d.run
assert_equal [:on_connection_open], d.server.handler.names
assert_equal [], d.client.handler.names
@@ -76,7 +78,7 @@ class TestMessagingHandler < Minitest::Test
assert_equal [:on_connection_open], d.client.handler.names
assert_equal [:on_connection_open], d.server.handler.names
d.clear
- d.client.connection.session.open; d.run
+ d.client.connection.open_session; d.run
assert_equal [:on_session_open], d.server.handler.names
assert_equal [], d.client.handler.names
d.clear
@@ -102,10 +104,10 @@ class TestMessagingHandler < Minitest::Test
# Close on half-open
def test_connection_error
- opts = { :auto_open => false }
- d = DriverPair.new(RecordingHandler.new(opts), RecordingHandler.new(opts))
+ d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
d.client.connection.open; d.run
d.server.connection.close "bad dog"; d.run
+ d.client.connection.close; d.run
assert_equal [:on_connection_open, :on_connection_error, :on_connection_close, :on_transport_close], d.client.handler.names
assert_equal "bad dog", d.client.handler.calls[1][1].condition.description
assert_equal [:on_connection_open, :on_connection_error, :on_connection_close, :on_transport_close], d.server.handler.names
@@ -137,24 +139,19 @@ class TestMessagingHandler < Minitest::Test
assert_equal "bad dog", d.server.handler.calls[0][1].condition.description
end
- def test_options_off
- handler_class = Class.new(RecordingHandler) do
- def on_link_open(l) super; @link = l; end
- def on_session_open(s) super; @session = s; end
- attr_reader :link, :session
- end
- off = {:prefetch => nil, :auto_settle => false, :auto_accept => false, :auto_open => false, :auto_close => false}
- d = DriverPair.new(handler_class.new(off), handler_class.new(off))
+ def test_options_off
+ linkopts = {:credit_window=>0, :auto_settle=>false, :auto_accept=>false}
+ d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
d.client.connection.open; d.run
assert_equal [[], [:on_connection_open]], d.names
d.server.connection.open; d.run
assert_equal [[:on_connection_open], [:on_connection_open]], d.names
d.clear
- s = d.client.connection.open_sender; d.run
+ s = d.client.connection.open_sender(linkopts); d.run
assert_equal [[], [:on_session_open, :on_link_open]], d.names
- d.server.handler.session.open
- d.server.handler.link.open # Return the opens
+ d.server.handler.session.open # Return session open
+ d.server.handler.link.open(linkopts) # Return link open
d.run
assert_equal [[:on_session_open, :on_link_open], [:on_session_open, :on_link_open]], d.names
d.clear
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org