thrift_client 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ v0.6.3 Document the :connect_timeout option.
2
+ Add support for specifying client-side timeouts when using FramedTransport
3
+ set transport timeout after connection is established
4
+ Add a method `add_callback` allowing a client to register a block that is invoked at a certain event.
5
+ Fixup socket timeouts.
6
+
7
+
8
+
1
9
  v0.6.2 Remove lingering thrift v0.5.0 reference.
2
10
 
3
11
  v0.6.1 Add connect timeout. Bump thrift dependency to ~> v0.6.0.
data/lib/thrift_client.rb CHANGED
@@ -21,6 +21,7 @@ Valid optional parameters are:
21
21
  <tt>:server_retry_period</tt>:: How many seconds to wait before trying to reconnect to a dead server. Defaults to <tt>1</tt>. Set to <tt>nil</tt> to disable.
22
22
  <tt>:server_max_requests</tt>:: How many requests to perform before moving on to the next server in the pool, regardless of error status. Defaults to <tt>nil</tt> (no limit).
23
23
  <tt>:timeout</tt>:: Specify the default timeout in seconds. Defaults to <tt>1</tt>.
24
+ <tt>:connect_timeout</tt>:: Specify the connection timeout in seconds. Defaults to <tt>0.1</tt>.
24
25
  <tt>:timeout_overrides</tt>:: Specify additional timeouts on a per-method basis, in seconds. Only works with <tt>Thrift::BufferedTransport</tt>.
25
26
  <tt>:defaults</tt>:: Specify default values to return on a per-method basis, if <tt>:raise</tt> is set to false.
26
27
  =end rdoc
@@ -52,6 +52,7 @@ class AbstractThriftClient
52
52
  @server_list = Array(servers).collect{|s| Server.new(s)}.sort_by { rand }
53
53
  @current_server = @server_list.first
54
54
 
55
+ @callbacks = {}
55
56
  @client_methods = []
56
57
  @client_class.instance_methods.each do |method_name|
57
58
  if method_name != 'send_message' && method_name =~ /^send_(.*)$/
@@ -70,6 +71,16 @@ class AbstractThriftClient
70
71
  end
71
72
  end
72
73
 
74
+ def add_callback(cb, &blk)
75
+ if cb == :post_connect
76
+ @callbacks[cb] = blk
77
+ # Allow chaining
78
+ return self
79
+ else
80
+ return nil
81
+ end
82
+ end
83
+
73
84
  def inspect
74
85
  "<#{self.class}(#{client_class}) @current_server=#{@current_server}>"
75
86
  end
@@ -81,7 +92,10 @@ class AbstractThriftClient
81
92
  @current_server = next_live_server
82
93
  @connection = Connection::Factory.create(@options[:transport], @options[:transport_wrapper], @current_server.connection_string, @options[:connect_timeout])
83
94
  @connection.connect!
84
- @client = @client_class.new(@options[:protocol].new(@connection.transport, *@options[:protocol_extra_params]))
95
+ transport = @connection.transport
96
+ transport.timeout = @options[:timeout] if transport_can_timeout?
97
+ @client = @client_class.new(@options[:protocol].new(transport, *@options[:protocol_extra_params]))
98
+ @callbacks[:post_connect].call(self) if @callbacks[:post_connect]
85
99
  end
86
100
 
87
101
  def disconnect!
@@ -1,4 +1,13 @@
1
1
  module Thrift
2
+ class BaseTransport
3
+ def timeout=(timeout)
4
+ end
5
+
6
+ def timeout
7
+ nil
8
+ end
9
+ end
10
+
2
11
  class BufferedTransport
3
12
  def timeout=(timeout)
4
13
  @transport.timeout = timeout
@@ -9,6 +18,16 @@ module Thrift
9
18
  end
10
19
  end
11
20
 
21
+ class FramedTransport
22
+ def timeout=(timeout)
23
+ @transport.timeout = timeout
24
+ end
25
+
26
+ def timeout
27
+ @transport.timeout
28
+ end
29
+ end
30
+
12
31
  module Client
13
32
  def timeout=(timeout)
14
33
  @iprot.trans.timeout = timeout
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'benchmark'
4
4
  $LOAD_PATH << "#{File.expand_path(File.dirname(__FILE__))}/../lib"
@@ -83,12 +83,42 @@ class ThriftClientTest < Test::Unit::TestCase
83
83
  end
84
84
  end
85
85
 
86
+ def test_post_conn_cb
87
+ calledcnt = 0
88
+ client = ThriftClient.new(Greeter::Client, @servers, @options.merge(:retries => 2))
89
+ r = client.add_callback :post_connect do |cl|
90
+ calledcnt += 1
91
+ assert_equal(client, cl)
92
+ end
93
+ assert_equal(client, r)
94
+ assert_nothing_raised do
95
+ client.greeting("someone")
96
+ client.disconnect!
97
+ end
98
+ assert_equal(1, calledcnt)
99
+ end
100
+
101
+
102
+ def test_unknown_cb
103
+ calledcnt = 0
104
+ client = ThriftClient.new(Greeter::Client, @servers, @options.merge(:retries => 2))
105
+ r = client.add_callback :unknown do |cl|
106
+ assert(false)
107
+ end
108
+ assert_equal(nil, r)
109
+ end
110
+
86
111
  def test_no_servers_eventually_raise
