Permalink
Browse files

Upgrade to onstomp 1.0.7 and re-fix initial connection failure test

  • Loading branch information...
Nick Sieger
Nick Sieger committed Jun 21, 2012
1 parent f1a8f1a commit 6bfa481da5281e52021914a5b709704f3c8a1a12
Showing with 33 additions and 6 deletions.
  1. +2 −0 Gemfile
  2. +1 −1 Gemfile.lock
  3. +1 −0 Rakefile
  4. +20 −5 lib/klomp/client.rb
  5. +1 −0 test/test_client.rb
  6. +8 −0 test/test_helper.rb
View
@@ -1,5 +1,7 @@
source "http://rubygems.org"
+
gem "onstomp"
+# gem 'onstomp', :path => '../onstomp'
gem "json"
group :development do
View
@@ -5,7 +5,7 @@ GEM
foreman (0.46.0)
thor (>= 0.13.6)
json (1.7.1)
- onstomp (1.0.6)
+ onstomp (1.0.7)
rake (0.9.2.2)
thor (0.15.2)
View
@@ -1,3 +1,4 @@
+require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'
View
@@ -7,6 +7,7 @@ module Klomp
class Client
attr_reader :read_conn, :write_conn
+ attr_accessor :last_connect_exception
def initialize(uri, options={})
@translate_json = options.fetch(:translate_json, true)
@@ -28,6 +29,23 @@ def initialize(uri, options={})
configure_connections
end
+ def connect
+ @all_conn.each do |conn|
+ begin
+ attempts = conn.retry_attempts
+ conn.retry_attempts = 1
+ conn.connect
+ rescue OnStomp::Failover::MaximumRetriesExceededError
+ location = conn.active_client.uri.dup.tap {|u| u.password = 'REDACTED' }.to_s
+ msg = ": #{last_connect_exception.message}" if last_connect_exception
+ raise OnStomp::ConnectFailedError, "initial connection failed for #{location}#{msg}"
+ ensure
+ conn.retry_attempts = attempts
+ end
+ end
+ self
+ end
+
def send(*args, &block)
if @translate_json && args[1].respond_to?(:to_json)
args[1] = args[1].to_json
@@ -39,7 +57,6 @@ def send(*args, &block)
log.info("[Sending] Destination=#{args[0]} Body=#{args[1]} Headers=#{args[2]}") if log
@write_conn.send(*args, &block)
end
- alias puts send
alias publish send
def subscribe(*args, &block)
@@ -89,19 +106,17 @@ def method_missing(method, *args, &block)
@write_conn.send(method, *args, &block)
when *READ_ONLY_METHODS
@read_conn.map {|c| c.__send__(method, *args, &block) }
- when :connect
- @all_conn.each {|c| c.connect}
- self
else
@all_conn.map {|c| c.__send__(method, *args) }
end
end
private
def configure_connections
+ klomp_client = self
@all_conn.each do |c|
c.on_failover_connect_failure do
- raise if OnStomp::FatalConnectionError === $!
+ klomp_client.last_connect_exception = $!
end
end
end
View
@@ -2,6 +2,7 @@
require 'minitest/pride'
require 'klomp'
+require File.expand_path('../test_helper', __FILE__)
describe Klomp::Client do
View
@@ -0,0 +1,8 @@
+trap("QUIT") do
+ $stderr.puts "\n\nThread dump:\n"
+ Thread.list.each do |t|
+ $stderr.puts t.inspect
+ $stderr.puts *t.backtrace
+ $stderr.puts
+ end
+end

0 comments on commit 6bfa481

Please sign in to comment.