thrift_client 0.2.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +2 -0
- data/lib/thrift_client.rb +15 -6
- data/test/thrift_client_test.rb +38 -18
- data/thrift_client.gemspec +2 -2
- metadata +2 -2
- metadata.gz.sig +2 -4
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
data/lib/thrift_client.rb
CHANGED
@@ -30,7 +30,8 @@ class ThriftClient
|
|
30
30
|
:raise => true,
|
31
31
|
:retries => nil,
|
32
32
|
:server_retry_period => 1,
|
33
|
-
:
|
33
|
+
:timeout => 1,
|
34
|
+
:timeout_overrides => {},
|
34
35
|
:defaults => {}
|
35
36
|
}.freeze
|
36
37
|
|
@@ -48,8 +49,9 @@ Valid optional parameters are:
|
|
48
49
|
<tt>:raise</tt>:: Whether to reraise errors if no responsive servers are found. Defaults to <tt>true</tt>.
|
49
50
|
<tt>:retries</tt>:: How many times to retry a request. Defaults to the number of servers defined.
|
50
51
|
<tt>:server_retry_period</tt>:: How many seconds to wait before trying to reconnect after marking all servers as down. Defaults to <tt>1</tt>. Set to <tt>nil</tt> to retry endlessly.
|
51
|
-
<tt>:
|
52
|
-
<tt>:
|
52
|
+
<tt>:timeout</tt>:: Specify the default timeout for every call. Defaults to <tt>.
|
53
|
+
<tt>:timeout_overrides</tt>:: Specify timeouts on a per-method basis. Only work with <tt>Thrift::BufferedTransport</tt>.
|
54
|
+
<tt>:defaults</tt>:: Specify default values to return on a per-method basis, if <tt>:raise</tt> is set to false.
|
53
55
|
|
54
56
|
=end rdoc
|
55
57
|
|
@@ -60,7 +62,14 @@ Valid optional parameters are:
|
|
60
62
|
@retries = options[:retries] || @server_list.size
|
61
63
|
@server_list = @server_list.sort_by { rand } if @options[:randomize_server_list]
|
62
64
|
|
63
|
-
|
65
|
+
if @options[:timeout_overrides].any?
|
66
|
+
if @options[:transport].instance_methods.include?("timeout=")
|
67
|
+
@set_timeout = true
|
68
|
+
else
|
69
|
+
warn "ThriftClient: Timeout overrides have no effect with with transport type #{@options[:transport]}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
64
73
|
@live_server_list = @server_list.dup
|
65
74
|
@last_retry = Time.now
|
66
75
|
|
@@ -77,7 +86,7 @@ Valid optional parameters are:
|
|
77
86
|
raise ArgumentError, 'Servers must be in the form "host:port"' if server.size != 2
|
78
87
|
|
79
88
|
@transport = @options[:transport].new(
|
80
|
-
Thrift::Socket.new(server.first, server.last.to_i, @options[:
|
89
|
+
Thrift::Socket.new(server.first, server.last.to_i, @options[:timeout]))
|
81
90
|
@transport.open
|
82
91
|
@client = @client_class.new(@options[:protocol].new(@transport, *@options[:protocol_extra_params]))
|
83
92
|
rescue Thrift::TransportException
|
@@ -109,7 +118,7 @@ Valid optional parameters are:
|
|
109
118
|
end
|
110
119
|
|
111
120
|
def set_timeout!(method_name)
|
112
|
-
@client.timeout = @options[:
|
121
|
+
@client.timeout = @options[:timeout_overrides][method_name.to_sym] || @options[:timeout]
|
113
122
|
end
|
114
123
|
|
115
124
|
def handle_exception(e, method_name, args)
|
data/test/thrift_client_test.rb
CHANGED
@@ -64,29 +64,47 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_framed_transport_timeout
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
stub_server(@socket) do |socket|
|
68
|
+
measurement = Benchmark.measure do
|
69
|
+
assert_raises(Thrift::TransportException) do
|
70
|
+
ThriftClient.new(ScribeThrift::Client, "127.0.0.1:#{@socket}",
|
71
|
+
@options.merge(:timeout => @timeout)
|
72
|
+
).Log(@entry)
|
73
|
+
end
|
73
74
|
end
|
75
|
+
assert((measurement.real > @timeout - 0.01), "#{measurement.real} < #{@timeout}")
|
76
|
+
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
74
77
|
end
|
75
|
-
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
76
|
-
socket.close
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
def test_buffered_transport_timeout
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
stub_server(@socket) do |socket|
|
82
|
+
measurement = Benchmark.measure do
|
83
|
+
assert_raises(Thrift::TransportException) do
|
84
|
+
ThriftClient.new(ScribeThrift::Client, "127.0.0.1:#{@socket}",
|
85
|
+
@options.merge(:timeout => @timeout, :transport => Thrift::BufferedTransport)
|
86
|
+
).Log(@entry)
|
87
|
+
end
|
86
88
|
end
|
89
|
+
assert((measurement.real > @timeout - 0.01), "#{measurement.real} < #{@timeout}")
|
90
|
+
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_buffered_transport_timeout_override
|
95
|
+
# FIXME Large timeout values always are applied twice for some bizarre reason
|
96
|
+
log_timeout = @timeout * 4
|
97
|
+
stub_server(@socket) do |socket|
|
98
|
+
measurement = Benchmark.measure do
|
99
|
+
assert_raises(Thrift::TransportException) do
|
100
|
+
ThriftClient.new(ScribeThrift::Client, "127.0.0.1:#{@socket}",
|
101
|
+
@options.merge(:timeout => @timeout, :timeout_overrides => {:Log => log_timeout}, :transport => Thrift::BufferedTransport)
|
102
|
+
).Log(@entry)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
assert((measurement.real > log_timeout - 0.01), "#{measurement.real} < #{log_timeout }")
|
106
|
+
assert((measurement.real < log_timeout + 0.01), "#{measurement.real} > #{log_timeout}")
|
87
107
|
end
|
88
|
-
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
89
|
-
socket.close
|
90
108
|
end
|
91
109
|
|
92
110
|
def test_retry_period
|
@@ -101,6 +119,8 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
101
119
|
def stub_server(port)
|
102
120
|
socket = TCPServer.new('127.0.0.1', port)
|
103
121
|
Thread.new { socket.accept }
|
104
|
-
socket
|
122
|
+
yield socket
|
123
|
+
ensure
|
124
|
+
socket.close
|
105
125
|
end
|
106
126
|
end
|
data/thrift_client.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{thrift_client}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Evan Weaver"]
|
9
9
|
s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
|
10
|
-
s.date = %q{2009-11-
|
10
|
+
s.date = %q{2009-11-30}
|
11
11
|
s.description = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
|
12
12
|
s.email = %q{}
|
13
13
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/thrift_client.rb", "lib/thrift_client/thrift.rb"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Weaver
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
yZ0=
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-11-
|
33
|
+
date: 2009-11-30 00:00:00 -08:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
CHANGED
@@ -1,4 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
�ԪG�������=�h��FO��sD���8���ۮ�I� �S/w�
|
4
|
-
w�/;Z��H��Tt��PS�J�����F!R\�rhJ�V��~���f�z�2S��.�a�T��1��^�˩~�T�ؿ
|
1
|
+
b�6�#}����hO_R}���fs�/������Q�_{�e��k��������{4�����������f�H?��G/:��0ճ��͓L�.L�M�y�1�g��W� ����m���e��C�Ti�!E�����뿃_�߯�V�"k���P�%R�����V��:^赽�>$1��������2�T�b��u0��
|
2
|
+
ϑz��,O�����[ژ��<�"��\��Tn�W�7�[Q�K�l/<
|