thrift_client 0.1.3 → 0.2.1
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 +3 -0
- data/README +1 -0
- data/Rakefile +1 -0
- data/lib/thrift_client.rb +3 -1
- data/test/simple_test.rb +137 -0
- data/test/test_helper.rb +1 -0
- data/test/thrift_client_test.rb +10 -9
- data/thrift_client.gemspec +4 -4
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +3 -1
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -14,6 +14,7 @@ The public certificate for this gem is here[http://rubyforge.org/frs/download.ph
|
|
14
14
|
* Transparent connection management
|
15
15
|
* Configurable failover and retry backoff
|
16
16
|
* Ruby 1.9 compatibility
|
17
|
+
* ThriftClient::Simple class, for working without generated bindings.
|
17
18
|
|
18
19
|
The Github source repository is {here}[http://github.com/fauna/thrift_client/]. Patches and contributions are very welcome.
|
19
20
|
|
data/Rakefile
CHANGED
@@ -12,5 +12,6 @@ Echoe.new("thrift_client") do |p|
|
|
12
12
|
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
13
13
|
p.url = "http://blog.evanweaver.com/files/doc/fauna/thrift_client/"
|
14
14
|
p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
|
15
|
+
p.spec_pattern = "spec/*_spec.rb"
|
15
16
|
end
|
16
17
|
|
data/lib/thrift_client.rb
CHANGED
@@ -9,6 +9,7 @@ class ThriftClient
|
|
9
9
|
|
10
10
|
DEFAULTS = {
|
11
11
|
:protocol => Thrift::BinaryProtocol,
|
12
|
+
:protocol_extra_params => [],
|
12
13
|
:transport => Thrift::FramedTransport,
|
13
14
|
:randomize_server_list => true,
|
14
15
|
:exception_classes => [
|
@@ -33,6 +34,7 @@ Create a new ThriftClient instance. Accepts an internal Thrift client class (suc
|
|
33
34
|
Valid optional parameters are:
|
34
35
|
|
35
36
|
<tt>:protocol</tt>:: Which Thrift protocol to use. Defaults to <tt>Thrift::BinaryProtocol</tt>.
|
37
|
+
<tt>:protocol_extra_params</tt>:: An array of additional parameters to pass to the protocol initialization call. Defaults to <tt>[]</tt>.
|
36
38
|
<tt>:transport</tt>:: Which Thrift transport to use. Defaults to <tt>Thrift::FramedTransport</tt>.
|
37
39
|
<tt>:randomize_server_list</tt>:: Whether to connect to the servers randomly, instead of in order. Defaults to <tt>true</tt>.
|
38
40
|
<tt>:raise</tt>:: Whether to reraise errors if no responsive servers are found. Defaults to <tt>true</tt>.
|
@@ -69,7 +71,7 @@ Valid optional parameters are:
|
|
69
71
|
@transport = @options[:transport].new(
|
70
72
|
Thrift::Socket.new(server.first, server.last.to_i, @options[:timeouts].default))
|
71
73
|
@transport.open
|
72
|
-
@client = @client_class.new(@options[:protocol].new(@transport,
|
74
|
+
@client = @client_class.new(@options[:protocol].new(@transport, *@options[:protocol_extra_params]))
|
73
75
|
end
|
74
76
|
|
75
77
|
# Force the client to disconnect from the server.
|
data/test/simple_test.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/test_helper"
|
3
|
+
|
4
|
+
class SimpleTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
S = ThriftClient::Simple
|
7
|
+
S.make_struct("Example", S::Field.new(:name, S::STRING, 1))
|
8
|
+
S.make_struct("Args")
|
9
|
+
S.make_struct("Retval", S::Field.new(:rv, S::I32, 0))
|
10
|
+
|
11
|
+
def test_definition
|
12
|
+
assert Struct::ST_Example
|
13
|
+
assert Struct::ST_Args
|
14
|
+
assert Struct::ST_Retval
|
15
|
+
end
|
16
|
+
|
17
|
+
## Encoding
|
18
|
+
|
19
|
+
def test_boolean_encoding
|
20
|
+
assert_equal "\001", S.pack_value(S::BOOL, true)
|
21
|
+
assert_equal "\000", S.pack_value(S::BOOL, false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_byte_encoding
|
25
|
+
assert_equal "\xc7", S.pack_value(S::BYTE, 199)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_i16_encoding
|
29
|
+
assert_equal "\x00\x96", S.pack_value(S::I16, 150)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_i32_encoding
|
33
|
+
assert_equal "\x00\x96\xb4\x3f", S.pack_value(S::I32, 9876543)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_i64_encoding
|
37
|
+
assert_equal "\x00\x00\x00\x1c\xbb\xf3\x09\x04", S.pack_value(S::I64, 123412351236)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_double_encoding
|
41
|
+
assert_equal "\x40\x23\x00\x00\x00\x00\x00\x00", S.pack_value(S::DOUBLE, 9.5)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_string_encoding
|
45
|
+
assert_equal "\x00\x00\x00\x05hello", S.pack_value(S::STRING, "hello")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_list_encoding
|
49
|
+
assert_equal "\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15",
|
50
|
+
S.pack_value(S::ListType.new(S::I32), [ 23, 22, 21 ])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_map_encoding
|
54
|
+
assert_equal "\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05",
|
55
|
+
S.pack_value(S::MapType.new(S::STRING, S::I32), "cat" => 5)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_set_encoding
|
59
|
+
assert_equal "\x08\x00\x00\x00\x01\x00\x00\x00\x04",
|
60
|
+
S.pack_value(S::SetType.new(S::I32), [ 4 ])
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_struct_encoding
|
64
|
+
assert_equal "\x0b\x00\x01\x00\x00\x00\x06Commie\x00",
|
65
|
+
S.pack_value(S::StructType.new(Struct::ST_Example), Struct::ST_Example.new("Commie"))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_request_encoding
|
69
|
+
assert_equal "\x80\x01\x00\x01\x00\x00\x00\x09getHeight\x00\x00\x00\x17\x00",
|
70
|
+
S.pack_request("getHeight", Struct::ST_Args.new, 23)
|
71
|
+
end
|
72
|
+
|
73
|
+
## Decoding
|
74
|
+
|
75
|
+
def test_boolean_decoding
|
76
|
+
assert_equal true, S.read_value(StringIO.new("\x01"), S::BOOL)
|
77
|
+
assert_equal false, S.read_value(StringIO.new("\x00"), S::BOOL)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_byte_decoding
|
81
|
+
assert_equal -57, S.read_value(StringIO.new("\xc7"), S::BYTE)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_i16_decoding
|
85
|
+
assert_equal 150, S.read_value(StringIO.new("\x00\x96"), S::I16)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_i32_decoding
|
89
|
+
assert_equal 9876543, S.read_value(StringIO.new("\x00\x96\xb4\x3f"), S::I32)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_i64_decoding
|
93
|
+
assert_equal 123412351236,
|
94
|
+
S.read_value(StringIO.new("\x00\x00\x00\x1c\xbb\xf3\x09\x04"), S::I64)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_double_decoding
|
98
|
+
assert_equal 9.5,
|
99
|
+
S.read_value(StringIO.new("\x40\x23\x00\x00\x00\x00\x00\x00"), S::DOUBLE)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_string_decoding
|
103
|
+
assert_equal "hello", S.read_value(StringIO.new("\x00\x00\x00\x05hello"), S::STRING)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_list_decoding
|
107
|
+
assert_equal [ 23, 22, 21 ],
|
108
|
+
S.read_value(StringIO.new("\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15"),
|
109
|
+
S::ListType.new(S::I32))
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_map_decoding
|
113
|
+
assert_equal({ "cat" => 5 },
|
114
|
+
S.read_value(StringIO.new("\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05"),
|
115
|
+
S::MapType.new(S::STRING, S::I32)))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_set_decoding
|
119
|
+
assert_equal [ 4 ],
|
120
|
+
S.read_value(StringIO.new("\x08\x00\x00\x00\x01\x00\x00\x00\x04"),
|
121
|
+
S::ListType.new(S::I32))
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_struct_decoding
|
125
|
+
assert_equal Struct::ST_Example.new("Commie"),
|
126
|
+
S.read_value(StringIO.new("\x0b\x00\x01\x00\x00\x00\x06Commie\x00"),
|
127
|
+
S::StructType.new(Struct::ST_Example))
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_response_decoding
|
131
|
+
assert_equal [ "getHeight", 255, 1 ],
|
132
|
+
S.read_response(
|
133
|
+
StringIO.new("\x80\x01\x00\x02\x00\x00\x00\x09getHeight\x00\x00\x00\xff\x08\x00\x00\x00\x00\x00\x01\x00"),
|
134
|
+
Struct::ST_Retval)
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/thrift_client_test.rb
CHANGED
@@ -4,45 +4,46 @@ 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
|
+
@options = {:protocol_extra_params => [false]}
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_live_server
|
10
11
|
assert_nothing_raised do
|
11
|
-
ThriftClient.new(ScribeThrift::Client, @servers.last).Log(@entry)
|
12
|
+
ThriftClient.new(ScribeThrift::Client, @servers.last, @options).Log(@entry)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_non_random_fall_through
|
16
17
|
assert_nothing_raised do
|
17
|
-
ThriftClient.new(ScribeThrift::Client, @servers,
|
18
|
+
ThriftClient.new(ScribeThrift::Client, @servers, @options).Log(@entry)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_dont_raise
|
22
23
|
assert_nothing_raised do
|
23
|
-
ThriftClient.new(ScribeThrift::Client, @servers.first, :raise => false).Log(@entry)
|
24
|
+
ThriftClient.new(ScribeThrift::Client, @servers.first, @options.merge(:raise => false)).Log(@entry)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_dont_raise_with_defaults
|
28
|
-
client = ThriftClient.new(ScribeThrift::Client, @servers.first, :raise => false,
|
29
|
+
client = ThriftClient.new(ScribeThrift::Client, @servers.first, @options.merge(:raise => false, :defaults => {:Log => 1}))
|
29
30
|
assert_equal 1, client.Log(@entry)
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_defaults_dont_override_no_method_error
|
33
|
-
client = ThriftClient.new(ScribeThrift::Client, @servers, :raise => false,
|
34
|
+
client = ThriftClient.new(ScribeThrift::Client, @servers, @options.merge(:raise => false, :defaults => {:Missing => 2}))
|
34
35
|
assert_raises(NoMethodError) { client.Missing(@entry) }
|
35
36
|
end
|
36
37
|
|
37
38
|
def test_random_server_list
|
38
39
|
@lists = []
|
39
|
-
@lists << ThriftClient.new(ScribeThrift::Client, @servers).server_list while @lists.size < 10
|
40
|
+
@lists << ThriftClient.new(ScribeThrift::Client, @servers, @options).server_list while @lists.size < 10
|
40
41
|
assert @lists.uniq.size > 1
|
41
42
|
end
|
42
43
|
|
43
44
|
def test_random_fall_through
|
44
45
|
assert_nothing_raised do
|
45
|
-
10.times { ThriftClient.new(ScribeThrift::Client, @servers).Log(@entry) }
|
46
|
+
10.times { ThriftClient.new(ScribeThrift::Client, @servers, @options).Log(@entry) }
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -54,12 +55,12 @@ class ThriftClientTest < Test::Unit::TestCase
|
|
54
55
|
|
55
56
|
def test_no_servers_eventually_raise
|
56
57
|
assert_raises(Thrift::TransportException) do
|
57
|
-
ThriftClient.new(ScribeThrift::Client, @servers[0,2]).Log(@entry)
|
58
|
+
ThriftClient.new(ScribeThrift::Client, @servers[0,2], @options).Log(@entry)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
62
|
def test_retry_period
|
62
|
-
client = ThriftClient.new(ScribeThrift::Client, @servers[0,2], :server_retry_period => 1)
|
63
|
+
client = ThriftClient.new(ScribeThrift::Client, @servers[0,2], @options.merge(:server_retry_period => 1))
|
63
64
|
assert_raises(Thrift::TransportException) { client.Log(@entry) }
|
64
65
|
assert_raises(ThriftClient::NoServersAvailable) { client.Log(@entry) }
|
65
66
|
sleep 1
|
data/thrift_client.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{thrift_client}
|
5
|
-
s.version = "0.1
|
5
|
+
s.version = "0.2.1"
|
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-
|
10
|
+
s.date = %q{2009-10-28}
|
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"]
|
14
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/thrift_client.rb", "lib/thrift_client/thrift.rb", "test/test_helper.rb", "test/thrift_client_test.rb", "thrift_client.gemspec"]
|
14
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/thrift_client.rb", "lib/thrift_client/thrift.rb", "test/test_helper.rb", "test/thrift_client_test.rb", "thrift_client.gemspec", "test/simple_test.rb"]
|
15
15
|
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/thrift_client/}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Thrift_client", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.rubygems_version = %q{1.3.4}
|
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
|
-
s.test_files = ["test/test_helper.rb", "test/thrift_client_test.rb"]
|
22
|
+
s.test_files = ["test/simple_test.rb", "test/test_helper.rb", "test/thrift_client_test.rb"]
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
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.1
|
4
|
+
version: 0.2.1
|
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-10-
|
33
|
+
date: 2009-10-28 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -100,5 +100,6 @@ signing_key:
|
|
100
100
|
specification_version: 3
|
101
101
|
summary: A Thrift client wrapper that encapsulates some common failover behavior.
|
102
102
|
test_files:
|
103
|
+
- test/simple_test.rb
|
103
104
|
- test/test_helper.rb
|
104
105
|
- test/thrift_client_test.rb
|
metadata.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
�Q1He�����H�)����8�2'X+0'�?�1(O/�0�˪v������9G�0u%����
|
2
|
+
�����d�U��bǷ��=��
|
3
|
+
^đ��
|