Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 6bfa481da5281e52021914a5b709704f3c8a1a12 1 parent f1a8f1a
Nick Sieger authored
2  Gemfile
... ...
@@ -1,5 +1,7 @@
1 1
 source "http://rubygems.org"
  2
+
2 3
 gem "onstomp"
  4
+# gem 'onstomp', :path => '../onstomp'
3 5
 gem "json"
4 6
 
5 7
 group :development do
2  Gemfile.lock
@@ -5,7 +5,7 @@ GEM
5 5
     foreman (0.46.0)
6 6
       thor (>= 0.13.6)
7 7
     json (1.7.1)
8  
-    onstomp (1.0.6)
  8
+    onstomp (1.0.7)
9 9
     rake (0.9.2.2)
10 10
     thor (0.15.2)
11 11
 
1  Rakefile
... ...
@@ -1,3 +1,4 @@
  1
+require 'bundler/setup'
1 2
 require 'bundler/gem_tasks'
2 3
 require 'rake/testtask'
3 4
 
25  lib/klomp/client.rb
@@ -7,6 +7,7 @@ module Klomp
7 7
 
8 8
   class Client
9 9
     attr_reader :read_conn, :write_conn
  10
+    attr_accessor :last_connect_exception
10 11
 
11 12
     def initialize(uri, options={})
12 13
       @translate_json = options.fetch(:translate_json, true)
@@ -28,6 +29,23 @@ def initialize(uri, options={})
28 29
       configure_connections
29 30
     end
30 31
 
  32
+    def connect
  33
+      @all_conn.each do |conn|
  34
+        begin
  35
+          attempts = conn.retry_attempts
  36
+          conn.retry_attempts = 1
  37
+          conn.connect
  38
+        rescue OnStomp::Failover::MaximumRetriesExceededError
  39
+          location = conn.active_client.uri.dup.tap {|u| u.password = 'REDACTED' }.to_s
  40
+          msg = ": #{last_connect_exception.message}" if last_connect_exception
  41
+          raise OnStomp::ConnectFailedError, "initial connection failed for #{location}#{msg}"
  42
+        ensure
  43
+          conn.retry_attempts = attempts
  44
+        end
  45
+      end
  46
+      self
  47
+    end
  48
+
31 49
     def send(*args, &block)
32 50
       if @translate_json && args[1].respond_to?(:to_json)
33 51
         args[1] = args[1].to_json
@@ -39,7 +57,6 @@ def send(*args, &block)
39 57
       log.info("[Sending] Destination=#{args[0]} Body=#{args[1]} Headers=#{args[2]}") if log
40 58
       @write_conn.send(*args, &block)
41 59
     end
42  
-    alias puts send
43 60
     alias publish send
44 61
 
45 62
     def subscribe(*args, &block)
@@ -89,9 +106,6 @@ def method_missing(method, *args, &block)
89 106
         @write_conn.send(method, *args, &block)
90 107
       when *READ_ONLY_METHODS
91 108
         @read_conn.map {|c| c.__send__(method, *args, &block) }
92  
-      when :connect
93  
-        @all_conn.each {|c| c.connect}
94  
-        self
95 109
       else
96 110
         @all_conn.map {|c| c.__send__(method, *args) }
97 111
       end
@@ -99,9 +113,10 @@ def method_missing(method, *args, &block)
99 113
 
100 114
     private
101 115
     def configure_connections
  116
+      klomp_client = self
102 117
       @all_conn.each do |c|
103 118
         c.on_failover_connect_failure do
104  
-          raise if OnStomp::FatalConnectionError === $!
  119
+          klomp_client.last_connect_exception = $!
105 120
         end
106 121
       end
107 122
     end
1  test/test_client.rb
@@ -2,6 +2,7 @@
2 2
 require 'minitest/pride'
3 3
 
4 4
 require 'klomp'
  5
+require File.expand_path('../test_helper', __FILE__)
5 6
 
6 7
 describe Klomp::Client do
7 8
 
8  test/test_helper.rb
... ...
@@ -0,0 +1,8 @@
  1
+trap("QUIT") do
  2
+  $stderr.puts "\n\nThread dump:\n"
  3
+  Thread.list.each do |t|
  4
+    $stderr.puts t.inspect
  5
+    $stderr.puts *t.backtrace
  6
+    $stderr.puts
  7
+  end
  8
+end

0 notes on commit 6bfa481

Please sign in to comment.
Something went wrong with that request. Please try again.