thrift-mavericks 0.8.0 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/ext/binary_protocol_accelerated.c +21 -2
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +24 -7
- data/ext/constants.h +5 -5
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +11 -8
- data/ext/protocol.c +0 -185
- data/ext/protocol.h +0 -20
- data/ext/struct.c +0 -3
- data/ext/thrift_native.c +10 -11
- data/lib/thrift.rb +3 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/exceptions.rb +3 -0
- data/lib/thrift/protocol/base_protocol.rb +96 -9
- data/lib/thrift/protocol/binary_protocol.rb +15 -7
- data/lib/thrift/protocol/compact_protocol.rb +14 -6
- data/lib/thrift/protocol/json_protocol.rb +766 -0
- data/lib/thrift/server/mongrel_http_server.rb +2 -0
- data/lib/thrift/server/thin_http_server.rb +91 -0
- data/lib/thrift/struct.rb +1 -1
- data/lib/thrift/struct_union.rb +2 -2
- data/lib/thrift/transport/base_transport.rb +22 -20
- data/lib/thrift/transport/buffered_transport.rb +16 -10
- data/lib/thrift/transport/framed_transport.rb +11 -10
- data/lib/thrift/transport/http_client_transport.rb +11 -6
- data/lib/thrift/transport/io_stream_transport.rb +1 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
- data/lib/thrift/transport/socket.rb +4 -2
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +108 -51
- data/spec/base_transport_spec.rb +49 -50
- data/spec/binary_protocol_accelerated_spec.rb +9 -13
- data/spec/binary_protocol_spec.rb +15 -10
- data/spec/binary_protocol_spec_shared.rb +92 -12
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +13 -14
- data/spec/compact_protocol_spec.rb +4 -5
- data/spec/exception_spec.rb +39 -40
- data/spec/gen-rb/thrift_spec_types.rb +192 -0
- data/spec/http_client_spec.rb +65 -9
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/nonblocking_server_spec.rb +18 -20
- data/spec/processor_spec.rb +13 -16
- data/spec/serializer_spec.rb +17 -19
- data/spec/server_socket_spec.rb +6 -7
- data/spec/server_spec.rb +46 -58
- data/spec/socket_spec.rb +11 -11
- data/spec/socket_spec_shared.rb +1 -1
- data/spec/spec_helper.rb +13 -10
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +84 -86
- data/spec/thin_http_server_spec.rb +140 -0
- data/spec/types_spec.rb +65 -66
- data/spec/union_spec.rb +57 -47
- data/spec/unix_socket_spec.rb +8 -9
- metadata +72 -14
- data/spec/mongrel_http_server_spec.rb +0 -117
@@ -34,8 +34,9 @@ module Thrift
|
|
34
34
|
|
35
35
|
def open
|
36
36
|
begin
|
37
|
-
addrinfo = ::Socket::getaddrinfo(@host, @port).first
|
37
|
+
addrinfo = ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM).first
|
38
38
|
@handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
|
39
|
+
@handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
39
40
|
sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
|
40
41
|
begin
|
41
42
|
@handle.connect_nonblock(sockaddr)
|
@@ -60,6 +61,7 @@ module Thrift
|
|
60
61
|
|
61
62
|
def write(str)
|
62
63
|
raise IOError, "closed stream" unless open?
|
64
|
+
str = Bytes.force_binary_encoding(str)
|
63
65
|
begin
|
64
66
|
if @timeout.nil? or @timeout == 0
|
65
67
|
@handle.write(str)
|
@@ -134,4 +136,4 @@ module Thrift
|
|
134
136
|
@handle
|
135
137
|
end
|
136
138
|
end
|
137
|
-
end
|
139
|
+
end
|
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,31 +17,61 @@
|
|
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
25
|
@trans = mock("MockTransport")
|
27
|
-
@prot = BaseProtocol.new(@trans)
|
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
|
|
33
32
|
it "should make trans accessible" do
|
34
33
|
@prot.trans.should eql(@trans)
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
36
|
+
it 'should write out a field nicely (deprecated write_field signature)' do
|
38
37
|
@prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
|
39
|
-
@prot.should_receive(:write_type).with('type', 'value').ordered
|
38
|
+
@prot.should_receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
|
40
39
|
@prot.should_receive(:write_field_end).ordered
|
41
40
|
@prot.write_field('field', 'type', 'fid', 'value')
|
42
41
|
end
|
43
42
|
|
44
|
-
it
|
43
|
+
it 'should write out a field nicely' do
|
44
|
+
@prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
|
45
|
+
@prot.should_receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
|
46
|
+
@prot.should_receive(:write_field_end).ordered
|
47
|
+
@prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should write out the different types (deprecated write_type signature)' do
|
51
|
+
@prot.should_receive(:write_bool).with('bool').ordered
|
52
|
+
@prot.should_receive(:write_byte).with('byte').ordered
|
53
|
+
@prot.should_receive(:write_double).with('double').ordered
|
54
|
+
@prot.should_receive(:write_i16).with('i16').ordered
|
55
|
+
@prot.should_receive(:write_i32).with('i32').ordered
|
56
|
+
@prot.should_receive(:write_i64).with('i64').ordered
|
57
|
+
@prot.should_receive(:write_string).with('string').ordered
|
58
|
+
struct = mock('Struct')
|
59
|
+
struct.should_receive(:write).with(@prot).ordered
|
60
|
+
@prot.write_type(Thrift::Types::BOOL, 'bool')
|
61
|
+
@prot.write_type(Thrift::Types::BYTE, 'byte')
|
62
|
+
@prot.write_type(Thrift::Types::DOUBLE, 'double')
|
63
|
+
@prot.write_type(Thrift::Types::I16, 'i16')
|
64
|
+
@prot.write_type(Thrift::Types::I32, 'i32')
|
65
|
+
@prot.write_type(Thrift::Types::I64, 'i64')
|
66
|
+
@prot.write_type(Thrift::Types::STRING, 'string')
|
67
|
+
@prot.write_type(Thrift::Types::STRUCT, struct)
|
68
|
+
# all other types are not implemented
|
69
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
|
70
|
+
expect { @prot.write_type(type, type.to_s) }.to raise_error(NotImplementedError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should write out the different types' do
|
45
75
|
@prot.should_receive(:write_bool).with('bool').ordered
|
46
76
|
@prot.should_receive(:write_byte).with('byte').ordered
|
47
77
|
@prot.should_receive(:write_double).with('double').ordered
|
@@ -49,23 +79,47 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
|
|
49
79
|
@prot.should_receive(:write_i32).with('i32').ordered
|
50
80
|
@prot.should_receive(:write_i64).with('i64').ordered
|
51
81
|
@prot.should_receive(:write_string).with('string').ordered
|
82
|
+
@prot.should_receive(:write_binary).with('binary').ordered
|
52
83
|
struct = mock('Struct')
|
53
84
|
struct.should_receive(:write).with(@prot).ordered
|
54
|
-
@prot.write_type(Types::BOOL, 'bool')
|
55
|
-
@prot.write_type(Types::BYTE, 'byte')
|
56
|
-
@prot.write_type(Types::DOUBLE, 'double')
|
57
|
-
@prot.write_type(Types::I16, 'i16')
|
58
|
-
@prot.write_type(Types::I32, 'i32')
|
59
|
-
@prot.write_type(Types::I64, 'i64')
|
60
|
-
@prot.write_type(Types::STRING, 'string')
|
61
|
-
@prot.write_type(Types::
|
85
|
+
@prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
|
86
|
+
@prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
|
87
|
+
@prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
|
88
|
+
@prot.write_type({:type => Thrift::Types::I16}, 'i16')
|
89
|
+
@prot.write_type({:type => Thrift::Types::I32}, 'i32')
|
90
|
+
@prot.write_type({:type => Thrift::Types::I64}, 'i64')
|
91
|
+
@prot.write_type({:type => Thrift::Types::STRING}, 'string')
|
92
|
+
@prot.write_type({:type => Thrift::Types::STRING, :binary => true}, 'binary')
|
93
|
+
@prot.write_type({:type => Thrift::Types::STRUCT}, struct)
|
94
|
+
# all other types are not implemented
|
95
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
|
96
|
+
expect { @prot.write_type({:type => type}, type.to_s) }.to raise_error(NotImplementedError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should read the different types (deprecated read_type signature)' do
|
101
|
+
@prot.should_receive(:read_bool).ordered
|
102
|
+
@prot.should_receive(:read_byte).ordered
|
103
|
+
@prot.should_receive(:read_i16).ordered
|
104
|
+
@prot.should_receive(:read_i32).ordered
|
105
|
+
@prot.should_receive(:read_i64).ordered
|
106
|
+
@prot.should_receive(:read_double).ordered
|
107
|
+
@prot.should_receive(:read_string).ordered
|
108
|
+
@prot.read_type(Thrift::Types::BOOL)
|
109
|
+
@prot.read_type(Thrift::Types::BYTE)
|
110
|
+
@prot.read_type(Thrift::Types::I16)
|
111
|
+
@prot.read_type(Thrift::Types::I32)
|
112
|
+
@prot.read_type(Thrift::Types::I64)
|
113
|
+
@prot.read_type(Thrift::Types::DOUBLE)
|
114
|
+
@prot.read_type(Thrift::Types::STRING)
|
62
115
|
# all other types are not implemented
|
63
|
-
[Types::STOP, Types::VOID, Types::MAP,
|
64
|
-
|
116
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
|
117
|
+
Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
|
118
|
+
expect { @prot.read_type(type) }.to raise_error(NotImplementedError)
|
65
119
|
end
|
66
120
|
end
|
67
121
|
|
68
|
-
it
|
122
|
+
it 'should read the different types' do
|
69
123
|
@prot.should_receive(:read_bool).ordered
|
70
124
|
@prot.should_receive(:read_byte).ordered
|
71
125
|
@prot.should_receive(:read_i16).ordered
|
@@ -73,16 +127,19 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
|
|
73
127
|
@prot.should_receive(:read_i64).ordered
|
74
128
|
@prot.should_receive(:read_double).ordered
|
75
129
|
@prot.should_receive(:read_string).ordered
|
76
|
-
@prot.
|
77
|
-
@prot.read_type(Types::
|
78
|
-
@prot.read_type(Types::
|
79
|
-
@prot.read_type(Types::
|
80
|
-
@prot.read_type(Types::
|
81
|
-
@prot.read_type(Types::
|
82
|
-
@prot.read_type(Types::
|
130
|
+
@prot.should_receive(:read_binary).ordered
|
131
|
+
@prot.read_type({:type => Thrift::Types::BOOL})
|
132
|
+
@prot.read_type({:type => Thrift::Types::BYTE})
|
133
|
+
@prot.read_type({:type => Thrift::Types::I16})
|
134
|
+
@prot.read_type({:type => Thrift::Types::I32})
|
135
|
+
@prot.read_type({:type => Thrift::Types::I64})
|
136
|
+
@prot.read_type({:type => Thrift::Types::DOUBLE})
|
137
|
+
@prot.read_type({:type => Thrift::Types::STRING})
|
138
|
+
@prot.read_type({:type => Thrift::Types::STRING, :binary => true})
|
83
139
|
# all other types are not implemented
|
84
|
-
[Types::STOP, Types::VOID, Types::MAP,
|
85
|
-
|
140
|
+
[Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
|
141
|
+
Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
|
142
|
+
expect { @prot.read_type({:type => type}) }.to raise_error(NotImplementedError)
|
86
143
|
end
|
87
144
|
end
|
88
145
|
|
@@ -94,67 +151,67 @@ class ThriftBaseProtocolSpec < Spec::ExampleGroup
|
|
94
151
|
@prot.should_receive(:read_i64).ordered
|
95
152
|
@prot.should_receive(:read_double).ordered
|
96
153
|
@prot.should_receive(:read_string).ordered
|
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
|
154
|
+
@prot.skip(Thrift::Types::BOOL)
|
155
|
+
@prot.skip(Thrift::Types::BYTE)
|
156
|
+
@prot.skip(Thrift::Types::I16)
|
157
|
+
@prot.skip(Thrift::Types::I32)
|
158
|
+
@prot.skip(Thrift::Types::I64)
|
159
|
+
@prot.skip(Thrift::Types::DOUBLE)
|
160
|
+
@prot.skip(Thrift::Types::STRING)
|
161
|
+
@prot.skip(Thrift::Types::STOP) # should do absolutely nothing
|
105
162
|
end
|
106
163
|
|
107
164
|
it "should skip structs" do
|
108
165
|
real_skip = @prot.method(:skip)
|
109
166
|
@prot.should_receive(:read_struct_begin).ordered
|
110
167
|
@prot.should_receive(:read_field_begin).exactly(4).times.and_return(
|
111
|
-
['field 1', Types::STRING, 1],
|
112
|
-
['field 2', Types::I32, 2],
|
113
|
-
['field 3', Types::MAP, 3],
|
114
|
-
[nil, Types::STOP, 0]
|
168
|
+
['field 1', Thrift::Types::STRING, 1],
|
169
|
+
['field 2', Thrift::Types::I32, 2],
|
170
|
+
['field 3', Thrift::Types::MAP, 3],
|
171
|
+
[nil, Thrift::Types::STOP, 0]
|
115
172
|
)
|
116
173
|
@prot.should_receive(:read_field_end).exactly(3).times
|
117
174
|
@prot.should_receive(:read_string).exactly(3).times
|
118
175
|
@prot.should_receive(:read_i32).ordered
|
119
|
-
@prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRING, 1])
|
176
|
+
@prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
|
120
177
|
# @prot.should_receive(:read_string).exactly(2).times
|
121
178
|
@prot.should_receive(:read_map_end).ordered
|
122
179
|
@prot.should_receive(:read_struct_end).ordered
|
123
|
-
real_skip.call(Types::STRUCT)
|
180
|
+
real_skip.call(Thrift::Types::STRUCT)
|
124
181
|
end
|
125
182
|
|
126
183
|
it "should skip maps" do
|
127
184
|
real_skip = @prot.method(:skip)
|
128
|
-
@prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRUCT, 1])
|
185
|
+
@prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
|
129
186
|
@prot.should_receive(:read_string).ordered
|
130
187
|
@prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
|
131
|
-
@prot.should_receive(:read_field_begin).ordered.and_return([nil, Types::STOP, nil]);
|
188
|
+
@prot.should_receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
|
132
189
|
@prot.should_receive(:read_struct_end).ordered
|
133
190
|
@prot.should_receive(:read_map_end).ordered
|
134
|
-
real_skip.call(Types::MAP)
|
191
|
+
real_skip.call(Thrift::Types::MAP)
|
135
192
|
end
|
136
193
|
|
137
194
|
it "should skip sets" do
|
138
195
|
real_skip = @prot.method(:skip)
|
139
|
-
@prot.should_receive(:read_set_begin).ordered.and_return([Types::I64, 9])
|
196
|
+
@prot.should_receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
|
140
197
|
@prot.should_receive(:read_i64).ordered.exactly(9).times
|
141
198
|
@prot.should_receive(:read_set_end)
|
142
|
-
real_skip.call(Types::SET)
|
199
|
+
real_skip.call(Thrift::Types::SET)
|
143
200
|
end
|
144
201
|
|
145
202
|
it "should skip lists" do
|
146
203
|
real_skip = @prot.method(:skip)
|
147
|
-
@prot.should_receive(:read_list_begin).ordered.and_return([Types::DOUBLE, 11])
|
204
|
+
@prot.should_receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
|
148
205
|
@prot.should_receive(:read_double).ordered.exactly(11).times
|
149
206
|
@prot.should_receive(:read_list_end)
|
150
|
-
real_skip.call(Types::LIST)
|
207
|
+
real_skip.call(Thrift::Types::LIST)
|
151
208
|
end
|
152
209
|
end
|
153
210
|
|
154
|
-
describe BaseProtocolFactory do
|
211
|
+
describe Thrift::BaseProtocolFactory do
|
155
212
|
it "should raise NotImplementedError" do
|
156
213
|
# returning nil since Protocol is just an abstract class
|
157
|
-
lambda {BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
|
214
|
+
lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
|
158
215
|
end
|
159
216
|
end
|
160
217
|
end
|
data/spec/base_transport_spec.rb
CHANGED
@@ -17,22 +17,21 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'BaseTransport' do
|
24
23
|
|
25
|
-
describe TransportException do
|
24
|
+
describe Thrift::TransportException do
|
26
25
|
it "should make type accessible" do
|
27
|
-
exc = TransportException.new(TransportException::ALREADY_OPEN, "msg")
|
28
|
-
exc.type.should == TransportException::ALREADY_OPEN
|
26
|
+
exc = Thrift::TransportException.new(Thrift::TransportException::ALREADY_OPEN, "msg")
|
27
|
+
exc.type.should == Thrift::TransportException::ALREADY_OPEN
|
29
28
|
exc.message.should == "msg"
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
describe BaseTransport do
|
32
|
+
describe Thrift::BaseTransport do
|
34
33
|
it "should read the specified size" do
|
35
|
-
transport = BaseTransport.new
|
34
|
+
transport = Thrift::BaseTransport.new
|
36
35
|
transport.should_receive(:read).with(40).ordered.and_return("10 letters")
|
37
36
|
transport.should_receive(:read).with(30).ordered.and_return("fifteen letters")
|
38
37
|
transport.should_receive(:read).with(15).ordered.and_return("more characters")
|
@@ -42,47 +41,47 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
42
41
|
it "should stub out the rest of the methods" do
|
43
42
|
# can't test for stubbiness, so just make sure they're defined
|
44
43
|
[:open?, :open, :close, :read, :write, :flush].each do |sym|
|
45
|
-
BaseTransport.method_defined?(sym).should be_true
|
44
|
+
Thrift::BaseTransport.method_defined?(sym).should be_true
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should alias << to write" do
|
50
|
-
BaseTransport.instance_method(:<<).should == BaseTransport.instance_method(:write)
|
49
|
+
Thrift::BaseTransport.instance_method(:<<).should == Thrift::BaseTransport.instance_method(:write)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
describe BaseServerTransport do
|
53
|
+
describe Thrift::BaseServerTransport do
|
55
54
|
it "should stub out its methods" do
|
56
55
|
[:listen, :accept, :close].each do |sym|
|
57
|
-
BaseServerTransport.method_defined?(sym).should be_true
|
56
|
+
Thrift::BaseServerTransport.method_defined?(sym).should be_true
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
|
-
describe BaseTransportFactory do
|
61
|
+
describe Thrift::BaseTransportFactory do
|
63
62
|
it "should return the transport it's given" do
|
64
63
|
transport = mock("Transport")
|
65
|
-
BaseTransportFactory.new.get_transport(transport).should eql(transport)
|
64
|
+
Thrift::BaseTransportFactory.new.get_transport(transport).should eql(transport)
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
describe BufferedTransport do
|
68
|
+
describe Thrift::BufferedTransport do
|
70
69
|
it "should pass through everything but write/flush/read" do
|
71
70
|
trans = mock("Transport")
|
72
71
|
trans.should_receive(:open?).ordered.and_return("+ open?")
|
73
72
|
trans.should_receive(:open).ordered.and_return("+ open")
|
74
73
|
trans.should_receive(:flush).ordered # from the close
|
75
74
|
trans.should_receive(:close).ordered.and_return("+ close")
|
76
|
-
btrans = BufferedTransport.new(trans)
|
75
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
77
76
|
btrans.open?.should == "+ open?"
|
78
77
|
btrans.open.should == "+ open"
|
79
78
|
btrans.close.should == "+ close"
|
80
79
|
end
|
81
|
-
|
82
|
-
it "should buffer reads in chunks of #{BufferedTransport::DEFAULT_BUFFER}" do
|
80
|
+
|
81
|
+
it "should buffer reads in chunks of #{Thrift::BufferedTransport::DEFAULT_BUFFER}" do
|
83
82
|
trans = mock("Transport")
|
84
|
-
trans.should_receive(:read).with(BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
|
85
|
-
btrans = BufferedTransport.new(trans)
|
83
|
+
trans.should_receive(:read).with(Thrift::BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
|
84
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
86
85
|
btrans.read(6).should == "lorum "
|
87
86
|
btrans.read(6).should == "ipsum "
|
88
87
|
btrans.read(6).should == "dolor "
|
@@ -91,7 +90,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
91
90
|
|
92
91
|
it "should buffer writes and send them on flush" do
|
93
92
|
trans = mock("Transport")
|
94
|
-
btrans = BufferedTransport.new(trans)
|
93
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
95
94
|
btrans.write("one/")
|
96
95
|
btrans.write("two/")
|
97
96
|
btrans.write("three/")
|
@@ -102,7 +101,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
102
101
|
|
103
102
|
it "should only send buffered data once" do
|
104
103
|
trans = mock("Transport")
|
105
|
-
btrans = BufferedTransport.new(trans)
|
104
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
106
105
|
btrans.write("one/")
|
107
106
|
btrans.write("two/")
|
108
107
|
btrans.write("three/")
|
@@ -112,39 +111,39 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
112
111
|
# Nothing to flush with no data
|
113
112
|
btrans.flush
|
114
113
|
end
|
115
|
-
|
114
|
+
|
116
115
|
it "should flush on close" do
|
117
116
|
trans = mock("Transport")
|
118
117
|
trans.should_receive(:close)
|
119
|
-
btrans = BufferedTransport.new(trans)
|
118
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
120
119
|
btrans.should_receive(:flush)
|
121
120
|
btrans.close
|
122
121
|
end
|
123
|
-
|
122
|
+
|
124
123
|
it "should not write to socket if there's no data" do
|
125
124
|
trans = mock("Transport")
|
126
125
|
trans.should_receive(:flush)
|
127
|
-
btrans = BufferedTransport.new(trans)
|
126
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
128
127
|
btrans.flush
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
132
|
-
describe BufferedTransportFactory do
|
131
|
+
describe Thrift::BufferedTransportFactory do
|
133
132
|
it "should wrap the given transport in a BufferedTransport" do
|
134
133
|
trans = mock("Transport")
|
135
134
|
btrans = mock("BufferedTransport")
|
136
|
-
BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
|
137
|
-
BufferedTransportFactory.new.get_transport(trans).should == btrans
|
135
|
+
Thrift::BufferedTransport.should_receive(:new).with(trans).and_return(btrans)
|
136
|
+
Thrift::BufferedTransportFactory.new.get_transport(trans).should == btrans
|
138
137
|
end
|
139
138
|
end
|
140
139
|
|
141
|
-
describe FramedTransport do
|
140
|
+
describe Thrift::FramedTransport do
|
142
141
|
before(:each) do
|
143
142
|
@trans = mock("Transport")
|
144
143
|
end
|
145
144
|
|
146
145
|
it "should pass through open?/open/close" do
|
147
|
-
ftrans = FramedTransport.new(@trans)
|
146
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
148
147
|
@trans.should_receive(:open?).ordered.and_return("+ open?")
|
149
148
|
@trans.should_receive(:open).ordered.and_return("+ open")
|
150
149
|
@trans.should_receive(:close).ordered.and_return("+ close")
|
@@ -154,13 +153,13 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
154
153
|
end
|
155
154
|
|
156
155
|
it "should pass through read when read is turned off" do
|
157
|
-
ftrans = FramedTransport.new(@trans, false, true)
|
156
|
+
ftrans = Thrift::FramedTransport.new(@trans, false, true)
|
158
157
|
@trans.should_receive(:read).with(17).ordered.and_return("+ read")
|
159
158
|
ftrans.read(17).should == "+ read"
|
160
159
|
end
|
161
160
|
|
162
161
|
it "should pass through write/flush when write is turned off" do
|
163
|
-
ftrans = FramedTransport.new(@trans, true, false)
|
162
|
+
ftrans = Thrift::FramedTransport.new(@trans, true, false)
|
164
163
|
@trans.should_receive(:write).with("foo").ordered.and_return("+ write")
|
165
164
|
@trans.should_receive(:flush).ordered.and_return("+ flush")
|
166
165
|
ftrans.write("foo").should == "+ write"
|
@@ -171,21 +170,21 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
171
170
|
frame = "this is a frame"
|
172
171
|
@trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
|
173
172
|
@trans.should_receive(:read_all).with(frame.length).and_return(frame)
|
174
|
-
FramedTransport.new(@trans).read(frame.length + 10).should == frame
|
173
|
+
Thrift::FramedTransport.new(@trans).read(frame.length + 10).should == frame
|
175
174
|
end
|
176
175
|
|
177
176
|
it "should return slices of the frame when asked for < the frame's length" do
|
178
177
|
frame = "this is a frame"
|
179
178
|
@trans.should_receive(:read_all).with(4).and_return("\000\000\000\017")
|
180
179
|
@trans.should_receive(:read_all).with(frame.length).and_return(frame)
|
181
|
-
ftrans = FramedTransport.new(@trans)
|
180
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
182
181
|
ftrans.read(4).should == "this"
|
183
182
|
ftrans.read(4).should == " is "
|
184
183
|
ftrans.read(16).should == "a frame"
|
185
184
|
end
|
186
185
|
|
187
186
|
it "should return nothing if asked for <= 0" do
|
188
|
-
FramedTransport.new(@trans).read(-2).should == ""
|
187
|
+
Thrift::FramedTransport.new(@trans).read(-2).should == ""
|
189
188
|
end
|
190
189
|
|
191
190
|
it "should pull a new frame when the first is exhausted" do
|
@@ -194,7 +193,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
194
193
|
@trans.should_receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
|
195
194
|
@trans.should_receive(:read_all).with(frame.length).and_return(frame)
|
196
195
|
@trans.should_receive(:read_all).with(frame2.length).and_return(frame2)
|
197
|
-
ftrans = FramedTransport.new(@trans)
|
196
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
198
197
|
ftrans.read(4).should == "this"
|
199
198
|
ftrans.read(8).should == " is a fr"
|
200
199
|
ftrans.read(6).should == "ame"
|
@@ -203,7 +202,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
203
202
|
end
|
204
203
|
|
205
204
|
it "should buffer writes" do
|
206
|
-
ftrans = FramedTransport.new(@trans)
|
205
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
207
206
|
@trans.should_not_receive(:write)
|
208
207
|
ftrans.write("foo")
|
209
208
|
ftrans.write("bar")
|
@@ -211,7 +210,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
211
210
|
end
|
212
211
|
|
213
212
|
it "should write slices of the buffer" do
|
214
|
-
ftrans = FramedTransport.new(@trans)
|
213
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
215
214
|
ftrans.write("foobar", 3)
|
216
215
|
ftrans.write("barfoo", 1)
|
217
216
|
@trans.stub!(:flush)
|
@@ -220,7 +219,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
220
219
|
end
|
221
220
|
|
222
221
|
it "should flush frames with a 4-byte header" do
|
223
|
-
ftrans = FramedTransport.new(@trans)
|
222
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
224
223
|
@trans.should_receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
|
225
224
|
@trans.should_receive(:flush).ordered
|
226
225
|
ftrans.write("one/")
|
@@ -231,7 +230,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
231
230
|
end
|
232
231
|
|
233
232
|
it "should not flush the same buffered data twice" do
|
234
|
-
ftrans = FramedTransport.new(@trans)
|
233
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
235
234
|
@trans.should_receive(:write).with("\000\000\000\007foo/bar")
|
236
235
|
@trans.stub!(:flush)
|
237
236
|
ftrans.write("foo")
|
@@ -242,22 +241,22 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
242
241
|
end
|
243
242
|
end
|
244
243
|
|
245
|
-
describe FramedTransportFactory do
|
244
|
+
describe Thrift::FramedTransportFactory do
|
246
245
|
it "should wrap the given transport in a FramedTransport" do
|
247
246
|
trans = mock("Transport")
|
248
|
-
FramedTransport.should_receive(:new).with(trans)
|
249
|
-
FramedTransportFactory.new.get_transport(trans)
|
247
|
+
Thrift::FramedTransport.should_receive(:new).with(trans)
|
248
|
+
Thrift::FramedTransportFactory.new.get_transport(trans)
|
250
249
|
end
|
251
250
|
end
|
252
251
|
|
253
|
-
describe MemoryBufferTransport do
|
252
|
+
describe Thrift::MemoryBufferTransport do
|
254
253
|
before(:each) do
|
255
|
-
@buffer = MemoryBufferTransport.new
|
254
|
+
@buffer = Thrift::MemoryBufferTransport.new
|
256
255
|
end
|
257
256
|
|
258
257
|
it "should accept a buffer on input and use it directly" do
|
259
258
|
s = "this is a test"
|
260
|
-
@buffer = MemoryBufferTransport.new(s)
|
259
|
+
@buffer = Thrift::MemoryBufferTransport.new(s)
|
261
260
|
@buffer.read(4).should == "this"
|
262
261
|
s.slice!(-4..-1)
|
263
262
|
@buffer.read(@buffer.available).should == " is a "
|
@@ -307,7 +306,7 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
307
306
|
@buffer.write " bar"
|
308
307
|
@buffer.read(@buffer.available).should == "foo bar"
|
309
308
|
end
|
310
|
-
|
309
|
+
|
311
310
|
it "should throw an EOFError when there isn't enough data in the buffer" do
|
312
311
|
@buffer.reset_buffer("")
|
313
312
|
lambda{@buffer.read(1)}.should raise_error(EOFError)
|
@@ -317,11 +316,11 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
317
316
|
end
|
318
317
|
end
|
319
318
|
|
320
|
-
describe IOStreamTransport do
|
319
|
+
describe Thrift::IOStreamTransport do
|
321
320
|
before(:each) do
|
322
321
|
@input = mock("Input", :closed? => false)
|
323
322
|
@output = mock("Output", :closed? => false)
|
324
|
-
@trans = IOStreamTransport.new(@input, @output)
|
323
|
+
@trans = Thrift::IOStreamTransport.new(@input, @output)
|
325
324
|
end
|
326
325
|
|
327
326
|
it "should be open as long as both input or output are open" do
|