rubberband 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,9 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - ruby-head
6
- # - jruby-18mode
7
- # - jruby-19mode
8
- # - jruby-head
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - jruby-head
9
9
  - rbx-18mode
10
10
  - rbx-19mode
11
11
 
@@ -21,6 +21,7 @@ module ElasticSearch
21
21
  given_servers = Array(servers_or_url).collect do |server|
22
22
  begin
23
23
  uri = URI.parse(server)
24
+ raise URI::InvalidURIError, server if uri.path.nil?
24
25
  _, default_index, default_type = uri.path.split("/")
25
26
  uri.path = "" # is this expected behavior of URI? may be dangerous to rely on
26
27
  uri.to_s
@@ -18,6 +18,8 @@ module ElasticSearch
18
18
  super
19
19
  @options = RETRYING_DEFAULTS.merge(@options)
20
20
  @retries = options[:retries] || @servers.size
21
+ @connect_retries_count = 0
22
+ @execute_retries_count = 0
21
23
  @request_count = 0
22
24
  @max_requests = @options[:server_max_requests]
23
25
  @retry_period = @options[:server_retry_period]
@@ -26,8 +28,11 @@ module ElasticSearch
26
28
 
27
29
  def connect!
28
30
  @current_server = next_server
29
- super
30
- rescue ElasticSearch::RetryableError
31
+ clear_connect_retries_count_after do
32
+ super
33
+ end
34
+ rescue ElasticSearch::RetryableError => exception
35
+ increment_or_raise_on_connect_retry( exception )
31
36
  retry
32
37
  end
33
38
 
@@ -50,7 +55,7 @@ module ElasticSearch
50
55
  elsif @live_server_list.empty?
51
56
  rebuild_live_server_list!
52
57
  end
53
- @live_server_list.pop
58
+ @live_server_list.shift
54
59
  end
55
60
 
56
61
  def rebuild_live_server_list!
@@ -66,9 +71,12 @@ module ElasticSearch
66
71
  disconnect_on_max! if @max_requests and @request_count >= @max_requests
67
72
  @request_count += 1
68
73
  begin
69
- super
70
- rescue ElasticSearch::RetryableError
74
+ clear_execute_retries_count_after do
75
+ super
76
+ end
77
+ rescue ElasticSearch::RetryableError => exception
71
78
  disconnect!
79
+ increment_or_raise_on_execute_retry( exception )
72
80
  retry
73
81
  end
74
82
  end
@@ -77,5 +85,41 @@ module ElasticSearch
77
85
  @live_server_list.push(@current_server)
78
86
  disconnect!
79
87
  end
88
+
89
+ protected
90
+
91
+ def clear_connect_retries_count_after
92
+ result = yield
93
+ @connect_retries_count = 0
94
+ result
95
+ end
96
+
97
+ def clear_execute_retries_count_after
98
+ result = yield
99
+ @execute_retries_count = 0
100
+ @connect_retries_count = 0
101
+ result
102
+ end
103
+
104
+ def increment_or_raise_on_connect_retry( exception )
105
+ if @retries <= @connect_retries_count
106
+ @connect_retries_count = 0
107
+ @execute_retries_count = 0
108
+ raise exception
109
+ else
110
+ @connect_retries_count += 1
111
+ end
112
+ end
113
+
114
+ def increment_or_raise_on_execute_retry( exception )
115
+ if @retries <= @execute_retries_count
116
+ @execute_retries_count = 0
117
+ @connect_retries_count = 0
118
+ raise exception
119
+ else
120
+ @execute_retries_count += 1
121
+ end
122
+ end
123
+
80
124
  end
81
125
  end
@@ -55,7 +55,7 @@ module ElasticSearch
55
55
  response
56
56
  rescue Exception => e
57
57
  case e
58
- when Faraday::Error::ConnectionFailed
58
+ when Faraday::Error::ConnectionFailed, Errno::EHOSTUNREACH
59
59
  raise ConnectionFailed, $!
60
60
  when Faraday::Error::TimeoutError
61
61
  raise TimeoutError, $!
