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/lib/thrift/union.rb
CHANGED
@@ -87,12 +87,9 @@ module Thrift
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def ==(other)
|
90
|
-
other
|
91
|
-
end
|
92
|
-
|
93
|
-
def eql?(other)
|
94
|
-
self.class == other.class && self == other
|
90
|
+
other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
|
95
91
|
end
|
92
|
+
alias_method :eql?, :==
|
96
93
|
|
97
94
|
def hash
|
98
95
|
[self.class.name, @setfield, @value].hash
|
@@ -176,4 +173,4 @@ module Thrift
|
|
176
173
|
end
|
177
174
|
end
|
178
175
|
end
|
179
|
-
end
|
176
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
namespace rb Base
|
20
|
+
|
21
|
+
struct Hello {
|
22
|
+
1: string greeting = "hello world"
|
23
|
+
}
|
24
|
+
|
25
|
+
service BaseService {
|
26
|
+
Hello greeting(1:bool english)
|
27
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
namespace rb Extended
|
20
|
+
|
21
|
+
include "BaseService.thrift"
|
22
|
+
|
23
|
+
service ExtendedService extends BaseService.BaseService {
|
24
|
+
void ping()
|
25
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#
|
21
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
22
|
+
# or more contributor license agreements. See the NOTICE file
|
23
|
+
# distributed with this work for additional information
|
24
|
+
# regarding copyright ownership. The ASF licenses this file
|
25
|
+
# to you under the Apache License, Version 2.0 (the
|
26
|
+
# "License"); you may not use this file except in compliance
|
27
|
+
# with the License. You may obtain a copy of the License at
|
28
|
+
#
|
29
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
30
|
+
#
|
31
|
+
# Unless required by applicable law or agreed to in writing,
|
32
|
+
# software distributed under the License is distributed on an
|
33
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
34
|
+
# KIND, either express or implied. See the License for the
|
35
|
+
# specific language governing permissions and limitations
|
36
|
+
# under the License.
|
37
|
+
#
|
38
|
+
|
39
|
+
namespace rb OtherNamespace
|
40
|
+
|
41
|
+
enum SomeEnum {
|
42
|
+
ONE
|
43
|
+
TWO
|
44
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#
|
21
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
22
|
+
# or more contributor license agreements. See the NOTICE file
|
23
|
+
# distributed with this work for additional information
|
24
|
+
# regarding copyright ownership. The ASF licenses this file
|
25
|
+
# to you under the Apache License, Version 2.0 (the
|
26
|
+
# "License"); you may not use this file except in compliance
|
27
|
+
# with the License. You may obtain a copy of the License at
|
28
|
+
#
|
29
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
30
|
+
#
|
31
|
+
# Unless required by applicable law or agreed to in writing,
|
32
|
+
# software distributed under the License is distributed on an
|
33
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
34
|
+
# KIND, either express or implied. See the License for the
|
35
|
+
# specific language governing permissions and limitations
|
36
|
+
# under the License.
|
37
|
+
#
|
38
|
+
|
39
|
+
namespace rb NamespacedSpecNamespace
|
40
|
+
|
41
|
+
include "Referenced.thrift"
|
42
|
+
|
43
|
+
struct Hello {
|
44
|
+
1: string greeting = "hello world"
|
45
|
+
}
|
46
|
+
|
47
|
+
service NamespacedNonblockingService {
|
48
|
+
Hello greeting(1:bool english)
|
49
|
+
bool block()
|
50
|
+
oneway void unblock(1:i32 n)
|
51
|
+
oneway void shutdown()
|
52
|
+
void sleep(1:double seconds)
|
53
|
+
}
|
data/spec/ThriftSpec.thrift
CHANGED
@@ -129,4 +129,55 @@ struct Struct_with_union {
|
|
129
129
|
|
130
130
|
struct StructWithEnumMap {
|
131
131
|
1: map<SomeEnum, list<SomeEnum>> my_map;
|
132
|
-
}
|
132
|
+
}
|
133
|
+
|
134
|
+
# Nested lists
|
135
|
+
struct NestedListInList {
|
136
|
+
1: list<list<byte>> value
|
137
|
+
}
|
138
|
+
|
139
|
+
struct NestedListInSet {
|
140
|
+
1: set<list<byte>> value
|
141
|
+
}
|
142
|
+
|
143
|
+
struct NestedListInMapKey {
|
144
|
+
1: map<list<byte>, byte> value
|
145
|
+
}
|
146
|
+
|
147
|
+
struct NestedListInMapValue {
|
148
|
+
1: map<byte, list<byte>> value
|
149
|
+
}
|
150
|
+
|
151
|
+
# Nested sets
|
152
|
+
struct NestedSetInList {
|
153
|
+
1: list<set<byte>> value
|
154
|
+
}
|
155
|
+
|
156
|
+
struct NestedSetInSet {
|
157
|
+
1: set<set<byte>> value
|
158
|
+
}
|
159
|
+
|
160
|
+
struct NestedSetInMapKey {
|
161
|
+
1: map<set<byte>, byte> value
|
162
|
+
}
|
163
|
+
|
164
|
+
struct NestedSetInMapValue {
|
165
|
+
1: map<byte, set<byte>> value
|
166
|
+
}
|
167
|
+
|
168
|
+
# Nested maps
|
169
|
+
struct NestedMapInList {
|
170
|
+
1: list<map<byte, byte>> value
|
171
|
+
}
|
172
|
+
|
173
|
+
struct NestedMapInSet {
|
174
|
+
1: set<map<byte, byte>> value
|
175
|
+
}
|
176
|
+
|
177
|
+
struct NestedMapInMapKey {
|
178
|
+
2: map<map<byte, byte>, byte> value
|
179
|
+
}
|
180
|
+
|
181
|
+
struct NestedMapInMapValue {
|
182
|
+
2: map<byte, map<byte, byte>> value
|
183
|
+
}
|
data/spec/base_protocol_spec.rb
CHANGED
@@ -17,144 +17,209 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'BaseProtocol' do
|
24
23
|
|
25
24
|
before(:each) do
|
26
|
-
@trans =
|
27
|
-
@prot = BaseProtocol.new(@trans)
|
25
|
+
@trans = double("MockTransport")
|
26
|
+
@prot = Thrift::BaseProtocol.new(@trans)
|
28
27
|
end
|
29
28
|
|
30
|
-
describe BaseProtocol do
|
29
|
+
describe Thrift::BaseProtocol do
|
31
30
|
# most of the methods are stubs, so we can ignore them
|
32
31
|
|
32
|
+
it "should provide a reasonable to_s" do
|
33
|
+
expect(@trans).to receive(:to_s).once.and_return("trans")
|
34
|
+
expect(@prot.to_s).to eq("trans")
|
35
|
+
end
|
36
|
+
|
33
37
|
it "should make trans accessible" do
|
34
|
-
@prot.trans.
|
38
|
+
expect(@prot.trans).to eql(@trans)
|
35
39
|
end
|
36
40
|
|
37
|
-
it
|
38
|
-
@prot.
|
39
|
-
@prot.
|
40
|
-
@prot.
|
41
|
+
it 'should write out a field nicely (deprecated write_field signature)' do
|
42
|
+
expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
|
43
|
+
expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
|
44
|
+
expect(@prot).to receive(:write_field_end).ordered
|
41
45
|
@prot.write_field('field', 'type', 'fid', 'value')
|
42
46
|
end
|
43
47
|
|
44
|
-
it
|
45
|
-
@prot.
|
46
|
-
@prot.
|
47
|
-
@prot.
|
48
|
-
@prot.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@prot.
|
55
|
-
@prot.
|
56
|
-
@prot.
|
57
|
-
@prot.
|
58
|
-
@prot.
|
59
|
-
|
60
|
-
@prot.
|
61
|
-
@prot.write_type(Types::
|
48
|
+
it 'should write out a field nicely' do
|
49
|
+
expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
|
50
|
+
expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
|
51
|
+
expect(@prot).to receive(:write_field_end).ordered
|
52
|
+
@prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should write out the different types (deprecated write_type signature)' do
|
56
|
+
expect(@prot).to receive(:write_bool).with('bool').ordered
|
57
|
+
expect(@prot).to receive(:write_byte).with('byte').ordered
|
58
|
+
expect(@prot).to receive(:write_double).with('double').ordered
|
59
|
+
expect(@prot).to receive(:write_i16).with('i16').ordered
|
60
|
+
expect(@prot).to receive(:write_i32).with('i32').ordered
|
61
|
+
expect(@prot).to receive(:write_i64).with('i64').ordered
|
62
|
+
expect(@prot).to receive(:write_string).with('string').ordered
|
63
|
+
struct = double('Struct')
|
64
|
+
expect(struct).to receive(:write).with(@prot).ordered
|
65
|
+
@prot.write_type(Thrift::Types::BOOL, 'bool')
|
66
|
+
@prot.write_type(Thrift::Types::BYTE, 'byte')
|
67
|
+
@prot.write_type(Thrift::Types::DOUBLE, 'double')
|
68
|
+
@prot.write_type(Thrift::Types::I16, 'i16')
|
69
|
+
@prot.write_type(Thrift::Types::I32, 'i32')
|
70
|
+
@prot.write_type(Thrift::Types::I64, 'i64')
|
71
|
+
@prot.write_type(Thrift::Types::STRING, 'string')
|
72
|
+
@prot.write_type(Thrift::Types::STRUCT, struct)
|
73
|
+
# all other types are not implemented
|
74
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
|
75
|
+
expect { @prot.write_type(type, type.to_s) }.to raise_error(NotImplementedError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should write out the different types' do
|
80
|
+
expect(@prot).to receive(:write_bool).with('bool').ordered
|
81
|
+
expect(@prot).to receive(:write_byte).with('byte').ordered
|
82
|
+
expect(@prot).to receive(:write_double).with('double').ordered
|
83
|
+
expect(@prot).to receive(:write_i16).with('i16').ordered
|
84
|
+
expect(@prot).to receive(:write_i32).with('i32').ordered
|
85
|
+
expect(@prot).to receive(:write_i64).with('i64').ordered
|
86
|
+
expect(@prot).to receive(:write_string).with('string').ordered
|
87
|
+
expect(@prot).to receive(:write_binary).with('binary').ordered
|
88
|
+
struct = double('Struct')
|
89
|
+
expect(struct).to receive(:write).with(@prot).ordered
|
90
|
+
@prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
|
91
|
+
@prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
|
92
|
+
@prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
|
93
|
+
@prot.write_type({:type => Thrift::Types::I16}, 'i16')
|
94
|
+
@prot.write_type({:type => Thrift::Types::I32}, 'i32')
|
95
|
+
@prot.write_type({:type => Thrift::Types::I64}, 'i64')
|
96
|
+
@prot.write_type({:type => Thrift::Types::STRING}, 'string')
|
97
|
+
@prot.write_type({:type => Thrift::Types::STRING, :binary => true}, 'binary')
|
98
|
+
@prot.write_type({:type => Thrift::Types::STRUCT}, struct)
|
62
99
|
# all other types are not implemented
|
63
|
-
[Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
|
64
|
-
|
100
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
|
101
|
+
expect { @prot.write_type({:type => type}, type.to_s) }.to raise_error(NotImplementedError)
|
65
102
|
end
|
66
103
|
end
|
67
104
|
|
68
|
-
it
|
69
|
-
@prot.
|
70
|
-
@prot.
|
71
|
-
@prot.
|
72
|
-
@prot.
|
73
|
-
@prot.
|
74
|
-
@prot.
|
75
|
-
@prot.
|
76
|
-
@prot.read_type(Types::BOOL)
|
77
|
-
@prot.read_type(Types::BYTE)
|
78
|
-
@prot.read_type(Types::I16)
|
79
|
-
@prot.read_type(Types::I32)
|
80
|
-
@prot.read_type(Types::I64)
|
81
|
-
@prot.read_type(Types::DOUBLE)
|
82
|
-
@prot.read_type(Types::STRING)
|
105
|
+
it 'should read the different types (deprecated read_type signature)' do
|
106
|
+
expect(@prot).to receive(:read_bool).ordered
|
107
|
+
expect(@prot).to receive(:read_byte).ordered
|
108
|
+
expect(@prot).to receive(:read_i16).ordered
|
109
|
+
expect(@prot).to receive(:read_i32).ordered
|
110
|
+
expect(@prot).to receive(:read_i64).ordered
|
111
|
+
expect(@prot).to receive(:read_double).ordered
|
112
|
+
expect(@prot).to receive(:read_string).ordered
|
113
|
+
@prot.read_type(Thrift::Types::BOOL)
|
114
|
+
@prot.read_type(Thrift::Types::BYTE)
|
115
|
+
@prot.read_type(Thrift::Types::I16)
|
116
|
+
@prot.read_type(Thrift::Types::I32)
|
117
|
+
@prot.read_type(Thrift::Types::I64)
|
118
|
+
@prot.read_type(Thrift::Types::DOUBLE)
|
119
|
+
@prot.read_type(Thrift::Types::STRING)
|
83
120
|
# all other types are not implemented
|
84
|
-
[Types::STOP, Types::VOID, Types::MAP,
|
85
|
-
|
121
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
|
122
|
+
Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
|
123
|
+
expect { @prot.read_type(type) }.to raise_error(NotImplementedError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should read the different types' do
|
128
|
+
expect(@prot).to receive(:read_bool).ordered
|
129
|
+
expect(@prot).to receive(:read_byte).ordered
|
130
|
+
expect(@prot).to receive(:read_i16).ordered
|
131
|
+
expect(@prot).to receive(:read_i32).ordered
|
132
|
+
expect(@prot).to receive(:read_i64).ordered
|
133
|
+
expect(@prot).to receive(:read_double).ordered
|
134
|
+
expect(@prot).to receive(:read_string).ordered
|
135
|
+
expect(@prot).to receive(:read_binary).ordered
|
136
|
+
@prot.read_type({:type => Thrift::Types::BOOL})
|
137
|
+
@prot.read_type({:type => Thrift::Types::BYTE})
|
138
|
+
@prot.read_type({:type => Thrift::Types::I16})
|
139
|
+
@prot.read_type({:type => Thrift::Types::I32})
|
140
|
+
@prot.read_type({:type => Thrift::Types::I64})
|
141
|
+
@prot.read_type({:type => Thrift::Types::DOUBLE})
|
142
|
+
@prot.read_type({:type => Thrift::Types::STRING})
|
143
|
+
@prot.read_type({:type => Thrift::Types::STRING, :binary => true})
|
144
|
+
# all other types are not implemented
|
145
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
|
146
|
+
Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
|
147
|
+
expect { @prot.read_type({:type => type}) }.to raise_error(NotImplementedError)
|
86
148
|
end
|
87
149
|
end
|
88
150
|
|
89
151
|
it "should skip the basic types" do
|
90
|
-
@prot.
|
91
|
-
@prot.
|
92
|
-
@prot.
|
93
|
-
@prot.
|
94
|
-
@prot.
|
95
|
-
@prot.
|
96
|
-
@prot.
|
97
|
-
@prot.skip(Types::BOOL)
|
98
|
-
@prot.skip(Types::BYTE)
|
99
|
-
@prot.skip(Types::I16)
|
100
|
-
@prot.skip(Types::I32)
|
101
|
-
@prot.skip(Types::I64)
|
102
|
-
@prot.skip(Types::DOUBLE)
|
103
|
-
@prot.skip(Types::STRING)
|
104
|
-
@prot.skip(Types::STOP) # should do absolutely nothing
|
152
|
+
expect(@prot).to receive(:read_bool).ordered
|
153
|
+
expect(@prot).to receive(:read_byte).ordered
|
154
|
+
expect(@prot).to receive(:read_i16).ordered
|
155
|
+
expect(@prot).to receive(:read_i32).ordered
|
156
|
+
expect(@prot).to receive(:read_i64).ordered
|
157
|
+
expect(@prot).to receive(:read_double).ordered
|
158
|
+
expect(@prot).to receive(:read_string).ordered
|
159
|
+
@prot.skip(Thrift::Types::BOOL)
|
160
|
+
@prot.skip(Thrift::Types::BYTE)
|
161
|
+
@prot.skip(Thrift::Types::I16)
|
162
|
+
@prot.skip(Thrift::Types::I32)
|
163
|
+
@prot.skip(Thrift::Types::I64)
|
164
|
+
@prot.skip(Thrift::Types::DOUBLE)
|
165
|
+
@prot.skip(Thrift::Types::STRING)
|
105
166
|
end
|
106
167
|
|
107
168
|
it "should skip structs" do
|
108
169
|
real_skip = @prot.method(:skip)
|
109
|
-
@prot.
|
110
|
-
@prot.
|
111
|
-
['field 1', Types::STRING, 1],
|
112
|
-
['field 2', Types::I32, 2],
|
113
|
-
['field 3', Types::MAP, 3],
|
114
|
-
[nil, Types::STOP, 0]
|
170
|
+
expect(@prot).to receive(:read_struct_begin).ordered
|
171
|
+
expect(@prot).to receive(:read_field_begin).exactly(4).times.and_return(
|
172
|
+
['field 1', Thrift::Types::STRING, 1],
|
173
|
+
['field 2', Thrift::Types::I32, 2],
|
174
|
+
['field 3', Thrift::Types::MAP, 3],
|
175
|
+
[nil, Thrift::Types::STOP, 0]
|
115
176
|
)
|
116
|
-
@prot.
|
117
|
-
@prot.
|
118
|
-
@prot.
|
119
|
-
@prot.
|
177
|
+
expect(@prot).to receive(:read_field_end).exactly(3).times
|
178
|
+
expect(@prot).to receive(:read_string).exactly(3).times
|
179
|
+
expect(@prot).to receive(:read_i32).ordered
|
180
|
+
expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
|
120
181
|
# @prot.should_receive(:read_string).exactly(2).times
|
121
|
-
@prot.
|
122
|
-
@prot.
|
123
|
-
real_skip.call(Types::STRUCT)
|
182
|
+
expect(@prot).to receive(:read_map_end).ordered
|
183
|
+
expect(@prot).to receive(:read_struct_end).ordered
|
184
|
+
real_skip.call(Thrift::Types::STRUCT)
|
124
185
|
end
|
125
186
|
|
126
187
|
it "should skip maps" do
|
127
188
|
real_skip = @prot.method(:skip)
|
128
|
-
@prot.
|
129
|
-
@prot.
|
130
|
-
@prot.
|
131
|
-
@prot.
|
132
|
-
@prot.
|
133
|
-
@prot.
|
134
|
-
real_skip.call(Types::MAP)
|
189
|
+
expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
|
190
|
+
expect(@prot).to receive(:read_string).ordered
|
191
|
+
expect(@prot).to receive(:read_struct_begin).ordered.and_return(["some_struct"])
|
192
|
+
expect(@prot).to receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
|
193
|
+
expect(@prot).to receive(:read_struct_end).ordered
|
194
|
+
expect(@prot).to receive(:read_map_end).ordered
|
195
|
+
real_skip.call(Thrift::Types::MAP)
|
135
196
|
end
|
136
197
|
|
137
198
|
it "should skip sets" do
|
138
199
|
real_skip = @prot.method(:skip)
|
139
|
-
@prot.
|
140
|
-
@prot.
|
141
|
-
@prot.
|
142
|
-
real_skip.call(Types::SET)
|
200
|
+
expect(@prot).to receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
|
201
|
+
expect(@prot).to receive(:read_i64).ordered.exactly(9).times
|
202
|
+
expect(@prot).to receive(:read_set_end)
|
203
|
+
real_skip.call(Thrift::Types::SET)
|
143
204
|
end
|
144
205
|
|
145
206
|
it "should skip lists" do
|
146
207
|
real_skip = @prot.method(:skip)
|
147
|
-
@prot.
|
148
|
-
@prot.
|
149
|
-
@prot.
|
150
|
-
real_skip.call(Types::LIST)
|
208
|
+
expect(@prot).to receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
|
209
|
+
expect(@prot).to receive(:read_double).ordered.exactly(11).times
|
210
|
+
expect(@prot).to receive(:read_list_end)
|
211
|
+
real_skip.call(Thrift::Types::LIST)
|
151
212
|
end
|
152
213
|
end
|
153
214
|
|
154
|
-
describe BaseProtocolFactory do
|
215
|
+
describe Thrift::BaseProtocolFactory do
|
155
216
|
it "should raise NotImplementedError" do
|
156
217
|
# returning nil since Protocol is just an abstract class
|
157
|
-
|
218
|
+
expect {Thrift::BaseProtocolFactory.new.get_protocol(double("MockTransport"))}.to raise_error(NotImplementedError)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should provide a reasonable to_s" do
|
222
|
+
expect(Thrift::BaseProtocolFactory.new.to_s).to eq("base")
|
158
223
|
end
|
159
224
|
end
|
160
225
|
end
|