thrift_client 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thrift_client/abstract_thrift_client.rb +19 -5
- data/test/thrift_client_test.rb +5 -0
- metadata +74 -56
@@ -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
|
-
|
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
|
-
|
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 =
|
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
|
data/test/thrift_client_test.rb
CHANGED
@@ -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,72 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift_client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 57
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Evan Weaver
|
9
14
|
- Ryan King
|
10
15
|
- Jeff Hodges
|
11
16
|
autorequire:
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
|
20
|
+
date: 2013-02-26 00:00:00 Z
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
17
23
|
name: thrift
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
|
-
requirements:
|
21
|
-
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.0
|
24
|
-
type: :runtime
|
25
24
|
prerelease: false
|
26
|
-
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
26
|
none: false
|
28
|
-
requirements:
|
27
|
+
requirements:
|
29
28
|
- - ~>
|
30
|
-
- !ruby/object:Gem::Version
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 59
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 9
|
34
|
+
- 0
|
31
35
|
version: 0.9.0
|
32
|
-
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
33
39
|
name: rake
|
34
|
-
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
|
-
requirements:
|
37
|
-
- - ! '>='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
40
|
-
type: :development
|
41
40
|
prerelease: false
|
42
|
-
|
43
|
-
none: false
|
44
|
-
requirements:
|
45
|
-
- - ! '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: mongrel
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
51
42
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
56
50
|
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: mongrel
|
57
54
|
prerelease: false
|
58
|
-
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
56
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
57
|
+
requirements:
|
58
|
+
- - "="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 2029539953
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
- pre
|
66
|
+
- 2
|
63
67
|
version: 1.2.0.pre2
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
64
70
|
description:
|
65
71
|
email:
|
66
72
|
executables: []
|
73
|
+
|
67
74
|
extensions: []
|
75
|
+
|
68
76
|
extra_rdoc_files: []
|
69
|
-
|
77
|
+
|
78
|
+
files:
|
70
79
|
- lib/thrift_client/abstract_thrift_client.rb
|
71
80
|
- lib/thrift_client/connection/base.rb
|
72
81
|
- lib/thrift_client/connection/factory.rb
|
@@ -87,29 +96,38 @@ files:
|
|
87
96
|
- test/thrift_client_test.rb
|
88
97
|
homepage: https://github.com/twitter/thrift_client
|
89
98
|
licenses: []
|
99
|
+
|
90
100
|
post_install_message:
|
91
101
|
rdoc_options: []
|
92
|
-
|
102
|
+
|
103
|
+
require_paths:
|
93
104
|
- lib
|
94
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
106
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
115
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
106
123
|
requirements: []
|
124
|
+
|
107
125
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.15
|
109
127
|
signing_key:
|
110
128
|
specification_version: 3
|
111
129
|
summary: A Thrift client wrapper that encapsulates some common failover behavior.
|
112
|
-
test_files:
|
130
|
+
test_files:
|
113
131
|
- test/greeter/greeter.rb
|
114
132
|
- test/greeter/server.rb
|
115
133
|
- test/multiple_working_servers_test.rb
|