thrift 0.8.0 → 0.13.0
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.
- 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/base_transport_spec.rb
CHANGED
@@ -17,212 +17,235 @@
|
|
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.
|
29
|
-
exc.message.
|
26
|
+
exc = Thrift::TransportException.new(Thrift::TransportException::ALREADY_OPEN, "msg")
|
27
|
+
expect(exc.type).to eq(Thrift::TransportException::ALREADY_OPEN)
|
28
|
+
expect(exc.message).to eq("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
|
36
|
-
transport.
|
37
|
-
transport.
|
38
|
-
transport.
|
39
|
-
transport.read_all(40).
|
34
|
+
transport = Thrift::BaseTransport.new
|
35
|
+
expect(transport).to receive(:read).with(40).ordered.and_return("10 letters")
|
36
|
+
expect(transport).to receive(:read).with(30).ordered.and_return("fifteen letters")
|
37
|
+
expect(transport).to receive(:read).with(15).ordered.and_return("more characters")
|
38
|
+
expect(transport.read_all(40)).to eq("10 lettersfifteen lettersmore characters")
|
40
39
|
end
|
41
40
|
|
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).
|
44
|
+
expect(Thrift::BaseTransport.method_defined?(sym)).to be_truthy
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should alias << to write" do
|
50
|
-
BaseTransport.instance_method(:<<).
|
49
|
+
expect(Thrift::BaseTransport.instance_method(:<<)).to eq(Thrift::BaseTransport.instance_method(:write))
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should provide a reasonable to_s" do
|
53
|
+
expect(Thrift::BaseTransport.new.to_s).to eq("base")
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
describe BaseServerTransport do
|
57
|
+
describe Thrift::BaseServerTransport do
|
55
58
|
it "should stub out its methods" do
|
56
59
|
[:listen, :accept, :close].each do |sym|
|
57
|
-
BaseServerTransport.method_defined?(sym).
|
60
|
+
expect(Thrift::BaseServerTransport.method_defined?(sym)).to be_truthy
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
|
-
describe BaseTransportFactory do
|
65
|
+
describe Thrift::BaseTransportFactory do
|
63
66
|
it "should return the transport it's given" do
|
64
|
-
transport =
|
65
|
-
BaseTransportFactory.new.get_transport(transport).
|
67
|
+
transport = double("Transport")
|
68
|
+
expect(Thrift::BaseTransportFactory.new.get_transport(transport)).to eql(transport)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should provide a reasonable to_s" do
|
72
|
+
expect(Thrift::BaseTransportFactory.new.to_s).to eq("base")
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
69
|
-
describe BufferedTransport do
|
70
|
-
it "should
|
71
|
-
trans =
|
72
|
-
trans.
|
73
|
-
|
74
|
-
trans.should_receive(:flush).ordered # from the close
|
75
|
-
trans.should_receive(:close).ordered.and_return("+ close")
|
76
|
-
btrans = BufferedTransport.new(trans)
|
77
|
-
btrans.open?.should == "+ open?"
|
78
|
-
btrans.open.should == "+ open"
|
79
|
-
btrans.close.should == "+ close"
|
76
|
+
describe Thrift::BufferedTransport do
|
77
|
+
it "should provide a to_s that describes the encapsulation" do
|
78
|
+
trans = double("Transport")
|
79
|
+
expect(trans).to receive(:to_s).and_return("mock")
|
80
|
+
expect(Thrift::BufferedTransport.new(trans).to_s).to eq("buffered(mock)")
|
80
81
|
end
|
81
|
-
|
82
|
-
it "should
|
83
|
-
trans =
|
84
|
-
trans.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
btrans.
|
89
|
-
btrans.
|
82
|
+
|
83
|
+
it "should pass through everything but write/flush/read" do
|
84
|
+
trans = double("Transport")
|
85
|
+
expect(trans).to receive(:open?).ordered.and_return("+ open?")
|
86
|
+
expect(trans).to receive(:open).ordered.and_return("+ open")
|
87
|
+
expect(trans).to receive(:flush).ordered # from the close
|
88
|
+
expect(trans).to receive(:close).ordered.and_return("+ close")
|
89
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
90
|
+
expect(btrans.open?).to eq("+ open?")
|
91
|
+
expect(btrans.open).to eq("+ open")
|
92
|
+
expect(btrans.close).to eq("+ close")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should buffer reads in chunks of #{Thrift::BufferedTransport::DEFAULT_BUFFER}" do
|
96
|
+
trans = double("Transport")
|
97
|
+
expect(trans).to receive(:read).with(Thrift::BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
|
98
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
99
|
+
expect(btrans.read(6)).to eq("lorum ")
|
100
|
+
expect(btrans.read(6)).to eq("ipsum ")
|
101
|
+
expect(btrans.read(6)).to eq("dolor ")
|
102
|
+
expect(btrans.read(6)).to eq("emet")
|
90
103
|
end
|
91
104
|
|
92
105
|
it "should buffer writes and send them on flush" do
|
93
|
-
trans =
|
94
|
-
btrans = BufferedTransport.new(trans)
|
106
|
+
trans = double("Transport")
|
107
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
95
108
|
btrans.write("one/")
|
96
109
|
btrans.write("two/")
|
97
110
|
btrans.write("three/")
|
98
|
-
trans.
|
99
|
-
trans.
|
111
|
+
expect(trans).to receive(:write).with("one/two/three/").ordered
|
112
|
+
expect(trans).to receive(:flush).ordered
|
100
113
|
btrans.flush
|
101
114
|
end
|
102
115
|
|
103
116
|
it "should only send buffered data once" do
|
104
|
-
trans =
|
105
|
-
btrans = BufferedTransport.new(trans)
|
117
|
+
trans = double("Transport")
|
118
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
106
119
|
btrans.write("one/")
|
107
120
|
btrans.write("two/")
|
108
121
|
btrans.write("three/")
|
109
|
-
trans.
|
110
|
-
trans.
|
122
|
+
expect(trans).to receive(:write).with("one/two/three/")
|
123
|
+
allow(trans).to receive(:flush)
|
111
124
|
btrans.flush
|
112
125
|
# Nothing to flush with no data
|
113
126
|
btrans.flush
|
114
127
|
end
|
115
|
-
|
128
|
+
|
116
129
|
it "should flush on close" do
|
117
|
-
trans =
|
118
|
-
trans.
|
119
|
-
btrans = BufferedTransport.new(trans)
|
120
|
-
btrans.
|
130
|
+
trans = double("Transport")
|
131
|
+
expect(trans).to receive(:close)
|
132
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
133
|
+
expect(btrans).to receive(:flush)
|
121
134
|
btrans.close
|
122
135
|
end
|
123
|
-
|
136
|
+
|
124
137
|
it "should not write to socket if there's no data" do
|
125
|
-
trans =
|
126
|
-
trans.
|
127
|
-
btrans = BufferedTransport.new(trans)
|
138
|
+
trans = double("Transport")
|
139
|
+
expect(trans).to receive(:flush)
|
140
|
+
btrans = Thrift::BufferedTransport.new(trans)
|
128
141
|
btrans.flush
|
129
142
|
end
|
130
143
|
end
|
131
144
|
|
132
|
-
describe BufferedTransportFactory do
|
145
|
+
describe Thrift::BufferedTransportFactory do
|
133
146
|
it "should wrap the given transport in a BufferedTransport" do
|
134
|
-
trans =
|
135
|
-
btrans =
|
136
|
-
BufferedTransport.
|
137
|
-
BufferedTransportFactory.new.get_transport(trans).
|
147
|
+
trans = double("Transport")
|
148
|
+
btrans = double("BufferedTransport")
|
149
|
+
expect(Thrift::BufferedTransport).to receive(:new).with(trans).and_return(btrans)
|
150
|
+
expect(Thrift::BufferedTransportFactory.new.get_transport(trans)).to eq(btrans)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should provide a reasonable to_s" do
|
154
|
+
expect(Thrift::BufferedTransportFactory.new.to_s).to eq("buffered")
|
138
155
|
end
|
139
156
|
end
|
140
157
|
|
141
|
-
describe FramedTransport do
|
158
|
+
describe Thrift::FramedTransport do
|
142
159
|
before(:each) do
|
143
|
-
@trans =
|
160
|
+
@trans = double("Transport")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should provide a to_s that describes the encapsulation" do
|
164
|
+
trans = double("Transport")
|
165
|
+
expect(trans).to receive(:to_s).and_return("mock")
|
166
|
+
expect(Thrift::FramedTransport.new(trans).to_s).to eq("framed(mock)")
|
144
167
|
end
|
145
168
|
|
146
169
|
it "should pass through open?/open/close" do
|
147
|
-
ftrans = FramedTransport.new(@trans)
|
148
|
-
@trans.
|
149
|
-
@trans.
|
150
|
-
@trans.
|
151
|
-
ftrans.open
|
152
|
-
ftrans.open.
|
153
|
-
ftrans.close.
|
170
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
171
|
+
expect(@trans).to receive(:open?).ordered.and_return("+ open?")
|
172
|
+
expect(@trans).to receive(:open).ordered.and_return("+ open")
|
173
|
+
expect(@trans).to receive(:close).ordered.and_return("+ close")
|
174
|
+
expect(ftrans.open?).to eq("+ open?")
|
175
|
+
expect(ftrans.open).to eq("+ open")
|
176
|
+
expect(ftrans.close).to eq("+ close")
|
154
177
|
end
|
155
178
|
|
156
179
|
it "should pass through read when read is turned off" do
|
157
|
-
ftrans = FramedTransport.new(@trans, false, true)
|
158
|
-
@trans.
|
159
|
-
ftrans.read(17).
|
180
|
+
ftrans = Thrift::FramedTransport.new(@trans, false, true)
|
181
|
+
expect(@trans).to receive(:read).with(17).ordered.and_return("+ read")
|
182
|
+
expect(ftrans.read(17)).to eq("+ read")
|
160
183
|
end
|
161
184
|
|
162
185
|
it "should pass through write/flush when write is turned off" do
|
163
|
-
ftrans = FramedTransport.new(@trans, true, false)
|
164
|
-
@trans.
|
165
|
-
@trans.
|
166
|
-
ftrans.write("foo").
|
167
|
-
ftrans.flush.
|
186
|
+
ftrans = Thrift::FramedTransport.new(@trans, true, false)
|
187
|
+
expect(@trans).to receive(:write).with("foo").ordered.and_return("+ write")
|
188
|
+
expect(@trans).to receive(:flush).ordered.and_return("+ flush")
|
189
|
+
expect(ftrans.write("foo")).to eq("+ write")
|
190
|
+
expect(ftrans.flush).to eq("+ flush")
|
168
191
|
end
|
169
192
|
|
170
193
|
it "should return a full frame if asked for >= the frame's length" do
|
171
194
|
frame = "this is a frame"
|
172
|
-
@trans.
|
173
|
-
@trans.
|
174
|
-
FramedTransport.new(@trans).read(frame.length + 10).
|
195
|
+
expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
|
196
|
+
expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
|
197
|
+
expect(Thrift::FramedTransport.new(@trans).read(frame.length + 10)).to eq(frame)
|
175
198
|
end
|
176
199
|
|
177
200
|
it "should return slices of the frame when asked for < the frame's length" do
|
178
201
|
frame = "this is a frame"
|
179
|
-
@trans.
|
180
|
-
@trans.
|
181
|
-
ftrans = FramedTransport.new(@trans)
|
182
|
-
ftrans.read(4).
|
183
|
-
ftrans.read(4).
|
184
|
-
ftrans.read(16).
|
202
|
+
expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
|
203
|
+
expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
|
204
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
205
|
+
expect(ftrans.read(4)).to eq("this")
|
206
|
+
expect(ftrans.read(4)).to eq(" is ")
|
207
|
+
expect(ftrans.read(16)).to eq("a frame")
|
185
208
|
end
|
186
209
|
|
187
210
|
it "should return nothing if asked for <= 0" do
|
188
|
-
FramedTransport.new(@trans).read(-2).
|
211
|
+
expect(Thrift::FramedTransport.new(@trans).read(-2)).to eq("")
|
189
212
|
end
|
190
213
|
|
191
214
|
it "should pull a new frame when the first is exhausted" do
|
192
215
|
frame = "this is a frame"
|
193
216
|
frame2 = "yet another frame"
|
194
|
-
@trans.
|
195
|
-
@trans.
|
196
|
-
@trans.
|
197
|
-
ftrans = FramedTransport.new(@trans)
|
198
|
-
ftrans.read(4).
|
199
|
-
ftrans.read(8).
|
200
|
-
ftrans.read(6).
|
201
|
-
ftrans.read(4).
|
202
|
-
ftrans.read(16).
|
217
|
+
expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
|
218
|
+
expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
|
219
|
+
expect(@trans).to receive(:read_all).with(frame2.length).and_return(frame2)
|
220
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
221
|
+
expect(ftrans.read(4)).to eq("this")
|
222
|
+
expect(ftrans.read(8)).to eq(" is a fr")
|
223
|
+
expect(ftrans.read(6)).to eq("ame")
|
224
|
+
expect(ftrans.read(4)).to eq("yet ")
|
225
|
+
expect(ftrans.read(16)).to eq("another frame")
|
203
226
|
end
|
204
227
|
|
205
228
|
it "should buffer writes" do
|
206
|
-
ftrans = FramedTransport.new(@trans)
|
207
|
-
@trans.
|
229
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
230
|
+
expect(@trans).not_to receive(:write)
|
208
231
|
ftrans.write("foo")
|
209
232
|
ftrans.write("bar")
|
210
233
|
ftrans.write("this is a frame")
|
211
234
|
end
|
212
235
|
|
213
236
|
it "should write slices of the buffer" do
|
214
|
-
ftrans = FramedTransport.new(@trans)
|
237
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
215
238
|
ftrans.write("foobar", 3)
|
216
239
|
ftrans.write("barfoo", 1)
|
217
|
-
@trans.
|
218
|
-
@trans.
|
240
|
+
allow(@trans).to receive(:flush)
|
241
|
+
expect(@trans).to receive(:write).with("\000\000\000\004foob")
|
219
242
|
ftrans.flush
|
220
243
|
end
|
221
244
|
|
222
245
|
it "should flush frames with a 4-byte header" do
|
223
|
-
ftrans = FramedTransport.new(@trans)
|
224
|
-
@trans.
|
225
|
-
@trans.
|
246
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
247
|
+
expect(@trans).to receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
|
248
|
+
expect(@trans).to receive(:flush).ordered
|
226
249
|
ftrans.write("one/")
|
227
250
|
ftrans.write("two/")
|
228
251
|
ftrans.write("three/")
|
@@ -231,120 +254,134 @@ class ThriftBaseTransportSpec < Spec::ExampleGroup
|
|
231
254
|
end
|
232
255
|
|
233
256
|
it "should not flush the same buffered data twice" do
|
234
|
-
ftrans = FramedTransport.new(@trans)
|
235
|
-
@trans.
|
236
|
-
@trans.
|
257
|
+
ftrans = Thrift::FramedTransport.new(@trans)
|
258
|
+
expect(@trans).to receive(:write).with("\000\000\000\007foo/bar")
|
259
|
+
allow(@trans).to receive(:flush)
|
237
260
|
ftrans.write("foo")
|
238
261
|
ftrans.write("/bar")
|
239
262
|
ftrans.flush
|
240
|
-
@trans.
|
263
|
+
expect(@trans).to receive(:write).with("\000\000\000\000")
|
241
264
|
ftrans.flush
|
242
265
|
end
|
243
266
|
end
|
244
267
|
|
245
|
-
describe FramedTransportFactory do
|
268
|
+
describe Thrift::FramedTransportFactory do
|
246
269
|
it "should wrap the given transport in a FramedTransport" do
|
247
|
-
trans =
|
248
|
-
FramedTransport.
|
249
|
-
FramedTransportFactory.new.get_transport(trans)
|
270
|
+
trans = double("Transport")
|
271
|
+
expect(Thrift::FramedTransport).to receive(:new).with(trans)
|
272
|
+
Thrift::FramedTransportFactory.new.get_transport(trans)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should provide a reasonable to_s" do
|
276
|
+
expect(Thrift::FramedTransportFactory.new.to_s).to eq("framed")
|
250
277
|
end
|
251
278
|
end
|
252
279
|
|
253
|
-
describe MemoryBufferTransport do
|
280
|
+
describe Thrift::MemoryBufferTransport do
|
254
281
|
before(:each) do
|
255
|
-
@buffer = MemoryBufferTransport.new
|
282
|
+
@buffer = Thrift::MemoryBufferTransport.new
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should provide a reasonable to_s" do
|
286
|
+
expect(@buffer.to_s).to eq("memory")
|
256
287
|
end
|
257
288
|
|
258
289
|
it "should accept a buffer on input and use it directly" do
|
259
290
|
s = "this is a test"
|
260
|
-
@buffer = MemoryBufferTransport.new(s)
|
261
|
-
@buffer.read(4).
|
291
|
+
@buffer = Thrift::MemoryBufferTransport.new(s)
|
292
|
+
expect(@buffer.read(4)).to eq("this")
|
262
293
|
s.slice!(-4..-1)
|
263
|
-
@buffer.read(@buffer.available).
|
294
|
+
expect(@buffer.read(@buffer.available)).to eq(" is a ")
|
264
295
|
end
|
265
296
|
|
266
297
|
it "should always remain open" do
|
267
|
-
@buffer.
|
298
|
+
expect(@buffer).to be_open
|
268
299
|
@buffer.close
|
269
|
-
@buffer.
|
300
|
+
expect(@buffer).to be_open
|
270
301
|
end
|
271
302
|
|
272
303
|
it "should respond to peek and available" do
|
273
304
|
@buffer.write "some data"
|
274
|
-
@buffer.peek.
|
275
|
-
@buffer.available.
|
305
|
+
expect(@buffer.peek).to be_truthy
|
306
|
+
expect(@buffer.available).to eq(9)
|
276
307
|
@buffer.read(4)
|
277
|
-
@buffer.peek.
|
278
|
-
@buffer.available.
|
308
|
+
expect(@buffer.peek).to be_truthy
|
309
|
+
expect(@buffer.available).to eq(5)
|
279
310
|
@buffer.read(5)
|
280
|
-
@buffer.peek.
|
281
|
-
@buffer.available.
|
311
|
+
expect(@buffer.peek).to be_falsey
|
312
|
+
expect(@buffer.available).to eq(0)
|
282
313
|
end
|
283
314
|
|
284
315
|
it "should be able to reset the buffer" do
|
285
316
|
@buffer.write "test data"
|
286
317
|
@buffer.reset_buffer("foobar")
|
287
|
-
@buffer.available.
|
288
|
-
@buffer.read(@buffer.available).
|
318
|
+
expect(@buffer.available).to eq(6)
|
319
|
+
expect(@buffer.read(@buffer.available)).to eq("foobar")
|
289
320
|
@buffer.reset_buffer
|
290
|
-
@buffer.available.
|
321
|
+
expect(@buffer.available).to eq(0)
|
291
322
|
end
|
292
323
|
|
293
324
|
it "should copy the given string when resetting the buffer" do
|
294
325
|
s = "this is a test"
|
295
326
|
@buffer.reset_buffer(s)
|
296
|
-
@buffer.available.
|
327
|
+
expect(@buffer.available).to eq(14)
|
297
328
|
@buffer.read(10)
|
298
|
-
@buffer.available.
|
299
|
-
s.
|
329
|
+
expect(@buffer.available).to eq(4)
|
330
|
+
expect(s).to eq("this is a test")
|
300
331
|
end
|
301
332
|
|
302
333
|
it "should return from read what was given in write" do
|
303
334
|
@buffer.write "test data"
|
304
|
-
@buffer.read(4).
|
305
|
-
@buffer.read(@buffer.available).
|
335
|
+
expect(@buffer.read(4)).to eq("test")
|
336
|
+
expect(@buffer.read(@buffer.available)).to eq(" data")
|
306
337
|
@buffer.write "foo"
|
307
338
|
@buffer.write " bar"
|
308
|
-
@buffer.read(@buffer.available).
|
339
|
+
expect(@buffer.read(@buffer.available)).to eq("foo bar")
|
309
340
|
end
|
310
|
-
|
341
|
+
|
311
342
|
it "should throw an EOFError when there isn't enough data in the buffer" do
|
312
343
|
@buffer.reset_buffer("")
|
313
|
-
|
344
|
+
expect{@buffer.read(1)}.to raise_error(EOFError)
|
314
345
|
|
315
346
|
@buffer.reset_buffer("1234")
|
316
|
-
|
347
|
+
expect{@buffer.read(5)}.to raise_error(EOFError)
|
317
348
|
end
|
318
349
|
end
|
319
350
|
|
320
|
-
describe IOStreamTransport do
|
351
|
+
describe Thrift::IOStreamTransport do
|
321
352
|
before(:each) do
|
322
|
-
@input =
|
323
|
-
@output =
|
324
|
-
@trans = IOStreamTransport.new(@input, @output)
|
353
|
+
@input = double("Input", :closed? => false)
|
354
|
+
@output = double("Output", :closed? => false)
|
355
|
+
@trans = Thrift::IOStreamTransport.new(@input, @output)
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should provide a reasonable to_s" do
|
359
|
+
expect(@input).to receive(:to_s).and_return("mock_input")
|
360
|
+
expect(@output).to receive(:to_s).and_return("mock_output")
|
361
|
+
expect(@trans.to_s).to eq("iostream(input=mock_input,output=mock_output)")
|
325
362
|
end
|
326
363
|
|
327
364
|
it "should be open as long as both input or output are open" do
|
328
|
-
@trans.
|
329
|
-
@input.
|
330
|
-
@trans.
|
331
|
-
@input.
|
332
|
-
@output.
|
333
|
-
@trans.
|
334
|
-
@input.
|
335
|
-
@trans.
|
365
|
+
expect(@trans).to be_open
|
366
|
+
allow(@input).to receive(:closed?).and_return(true)
|
367
|
+
expect(@trans).to be_open
|
368
|
+
allow(@input).to receive(:closed?).and_return(false)
|
369
|
+
allow(@output).to receive(:closed?).and_return(true)
|
370
|
+
expect(@trans).to be_open
|
371
|
+
allow(@input).to receive(:closed?).and_return(true)
|
372
|
+
expect(@trans).not_to be_open
|
336
373
|
end
|
337
374
|
|
338
375
|
it "should pass through read/write to input/output" do
|
339
|
-
@input.
|
340
|
-
@output.
|
341
|
-
@trans.read(17).
|
342
|
-
@trans.write("foobar").
|
376
|
+
expect(@input).to receive(:read).with(17).and_return("+ read")
|
377
|
+
expect(@output).to receive(:write).with("foobar").and_return("+ write")
|
378
|
+
expect(@trans.read(17)).to eq("+ read")
|
379
|
+
expect(@trans.write("foobar")).to eq("+ write")
|
343
380
|
end
|
344
381
|
|
345
382
|
it "should close both input and output when closed" do
|
346
|
-
@input.
|
347
|
-
@output.
|
383
|
+
expect(@input).to receive(:close)
|
384
|
+
expect(@output).to receive(:close)
|
348
385
|
@trans.close
|
349
386
|
end
|
350
387
|
end
|