@@ -1,3 +1,3 @@
1
1
  module ElasticSearch
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -0,0 +1,124 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ElasticSearch::RetryingClient do
4
+
5
+ context 'will all timeouts' do
6
+
7
+ def new_client
8
+ TimeoutRetryingClient.new( "http://noserverhere.local:9456", :retries => 3, :server_retry_period => nil )
9
+ end
10
+
11
+ describe 'when connecting' do
12
+ it 'should give up retrying after 3 failures' do
13
+
14
+ @client = new_client
15
+ expect { @client.connect! }.to raise_error( ElasticSearch::TimeoutError )
16
+ @client.connect_calls.should == 4
17
+
18
+ end
19
+ end
20
+
21
+ describe 'when executing' do
22
+
23
+ it 'should give up retrying after 3 failures' do
24
+
25
+ @client = new_client
26
+ expect { @client.execute( "get" ) }.to raise_error( ElasticSearch::TimeoutError )
27
+ @client.execute_calls.should == 4
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ context 'with successful response' do
36
+
37
+ def new_client
38
+ CountingClient.new( "http://noserverhere.local:9456", :retries => 3, :server_retry_period => nil )
39
+ end
40
+
41
+ context 'when connecting' do
42
+
43
+ it 'should try to connect only once' do
44
+
45
+ @client = new_client
46
+ @client.connect!
47
+
48
+ @client.connect_calls.should == 1
49
+ end
50
+
51
+ end
52
+
53
+ context 'when executing' do
54
+
55
+ it 'should try to execute only once' do
56
+ @client = new_client
57
+ @client.execute('get')
58
+ @client.execute_calls.should == 1
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ context 'with non-retryable-exception' do
66
+
67
+ def new_client
68
+ TimeoutRetryingClient.new( "http://noserverhere.local:9456", :retries => 3, :server_retry_period => nil, :exception => StandardError )
69
+ end
70
+
71
+ it 'should try to connect once and give up' do
72
+
73
+ @client = new_client
74
+ expect { @client.connect! }.to raise_error(StandardError)
75
+ @client.connect_calls.should == 1
76
+
77
+ end
78
+
79
+ it 'should try to execute once and give up' do
80
+ @client = new_client
81
+ expect { @client.execute('get') }.to raise_error(StandardError)
82
+ @client.execute_calls.should == 1
83
+ end
84
+
85
+ end
86
+
87
+ context 'on next_server calls' do
88
+
89
+ before do
90
+ @servers = [ 'http://noserver.local1', 'http://noserver.local2' ]
91
+ end
92
+
93
+ def new_client( retry_period = nil )
94
+ CountingRetryingClient.new( @servers, :server_retry_period => retry_period, :randomize_server_list => false )
95
+ end
96
+
97
+ it 'should pick up the next server if one is available' do
98
+ @client = new_client
99
+
100
+ @client.next_server.should == @servers.first
101
+ @client.next_server.should == @servers.last
102
+ end
103
+
104
+ it 'should re-seed the list if client tries to pick more servers than available' do
105
+ @client = new_client
106
+
107
+ @client.next_server.should == @servers.first
108
+ @client.next_server.should == @servers.last
109
+ @client.next_server.should == @servers.first
110
+ end
111
+
112
+ it 'should raise a NoServersAvailable if tried to take too many servers without waiting' do
113
+
114
+ @client = new_client 10
115
+
116
+ @client.next_server.should == @servers.first
117
+ @client.next_server.should == @servers.last
118
+ expect { @client.next_server }.to raise_error(ElasticSearch::NoServersAvailable)
119
+
120
+ end
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,24 @@
1
+ class CountingClient < ElasticSearch::AbstractClient
2
+
3
+ attr_accessor :connect_calls, :disconnect_calls, :execute_calls
4
+
5
+ def initialize(servers_or_url, options={})
6
+ super
7
+ @connect_calls = 0
8
+ @disconnect_calls = 0
9
+ @execute_calls = 0
10
+ end
11
+
12
+ def connect!
13
+ @connect_calls += 1
14
+ end
15
+
16
+ def disconnect!
17
+ @disconnect_calls += 1
18
+ end
19
+
20
+ def execute(method_name, *args)
21
+ @execute_calls += 1
22
+ end
23
+
24
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../counting_client', __FILE__)
2
+
3
+ class CountingRetryingClient < CountingClient
4
+
5
+ include ElasticSearch::RetryingClient
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../counting_client', __FILE__)
2
+
3
+ class ExceptionClient < CountingClient
4
+
5
+ def initialize(servers_or_url, options={})
6
+ super
7
+ @exception = options[:exception] || ElasticSearch::TimeoutError
8
+ end
9
+
10
+ def connect!
11
+ super
12
+ raise @exception
13
+ end
14
+
15
+ def execute(method_name, *args)
16
+ super
17
+ raise @exception
18
+ end
19
+
20
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../exception_client', __FILE__)
2
+
3
+ class TimeoutRetryingClient < ExceptionClient
4
+ include ElasticSearch::RetryingClient
5
+ end
metadata CHANGED
@@ -1,199 +1,183 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rubberband
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.3
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.9.4
6
6
  platform: ruby
