thrift 0.8.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{README → README.md} +0 -0
- data/ext/binary_protocol_accelerated.c +33 -14
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +27 -8
- data/ext/constants.h +8 -5
- data/ext/extconf.rb +5 -1
- data/ext/memory_buffer.c +12 -9
- data/ext/protocol.c +0 -185
- data/ext/protocol.h +0 -20
- data/ext/strlcpy.h +7 -3
- data/ext/struct.c +27 -7
- data/ext/thrift_native.c +16 -11
- data/lib/thrift.rb +10 -4
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +13 -4
- data/lib/thrift/exceptions.rb +3 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +24 -6
- data/lib/thrift/protocol/base_protocol.rb +109 -12
- data/lib/thrift/protocol/binary_protocol.rb +22 -7
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +23 -6
- data/lib/thrift/protocol/json_protocol.rb +786 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/mongrel_http_server.rb +2 -0
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thin_http_server.rb +91 -0
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/struct.rb +1 -1
- data/lib/thrift/struct_union.rb +2 -2
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +30 -20
- data/lib/thrift/transport/buffered_transport.rb +25 -11
- data/lib/thrift/transport/framed_transport.rb +20 -11
- data/lib/thrift/transport/http_client_transport.rb +16 -6
- data/lib/thrift/transport/io_stream_transport.rb +5 -2
- data/lib/thrift/transport/memory_buffer_transport.rb +10 -6
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +23 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/lib/thrift/union.rb +3 -6
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +158 -93
- data/spec/base_transport_spec.rb +194 -157
- data/spec/binary_protocol_accelerated_spec.rb +14 -14
- data/spec/binary_protocol_spec.rb +29 -16
- data/spec/binary_protocol_spec_shared.rb +148 -65
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +45 -47
- data/spec/compact_protocol_spec.rb +36 -22
- data/spec/exception_spec.rb +79 -80
- data/spec/flat_spec.rb +62 -0
- data/spec/http_client_spec.rb +91 -16
- data/spec/json_protocol_spec.rb +552 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +26 -28
- data/spec/processor_spec.rb +29 -32
- data/spec/serializer_spec.rb +31 -33
- data/spec/server_socket_spec.rb +32 -28
- data/spec/server_spec.rb +112 -84
- data/spec/socket_spec.rb +27 -20
- data/spec/socket_spec_shared.rb +32 -32
- data/spec/spec_helper.rb +17 -11
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +159 -161
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +71 -69
- data/spec/union_spec.rb +97 -76
- data/spec/unix_socket_spec.rb +49 -41
- metadata +268 -188
- data/CHANGELOG +0 -1
- data/benchmark/gen-rb/benchmark_constants.rb +0 -10
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -9
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/thrift_spec_constants.rb +0 -10
- data/spec/gen-rb/thrift_spec_types.rb +0 -345
- data/spec/mongrel_http_server_spec.rb +0 -117
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -273
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -760
- data/test/debug_proto/gen-rb/empty_service.rb +0 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
data/spec/bytes_spec.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'spec_helper'
|
22
|
+
|
23
|
+
describe Thrift::Bytes do
|
24
|
+
if RUBY_VERSION >= '1.9'
|
25
|
+
describe '.empty_byte_buffer' do
|
26
|
+
it 'should create an empty buffer' do
|
27
|
+
b = Thrift::Bytes.empty_byte_buffer
|
28
|
+
expect(b.length).to eq(0)
|
29
|
+
expect(b.encoding).to eq(Encoding::BINARY)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create an empty buffer of given size' do
|
33
|
+
b = Thrift::Bytes.empty_byte_buffer 2
|
34
|
+
expect(b.length).to eq(2)
|
35
|
+
expect(b.getbyte(0)).to eq(0)
|
36
|
+
expect(b.getbyte(1)).to eq(0)
|
37
|
+
expect(b.encoding).to eq(Encoding::BINARY)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.force_binary_encoding' do
|
42
|
+
it 'should change encoding' do
|
43
|
+
e = 'STRING'.encode('UTF-8')
|
44
|
+
expect(e.encoding).not_to eq(Encoding::BINARY)
|
45
|
+
a = Thrift::Bytes.force_binary_encoding e
|
46
|
+
expect(a.encoding).to eq(Encoding::BINARY)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.get_string_byte' do
|
51
|
+
it 'should get the byte at index' do
|
52
|
+
s = "\x41\x42"
|
53
|
+
expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
|
54
|
+
expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.set_string_byte' do
|
59
|
+
it 'should set byte value at index' do
|
60
|
+
s = "\x41\x42"
|
61
|
+
Thrift::Bytes.set_string_byte(s, 0, 0x43)
|
62
|
+
expect(s.getbyte(0)).to eq(0x43)
|
63
|
+
expect(s).to eq('CB')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.convert_to_utf8_byte_buffer' do
|
68
|
+
it 'should convert UTF-8 String to byte buffer' do
|
69
|
+
e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
|
70
|
+
expect(e.length).to eq(1)
|
71
|
+
|
72
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
73
|
+
expect(a.encoding).to eq(Encoding::BINARY)
|
74
|
+
expect(a.length).to eq(3)
|
75
|
+
expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
|
79
|
+
# Assumptions
|
80
|
+
e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
|
81
|
+
expect(e.length).to eq(1)
|
82
|
+
expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
|
83
|
+
|
84
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
85
|
+
expect(a.encoding).to eq(Encoding::BINARY)
|
86
|
+
expect(a.length).to eq(3)
|
87
|
+
expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '.convert_to_string' do
|
92
|
+
it 'should convert UTF-8 byte buffer to a UTF-8 String' do
|
93
|
+
e = [0xE2, 0x82, 0xAC].pack("C*")
|
94
|
+
expect(e.encoding).to eq(Encoding::BINARY)
|
95
|
+
a = Thrift::Bytes.convert_to_string e
|
96
|
+
expect(a.encoding).to eq(Encoding::UTF_8)
|
97
|
+
expect(a).to eq("\u20AC")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
else # RUBY_VERSION
|
102
|
+
describe '.empty_byte_buffer' do
|
103
|
+
it 'should create an empty buffer' do
|
104
|
+
b = Thrift::Bytes.empty_byte_buffer
|
105
|
+
expect(b.length).to eq(0)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should create an empty buffer of given size' do
|
109
|
+
b = Thrift::Bytes.empty_byte_buffer 2
|
110
|
+
expect(b.length).to eq(2)
|
111
|
+
expect(b[0]).to eq(0)
|
112
|
+
expect(b[1]).to eq(0)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '.force_binary_encoding' do
|
117
|
+
it 'should be a no-op' do
|
118
|
+
e = 'STRING'
|
119
|
+
a = Thrift::Bytes.force_binary_encoding e
|
120
|
+
expect(a).to eq(e)
|
121
|
+
expect(a).to be(e)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '.get_string_byte' do
|
126
|
+
it 'should get the byte at index' do
|
127
|
+
s = "\x41\x42"
|
128
|
+
expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
|
129
|
+
expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '.set_string_byte' do
|
134
|
+
it 'should set byte value at index' do
|
135
|
+
s = "\x41\x42"
|
136
|
+
Thrift::Bytes.set_string_byte(s, 0, 0x43)
|
137
|
+
expect(s[0]).to eq(0x43)
|
138
|
+
expect(s).to eq('CB')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '.convert_to_utf8_byte_buffer' do
|
143
|
+
it 'should be a no-op' do
|
144
|
+
e = 'STRING'
|
145
|
+
a = Thrift::Bytes.convert_to_utf8_byte_buffer e
|
146
|
+
expect(a).to eq(e)
|
147
|
+
expect(a).to be(e)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '.convert_to_string' do
|
152
|
+
it 'should be a no-op' do
|
153
|
+
e = 'STRING'
|
154
|
+
a = Thrift::Bytes.convert_to_string e
|
155
|
+
expect(a).to eq(e)
|
156
|
+
expect(a).to be(e)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -17,84 +17,82 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Client' do
|
24
23
|
|
25
24
|
class ClientSpec
|
26
25
|
include Thrift::Client
|
27
26
|
end
|
28
27
|
|
29
28
|
before(:each) do
|
30
|
-
@prot =
|
29
|
+
@prot = double("MockProtocol")
|
31
30
|
@client = ClientSpec.new(@prot)
|
32
31
|
end
|
33
32
|
|
34
|
-
describe Client do
|
33
|
+
describe Thrift::Client do
|
35
34
|
it "should re-use iprot for oprot if not otherwise specified" do
|
36
|
-
@client.instance_variable_get(:'@iprot').
|
37
|
-
@client.instance_variable_get(:'@oprot').
|
35
|
+
expect(@client.instance_variable_get(:'@iprot')).to eql(@prot)
|
36
|
+
expect(@client.instance_variable_get(:'@oprot')).to eql(@prot)
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should send a test message" do
|
41
|
-
@prot.
|
42
|
-
mock_args =
|
43
|
-
mock_args.
|
44
|
-
mock_args.
|
45
|
-
mock_args.
|
46
|
-
@prot.
|
47
|
-
@prot.
|
48
|
-
|
49
|
-
trans.
|
40
|
+
expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
|
41
|
+
mock_args = double('#<TestMessage_args:mock>')
|
42
|
+
expect(mock_args).to receive(:foo=).with('foo')
|
43
|
+
expect(mock_args).to receive(:bar=).with(42)
|
44
|
+
expect(mock_args).to receive(:write).with(@prot)
|
45
|
+
expect(@prot).to receive(:write_message_end)
|
46
|
+
expect(@prot).to receive(:trans) do
|
47
|
+
double('trans').tap do |trans|
|
48
|
+
expect(trans).to receive(:flush)
|
50
49
|
end
|
51
50
|
end
|
52
|
-
klass =
|
51
|
+
klass = double("TestMessage_args", :new => mock_args)
|
53
52
|
@client.send_message('testMessage', klass, :foo => 'foo', :bar => 42)
|
54
53
|
end
|
55
54
|
|
56
55
|
it "should increment the sequence id when sending messages" do
|
57
|
-
pending "it seems sequence ids are completely ignored right now"
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
56
|
+
pending "it seems sequence ids are completely ignored right now"
|
57
|
+
@prot.expect(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
|
58
|
+
@prot.expect(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
|
59
|
+
@prot.expect(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
|
60
|
+
@prot.stub!(:write_message_end)
|
61
|
+
@prot.stub!(:trans).and_return double("trans").as_null_object
|
62
|
+
@client.send_message('testMessage', double("args class").as_null_object)
|
63
|
+
@client.send_message('testMessage2', double("args class").as_null_object)
|
64
|
+
@client.send_message('testMessage3', double("args class").as_null_object)
|
67
65
|
end
|
68
66
|
|
69
67
|
it "should receive a test message" do
|
70
|
-
@prot.
|
71
|
-
@prot.
|
72
|
-
mock_klass =
|
73
|
-
mock_klass.
|
74
|
-
@client.receive_message(
|
68
|
+
expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
|
69
|
+
expect(@prot).to receive(:read_message_end)
|
70
|
+
mock_klass = double("#<MockClass:mock>")
|
71
|
+
expect(mock_klass).to receive(:read).with(@prot)
|
72
|
+
@client.receive_message(double("MockClass", :new => mock_klass))
|
75
73
|
end
|
76
74
|
|
77
75
|
it "should handle received exceptions" do
|
78
|
-
@prot.
|
79
|
-
@prot.
|
80
|
-
ApplicationException.
|
81
|
-
StandardError.new.
|
82
|
-
mock_exc.
|
76
|
+
expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
|
77
|
+
expect(@prot).to receive(:read_message_end)
|
78
|
+
expect(Thrift::ApplicationException).to receive(:new) do
|
79
|
+
StandardError.new.tap do |mock_exc|
|
80
|
+
expect(mock_exc).to receive(:read).with(@prot)
|
83
81
|
end
|
84
82
|
end
|
85
|
-
|
83
|
+
expect { @client.receive_message(nil) }.to raise_error(StandardError)
|
86
84
|
end
|
87
85
|
|
88
86
|
it "should close the transport if an error occurs while sending a message" do
|
89
|
-
@prot.
|
90
|
-
@prot.
|
91
|
-
mock_args =
|
92
|
-
mock_args.
|
93
|
-
trans =
|
94
|
-
@prot.
|
95
|
-
trans.
|
96
|
-
klass =
|
97
|
-
|
87
|
+
allow(@prot).to receive(:write_message_begin)
|
88
|
+
expect(@prot).not_to receive(:write_message_end)
|
89
|
+
mock_args = double("#<TestMessage_args:mock>")
|
90
|
+
expect(mock_args).to receive(:write).with(@prot).and_raise(StandardError)
|
91
|
+
trans = double("MockTransport")
|
92
|
+
allow(@prot).to receive(:trans).and_return(trans)
|
93
|
+
expect(trans).to receive(:close)
|
94
|
+
klass = double("TestMessage_args", :new => mock_args)
|
95
|
+
expect { @client.send_message("testMessage", klass) }.to raise_error(StandardError)
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
#
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
@@ -17,7 +18,7 @@
|
|
17
18
|
# under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
+
require 'spec_helper'
|
21
22
|
|
22
23
|
describe Thrift::CompactProtocol do
|
23
24
|
TESTS = {
|
@@ -25,7 +26,7 @@ describe Thrift::CompactProtocol do
|
|
25
26
|
:i16 => (0..14).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
26
27
|
:i32 => (0..30).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
27
28
|
:i64 => (0..62).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
28
|
-
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "1" * 127, "1" * 3000],
|
29
|
+
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "unicode characters: \u20AC \u20AD", "1" * 127, "1" * 3000],
|
29
30
|
:binary => ["", "\001", "\001" * 5, "\001" * 14, "\001" * 15, "\001" * 127, "\001" * 3000],
|
30
31
|
:double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
|
31
32
|
:bool => [true, false]
|
@@ -41,7 +42,7 @@ describe Thrift::CompactProtocol do
|
|
41
42
|
proto.send(writer(primitive_type), value)
|
42
43
|
# puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
|
43
44
|
read_back = proto.send(reader(primitive_type))
|
44
|
-
read_back.
|
45
|
+
expect(read_back).to eq(value)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -61,10 +62,10 @@ describe Thrift::CompactProtocol do
|
|
61
62
|
|
62
63
|
proto = Thrift::CompactProtocol.new(trans)
|
63
64
|
name, type, id = proto.read_field_begin
|
64
|
-
type.
|
65
|
-
id.
|
65
|
+
expect(type).to eq(thrift_type)
|
66
|
+
expect(id).to eq(15)
|
66
67
|
read_back = proto.send(reader(primitive_type))
|
67
|
-
read_back.
|
68
|
+
expect(read_back).to eq(value)
|
68
69
|
proto.read_field_end
|
69
70
|
end
|
70
71
|
end
|
@@ -74,13 +75,13 @@ describe Thrift::CompactProtocol do
|
|
74
75
|
trans = Thrift::MemoryBufferTransport.new
|
75
76
|
proto = Thrift::CompactProtocol.new(trans)
|
76
77
|
|
77
|
-
struct = CompactProtoTestStruct.new
|
78
|
+
struct = Thrift::Test::CompactProtoTestStruct.new
|
78
79
|
# sets and maps don't hash well... not sure what to do here.
|
79
80
|
struct.write(proto)
|
80
81
|
|
81
|
-
struct2 = CompactProtoTestStruct.new
|
82
|
+
struct2 = Thrift::Test::CompactProtoTestStruct.new
|
82
83
|
struct2.read(proto)
|
83
|
-
struct2.
|
84
|
+
expect(struct2).to eq(struct)
|
84
85
|
end
|
85
86
|
|
86
87
|
it "should make method calls correctly" do
|
@@ -90,19 +91,19 @@ describe Thrift::CompactProtocol do
|
|
90
91
|
client_in_trans = Thrift::MemoryBufferTransport.new
|
91
92
|
client_in_proto = Thrift::CompactProtocol.new(client_in_trans)
|
92
93
|
|
93
|
-
processor = Srv::Processor.new(JankyHandler.new)
|
94
|
+
processor = Thrift::Test::Srv::Processor.new(JankyHandler.new)
|
94
95
|
|
95
|
-
client = Srv::Client.new(client_in_proto, client_out_proto)
|
96
|
+
client = Thrift::Test::Srv::Client.new(client_in_proto, client_out_proto)
|
96
97
|
client.send_Janky(1)
|
97
98
|
# puts client_out_trans.inspect_buffer
|
98
99
|
processor.process(client_out_proto, client_in_proto)
|
99
|
-
client.recv_Janky.
|
100
|
+
expect(client.recv_Janky).to eq(2)
|
100
101
|
end
|
101
102
|
|
102
103
|
it "should deal with fields following fields that have non-delta ids" do
|
103
|
-
brcp = BreaksRubyCompactProtocol.new(
|
104
|
+
brcp = Thrift::Test::BreaksRubyCompactProtocol.new(
|
104
105
|
:field1 => "blah",
|
105
|
-
:field2 => BigFieldIdStruct.new(
|
106
|
+
:field2 => Thrift::Test::BigFieldIdStruct.new(
|
106
107
|
:field1 => "string1",
|
107
108
|
:field2 => "string2"),
|
108
109
|
:field3 => 3)
|
@@ -110,20 +111,25 @@ describe Thrift::CompactProtocol do
|
|
110
111
|
bytes = ser.serialize(brcp)
|
111
112
|
|
112
113
|
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
|
113
|
-
brcp2 = BreaksRubyCompactProtocol.new
|
114
|
+
brcp2 = Thrift::Test::BreaksRubyCompactProtocol.new
|
114
115
|
deser.deserialize(brcp2, bytes)
|
115
|
-
brcp2.
|
116
|
+
expect(brcp2).to eq(brcp)
|
116
117
|
end
|
117
118
|
|
118
119
|
it "should deserialize an empty map to an empty hash" do
|
119
|
-
struct = SingleMapTestStruct.new(:i32_map => {})
|
120
|
+
struct = Thrift::Test::SingleMapTestStruct.new(:i32_map => {})
|
120
121
|
ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
|
121
122
|
bytes = ser.serialize(struct)
|
122
123
|
|
123
124
|
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
|
124
|
-
struct2 = SingleMapTestStruct.new
|
125
|
+
struct2 = Thrift::Test::SingleMapTestStruct.new
|
125
126
|
deser.deserialize(struct2, bytes)
|
126
|
-
struct.
|
127
|
+
expect(struct).to eq(struct2)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should provide a reasonable to_s" do
|
131
|
+
trans = Thrift::MemoryBufferTransport.new
|
132
|
+
expect(Thrift::CompactProtocol.new(trans).to_s).to eq("compact(memory)")
|
127
133
|
end
|
128
134
|
|
129
135
|
class JankyHandler
|
@@ -133,12 +139,20 @@ describe Thrift::CompactProtocol do
|
|
133
139
|
end
|
134
140
|
|
135
141
|
def writer(sym)
|
136
|
-
sym = sym == :binary ? :string : sym
|
137
142
|
"write_#{sym.to_s}"
|
138
143
|
end
|
139
144
|
|
140
145
|
def reader(sym)
|
141
|
-
sym = sym == :binary ? :string : sym
|
142
146
|
"read_#{sym.to_s}"
|
143
147
|
end
|
144
|
-
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe Thrift::CompactProtocolFactory do
|
151
|
+
it "should create a CompactProtocol" do
|
152
|
+
expect(Thrift::CompactProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::CompactProtocol)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should provide a reasonable to_s" do
|
156
|
+
expect(Thrift::CompactProtocolFactory.new.to_s).to eq("compact")
|
157
|
+
end
|
158
|
+
end
|
data/spec/exception_spec.rb
CHANGED
@@ -17,126 +17,125 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Exception' do
|
24
23
|
|
25
|
-
describe Exception do
|
24
|
+
describe Thrift::Exception do
|
26
25
|
it "should have an accessible message" do
|
27
|
-
e = Exception.new("test message")
|
28
|
-
e.message.
|
26
|
+
e = Thrift::Exception.new("test message")
|
27
|
+
expect(e.message).to eq("test message")
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe ApplicationException do
|
31
|
+
describe Thrift::ApplicationException do
|
33
32
|
it "should inherit from Thrift::Exception" do
|
34
|
-
ApplicationException.superclass.
|
33
|
+
expect(Thrift::ApplicationException.superclass).to eq(Thrift::Exception)
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should have an accessible type and message" do
|
38
|
-
e = ApplicationException.new
|
39
|
-
e.type.
|
40
|
-
e.message.
|
41
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
42
|
-
e.type.
|
43
|
-
e.message.
|
37
|
+
e = Thrift::ApplicationException.new
|
38
|
+
expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN)
|
39
|
+
expect(e.message).to be_nil
|
40
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
41
|
+
expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN_METHOD)
|
42
|
+
expect(e.message).to eq("test message")
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should read a struct off of a protocol" do
|
47
|
-
prot =
|
48
|
-
prot.
|
49
|
-
prot.
|
50
|
-
["message", Types::STRING, 1],
|
51
|
-
["type", Types::I32, 2],
|
52
|
-
[nil, Types::STOP, 0]
|
46
|
+
prot = double("MockProtocol")
|
47
|
+
expect(prot).to receive(:read_struct_begin).ordered
|
48
|
+
expect(prot).to receive(:read_field_begin).exactly(3).times.and_return(
|
49
|
+
["message", Thrift::Types::STRING, 1],
|
50
|
+
["type", Thrift::Types::I32, 2],
|
51
|
+
[nil, Thrift::Types::STOP, 0]
|
53
52
|
)
|
54
|
-
prot.
|
55
|
-
prot.
|
56
|
-
prot.
|
57
|
-
prot.
|
53
|
+
expect(prot).to receive(:read_string).ordered.and_return "test message"
|
54
|
+
expect(prot).to receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
|
55
|
+
expect(prot).to receive(:read_field_end).exactly(2).times
|
56
|
+
expect(prot).to receive(:read_struct_end).ordered
|
58
57
|
|
59
|
-
e = ApplicationException.new
|
58
|
+
e = Thrift::ApplicationException.new
|
60
59
|
e.read(prot)
|
61
|
-
e.message.
|
62
|
-
e.type.
|
60
|
+
expect(e.message).to eq("test message")
|
61
|
+
expect(e.type).to eq(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
63
62
|
end
|
64
63
|
|
65
64
|
it "should skip bad fields when reading a struct" do
|
66
|
-
prot =
|
67
|
-
prot.
|
68
|
-
prot.
|
69
|
-
["type", Types::I32, 2],
|
70
|
-
["type", Types::STRING, 2],
|
71
|
-
["message", Types::MAP, 1],
|
72
|
-
["message", Types::STRING, 3],
|
73
|
-
[nil, Types::STOP, 0]
|
65
|
+
prot = double("MockProtocol")
|
66
|
+
expect(prot).to receive(:read_struct_begin).ordered
|
67
|
+
expect(prot).to receive(:read_field_begin).exactly(5).times.and_return(
|
68
|
+
["type", Thrift::Types::I32, 2],
|
69
|
+
["type", Thrift::Types::STRING, 2],
|
70
|
+
["message", Thrift::Types::MAP, 1],
|
71
|
+
["message", Thrift::Types::STRING, 3],
|
72
|
+
[nil, Thrift::Types::STOP, 0]
|
74
73
|
)
|
75
|
-
prot.
|
76
|
-
prot.
|
77
|
-
prot.
|
78
|
-
prot.
|
79
|
-
prot.
|
74
|
+
expect(prot).to receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
75
|
+
expect(prot).to receive(:skip).with(Thrift::Types::STRING).twice
|
76
|
+
expect(prot).to receive(:skip).with(Thrift::Types::MAP)
|
77
|
+
expect(prot).to receive(:read_field_end).exactly(4).times
|
78
|
+
expect(prot).to receive(:read_struct_end).ordered
|
80
79
|
|
81
|
-
e = ApplicationException.new
|
80
|
+
e = Thrift::ApplicationException.new
|
82
81
|
e.read(prot)
|
83
|
-
e.message.
|
84
|
-
e.type.
|
82
|
+
expect(e.message).to be_nil
|
83
|
+
expect(e.type).to eq(Thrift::ApplicationException::INVALID_MESSAGE_TYPE)
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should write a Thrift::ApplicationException struct to the oprot" do
|
88
|
-
prot =
|
89
|
-
prot.
|
90
|
-
prot.
|
91
|
-
prot.
|
92
|
-
prot.
|
93
|
-
prot.
|
94
|
-
prot.
|
95
|
-
prot.
|
96
|
-
prot.
|
97
|
-
|
98
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
87
|
+
prot = double("MockProtocol")
|
88
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
89
|
+
expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
90
|
+
expect(prot).to receive(:write_string).with("test message").ordered
|
91
|
+
expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
92
|
+
expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
|
93
|
+
expect(prot).to receive(:write_field_end).twice
|
94
|
+
expect(prot).to receive(:write_field_stop).ordered
|
95
|
+
expect(prot).to receive(:write_struct_end).ordered
|
96
|
+
|
97
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
99
98
|
e.write(prot)
|
100
99
|
end
|
101
100
|
|
102
101
|
it "should skip nil fields when writing to the oprot" do
|
103
|
-
prot =
|
104
|
-
prot.
|
105
|
-
prot.
|
106
|
-
prot.
|
107
|
-
prot.
|
108
|
-
prot.
|
109
|
-
prot.
|
110
|
-
|
111
|
-
e = ApplicationException.new(nil, "test message")
|
102
|
+
prot = double("MockProtocol")
|
103
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
104
|
+
expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
105
|
+
expect(prot).to receive(:write_string).with("test message").ordered
|
106
|
+
expect(prot).to receive(:write_field_end).ordered
|
107
|
+
expect(prot).to receive(:write_field_stop).ordered
|
108
|
+
expect(prot).to receive(:write_struct_end).ordered
|
109
|
+
|
110
|
+
e = Thrift::ApplicationException.new(nil, "test message")
|
112
111
|
e.write(prot)
|
113
112
|
|
114
|
-
prot =
|
115
|
-
prot.
|
116
|
-
prot.
|
117
|
-
prot.
|
118
|
-
prot.
|
119
|
-
prot.
|
120
|
-
prot.
|
113
|
+
prot = double("MockProtocol")
|
114
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
115
|
+
expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
116
|
+
expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
|
117
|
+
expect(prot).to receive(:write_field_end).ordered
|
118
|
+
expect(prot).to receive(:write_field_stop).ordered
|
119
|
+
expect(prot).to receive(:write_struct_end).ordered
|
121
120
|
|
122
|
-
e = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)
|
121
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
123
122
|
e.write(prot)
|
124
123
|
|
125
|
-
prot =
|
126
|
-
prot.
|
127
|
-
prot.
|
128
|
-
prot.
|
124
|
+
prot = double("MockProtocol")
|
125
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
126
|
+
expect(prot).to receive(:write_field_stop).ordered
|
127
|
+
expect(prot).to receive(:write_struct_end).ordered
|
129
128
|
|
130
|
-
e = ApplicationException.new(nil)
|
129
|
+
e = Thrift::ApplicationException.new(nil)
|
131
130
|
e.write(prot)
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
describe ProtocolException do
|
134
|
+
describe Thrift::ProtocolException do
|
136
135
|
it "should have an accessible type" do
|
137
|
-
prot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")
|
138
|
-
prot.type.
|
139
|
-
prot.message.
|
136
|
+
prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
|
137
|
+
expect(prot.type).to eq(Thrift::ProtocolException::SIZE_LIMIT)
|
138
|
+
expect(prot.message).to eq("message")
|
140
139
|
end
|
141
140
|
end
|
142
141
|
end
|