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 CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ v0.3. Change default timeout semantics; hash default was too sneaky. Fix bug.
3
+
2
4
  v0.2.2. Fix connect bug.
3
5
 
4
6
  v0.2.1. Don't turn off strict_read by default; allow override.
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
- :timeouts => Hash.new(1),
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>: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>.)
52
- <tt>:defaults</tt>:: Specify defaults to return on a per-method basis, if <tt>:raise</tt> is set to false.
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
- @set_timeout = @options[:transport].instance_methods.include?("timeout=")
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[:timeouts].default))
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[:timeouts][:method_name.to_sym]
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)
@@ -64,29 +64,47 @@ class ThriftClientTest < Test::Unit::TestCase
64
64
  end
65
65
 
66
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)
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
- 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)
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
@@ -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.2"
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-18}
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.2.2
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-18 00:00:00 -08:00
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
- �4E��X����h.BZ����Jq-�'����O6OX�̞�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�ؿ
1
+ b6�#}����hO_R}���fs�/������Q_{e��k��� �����{4�����������fH?��G/:��0ճ��͓L�.LM�y1�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/<