7
- authors:
8
- - Grant Rodgers
7
+ authors:
8
+ - Grant Rodgers
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: faraday
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.8.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.8.0
30
- - !ruby/object:Gem::Dependency
31
- name: multi_json
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: rake
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: rspec
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '2.0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '2.0'
78
- - !ruby/object:Gem::Dependency
79
- name: simplecov
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: 0.3.8
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: 0.3.8
94
- - !ruby/object:Gem::Dependency
95
- name: mocha
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 0.9.0
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 0.9.0
12
+
13
+ date: 2012-09-10 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.0
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: multi_json
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: "2.0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: simplecov
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.8
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: mocha
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.9.0
79
+ type: :development
80
+ version_requirements: *id006
110
81
  description: An ElasticSearch client with ThriftClient-like failover handling.
111
- email:
112
- - grantr@gmail.com
82
+ email:
83
+ - grantr@gmail.com
113
84
  executables: []
85
+
114
86
  extensions: []
115
- extra_rdoc_files:
116
- - LICENSE
117
- - README.md
118
- files:
119
- - .autotest
120
- - .gitignore
121
- - .rspec
122
- - .travis.yml
123
- - CONTRIBUTORS
124
- - Gemfile
125
- - LICENSE
126
- - README.md
127
- - Rakefile
128
- - TODO
129
- - lib/elasticsearch.rb
130
- - lib/elasticsearch/client.rb
131
- - lib/elasticsearch/client/abstract_client.rb
132
- - lib/elasticsearch/client/admin_cluster.rb
133
- - lib/elasticsearch/client/admin_index.rb
134
- - lib/elasticsearch/client/auto_discovering_client.rb
135
- - lib/elasticsearch/client/default_scope.rb
136
- - lib/elasticsearch/client/hits.rb
137
- - lib/elasticsearch/client/index.rb
138
- - lib/elasticsearch/client/retrying_client.rb
139
- - lib/elasticsearch/encoding.rb
140
- - lib/elasticsearch/encoding/base.rb
141
- - lib/elasticsearch/encoding/json.rb
142
- - lib/elasticsearch/transport.rb
143
- - lib/elasticsearch/transport/base.rb
144
- - lib/elasticsearch/transport/base_protocol.rb
145
- - lib/elasticsearch/transport/http.rb
146
- - lib/elasticsearch/transport/memcached.rb
147
- - lib/elasticsearch/transport/thrift.rb
148
- - lib/elasticsearch/transport/thrift/elasticsearch_constants.rb
149
- - lib/elasticsearch/transport/thrift/elasticsearch_types.rb
150
- - lib/elasticsearch/transport/thrift/rest.rb
151
- - lib/elasticsearch/version.rb
152
- - lib/rubberband.rb
153
- - rubberband.gemspec
154
- - spec/admin_spec.rb
155
- - spec/bulk_spec.rb
156
- - spec/connect_spec.rb
157
- - spec/hits_spec.rb
158
- - spec/http_spec.rb
159
- - spec/index_spec.rb
160
- - spec/spec_helper.rb
161
- - spec/support/dummy_transport.rb
162
- - spec/type_spec.rb
163
- - vendor/elasticsearch/elasticsearch.thrift
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.md
91
+ files:
92
+ - .autotest
93
+ - .gitignore
94
+ - .rspec
95
+ - .travis.yml
96
+ - CONTRIBUTORS
97
+ - Gemfile
98
+ - LICENSE
99
+ - README.md
100
+ - Rakefile
101
+ - TODO
102
+ - lib/elasticsearch.rb
103
+ - lib/elasticsearch/client.rb
104
+ - lib/elasticsearch/client/abstract_client.rb
105
+ - lib/elasticsearch/client/admin_cluster.rb
106
+ - lib/elasticsearch/client/admin_index.rb
107
+ - lib/elasticsearch/client/auto_discovering_client.rb
108
+ - lib/elasticsearch/client/default_scope.rb
109
+ - lib/elasticsearch/client/hits.rb
110
+ - lib/elasticsearch/client/index.rb
111
+ - lib/elasticsearch/client/retrying_client.rb
112
+ - lib/elasticsearch/encoding.rb
113
+ - lib/elasticsearch/encoding/base.rb
114
+ - lib/elasticsearch/encoding/json.rb
115
+ - lib/elasticsearch/transport.rb
116
+ - lib/elasticsearch/transport/base.rb
117
+ - lib/elasticsearch/transport/base_protocol.rb
118
+ - lib/elasticsearch/transport/http.rb
119
+ - lib/elasticsearch/transport/memcached.rb
120
+ - lib/elasticsearch/transport/thrift.rb
121
+ - lib/elasticsearch/transport/thrift/elasticsearch_constants.rb
122
+ - lib/elasticsearch/transport/thrift/elasticsearch_types.rb
123
+ - lib/elasticsearch/transport/thrift/rest.rb
124
+ - lib/elasticsearch/version.rb
125
+ - lib/rubberband.rb
126
+ - rubberband.gemspec
127
+ - spec/admin_spec.rb
128
+ - spec/bulk_spec.rb
129
+ - spec/connect_spec.rb
130
+ - spec/hits_spec.rb
131
+ - spec/http_spec.rb
132
+ - spec/index_spec.rb
133
+ - spec/retrying_client_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/support/counting_client.rb
136
+ - spec/support/counting_retrying_client.rb
137
+ - spec/support/dummy_transport.rb
138
+ - spec/support/exception_client.rb
139
+ - spec/support/timeout_retrying_client.rb
140
+ - spec/type_spec.rb
141
+ - vendor/elasticsearch/elasticsearch.thrift
164
142
  homepage: http://github.com/grantr/rubberband
