[DRE-commits] [ruby-stomp] 01/05: Imported Upstream version 1.2.16
Jonas Genannt
jonas at brachium-system.net
Fri Sep 20 20:01:52 UTC 2013
This is an automated email from the git hooks/post-receive script.
hggh-guest pushed a commit to branch master
in repository ruby-stomp.
commit 72a2b56ada1c0fe45b653f1136efb394889f3193
Author: Jonas Genannt <jonas at brachium-system.net>
Date: Fri Sep 20 21:47:56 2013 +0200
Imported Upstream version 1.2.16
---
CHANGELOG.rdoc | 21 ++++++++-
README.rdoc | 6 +++
Rakefile | 1 +
checksums.yaml.gz | Bin 0 -> 427 bytes
examples/ssl_uc2.rb | 2 +-
examples/ssl_uc3.rb | 4 +-
lib/client/utils.rb | 59 +++++++++++--------------
lib/connection/netio.rb | 65 ++++++++++++++++++---------
lib/connection/utils.rb | 4 +-
lib/stomp/client.rb | 31 ++++---------
lib/stomp/connection.rb | 14 ++++--
lib/stomp/errors.rb | 8 ++++
lib/stomp/version.rb | 2 +-
metadata.yml | 99 +++++++++++++++++------------------------
spec/client_spec.rb | 113 ++++++++++++++++++++++++++++++-----------------
spec/connection_spec.rb | 14 +++---
stomp.gemspec | 5 ++-
test/test_client.rb | 28 +++++++++++-
18 files changed, 283 insertions(+), 193 deletions(-)
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index e5cd967..b9711c6 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,4 +1,23 @@
-== 1.2.12 20130728
+== 1.2.16 20130812
+
+* Stomp::Client's should expose connection's host params
+
+== 1.2.15 20130809
+
+* Add user-specified timeout for initial CONNECTED/ERROR frame read.
+* Eliminate dup Timeout::timeout in ssl connect
+* Add license information to gemspec (#69)
+
+== 1.2.14 20130819
+
+* Version bump (1.2.13 release had Stomp::Version of 1.1.12.)
+* Prevent dup subscription header on re-receive
+
+== 1.2.13 20130817
+
+* Issue #68, Stomp::Client#unreceive max_redeliveries off-by-one error
+
+== 1.2.12 20130811
* Fix infinite loop when max reconn attempts is reached
* Enhance JRuby support in tests
diff --git a/README.rdoc b/README.rdoc
index c81097f..34615a3 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -12,6 +12,10 @@ An implementation of the Stomp protocol for Ruby. See:
See _CHANGELOG.rdoc_ for details.
+* Gem version 1.2.16. Fixed Stomp::Client to expose its connection's host parameters.
+* Gem version 1.2.15. Timeout cleanup, added license info to gemspec.
+* Gem version 1.2.14. Cleanup.
+* Gem version 1.2.13. Stomp::Client#unreceive max_redeliveries fix.
* Gem version 1.2.12. Miscellaneous issue fixes and cleanup.
* Gem version 1.2.11. JRuby and AMQ support fixes.
* Gem version 1.2.10. Support failover from heartbeat threads.
@@ -58,6 +62,7 @@ See _CHANGELOG.rdoc_ for details.
:fast_hbs_adjust => 0.0, # Fast heartbeat senders sleep adjustment, seconds, needed ...
# For fast heartbeat senders. 'fast' == YMMV. If not
# correct for your environment, expect unnecessary fail overs
+ :connread_timeout => 0, # Timeout during CONNECT for read of CONNECTED/ERROR, secs
}
# for client
@@ -140,4 +145,5 @@ The following people have contributed to Stomp:
* Jeremy Gailor
* JP Hastings-Spital
* Glenn Roberts
+* Ian Smith
diff --git a/Rakefile b/Rakefile
index 2644257..03826b6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -30,6 +30,7 @@ begin
gem.name = "stomp"
gem.version = Stomp::Version::STRING
gem.summary = %Q{Ruby client for the Stomp messaging protocol}
+ gem.license = "Apache 2.0"
gem.description = %Q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
gem.email = ["brianm at apache.org", 'marius at stones.com', 'morellon at gmail.com',
'allard.guy.m at gmail.com' ]
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
new file mode 100644
index 0000000..88fb18b
Binary files /dev/null and b/checksums.yaml.gz differ
diff --git a/examples/ssl_uc2.rb b/examples/ssl_uc2.rb
index 243ee00..23b0213 100644
--- a/examples/ssl_uc2.rb
+++ b/examples/ssl_uc2.rb
@@ -26,7 +26,7 @@ class ExampleSSL2
def run
ts_flist = []
- # Change the following to the location of your CA's signed certificate.
+ # Change the following to the location of the server's CA signed certificate.
ts_flist << "/home/gmallard/sslwork/2013/TestCA.crt"
ssl_opts = Stomp::SSLParams.new(:ts_files => ts_flist.join(","),
diff --git a/examples/ssl_uc3.rb b/examples/ssl_uc3.rb
index cfb33cb..3f5a767 100644
--- a/examples/ssl_uc3.rb
+++ b/examples/ssl_uc3.rb
@@ -27,8 +27,8 @@ class ExampleSSL3
# Run example.
def run
# Change the following:
- # * location of your client's signed certificate
- # * location of tour client's private key.
+ # * location of the client's signed certificate
+ # * location of the client's private key.
ssl_opts = Stomp::SSLParams.new(
:key_file => "/home/gmallard/sslwork/2013/client.key", # the client's private key
:cert_file => "/home/gmallard/sslwork/2013/client.crt", # the client's signed certificate
diff --git a/lib/client/utils.rb b/lib/client/utils.rb
index 9170344..925a092 100644
--- a/lib/client/utils.rb
+++ b/lib/client/utils.rb
@@ -13,25 +13,20 @@ module Stomp
return false unless params.is_a?(Hash)
@parameters = params
- first_host = @parameters[:hosts][0]
- @login = first_host[:login]
- @passcode = first_host[:passcode]
- @host = first_host[:host]
- @port = first_host[:port] || Connection::default_port(first_host[:ssl])
- @reliable = true
+ @parameters[:reliable] = true
+
true
end
def parse_stomp_url(login)
regexp = /^stomp:\/\/#{URL_REPAT}/
- return false unless login =~ regexp
-
- @login = $3 || ""
- @passcode = $4 || ""
- @host = $5
- @port = $6.to_i
+ return false unless url = regexp.match(login)
- @reliable = false
+ @parameters = { :reliable => false,
+ :hosts => [ { :login => url[3] || "",
+ :passcode => url[4] || "",
+ :host => url[5],
+ :port => url[6].to_i} ] }
true
end
@@ -40,31 +35,28 @@ module Stomp
rval = nil
if md = FAILOVER_REGEX.match(login)
finhosts = parse_hosts(login)
- #
- @login = finhosts[0][:login] || ""
- @passcode = finhosts[0][:passcode] || ""
- @host = finhosts[0][:host] || ""
- @port = finhosts[0][:port] || ""
- #
+
options = {}
- if md_last = md[md.size-1]
+ if md_last = md[-1]
parts = md_last.split(/&|=/)
- raise Stomp::Error::MalformedFailoverOptionsError unless (parts.size % 2 ) == 0
+ raise Stomp::Error::MalformedFailoverOptionsError unless ( parts.size % 2 ) == 0
options = Hash[*parts]
end
- @parameters = {:hosts => finhosts}.merge! filter_options(options)
- @reliable = true
+
+ @parameters = {:hosts => finhosts}.merge!(filter_options(options))
+
+ @parameters[:reliable] = true
rval = true
end
rval
end
def parse_positional_params(login, passcode, host, port, reliable)
- @login = login
- @passcode = passcode
- @host = host
- @port = port.to_i
- @reliable = reliable
+ @parameters = { :reliable => reliable,
+ :hosts => [ { :login => login,
+ :passcode => passcode,
+ :host => host,
+ :port => port.to_i } ] }
true
end
@@ -108,9 +100,12 @@ end
# A very basic check of required arguments.
def check_arguments!()
- raise ArgumentError if @host.nil? || @host.empty?
- raise ArgumentError if @port.nil? || @port == '' || @port < 1 || @port > 65535
- raise ArgumentError unless @reliable.is_a?(TrueClass) || @reliable.is_a?(FalseClass)
+ first_host = @parameters && @parameters[:hosts] && @parameters[:hosts].first
+
+ raise ArgumentError if first_host.nil?
+ raise ArgumentError if first_host[:host].nil? || first_host[:host].empty?
+ raise ArgumentError if first_host[:port].nil? || first_host[:port] == '' || first_host[:port] < 1 || first_host[:port] > 65535
+ raise ArgumentError unless @parameters[:reliable].is_a?(TrueClass) || @parameters[:reliable].is_a?(FalseClass)
end
# filter_options returns a new Hash of filtered options.
@@ -149,7 +144,7 @@ end
while true
message = @connection.receive
# AMQ specific behavior
- if message.nil? && (!@reliable)
+ if message.nil? && (!@parameters[:reliable])
raise Stomp::Error::NilMessageError
end
if message # message can be nil on rapid AMQ stop / start sequences
diff --git a/lib/connection/netio.rb b/lib/connection/netio.rb
index dd08213..9a4c99c 100644
--- a/lib/connection/netio.rb
+++ b/lib/connection/netio.rb
@@ -12,28 +12,24 @@ module Stomp
private
# Really read from the wire.
- def _receive(read_socket)
+ def _receive(read_socket, connread = false)
@read_semaphore.synchronize do
- line = ''
- if @protocol == Stomp::SPL_10 || (@protocol >= Stomp::SPL_11 && !@hbr)
- if @jruby
- # Handle JRuby specific behavior.
- while true
- line = read_socket.gets # Data from wire
- break unless line == "\n"
- line = ''
+ line = nil
+ if connread
+ begin
+ Timeout::timeout(@connread_timeout, Stomp::Error::ConnectReadTimeout) do
+ line = _init_line_read(read_socket)
end
- else
- line = read_socket.gets # The old way
- end
- else # We are >= 1.1 *AND* receiving heartbeats.
- while true
- line = read_socket.gets # Data from wire
- break unless line == "\n"
- line = ''
- @lr = Time.now.to_f
+ rescue Stomp::Error::ConnectReadTimeout => ex
+ if @reliable
+ _reconn_prep()
+ end
+ raise ex
end
+ else
+ line = _init_line_read(read_socket)
end
+ #
return nil if line.nil?
# p [ "wiredatain_01", line ]
line = _normalize_line_end(line) if @protocol >= Stomp::SPL_12
@@ -290,7 +286,8 @@ module Stomp
end
Timeout::timeout(@connect_timeout, Stomp::Error::SocketOpenTimeout) do
- ssl = OpenSSL::SSL::SSLSocket.new(open_tcp_socket, ctx)
+ tcp_socket = TCPSocket.open(@host, @port)
+ ssl = OpenSSL::SSL::SSLSocket.new(tcp_socket, ctx)
ssl.hostname = @host if ssl.respond_to? :hostname=
ssl.sync_close = true # Sync ssl close with underlying TCP socket
ssl.connect
@@ -345,7 +342,9 @@ module Stomp
@closed = false
if @parameters # nil in some rspec tests
- @reconnect_delay = @parameters[:initial_reconnect_delay] ? @parameters[:initial_reconnect_delay] : 0.01
+ unless @reconnect_delay
+ @reconnect_delay = @parameters[:initial_reconnect_delay] ? @parameters[:initial_reconnect_delay] : 0.01
+ end
end
# Use keepalive
used_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
@@ -364,7 +363,7 @@ module Stomp
else
_transmit(used_socket, Stomp::CMD_CONNECT, headers)
end
- @connection_frame = _receive(used_socket)
+ @connection_frame = _receive(used_socket, true)
_post_connect
@disconnect_receipt = nil
@session = @connection_frame.headers["session"] if @connection_frame
@@ -374,6 +373,30 @@ module Stomp
}
end
+ def _init_line_read(read_socket)
+ line = ''
+ if @protocol == Stomp::SPL_10 || (@protocol >= Stomp::SPL_11 && !@hbr)
+ if @jruby
+ # Handle JRuby specific behavior.
+ while true
+ line = read_socket.gets # Data from wire
+ break unless line == "\n"
+ line = ''
+ end
+ else
+ line = read_socket.gets # The old way
+ end
+ else # We are >= 1.1 *AND* receiving heartbeats.
+ while true
+ line = read_socket.gets # Data from wire
+ break unless line == "\n"
+ line = ''
+ @lr = Time.now.to_f
+ end
+ end
+ line
+ end
+
end # class Connection
end # module Stomp
diff --git a/lib/connection/utils.rb b/lib/connection/utils.rb
index 548bf0b..624b114 100644
--- a/lib/connection/utils.rb
+++ b/lib/connection/utils.rb
@@ -182,6 +182,7 @@ module Stomp
:max_hbread_fails => 0,
:max_hbrlck_fails => 0,
:fast_hbs_adjust => 0.0,
+ :connread_timeout => 0,
}
res_params = default_params.merge(params)
@@ -191,7 +192,7 @@ module Stomp
return res_params
end
- # change_host selects the next host for retires.
+ # change_host selects the next host for retries.
def change_host
@parameters[:hosts] = @parameters[:hosts].sort_by { rand } if @parameters[:randomize]
@@ -204,7 +205,6 @@ module Stomp
@port = current_host[:port] || Connection::default_port(@ssl)
@login = current_host[:login] || ""
@passcode = current_host[:passcode] || ""
-
end
# max_reconnect_attempts? returns nil or the number of maximum reconnect
diff --git a/lib/stomp/client.rb b/lib/stomp/client.rb
index 28625c2..223c5a6 100644
--- a/lib/stomp/client.rb
+++ b/lib/stomp/client.rb
@@ -2,6 +2,7 @@
require 'thread'
require 'digest/sha1'
+require 'forwardable'
module Stomp
@@ -11,25 +12,14 @@ module Stomp
# Receives all happen in one thread, so consider not doing much processing
# in that thread if you have much message volume.
class Client
+ extend Forwardable
- # The login ID used by the client.
- attr_reader :login
-
- # The login credentials used by the client.
- attr_reader :passcode
-
- # The Stomp host specified by the client.
- attr_reader :host
-
- # The Stomp host's listening port.
- attr_reader :port
-
- # Is this connection reliable?
- attr_reader :reliable
-
- # Parameters Hash, possibly nil for a non-hashed connect.
+ # Parameters hash
attr_reader :parameters
+ def_delegators :@connection, :login, :passcode, :port, :host, :ssl
+ def_delegator :@parameters, :reliable
+
# A new Client object can be initialized using three forms:
#
# Hash (this is the recommended Client initialization method):
@@ -58,6 +48,7 @@ module Stomp
# :max_hbread_fails => 0,
# :max_hbrlck_fails => 0,
# :fast_hbs_adjust => 0.0,
+ # :connread_timeout => 0,
# }
#
# e.g. c = Stomp::Client.new(hash)
@@ -99,12 +90,8 @@ module Stomp
end
def create_connection(autoflush)
- if @parameters
- @connection = Connection.new(@parameters)
- else
- @connection = Connection.new(@login, @passcode, @host, @port, @reliable)
- @connection.autoflush = autoflush
- end
+ @connection = Connection.new(@parameters)
+ @connection.autoflush = autoflush
end
private :create_connection
diff --git a/lib/stomp/connection.rb b/lib/stomp/connection.rb
index c20d978..181d2b8 100644
--- a/lib/stomp/connection.rb
+++ b/lib/stomp/connection.rb
@@ -38,6 +38,9 @@ module Stomp
# dynamically by calling code.
attr_accessor :autoflush
+ # Currently-connected host and port
+ attr_reader :host, :port
+
# default_port returns the default port used by the gem for TCP or SSL.
def self.default_port(ssl)
ssl ? 61612 : 61613
@@ -71,6 +74,7 @@ module Stomp
# :max_hbread_fails => 0,
# :max_hbrlck_fails => 0,
# :fast_hbs_adjust => 0.0,
+ # :connread_timeout => 0,
# }
#
# e.g. c = Stomp::Connection.new(hash)
@@ -117,7 +121,8 @@ module Stomp
@usecrlf = false # If true, use \r\n as line ends (1.2 only)
@max_hbread_fails = 0 # 0 means never retry for HB read failures
@max_hbrlck_fails = 0 # 0 means never retry for HB read lock failures
- @fast_hbs_adjust = 0.0 # Fast heartbeat senders sleep adjustment
+ @fast_hbs_adjust = 0.0 # Fast heartbeat senders sleep adjustment
+ @connread_timeout = 0 # Connect read CONNECTED/ERROR timeout
warn "login looks like a URL, do you have the correct parameters?" if @login =~ /:\/\//
end
@@ -153,6 +158,7 @@ module Stomp
@max_hbread_fails = @parameters[:max_hbread_fails]
@max_hbrlck_fails = @parameters[:max_hbrlck_fails]
@fast_hbs_adjust = @parameters[:fast_hbs_adjust]
+ @connread_timeout = @parameters[:connread_timeout]
#sets the first host to connect
change_host
end
@@ -336,12 +342,14 @@ module Stomp
options = { :dead_letter_queue => "/queue/DLQ", :max_redeliveries => 6 }.merge(options)
# Lets make sure all keys are symbols
message.headers = message.headers.symbolize_keys
-
retry_count = message.headers[:retry_count].to_i || 0
message.headers[:retry_count] = retry_count + 1
transaction_id = "transaction-#{message.headers[:'message-id']}-#{retry_count}"
message_id = message.headers.delete(:'message-id')
+ # Prevent duplicate 'subscription' headers on subsequent receives
+ message.headers.delete(:subscription) if message.headers[:subscription]
+
begin
self.begin transaction_id
@@ -349,7 +357,7 @@ module Stomp
self.ack(message_id, :transaction => transaction_id)
end
- if retry_count <= options[:max_redeliveries]
+ if message.headers[:retry_count] <= options[:max_redeliveries]
self.publish(message.headers[:destination], message.body,
message.headers.merge(:transaction => transaction_id))
else
diff --git a/lib/stomp/errors.rb b/lib/stomp/errors.rb
index 4ed7bb2..bf1e526 100644
--- a/lib/stomp/errors.rb
+++ b/lib/stomp/errors.rb
@@ -213,6 +213,14 @@ module Stomp
end
end
+ # ConnectReadTimeout is raised if:
+ # * A read for CONNECTED/ERROR is untimely
+ class ConnectReadTimeout < RuntimeError
+ def message
+ "Connect read for CONNECTED/ERROR timeout"
+ end
+ end
+
end # module Error
end # module Stomp
diff --git a/lib/stomp/version.rb b/lib/stomp/version.rb
index c34105b..7070208 100644
--- a/lib/stomp/version.rb
+++ b/lib/stomp/version.rb
@@ -6,7 +6,7 @@ module Stomp
module Version #:nodoc: all
MAJOR = 1
MINOR = 2
- PATCH = 12
+ PATCH = 16
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
end
end
diff --git a/metadata.yml b/metadata.yml
index ff2abbd..88f9646 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,15 +1,9 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
name: stomp
-version: !ruby/object:Gem::Version
- hash: 7
- prerelease: false
- segments:
- - 1
- - 2
- - 12
- version: 1.2.12
+version: !ruby/object:Gem::Version
+ version: 1.2.16
platform: ruby
-authors:
+authors:
- Brian McCallister
- Marius Mathiesen
- Thiago Morello
@@ -17,37 +11,34 @@ authors:
autorequire:
bindir: bin
cert_chain: []
-
-date: 2013-08-11 00:00:00 -04:00
-default_executable:
-dependencies:
-- !ruby/object:Gem::Dependency
+date: 2013-08-19 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
name: rspec
- prerelease: false
- requirement: &id001 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 5
- segments:
- - 2
- - 3
- version: "2.3"
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '2.3'
type: :development
- version_requirements: *id001
-description: Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.
-email:
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '2.3'
+description: Ruby client for the Stomp messaging protocol. Note that this gem is
+ no longer supported on rubyforge.
+email:
- brianm at apache.org
- marius at stones.com
- morellon at gmail.com
- allard.guy.m at gmail.com
-executables:
+executables:
- catstomp
- stompcat
extensions: []
-
-extra_rdoc_files:
+extra_rdoc_files:
- CHANGELOG.rdoc
- LICENSE
- README.rdoc
@@ -101,7 +92,7 @@ extra_rdoc_files:
- test/test_ssl.rb
- test/test_urlogin.rb
- test/tlogger.rb
-files:
+files:
- CHANGELOG.rdoc
- LICENSE
- README.rdoc
@@ -165,39 +156,29 @@ files:
- test/test_ssl.rb
- test/test_urlogin.rb
- test/tlogger.rb
-has_rdoc: true
homepage: https://github.com/stompgem/stomp
-licenses: []
-
+licenses:
+- Apache 2.0
+metadata: {}
post_install_message:
rdoc_options: []
-
-require_paths:
+require_paths:
- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
requirements: []
-
rubyforge_project:
-rubygems_version: 1.3.7
+rubygems_version: 2.0.5
signing_key:
specification_version: 3
summary: Ruby client for the Stomp messaging protocol
test_files: []
-
+has_rdoc:
diff --git a/spec/client_spec.rb b/spec/client_spec.rb
index 35c5c5b..5e305e4 100644
--- a/spec/client_spec.rb
+++ b/spec/client_spec.rb
@@ -7,8 +7,8 @@ require 'client_shared_examples'
describe Stomp::Client do
before(:each) do
- @mock_connection = mock('connection', :autoflush= => true)
- Stomp::Connection.stub!(:new).and_return(@mock_connection)
+ @mock_connection = double('connection', :autoflush= => true)
+ Stomp::Connection.stub(:new).and_return(@mock_connection)
end
describe "(created with no params)" do
@@ -33,6 +33,29 @@ describe Stomp::Client do
end
+ describe 'delegated params' do
+ before :each do
+ @mock_connection = double('connection', :autoflush= => true,
+ :login => 'dummy login',
+ :passcode => 'dummy passcode',
+ :port => 12345,
+ :host => 'dummy host',
+ :ssl => 'dummy ssl')
+ Stomp::Connection.stub(:new).and_return(@mock_connection)
+ @client = Stomp::Client.new
+ end
+
+ describe 'it should delegate parameters to its connection' do
+ subject { @client }
+
+ its(:login) { should eql 'dummy login' }
+ its(:passcode) { should eql 'dummy passcode' }
+ its(:port) { should eql 12345 }
+ its(:host) { should eql 'dummy host' }
+ its(:ssl) { should eql 'dummy ssl' }
+ end
+ end
+
describe "(autoflush)" do
it "should delegate to the connection for accessing the autoflush property" do
@mock_connection.should_receive(:autoflush)
@@ -98,17 +121,17 @@ describe Stomp::Client do
describe "(created with positional params)" do
-
before(:each) do
@client = Stomp::Client.new('testlogin', 'testpassword', 'localhost', '12345', false)
end
it "should properly parse the URL provided" do
- @client.login.should eql('testlogin')
- @client.passcode.should eql('testpassword')
- @client.host.should eql('localhost')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => 'testlogin',
+ :passcode => 'testpassword',
+ :host => 'localhost',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('testlogin', 'testpassword', 'localhost', '12345', false)
end
it_should_behave_like "standard Client"
@@ -122,11 +145,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('')
- @client.passcode.should eql('')
- @client.host.should eql('foobar')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => '',
+ :passcode => '',
+ :host => 'foobar',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://foobar:12345')
end
it_should_behave_like "standard Client"
@@ -140,11 +164,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('')
- @client.passcode.should eql('')
- @client.host.should eql('foo-bar')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => '',
+ :passcode => '',
+ :host => 'foo-bar',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://foo-bar:12345')
end
it_should_behave_like "standard Client"
@@ -158,11 +183,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('test-login')
- @client.passcode.should eql('testpasscode')
- @client.host.should eql('foobar')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => 'test-login',
+ :passcode => 'testpasscode',
+ :host => 'foobar',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://test-login:testpasscode@foobar:12345')
end
it_should_behave_like "standard Client"
@@ -176,11 +202,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('test-login')
- @client.passcode.should eql('testpasscode')
- @client.host.should eql('foo-bar')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => 'test-login',
+ :passcode => 'testpasscode',
+ :host => 'foo-bar',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://test-login:testpasscode@foo-bar:12345')
end
it_should_behave_like "standard Client"
@@ -197,11 +224,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('')
- @client.passcode.should eql('')
- @client.host.should eql('host.foobar.com')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => '',
+ :passcode => '',
+ :host => 'host.foobar.com',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://host.foobar.com:12345')
end
it_should_behave_like "standard Client"
@@ -215,11 +243,12 @@ describe Stomp::Client do
end
it "should properly parse the URL provided" do
- @client.login.should eql('testlogin')
- @client.passcode.should eql('testpasscode')
- @client.host.should eql('host.foobar.com')
- @client.port.should eql(12345)
- @client.reliable.should be_false
+ Stomp::Connection.should_receive(:new).with(:hosts => [{:login => 'testlogin',
+ :passcode => 'testpasscode',
+ :host => 'host.foobar.com',
+ :port => 12345}],
+ :reliable => false)
+ Stomp::Client.new('stomp://testlogin:testpasscode@host.foobar.com:12345')
end
it_should_behave_like "standard Client"
@@ -236,7 +265,8 @@ describe Stomp::Client do
:back_off_multiplier => 2,
:max_reconnect_attempts => 0,
:randomize => false,
- :connect_timeout => 0
+ :connect_timeout => 0,
+ :reliable => true
}
end
it "should properly parse a URL with failover://" do
@@ -303,14 +333,15 @@ describe Stomp::Client do
url = "failover:(stomp://login1:passcode1@localhost:61616,stomp://login2:passcode2@remotehost:61617)?#{query}"
#
- @parameters = {
+ @parameters = {
:initial_reconnect_delay => 5.0,
:max_reconnect_delay => 60.0,
:use_exponential_back_off => false,
:back_off_multiplier => 3,
:max_reconnect_attempts => 4,
:randomize => true,
- :connect_timeout => 0
+ :connect_timeout => 0,
+ :reliable => true
}
@parameters[:hosts] = [
diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb
index b471333..81cf532 100644
--- a/spec/connection_spec.rb
+++ b/spec/connection_spec.rb
@@ -28,11 +28,12 @@ describe Stomp::Connection do
:max_hbread_fails => 0,
:max_hbrlck_fails => 0,
:fast_hbs_adjust => 0.0,
+ :connread_timeout => 0,
}
#POG:
class Stomp::Connection
- def _receive( s )
+ def _receive( s, connread = false )
end
end
@@ -96,6 +97,7 @@ describe Stomp::Connection do
:maxHbreadFails => 0,
:maxHbrlckFails => 0,
:fastHbsAdjust => 0.0,
+ :connreadTimeout => 0,
}
@connection = Stomp::Connection.new(used_hash)
@@ -217,22 +219,23 @@ describe Stomp::Connection do
@message.headers[:retry_count].should == 5
end
- it "should not send the message to the dead letter queue as persistent if redeliveries equal max redeliveries" do
+ it "should not send the message to the dead letter queue as persistent if retry_count is less than max redeliveries" do
max_redeliveries = 5
dead_letter_queue = "/queue/Dead"
- @message.headers["retry_count"] = max_redeliveries
+ @message.headers["retry_count"] = max_redeliveries - 1
transaction_id = "transaction-#{@message.headers["message-id"]}-#{@message.headers["retry_count"]}"
@retry_headers = @retry_headers.merge :transaction => transaction_id, :retry_count => @message.headers["retry_count"] + 1
@connection.should_receive(:publish).with(@message.headers["destination"], @message.body, @retry_headers)
@connection.unreceive @message, :dead_letter_queue => dead_letter_queue, :max_redeliveries => max_redeliveries
end
+ # If the retry_count has reached max_redeliveries, then we're done.
it "should send the message to the dead letter queue as persistent if max redeliveries have been reached" do
max_redeliveries = 5
dead_letter_queue = "/queue/Dead"
- @message.headers["retry_count"] = max_redeliveries + 1
+ @message.headers["retry_count"] = max_redeliveries
transaction_id = "transaction-#{@message.headers["message-id"]}-#{@message.headers["retry_count"]}"
@retry_headers = @retry_headers.merge :persistent => true, :transaction => transaction_id, :retry_count => @message.headers["retry_count"] + 1, :original_destination=> @message.headers["destination"]
@connection.should_receive(:publish).with(dead_letter_queue, @message.body, @retry_headers)
@@ -349,6 +352,7 @@ describe Stomp::Connection do
:max_hbread_fails => 0,
:max_hbrlck_fails => 0,
:fast_hbs_adjust => 0.0,
+ :connread_timeout => 0,
}
used_hash = {
@@ -388,6 +392,7 @@ describe Stomp::Connection do
:max_hbread_fails => 123,
:max_hbrlck_fails => 456,
:fast_hbs_adjust => 0.2,
+ :connread_timeout => 42,
}
@connection = Stomp::Connection.new(used_hash)
@@ -437,7 +442,6 @@ describe Stomp::Connection do
@connection.instance_variable_set(:@connection_attempts, limit)
@connection.send(:max_reconnect_attempts?).should be_true
end
-
# These should be raised for the user to deal with
it "should not rescue MaxReconnectAttempts" do
@connection = Stomp::Connection.new(@parameters)
diff --git a/stomp.gemspec b/stomp.gemspec
index 3e1b001..7a866eb 100644
--- a/stomp.gemspec
+++ b/stomp.gemspec
@@ -5,11 +5,12 @@
Gem::Specification.new do |s|
s.name = %q{stomp}
- s.version = "1.2.12"
+ s.version = "1.2.16"
+ s.license = "Apache 2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
- s.date = %q{2013-08-11}
+ s.date = %q{2013-08-19}
s.description = %q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
s.email = ["brianm at apache.org", "marius at stones.com", "morellon at gmail.com", "allard.guy.m at gmail.com"]
s.executables = ["catstomp", "stompcat"]
diff --git a/test/test_client.rb b/test/test_client.rb
index ed97dae..756fbdf 100644
--- a/test/test_client.rb
+++ b/test/test_client.rb
@@ -443,7 +443,7 @@ class TestClient < Test::Unit::TestCase
# Test that a connection frame is received.
def test_connection_frame
- assert_not_nil @client.connection_frame
+ assert_not_nil @client.connection_frame
checkEmsg(@client)
end unless RUBY_ENGINE =~ /jruby/
@@ -614,6 +614,32 @@ class TestClient < Test::Unit::TestCase
end
end
+ # test max redeliveries is not broken (6c2c1c1)
+ def test_max_redeliveries
+ @client.close
+ rdmsg = "To Be Redelivered"
+ dest = make_destination
+ [1, 2, 3].each do |max_re|
+ @client = get_client()
+ sid = @client.uuid()
+ received = nil
+ rm_actual = 0
+ sh = @client.protocol() == Stomp::SPL_10 ? {} : {:id => sid}
+ @client.subscribe(dest, sh) {|msg|
+ rm_actual += 1
+ @client.unreceive(msg, :max_redeliveries => max_re)
+ received = msg if rm_actual - 1 == max_re
+ }
+ @client.publish(dest, rdmsg)
+ sleep 0.01 until received
+ assert_equal rdmsg, received.body
+ sleep 0.5
+ @client.unsubscribe dest, sh
+ assert_equal max_re, rm_actual - 1
+ @client.close
+ end
+ end
+
private
def message_text
name = caller_method_name unless name
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-stomp.git
More information about the Pkg-ruby-extras-commits
mailing list