thrift_client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/thrift_client/thrift.rb +3 -3
- data/lib/thrift_client.rb +21 -10
- data/test/test_helper.rb +1 -0
- data/test/thrift_client_test.rb +43 -6
- data/thrift_client.gemspec +3 -3
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +4 -3
data/CHANGELOG
CHANGED
data/lib/thrift_client/thrift.rb
CHANGED
@@ -4,17 +4,17 @@ module Thrift
|
|
4
4
|
def timeout=(timeout)
|
5
5
|
@transport.timeout = timeout
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def timeout
|
9
9
|
@transport.timeout
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
module Client
|
14
14
|
def timeout=(timeout)
|
15
15
|
@iprot.trans.timeout = timeout
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def timeout
|
19
19
|
@iprot.trans.timeout
|
20
20
|
end
|
data/lib/thrift_client.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
|
2
|
+
if ENV["ANCIENT_THRIFT"]
|
3
|
+
$LOAD_PATH.unshift("/Users/eweaver/p/twitter/rails/vendor/gems/thrift-751142/lib")
|
4
|
+
$LOAD_PATH.unshift("/Users/eweaver/p/twitter/rails/vendor/gems/thrift-751142/ext")
|
5
|
+
require 'thrift'
|
6
|
+
else
|
7
|
+
require 'rubygems'
|
8
|
+
require 'thrift'
|
9
|
+
end
|
10
|
+
|
2
11
|
require 'rubygems'
|
3
|
-
require 'thrift'
|
4
12
|
require 'thrift_client/thrift'
|
5
13
|
|
6
14
|
class ThriftClient
|
@@ -21,7 +29,7 @@ class ThriftClient
|
|
21
29
|
NoServersAvailable],
|
22
30
|
:raise => true,
|
23
31
|
:retries => nil,
|
24
|
-
:server_retry_period =>
|
32
|
+
:server_retry_period => 1,
|
25
33
|
:timeouts => Hash.new(1),
|
26
34
|
:defaults => {}
|
27
35
|
}.freeze
|
@@ -39,7 +47,7 @@ Valid optional parameters are:
|
|
39
47
|
<tt>:randomize_server_list</tt>:: Whether to connect to the servers randomly, instead of in order. Defaults to <tt>true</tt>.
|
40
48
|
<tt>:raise</tt>:: Whether to reraise errors if no responsive servers are found. Defaults to <tt>true</tt>.
|
41
49
|
<tt>:retries</tt>:: How many times to retry a request. Defaults to the number of servers defined.
|
42
|
-
<tt>:server_retry_period</tt>:: How
|
50
|
+
<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.
|
43
51
|
<tt>:timeouts</tt>:: Specify timeouts on a per-method basis. Defaults to 1 second for everything. (Per-method values only work with <tt>Thrift::BufferedTransport</tt>.)
|
44
52
|
<tt>:defaults</tt>:: Specify defaults to return on a per-method basis, if <tt>:raise</tt> is set to false.
|
45
53
|
|
@@ -54,7 +62,7 @@ Valid optional parameters are:
|
|
54
62
|
|
55
63
|
@set_timeout = @options[:transport].instance_methods.include?("timeout=")
|
56
64
|
@live_server_list = @server_list.dup
|
57
|
-
@last_retry = Time.now
|
65
|
+
@last_retry = Time.now
|
58
66
|
|
59
67
|
@client_class.instance_methods.each do |method_name|
|
60
68
|
if method_name =~ /^recv_(.*)$/
|
@@ -72,6 +80,8 @@ Valid optional parameters are:
|
|
72
80
|
Thrift::Socket.new(server.first, server.last.to_i, @options[:timeouts].default))
|
73
81
|
@transport.open
|
74
82
|
@client = @client_class.new(@options[:protocol].new(@transport, *@options[:protocol_extra_params]))
|
83
|
+
rescue Thrift::TransportException
|
84
|
+
retry
|
75
85
|
end
|
76
86
|
|
77
87
|
# Force the client to disconnect from the server.
|
@@ -86,21 +96,22 @@ Valid optional parameters are:
|
|
86
96
|
connect! unless @client
|
87
97
|
set_timeout!(method_name) if @set_timeout
|
88
98
|
@client.send(method_name, *args)
|
99
|
+
rescue NoServersAvailable => e
|
100
|
+
handle_exception(e, method_name, args)
|
89
101
|
rescue *@options[:exception_classes] => e
|
90
|
-
tries ||= @retries
|
91
|
-
tries -= 1
|
92
|
-
if tries.zero? or e.is_a?(NoServersAvailable)
|
102
|
+
tries ||= @retries
|
103
|
+
if (tries -= 1) == 0
|
93
104
|
handle_exception(e, method_name, args)
|
94
105
|
else
|
95
106
|
disconnect!
|
96
107
|
retry
|
97
108
|
end
|
98
109
|
end
|
99
|
-
|
110
|
+
|
100
111
|
def set_timeout!(method_name)
|
101
112
|
@client.timeout = @options[:timeouts][:method_name.to_sym]
|
102
113
|
end
|
103
|
-
|
114
|
+
|
104
115
|
def handle_exception(e, method_name, args)
|
105
116
|
raise e if @options[:raise]
|
106
117
|
@options[:defaults][method_name.to_sym]
|
@@ -115,5 +126,5 @@ Valid optional parameters are:
|
|
115
126
|
@live_server_list = @server_list.dup
|
116
127
|
end
|
117
128
|
@live_server_list.pop
|
118
|
-
end
|
129
|
+
end
|
119
130
|
end
|
data/test/test_helper.rb
CHANGED
data/test/thrift_client_test.rb
CHANGED
@@ -4,6 +4,8 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
@entry = [ScribeThrift::LogEntry.new(:message => "something", :category => "thrift_client")]
|
6
6
|
@servers = ["127.0.0.1:1461", "127.0.0.1:1462", "127.0.0.1:1463"]
|
7
|
+
@socket = 1461
|
8
|
+
@timeout = 0.2
|
7
9
|
@options = {:protocol_extra_params => [false]}
|
8
10
|
end
|
9
11
|
|
@@ -15,7 +17,7 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
15
17
|
|
16
18
|
def test_non_random_fall_through
|
17
19
|
assert_nothing_raised do
|
18
|
-
ThriftClient.new(ScribeThrift::Client, @servers, @options).Log(@entry)
|
20
|
+
ThriftClient.new(ScribeThrift::Client, @servers, @options.merge(:randomize_server_list => false)).Log(@entry)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -54,16 +56,51 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def test_no_servers_eventually_raise
|
57
|
-
|
58
|
-
|
59
|
+
client = ThriftClient.new(ScribeThrift::Client, @servers[0,2], @options)
|
60
|
+
assert_raises(ThriftClient::NoServersAvailable) do
|
61
|
+
client.Log(@entry)
|
62
|
+
client.disconnect!
|
59
63
|
end
|
60
64
|
end
|
65
|
+
|
66
|
+
def test_framed_transport_timeout
|
67
|
+
socket = stub_server(@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(:timeouts => Hash.new(@timeout))
|
72
|
+
).Log(@entry)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
76
|
+
socket.close
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_buffered_transport_timeout
|
80
|
+
socket = stub_server(@socket)
|
81
|
+
measurement = Benchmark.measure do
|
82
|
+
assert_raises(Thrift::TransportException) do
|
83
|
+
ThriftClient.new(ScribeThrift::Client, "127.0.0.1:#{@socket}",
|
84
|
+
@options.merge(:timeouts => Hash.new(@timeout), :transport => Thrift::BufferedTransport)
|
85
|
+
).Log(@entry)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
assert((measurement.real < @timeout + 0.01), "#{measurement.real} > #{@timeout}")
|
89
|
+
socket.close
|
90
|
+
end
|
61
91
|
|
62
92
|
def test_retry_period
|
63
93
|
client = ThriftClient.new(ScribeThrift::Client, @servers[0,2], @options.merge(:server_retry_period => 1))
|
64
|
-
assert_raises(Thrift::TransportException) { client.Log(@entry) }
|
65
94
|
assert_raises(ThriftClient::NoServersAvailable) { client.Log(@entry) }
|
66
|
-
sleep 1
|
67
|
-
assert_raises(
|
95
|
+
sleep 1.1
|
96
|
+
assert_raises(ThriftClient::NoServersAvailable) { client.Log(@entry) }
|
68
97
|
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def stub_server(port)
|
102
|
+
socket = TCPServer.new('127.0.0.1', port)
|
103
|
+
Thread.new { socket.accept }
|
104
|
+
socket
|
105
|
+
end
|
69
106
|
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.2.
|
5
|
+
s.version = "0.2.2"
|
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-
|
10
|
+
s.date = %q{2009-11-18}
|
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"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Thrift_client", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{fauna}
|
19
|
-
s.rubygems_version = %q{1.3.
|
19
|
+
s.rubygems_version = %q{1.3.5}
|
20
20
|
s.signing_key = %q{/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem}
|
21
21
|
s.summary = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
|
22
22
|
s.test_files = ["test/simple_test.rb", "test/test_helper.rb", "test/thrift_client_test.rb"]
|
data.tar.gz.sig
CHANGED
Binary file
|
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.2.
|
4
|
+
version: 0.2.2
|
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-
|
33
|
+
date: 2009-11-18 00:00:00 -08:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements: []
|
96
96
|
|
97
97
|
rubyforge_project: fauna
|
98
|
-
rubygems_version: 1.3.
|
98
|
+
rubygems_version: 1.3.5
|
99
99
|
signing_key:
|
100
100
|
specification_version: 3
|
101
101
|
summary: A Thrift client wrapper that encapsulates some common failover behavior.
|
metadata.gz.sig
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
�
|
2
|
-
|
3
|
-
|
1
|
+
�4�E��X����h.B�Z����J�q-�'����O6�O�X�̞�Mk)/6���eg���+�v�
|
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�ؿ
|