165
- licenses:
166
- - Apache v2
143
+ licenses:
144
+ - Apache v2
167
145
  post_install_message:
168
146
  rdoc_options: []
169
- require_paths:
170
- - lib
171
- required_ruby_version: !ruby/object:Gem::Requirement
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
172
151
  none: false
173
- requirements:
174
- - - ! '>='
175
- - !ruby/object:Gem::Version
176
- version: '0'
177
- required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: "0"
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
157
  none: false
179
- requirements:
180
- - - ! '>='
181
- - !ruby/object:Gem::Version
182
- version: '0'
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: "0"
183
162
  requirements: []
163
+
184
164
  rubyforge_project: rubberband
185
- rubygems_version: 1.8.23
165
+ rubygems_version: 1.8.15
186
166
  signing_key:
187
167
  specification_version: 3
188
168
  summary: An ElasticSearch client with ThriftClient-like failover handling.
189
- test_files:
190
- - spec/admin_spec.rb
191
- - spec/bulk_spec.rb
192
- - spec/connect_spec.rb
193
- - spec/hits_spec.rb
194
- - spec/http_spec.rb
195
- - spec/index_spec.rb
196
- - spec/spec_helper.rb
197
- - spec/support/dummy_transport.rb
198
- - spec/type_spec.rb
199
- has_rdoc:
169
+ test_files:
170
+ - spec/admin_spec.rb
171
+ - spec/bulk_spec.rb
172
+ - spec/connect_spec.rb
173
+ - spec/hits_spec.rb
174
+ - spec/http_spec.rb
175
+ - spec/index_spec.rb
176
+ - spec/retrying_client_spec.rb
177
+ - spec/spec_helper.rb
178
+ - spec/support/counting_client.rb
179
+ - spec/support/counting_retrying_client.rb
180
+ - spec/support/dummy_transport.rb
181
+ - spec/support/exception_client.rb
182
+ - spec/support/timeout_retrying_client.rb
183
+ - spec/type_spec.rb