112
+ wascalled = false
87
113
  client = ThriftClient.new(Greeter::Client, @servers[0,2], @options.merge(:retries => 2))
114
+ client.add_callback :post_connect do
115
+ wascalled = true
116
+ end
88
117
  assert_raises(ThriftClient::NoServersAvailable) do
89
118
  client.greeting("someone")
90
119
  client.disconnect!
91
120
  end
121
+ assert(!wascalled)
92
122
  end
93
123
 
94
124
  def test_socket_timeout
@@ -100,7 +130,7 @@ class ThriftClientTest < Test::Unit::TestCase
100
130
  ).greeting("someone")
101
131
  end
102
132
  end
103
- assert(measurement.real > 0.5 && measurement.real < 1)
133
+ assert(measurement.real > 0.5 && measurement.real < 1.05)
104
134
  end
105
135
  end
106
136
 
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{thrift_client}
5
- s.version = "0.6.2"
5
+ s.version = "0.6.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Evan Weaver, Ryan King, Jeff Hodges"]
9
- s.date = %q{2011-05-09}
8
+ s.authors = [%q{Evan Weaver, Ryan King, Jeff Hodges}]
9
+ s.date = %q{2011-06-30}
10
10
  s.description = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
11
11
  s.email = %q{}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/thrift_client.rb", "lib/thrift_client/abstract_thrift_client.rb", "lib/thrift_client/connection.rb", "lib/thrift_client/connection/base.rb", "lib/thrift_client/connection/factory.rb", "lib/thrift_client/connection/http.rb", "lib/thrift_client/connection/socket.rb", "lib/thrift_client/event_machine.rb", "lib/thrift_client/simple.rb", "lib/thrift_client/thrift.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/thrift_client.rb", "lib/thrift_client/abstract_thrift_client.rb", "lib/thrift_client/connection.rb", "lib/thrift_client/connection/base.rb", "lib/thrift_client/connection/factory.rb", "lib/thrift_client/connection/http.rb", "lib/thrift_client/connection/socket.rb", "lib/thrift_client/event_machine.rb", "lib/thrift_client/simple.rb", "lib/thrift_client/thrift.rb", "test/greeter/greeter.rb", "test/greeter/greeter.thrift", "test/greeter/server.rb", "test/multiple_working_servers_test.rb", "test/simple_test.rb", "test/test_helper.rb", "test/thrift_client_http_test.rb", "test/thrift_client_test.rb", "thrift_client.gemspec"]
12
+ s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.rdoc}, %q{lib/thrift_client.rb}, %q{lib/thrift_client/abstract_thrift_client.rb}, %q{lib/thrift_client/connection.rb}, %q{lib/thrift_client/connection/base.rb}, %q{lib/thrift_client/connection/factory.rb}, %q{lib/thrift_client/connection/http.rb}, %q{lib/thrift_client/connection/socket.rb}, %q{lib/thrift_client/event_machine.rb}, %q{lib/thrift_client/simple.rb}, %q{lib/thrift_client/thrift.rb}]
13
+ s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{lib/thrift_client.rb}, %q{lib/thrift_client/abstract_thrift_client.rb}, %q{lib/thrift_client/connection.rb}, %q{lib/thrift_client/connection/base.rb}, %q{lib/thrift_client/connection/factory.rb}, %q{lib/thrift_client/connection/http.rb}, %q{lib/thrift_client/connection/socket.rb}, %q{lib/thrift_client/event_machine.rb}, %q{lib/thrift_client/simple.rb}, %q{lib/thrift_client/thrift.rb}, %q{test/greeter/greeter.rb}, %q{test/greeter/greeter.thrift}, %q{test/greeter/server.rb}, %q{test/multiple_working_servers_test.rb}, %q{test/simple_test.rb}, %q{test/test_helper.rb}, %q{test/thrift_client_http_test.rb}, %q{test/thrift_client_test.rb}, %q{thrift_client.gemspec}]
14
14
  s.homepage = %q{http://fauna.github.com/fauna/thrift_client/}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Thrift_client", "--main", "README.rdoc"]
16
- s.require_paths = ["lib"]
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Thrift_client}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
17
  s.rubyforge_project = %q{fauna}
18
- s.rubygems_version = %q{1.7.2}
18
+ s.rubygems_version = %q{1.8.5}
19
19
  s.summary = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
20
- s.test_files = ["test/multiple_working_servers_test.rb", "test/simple_test.rb", "test/test_helper.rb", "test/thrift_client_http_test.rb", "test/thrift_client_test.rb"]
20
+ s.test_files = [%q{test/multiple_working_servers_test.rb}, %q{test/simple_test.rb}, %q{test/test_helper.rb}, %q{test/thrift_client_http_test.rb}, %q{test/thrift_client_test.rb}]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Evan Weaver, Ryan King, Jeff Hodges
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-09 00:00:00 Z
18
+ date: 2011-06-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thrift
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements: []
114
114
 
115
115
  rubyforge_project: fauna
116
- rubygems_version: 1.7.2
116
+ rubygems_version: 1.8.5
117
117
  signing_key:
118
118
  specification_version: 3
119
119
  summary: A Thrift client wrapper that encapsulates some common failover behavior.