thrift_client 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -92,14 +92,20 @@ class AbstractThriftClient
92
92
  # Force the client to connect to the server. Not necessary to be
93
93
  # called as the connection will be made on the first RPC method
94
94
  # call.
95
- def connect!
95
+ def connect!(method = nil)
96
+ start_time ||= Time.now
96
97
  @current_server = next_live_server
97
98
  @client = @current_server.client
98
99
  @last_client = @client
99
100
  do_callbacks(:post_connect, self)
100
101
  rescue IOError, Thrift::TransportException
101
102
  disconnect!(true)
102
- retry
103
+ timeout = timeout(method)
104
+ if timeout && Time.now - start_time > timeout
105
+ no_servers_available!
106
+ else
107
+ retry
108
+ end
103
109
  end
104
110
 
105
111
  def disconnect!(error = false)
@@ -132,7 +138,7 @@ class AbstractThriftClient
132
138
  return @server_list[cur]
133
139
  end
134
140
  end
135
- raise ThriftClient::NoServersAvailable, "No live servers in #{@server_list.inspect}."
141
+ no_servers_available!
136
142
  end
137
143
 
138
144
  def ensure_socket_alignment
@@ -150,9 +156,9 @@ class AbstractThriftClient
150
156
 
151
157
  def handled_proxy(method_name, *args)
152
158
  begin
153
- connect! unless @client
159
+ connect!(method_name.to_sym) unless @client
154
160
  if has_timeouts?
155
- @client.timeout = @options[:timeout_overrides][method_name.to_sym] || @options[:timeout]
161
+ @client.timeout = timeout(method_name.to_sym)
156
162
  end
157
163
  @request_count += 1
158
164
  do_callbacks(:before_method, method_name)
@@ -196,6 +202,10 @@ class AbstractThriftClient
196
202
  @has_timeouts ||= @options[:timeout_overrides].any? && transport_can_timeout?
197
203
  end
198
204
 
205
+ def timeout(method = nil)
206
+ @options[:timeout_overrides][method] || @options[:timeout]
207
+ end
208
+
199
209
  def transport_can_timeout?
200
210
  if (@options[:transport_wrapper] || @options[:transport]).method_defined?(:timeout=)
201
211
  true
@@ -204,4 +214,8 @@ class AbstractThriftClient
204
214
  false
205
215
  end
206
216
  end
217
+
218
+ def no_servers_available!
219
+ raise ThriftClient::NoServersAvailable, "No live servers in #{@server_list.inspect}."
220
+ end
207
221
  end
@@ -230,6 +230,11 @@ class ThriftClientTest < Test::Unit::TestCase
230
230
  assert_raises(ThriftClient::NoServersAvailable) { client.greeting("someone") }
231
231
  end
232
232
 
233
+ def test_connect_retry_period
234
+ client = ThriftClient.new(Greeter::Client, @servers[0], @options.merge(:server_retry_period => 0))
235
+ assert_raises(ThriftClient::NoServersAvailable) { client.connect! }
236
+ end
237
+
233
238
  def test_client_with_retry_period_drops_servers
234
239
  client = ThriftClient.new(Greeter::Client, @servers[0,2], @options.merge(:server_retry_period => 1, :retries => 2))
235
240
  assert_raises(ThriftClient::NoServersAvailable) { client.greeting("someone") }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 3
10
- version: 0.8.3
9
+ - 4
10
+ version: 0.8.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Evan Weaver
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-11-26 00:00:00 Z
20
+ date: 2013-02-26 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: thrift
@@ -36,14 +36,28 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: mongrel
39
+ name: rake
40
40
  prerelease: false
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: mongrel
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
42
56
  none: false
43
57
  requirements:
44
58
  - - "="
45
59
  - !ruby/object:Gem::Version
46
- hash: -3814261918
60
+ hash: 2328195415
47
61
  segments:
48
62
  - 1
49
63
  - 2
@@ -52,7 +66,7 @@ dependencies:
52
66
  - 2
53
67
  version: 1.2.0.pre2
54
68
  type: :development
55
- version_requirements: *id002
69
+ version_requirements: *id003
56
70
  description:
57
71
  email:
58
72
  executables: []
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  requirements: []
110
124
 
111
125
  rubyforge_project:
112
- rubygems_version: 1.8.24
126
+ rubygems_version: 1.8.15
113
127
  signing_key:
114
128
  specification_version: 3
115
129
  summary: A Thrift client wrapper that encapsulates some common failover behavior.