thrift_client 0.4.5 → 0.4.6
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/CHANGELOG +2 -0
- data/lib/thrift_client/abstract_thrift_client.rb +6 -10
- data/test/greeter/greeter.rb +43 -0
- data/test/greeter/greeter.thrift +1 -0
- data/test/greeter/server.rb +4 -0
- data/test/thrift_client_test.rb +16 -9
- data/thrift_client.gemspec +4 -2
- data.tar.gz.sig +0 -0
- metadata +26 -5
- metadata.gz.sig +0 -0
data/CHANGELOG
CHANGED
@@ -19,7 +19,7 @@ class AbstractThriftClient
|
|
19
19
|
|
20
20
|
@client_methods = []
|
21
21
|
@client_class.instance_methods.each do |method_name|
|
22
|
-
if method_name =~ /^
|
22
|
+
if method_name != 'send_message' && method_name =~ /^send_(.*)$/
|
23
23
|
instance_eval("def #{$1}(*args); handled_proxy(:'#{$1}', *args); end", __FILE__, __LINE__)
|
24
24
|
@client_methods << $1
|
25
25
|
end
|
@@ -55,8 +55,11 @@ class AbstractThriftClient
|
|
55
55
|
handle_exception(e, method_name, args)
|
56
56
|
end
|
57
57
|
|
58
|
+
def post_connect(method_name); end
|
59
|
+
|
58
60
|
def proxy(method_name, *args)
|
59
61
|
connect! unless @client
|
62
|
+
post_connect(method_name)
|
60
63
|
send_rpc(method_name, *args)
|
61
64
|
end
|
62
65
|
|
@@ -184,17 +187,10 @@ class AbstractThriftClient
|
|
184
187
|
@options = TIMINGOUT_DEFAULTS.merge(@options)
|
185
188
|
end
|
186
189
|
|
187
|
-
def connect!
|
188
|
-
super
|
189
|
-
set_method_timeouts!
|
190
|
-
end
|
191
|
-
|
192
190
|
private
|
193
|
-
def
|
191
|
+
def post_connect(method_name)
|
194
192
|
return unless has_timeouts?
|
195
|
-
@
|
196
|
-
@client.timeout = @options[:timeout_overrides][method_name.to_sym] || @options[:timeout]
|
197
|
-
end
|
193
|
+
@client.timeout = @options[:timeout_overrides][method_name.to_sym] || @options[:timeout]
|
198
194
|
end
|
199
195
|
|
200
196
|
def has_timeouts?
|
data/test/greeter/greeter.rb
CHANGED
@@ -25,6 +25,13 @@ module Greeter
|
|
25
25
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'greeting failed: unknown result')
|
26
26
|
end
|
27
27
|
|
28
|
+
def yo(name)
|
29
|
+
send_yo(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_yo(name)
|
33
|
+
send_message('yo', Yo_args, :name => name)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
class Processor
|
@@ -37,6 +44,12 @@ module Greeter
|
|
37
44
|
write_result(result, oprot, 'greeting', seqid)
|
38
45
|
end
|
39
46
|
|
47
|
+
def process_yo(seqid, iprot, oprot)
|
48
|
+
args = read_args(iprot, Yo_args)
|
49
|
+
@handler.yo(args.name)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
40
53
|
end
|
41
54
|
|
42
55
|
# HELPER FUNCTIONS AND STRUCTURES
|
@@ -73,5 +86,35 @@ module Greeter
|
|
73
86
|
|
74
87
|
end
|
75
88
|
|
89
|
+
class Yo_args
|
90
|
+
include ::Thrift::Struct
|
91
|
+
NAME = 1
|
92
|
+
|
93
|
+
::Thrift::Struct.field_accessor self, :name
|
94
|
+
FIELDS = {
|
95
|
+
NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}
|
96
|
+
}
|
97
|
+
|
98
|
+
def struct_fields; FIELDS; end
|
99
|
+
|
100
|
+
def validate
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
class Yo_result
|
106
|
+
include ::Thrift::Struct
|
107
|
+
|
108
|
+
FIELDS = {
|
109
|
+
|
110
|
+
}
|
111
|
+
|
112
|
+
def struct_fields; FIELDS; end
|
113
|
+
|
114
|
+
def validate
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
76
119
|
end
|
77
120
|
|
data/test/greeter/greeter.thrift
CHANGED
data/test/greeter/server.rb
CHANGED
data/test/thrift_client_test.rb
CHANGED
@@ -4,7 +4,7 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
@servers = ["127.0.0.1:1461", "127.0.0.1:1462", "127.0.0.1:1463"]
|
7
|
-
@
|
7
|
+
@port = 1461
|
8
8
|
@timeout = 0.2
|
9
9
|
@options = {:protocol_extra_params => [false]}
|
10
10
|
@pid = Process.fork do
|
@@ -60,9 +60,9 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_retries_correct_number_of_times
|
63
|
-
stub_server(@
|
63
|
+
stub_server(@port) do |socket|
|
64
64
|
opts = @options.merge(:timeout => @timeout, :retries => 4, :server_retry_period => nil)
|
65
|
-
client = ThriftClient.new(Greeter::Client, "127.0.0.1:#{@
|
65
|
+
client = ThriftClient.new(Greeter::Client, "127.0.0.1:#{@port}", opts)
|
66
66
|
times_called = 0
|
67
67
|
|
68
68
|
singleton_class = (class << client; self end)
|
@@ -113,10 +113,10 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def test_framed_transport_timeout
|
116
|
-
stub_server(@
|
116
|
+
stub_server(@port) do |socket|
|
117
117
|
measurement = Benchmark.measure do
|
118
118
|
assert_raises(Thrift::TransportException) do
|
119
|
-
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@
|
119
|
+
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@port}",
|
120
120
|
@options.merge(:timeout => @timeout)
|
121
121
|
).greeting("someone")
|
122
122
|
end
|
@@ -126,10 +126,10 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_buffered_transport_timeout
|
129
|
-
stub_server(@
|
129
|
+
stub_server(@port) do |socket|
|
130
130
|
measurement = Benchmark.measure do
|
131
131
|
assert_raises(Thrift::TransportException) do
|
132
|
-
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@
|
132
|
+
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@port}",
|
133
133
|
@options.merge(:timeout => @timeout, :transport_wrapper => Thrift::BufferedTransport)
|
134
134
|
).greeting("someone")
|
135
135
|
end
|
@@ -141,10 +141,10 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
141
141
|
def test_buffered_transport_timeout_override
|
142
142
|
# FIXME Large timeout values always are applied twice for some bizarre reason
|
143
143
|
log_timeout = @timeout * 4
|
144
|
-
stub_server(@
|
144
|
+
stub_server(@port) do |socket|
|
145
145
|
measurement = Benchmark.measure do
|
146
146
|
assert_raises(Thrift::TransportException) do
|
147
|
-
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@
|
147
|
+
ThriftClient.new(Greeter::Client, "127.0.0.1:#{@port}",
|
148
148
|
@options.merge(:timeout => @timeout, :timeout_overrides => {:greeting => log_timeout}, :transport_wrapper => Thrift::BufferedTransport)
|
149
149
|
).greeting("someone")
|
150
150
|
end
|
@@ -167,6 +167,13 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
167
167
|
assert_raises(ThriftClient::NoServersAvailable) { client.greeting("someone") }
|
168
168
|
end
|
169
169
|
|
170
|
+
def test_oneway_method
|
171
|
+
client = ThriftClient.new(Greeter::Client, @servers, @options.merge(:server_max_requests => 2))
|
172
|
+
assert_nothing_raised do
|
173
|
+
response = client.yo("dude")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
170
177
|
def test_server_max_requests_with_downed_servers
|
171
178
|
client = ThriftClient.new(Greeter::Client, @servers, @options.merge(:server_max_requests => 2))
|
172
179
|
client.greeting("someone")
|
data/thrift_client.gemspec
CHANGED
@@ -2,11 +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.6"
|
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.
|
9
|
+
s.cert_chain = ["/Users/ryan/.gemkeys/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-08-02}
|
10
11
|
s.description = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
|
11
12
|
s.email = %q{}
|
12
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,6 +17,7 @@ Gem::Specification.new do |s|
|
|
16
17
|
s.require_paths = ["lib"]
|
17
18
|
s.rubyforge_project = %q{fauna}
|
18
19
|
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/ryan/.gemkeys/gem-private_key.pem}
|
19
21
|
s.summary = %q{A Thrift client wrapper that encapsulates some common failover behavior.}
|
20
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"]
|
21
23
|
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,21 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 6
|
10
|
+
version: 0.4.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Evan Weaver
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
|
-
cert_chain:
|
16
|
+
cert_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SvomC9IzyN37+eWwOS16cC+5XnBT6KRCaXYg2Fh6WpTgde67OVgXr4Q58HXlaZ+
|
34
|
+
/2BB3wq9lZ4JskvlpYpYnlPAUyiyc6R2Mjts1pURz5nkW4SuS7Kd1KCOOyr1McDH
|
35
|
+
VP12sTSjJclmI17BjDGQpAF0n9v5ExhJxWpeOjeBUPQsOin3ypEM1KkckLmOKvH6
|
36
|
+
zyKMYVRO0z/58g==
|
37
|
+
-----END CERTIFICATE-----
|
17
38
|
|
18
|
-
date: 2010-
|
39
|
+
date: 2010-08-02 00:00:00 -07:00
|
19
40
|
default_executable:
|
20
41
|
dependencies:
|
21
42
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
ADDED
Binary file
|