thrift_client 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +3 -1
- data/lib/thrift_client.rb +2 -1
- data/lib/thrift_client/abstract_thrift_client.rb +1 -1
- data/lib/thrift_client/event_machine.rb +22 -20
- data/lib/thrift_client/simple.rb +11 -2
- data/test/thrift_client_test.rb +15 -0
- data/thrift_client.gemspec +5 -5
- metadata +37 -27
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
v0.4.3 Bug fixes: handle_exception could be called more than once. Integer types are read signed.
|
2
|
+
|
1
3
|
v0.4.2 Allow per-method overrides of retries. Fix several bugs with EventMachine.
|
2
4
|
|
3
5
|
v0.4.1 Making ThriftClient decoratable. Able to add new functionality a class definition.
|
4
6
|
|
5
7
|
v0.4.0. Add new EventMachine transport. This requires two layers of transport
|
6
|
-
configurability:
|
8
|
+
configurability:
|
7
9
|
options[:transport] for EventMachine or Socket transports
|
8
10
|
options[:transport_wrapper] for optional Buffered or Framed Transport.
|
9
11
|
Clients will need to update their options to ensure they don't conflict with this change. (mperham)
|
data/lib/thrift_client.rb
CHANGED
@@ -26,7 +26,8 @@ Valid optional parameters are:
|
|
26
26
|
|
27
27
|
<tt>:protocol</tt>:: Which Thrift protocol to use. Defaults to <tt>Thrift::BinaryProtocol</tt>.
|
28
28
|
<tt>:protocol_extra_params</tt>:: An array of additional parameters to pass to the protocol initialization call. Defaults to <tt>[]</tt>.
|
29
|
-
<tt>:transport</tt>:: Which Thrift transport to use. Defaults to <tt>Thrift::
|
29
|
+
<tt>:transport</tt>:: Which Thrift transport to use. Defaults to <tt>Thrift::Socket</tt>.
|
30
|
+
<tt>:transport_wrapper</tt>:: Which Thrift transport wrapper to use. Defaults to <tt>Thrift::FramedTransport</tt>.
|
30
31
|
<tt>:randomize_server_list</tt>:: Whether to connect to the servers randomly, instead of in order. Defaults to <tt>true</tt>.
|
31
32
|
<tt>:exception_classes</tt>:: Which exceptions to catch and retry when sending a request. Defaults to <tt>[IOError, Thrift::Exception, Thrift::ProtocolException, Thrift::ApplicationException, Thrift::TransportException, NoServersAvailable]</tt>
|
32
33
|
<tt>:raise</tt>:: Whether to reraise errors if no responsive servers are found. Defaults to <tt>true</tt>.
|
@@ -153,7 +153,7 @@ class AbstractThriftClient
|
|
153
153
|
disconnect_on_error!
|
154
154
|
tries ||= (@options[:retry_overrides][method_name.to_sym] || @retries)
|
155
155
|
tries -= 1
|
156
|
-
tries == 0 ?
|
156
|
+
tries == 0 ? raise : retry
|
157
157
|
end
|
158
158
|
|
159
159
|
def send_rpc(method_name, *args)
|
@@ -26,6 +26,10 @@ module Thrift
|
|
26
26
|
fiber.resume
|
27
27
|
end
|
28
28
|
Fiber.yield
|
29
|
+
|
30
|
+
# Use Thrift::TransportException so the RetryingThriftClient knows to try the next
|
31
|
+
# server instead of raising the error.
|
32
|
+
raise Thrift::TransportException, "Unable to connect to #{@host}:#{@port}" unless @connection.connected?
|
29
33
|
@connection
|
30
34
|
end
|
31
35
|
|
@@ -65,32 +69,30 @@ module Thrift
|
|
65
69
|
def initialize(host, port=9090)
|
66
70
|
@host, @port = host, port
|
67
71
|
@index = 0
|
68
|
-
@
|
72
|
+
@disconnected = 'not connected'
|
69
73
|
@buf = ''
|
70
74
|
end
|
71
75
|
|
72
76
|
def close
|
73
77
|
trap do
|
74
|
-
@
|
78
|
+
@disconnected = 'closed'
|
75
79
|
close_connection(true)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
83
|
def blocking_read(size)
|
80
|
-
raise IOError, "lost connection to #{@host}:#{@port}"
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Fiber.yield
|
93
|
-
end
|
84
|
+
raise IOError, "lost connection to #{@host}:#{@port}: #{@disconnected}" if @disconnected
|
85
|
+
if can_read?(size)
|
86
|
+
yank(size)
|
87
|
+
else
|
88
|
+
raise ArgumentError, "Unexpected state" if @size or @callback
|
89
|
+
|
90
|
+
fiber = Fiber.current
|
91
|
+
@size = size
|
92
|
+
@callback = proc { |data|
|
93
|
+
fiber.resume(data)
|
94
|
+
}
|
95
|
+
Fiber.yield
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -108,17 +110,17 @@ module Thrift
|
|
108
110
|
end
|
109
111
|
|
110
112
|
def connected?
|
111
|
-
|
113
|
+
!@disconnected
|
112
114
|
end
|
113
115
|
|
114
116
|
def connection_completed
|
115
|
-
@
|
117
|
+
@disconnected = nil
|
116
118
|
succeed
|
117
119
|
end
|
118
120
|
|
119
121
|
def unbind
|
120
|
-
if
|
121
|
-
@
|
122
|
+
if !@disconnected
|
123
|
+
@disconnected = 'unbound'
|
122
124
|
else
|
123
125
|
fail
|
124
126
|
end
|
data/lib/thrift_client/simple.rb
CHANGED
@@ -100,7 +100,8 @@ class ThriftClient
|
|
100
100
|
s.read(len)
|
101
101
|
when I64
|
102
102
|
hi, lo = s.read(8).unpack("NN")
|
103
|
-
(hi << 32) | lo
|
103
|
+
rv = (hi << 32) | lo
|
104
|
+
(rv >= (1 << 63)) ? (rv - (1 << 64)) : rv
|
104
105
|
when LIST
|
105
106
|
read_list(s)
|
106
107
|
when MAP
|
@@ -114,7 +115,15 @@ class ThriftClient
|
|
114
115
|
when StructType
|
115
116
|
read_struct(s, type.struct_class)
|
116
117
|
else
|
117
|
-
s.read(SIZES[type]).unpack(FORMATS[type]).first
|
118
|
+
rv = s.read(SIZES[type]).unpack(FORMATS[type]).first
|
119
|
+
case type
|
120
|
+
when I16
|
121
|
+
(rv >= (1 << 15)) ? (rv - (1 << 16)) : rv
|
122
|
+
when I32
|
123
|
+
(rv >= (1 << 31)) ? (rv - (1 << 32)) : rv
|
124
|
+
else
|
125
|
+
rv
|
126
|
+
end
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
data/test/thrift_client_test.rb
CHANGED
@@ -44,6 +44,21 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_handle_exception_is_called_once_when_retrying
|
48
|
+
client = ThriftClient.new(Greeter::Client, @servers.first, @options.merge(:raise => false, :retries => 1))
|
49
|
+
client.options[:exception_classes] += [ThriftClient::NoServersAvailable]
|
50
|
+
singleton_class = (class << client; self end)
|
51
|
+
|
52
|
+
times_called = 0
|
53
|
+
singleton_class.send :define_method, :handle_exception do |*args|
|
54
|
+
times_called += 1
|
55
|
+
raise IOError
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_raises(IOError) { client.greeting('someone') }
|
59
|
+
assert_equal 1, times_called
|
60
|
+
end
|
61
|
+
|
47
62
|
def test_dont_raise_with_defaults
|
48
63
|
client = ThriftClient.new(Greeter::Client, @servers.first, @options.merge(:raise => false, :defaults => {:greeting => 1}))
|
49
64
|
assert_equal 1, client.greeting
|
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.4.
|
5
|
+
s.version = "0.4.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
|
-
s.cert_chain = ["/Users/
|
10
|
-
s.date = %q{2010-
|
9
|
+
s.cert_chain = ["/Users/freels/.gemkeys/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-05-10}
|
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.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"]
|
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Thrift_client", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{fauna}
|
19
|
-
s.rubygems_version = %q{1.3.
|
20
|
-
s.signing_key = %q{/Users/
|
19
|
+
s.rubygems_version = %q{1.3.6}
|
20
|
+
s.signing_key = %q{/Users/freels/.gemkeys/gem-private_key.pem}
|
21
21
|
s.summary = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
|
22
22
|
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"]
|
23
23
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 3
|
9
|
+
version: 0.4.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Evan Weaver
|
@@ -10,39 +15,41 @@ bindir: bin
|
|
10
15
|
cert_chain:
|
11
16
|
- |
|
12
17
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0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UdFLVl8y27MG7seE2788E6WaHrLWNhN+/dReDiOA5VjrkPI2lfHRqXDnaZTjvCir
|
34
|
+
5Cd6/wLNizaHOQCmp6VxpCuDA67P+TzXCvR7ElyQ2ErG2IHeSAoB/57bxToe40Rz
|
35
|
+
1LE=
|
31
36
|
-----END CERTIFICATE-----
|
32
37
|
|
33
|
-
date: 2010-
|
38
|
+
date: 2010-05-10 00:00:00 -07:00
|
34
39
|
default_executable:
|
35
40
|
dependencies:
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: thrift
|
38
|
-
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
41
45
|
requirements:
|
42
46
|
- - ">="
|
43
47
|
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
44
50
|
version: "0"
|
45
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id001
|
46
53
|
description: A Thrift client wrapper that encapsulates some common failover behavior.
|
47
54
|
email: ""
|
48
55
|
executables: []
|
@@ -106,18 +113,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
113
|
requirements:
|
107
114
|
- - ">="
|
108
115
|
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
109
118
|
version: "0"
|
110
|
-
version:
|
111
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
120
|
requirements:
|
113
121
|
- - ">="
|
114
122
|
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
- 8
|
115
126
|
version: "0.8"
|
116
|
-
version:
|
117
127
|
requirements: []
|
118
128
|
|
119
129
|
rubyforge_project: fauna
|
120
|
-
rubygems_version: 1.3.
|
130
|
+
rubygems_version: 1.3.6
|
121
131
|
signing_key:
|
122
132
|
specification_version: 3
|
123
133
|
summary: A Thrift client wrapper that encapsulates some common failover behavior.
|
metadata.gz.sig
CHANGED
Binary file
|