thrift 0.23.0 → 0.25.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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +203 -40
  3. data/ext/binary_protocol_accelerated.c +130 -40
  4. data/ext/bytes.c +14 -0
  5. data/ext/compact_protocol.c +184 -91
  6. data/ext/constants.h +3 -0
  7. data/ext/extconf.rb +12 -4
  8. data/ext/macros.h +11 -0
  9. data/ext/memory_buffer.c +67 -12
  10. data/ext/struct.c +192 -71
  11. data/ext/thrift_native.c +7 -0
  12. data/lib/thrift/bytes.rb +6 -3
  13. data/lib/thrift/client.rb +31 -33
  14. data/lib/thrift/exceptions.rb +11 -8
  15. data/lib/thrift/multiplexed_processor.rb +17 -8
  16. data/lib/thrift/processor.rb +25 -3
  17. data/lib/thrift/protocol/base_protocol.rb +66 -31
  18. data/lib/thrift/protocol/binary_protocol.rb +80 -37
  19. data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
  20. data/lib/thrift/protocol/compact_protocol.rb +204 -88
  21. data/lib/thrift/protocol/header_protocol.rb +15 -3
  22. data/lib/thrift/protocol/json_protocol.rb +158 -109
  23. data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
  24. data/lib/thrift/protocol/protocol_decorator.rb +6 -2
  25. data/lib/thrift/serializer/deserializer.rb +1 -0
  26. data/lib/thrift/serializer/serializer.rb +7 -0
  27. data/lib/thrift/server/base_server.rb +11 -2
  28. data/lib/thrift/server/nonblocking_server.rb +69 -20
  29. data/lib/thrift/server/rack_application.rb +69 -0
  30. data/lib/thrift/server/simple_server.rb +27 -15
  31. data/lib/thrift/server/thin_http_server.rb +21 -44
  32. data/lib/thrift/server/thread_pool_server.rb +21 -17
  33. data/lib/thrift/server/threaded_server.rb +22 -18
  34. data/lib/thrift/struct.rb +34 -18
  35. data/lib/thrift/struct_union.rb +37 -36
  36. data/lib/thrift/thrift_native.rb +2 -1
  37. data/lib/thrift/transport/base_server_transport.rb +3 -0
  38. data/lib/thrift/transport/base_transport.rb +26 -4
  39. data/lib/thrift/transport/buffered_transport.rb +5 -4
  40. data/lib/thrift/transport/framed_transport.rb +33 -7
  41. data/lib/thrift/transport/header_transport.rb +159 -33
  42. data/lib/thrift/transport/http_client_transport.rb +28 -14
  43. data/lib/thrift/transport/io_stream_transport.rb +3 -1
  44. data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
  45. data/lib/thrift/transport/server_socket.rb +10 -8
  46. data/lib/thrift/transport/socket.rb +85 -48
  47. data/lib/thrift/transport/ssl_server_socket.rb +67 -6
  48. data/lib/thrift/transport/ssl_socket.rb +73 -14
  49. data/lib/thrift/transport/unix_server_socket.rb +6 -2
  50. data/lib/thrift/transport/unix_socket.rb +5 -6
  51. data/lib/thrift/types.rb +23 -22
  52. data/lib/thrift/union.rb +21 -11
  53. data/lib/thrift/uuid.rb +9 -8
  54. data/lib/thrift.rb +40 -39
  55. metadata +7 -266
  56. data/benchmark/Benchmark.thrift +0 -24
  57. data/benchmark/benchmark.rb +0 -285
  58. data/benchmark/client.rb +0 -117
  59. data/benchmark/server.rb +0 -120
  60. data/benchmark/thin_server.rb +0 -45
  61. data/lib/thrift/server/mongrel_http_server.rb +0 -60
  62. data/spec/BaseService.thrift +0 -27
  63. data/spec/ExtendedService.thrift +0 -25
  64. data/spec/Referenced.thrift +0 -44
  65. data/spec/ThriftNamespacedSpec.thrift +0 -53
  66. data/spec/ThriftSpec.thrift +0 -187
  67. data/spec/base_protocol_spec.rb +0 -224
  68. data/spec/base_transport_spec.rb +0 -387
  69. data/spec/binary_protocol_accelerated_spec.rb +0 -46
  70. data/spec/binary_protocol_spec.rb +0 -72
  71. data/spec/binary_protocol_spec_shared.rb +0 -445
  72. data/spec/bytes_spec.rb +0 -99
  73. data/spec/client_spec.rb +0 -166
  74. data/spec/compact_protocol_spec.rb +0 -196
  75. data/spec/constants_demo_spec.rb +0 -101
  76. data/spec/exception_spec.rb +0 -140
  77. data/spec/flat_spec.rb +0 -62
  78. data/spec/header_protocol_spec.rb +0 -475
  79. data/spec/header_transport_spec.rb +0 -386
  80. data/spec/http_client_spec.rb +0 -159
  81. data/spec/json_protocol_spec.rb +0 -552
  82. data/spec/namespaced_spec.rb +0 -66
  83. data/spec/nonblocking_server_spec.rb +0 -361
  84. data/spec/processor_spec.rb +0 -79
  85. data/spec/serializer_spec.rb +0 -66
  86. data/spec/server_socket_spec.rb +0 -84
  87. data/spec/server_spec.rb +0 -186
  88. data/spec/socket_spec.rb +0 -67
  89. data/spec/socket_spec_shared.rb +0 -167
  90. data/spec/spec_helper.rb +0 -69
  91. data/spec/ssl_server_socket_spec.rb +0 -45
  92. data/spec/ssl_socket_spec.rb +0 -87
  93. data/spec/struct_nested_containers_spec.rb +0 -190
  94. data/spec/struct_spec.rb +0 -397
  95. data/spec/support/header_protocol_helper.rb +0 -54
  96. data/spec/thin_http_server_spec.rb +0 -126
  97. data/spec/types_spec.rb +0 -117
  98. data/spec/union_spec.rb +0 -272
  99. data/spec/unix_socket_spec.rb +0 -115
  100. data/spec/uuid_validation_spec.rb +0 -238
  101. data/test/fuzz/Makefile.am +0 -173
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -95
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
  120. data/test/fuzz/fuzz_tracer.rb +0 -28
@@ -1,387 +0,0 @@
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
- require 'spec_helper'
21
-
22
- describe 'BaseTransport' do
23
- describe Thrift::TransportException do
24
- it "should make type accessible" do
25
- exc = Thrift::TransportException.new(Thrift::TransportException::ALREADY_OPEN, "msg")
26
- expect(exc.type).to eq(Thrift::TransportException::ALREADY_OPEN)
27
- expect(exc.message).to eq("msg")
28
- end
29
- end
30
-
31
- describe Thrift::BaseTransport do
32
- it "should read the specified size" do
33
- transport = Thrift::BaseTransport.new
34
- expect(transport).to receive(:read).with(40).ordered.and_return("10 letters")
35
- expect(transport).to receive(:read).with(30).ordered.and_return("fifteen letters")
36
- expect(transport).to receive(:read).with(15).ordered.and_return("more characters")
37
- expect(transport.read_all(40)).to eq("10 lettersfifteen lettersmore characters")
38
- end
39
-
40
- it "should stub out the rest of the methods" do
41
- # can't test for stubbiness, so just make sure they're defined
42
- [:open?, :open, :close, :read, :write, :flush].each do |sym|
43
- expect(Thrift::BaseTransport.method_defined?(sym)).to be_truthy
44
- end
45
- end
46
-
47
- it "should alias << to write" do
48
- expect(Thrift::BaseTransport.instance_method(:<<)).to eq(Thrift::BaseTransport.instance_method(:write))
49
- end
50
-
51
- it "should provide a reasonable to_s" do
52
- expect(Thrift::BaseTransport.new.to_s).to eq("base")
53
- end
54
- end
55
-
56
- describe Thrift::BaseServerTransport do
57
- it "should stub out its methods" do
58
- [:listen, :accept, :close].each do |sym|
59
- expect(Thrift::BaseServerTransport.method_defined?(sym)).to be_truthy
60
- end
61
- end
62
- end
63
-
64
- describe Thrift::BaseTransportFactory do
65
- it "should return the transport it's given" do
66
- transport = double("Transport")
67
- expect(Thrift::BaseTransportFactory.new.get_transport(transport)).to eql(transport)
68
- end
69
-
70
- it "should provide a reasonable to_s" do
71
- expect(Thrift::BaseTransportFactory.new.to_s).to eq("base")
72
- end
73
- end
74
-
75
- describe Thrift::BufferedTransport do
76
- it "should provide a to_s that describes the encapsulation" do
77
- trans = double("Transport")
78
- expect(trans).to receive(:to_s).and_return("mock")
79
- expect(Thrift::BufferedTransport.new(trans).to_s).to eq("buffered(mock)")
80
- end
81
-
82
- it "should pass through everything but write/flush/read" do
83
- trans = double("Transport")
84
- expect(trans).to receive(:open?).ordered.and_return("+ open?")
85
- expect(trans).to receive(:open).ordered.and_return("+ open")
86
- expect(trans).to receive(:flush).ordered # from the close
87
- expect(trans).to receive(:close).ordered.and_return("+ close")
88
- btrans = Thrift::BufferedTransport.new(trans)
89
- expect(btrans.open?).to eq("+ open?")
90
- expect(btrans.open).to eq("+ open")
91
- expect(btrans.close).to eq("+ close")
92
- end
93
-
94
- it "should buffer reads in chunks of #{Thrift::BufferedTransport::DEFAULT_BUFFER}" do
95
- trans = double("Transport")
96
- expect(trans).to receive(:read).with(Thrift::BufferedTransport::DEFAULT_BUFFER).and_return("lorum ipsum dolor emet")
97
- btrans = Thrift::BufferedTransport.new(trans)
98
- expect(btrans.read(6)).to eq("lorum ")
99
- expect(btrans.read(6)).to eq("ipsum ")
100
- expect(btrans.read(6)).to eq("dolor ")
101
- expect(btrans.read(6)).to eq("emet")
102
- end
103
-
104
- it "should buffer writes and send them on flush" do
105
- trans = double("Transport")
106
- btrans = Thrift::BufferedTransport.new(trans)
107
- btrans.write("one/")
108
- btrans.write("two/")
109
- btrans.write("three/")
110
- expect(trans).to receive(:write).with("one/two/three/").ordered
111
- expect(trans).to receive(:flush).ordered
112
- btrans.flush
113
- end
114
-
115
- it "should only send buffered data once" do
116
- trans = double("Transport")
117
- btrans = Thrift::BufferedTransport.new(trans)
118
- btrans.write("one/")
119
- btrans.write("two/")
120
- btrans.write("three/")
121
- expect(trans).to receive(:write).with("one/two/three/")
122
- allow(trans).to receive(:flush)
123
- btrans.flush
124
- # Nothing to flush with no data
125
- btrans.flush
126
- end
127
-
128
- it "should flush on close" do
129
- trans = double("Transport")
130
- expect(trans).to receive(:close)
131
- btrans = Thrift::BufferedTransport.new(trans)
132
- expect(btrans).to receive(:flush)
133
- btrans.close
134
- end
135
-
136
- it "should not write to socket if there's no data" do
137
- trans = double("Transport")
138
- expect(trans).to receive(:flush)
139
- btrans = Thrift::BufferedTransport.new(trans)
140
- btrans.flush
141
- end
142
- end
143
-
144
- describe Thrift::BufferedTransportFactory do
145
- it "should wrap the given transport in a BufferedTransport" do
146
- trans = double("Transport")
147
- btrans = double("BufferedTransport")
148
- expect(Thrift::BufferedTransport).to receive(:new).with(trans).and_return(btrans)
149
- expect(Thrift::BufferedTransportFactory.new.get_transport(trans)).to eq(btrans)
150
- end
151
-
152
- it "should provide a reasonable to_s" do
153
- expect(Thrift::BufferedTransportFactory.new.to_s).to eq("buffered")
154
- end
155
- end
156
-
157
- describe Thrift::FramedTransport do
158
- before(:each) do
159
- @trans = double("Transport")
160
- end
161
-
162
- it "should provide a to_s that describes the encapsulation" do
163
- trans = double("Transport")
164
- expect(trans).to receive(:to_s).and_return("mock")
165
- expect(Thrift::FramedTransport.new(trans).to_s).to eq("framed(mock)")
166
- end
167
-
168
- it "should pass through open?/open/close" do
169
- ftrans = Thrift::FramedTransport.new(@trans)
170
- expect(@trans).to receive(:open?).ordered.and_return("+ open?")
171
- expect(@trans).to receive(:open).ordered.and_return("+ open")
172
- expect(@trans).to receive(:close).ordered.and_return("+ close")
173
- expect(ftrans.open?).to eq("+ open?")
174
- expect(ftrans.open).to eq("+ open")
175
- expect(ftrans.close).to eq("+ close")
176
- end
177
-
178
- it "should pass through read when read is turned off" do
179
- ftrans = Thrift::FramedTransport.new(@trans, false, true)
180
- expect(@trans).to receive(:read).with(17).ordered.and_return("+ read")
181
- expect(ftrans.read(17)).to eq("+ read")
182
- end
183
-
184
- it "should pass through write/flush when write is turned off" do
185
- ftrans = Thrift::FramedTransport.new(@trans, true, false)
186
- expect(@trans).to receive(:write).with("foo").ordered.and_return("+ write")
187
- expect(@trans).to receive(:flush).ordered.and_return("+ flush")
188
- expect(ftrans.write("foo")).to eq("+ write")
189
- expect(ftrans.flush).to eq("+ flush")
190
- end
191
-
192
- it "should return a full frame if asked for >= the frame's length" do
193
- frame = "this is a frame"
194
- expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
195
- expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
196
- expect(Thrift::FramedTransport.new(@trans).read(frame.length + 10)).to eq(frame)
197
- end
198
-
199
- it "should return slices of the frame when asked for < the frame's length" do
200
- frame = "this is a frame"
201
- expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017")
202
- expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
203
- ftrans = Thrift::FramedTransport.new(@trans)
204
- expect(ftrans.read(4)).to eq("this")
205
- expect(ftrans.read(4)).to eq(" is ")
206
- expect(ftrans.read(16)).to eq("a frame")
207
- end
208
-
209
- it "should return nothing if asked for <= 0" do
210
- expect(Thrift::FramedTransport.new(@trans).read(-2)).to eq("")
211
- end
212
-
213
- it "should pull a new frame when the first is exhausted" do
214
- frame = "this is a frame"
215
- frame2 = "yet another frame"
216
- expect(@trans).to receive(:read_all).with(4).and_return("\000\000\000\017", "\000\000\000\021")
217
- expect(@trans).to receive(:read_all).with(frame.length).and_return(frame)
218
- expect(@trans).to receive(:read_all).with(frame2.length).and_return(frame2)
219
- ftrans = Thrift::FramedTransport.new(@trans)
220
- expect(ftrans.read(4)).to eq("this")
221
- expect(ftrans.read(8)).to eq(" is a fr")
222
- expect(ftrans.read(6)).to eq("ame")
223
- expect(ftrans.read(4)).to eq("yet ")
224
- expect(ftrans.read(16)).to eq("another frame")
225
- end
226
-
227
- it "should buffer writes" do
228
- ftrans = Thrift::FramedTransport.new(@trans)
229
- expect(@trans).not_to receive(:write)
230
- ftrans.write("foo")
231
- ftrans.write("bar")
232
- ftrans.write("this is a frame")
233
- end
234
-
235
- it "should write slices of the buffer" do
236
- ftrans = Thrift::FramedTransport.new(@trans)
237
- ftrans.write("foobar", 3)
238
- ftrans.write("barfoo", 1)
239
- allow(@trans).to receive(:flush)
240
- expect(@trans).to receive(:write).with("\000\000\000\004foob")
241
- ftrans.flush
242
- end
243
-
244
- it "should flush frames with a 4-byte header" do
245
- ftrans = Thrift::FramedTransport.new(@trans)
246
- expect(@trans).to receive(:write).with("\000\000\000\035one/two/three/this is a frame").ordered
247
- expect(@trans).to receive(:flush).ordered
248
- ftrans.write("one/")
249
- ftrans.write("two/")
250
- ftrans.write("three/")
251
- ftrans.write("this is a frame")
252
- ftrans.flush
253
- end
254
-
255
- it "should not flush the same buffered data twice" do
256
- ftrans = Thrift::FramedTransport.new(@trans)
257
- expect(@trans).to receive(:write).with("\000\000\000\007foo/bar")
258
- allow(@trans).to receive(:flush)
259
- ftrans.write("foo")
260
- ftrans.write("/bar")
261
- ftrans.flush
262
- expect(@trans).to receive(:write).with("\000\000\000\000")
263
- ftrans.flush
264
- end
265
- end
266
-
267
- describe Thrift::FramedTransportFactory do
268
- it "should wrap the given transport in a FramedTransport" do
269
- trans = double("Transport")
270
- expect(Thrift::FramedTransport).to receive(:new).with(trans)
271
- Thrift::FramedTransportFactory.new.get_transport(trans)
272
- end
273
-
274
- it "should provide a reasonable to_s" do
275
- expect(Thrift::FramedTransportFactory.new.to_s).to eq("framed")
276
- end
277
- end
278
-
279
- describe Thrift::MemoryBufferTransport do
280
- before(:each) do
281
- @buffer = Thrift::MemoryBufferTransport.new
282
- end
283
-
284
- it "should provide a reasonable to_s" do
285
- expect(@buffer.to_s).to eq("memory")
286
- end
287
-
288
- it "should accept a buffer on input and use it directly" do
289
- s = "this is a test"
290
- @buffer = Thrift::MemoryBufferTransport.new(s)
291
- expect(@buffer.read(4)).to eq("this")
292
- s.slice!(-4..-1)
293
- expect(@buffer.read(@buffer.available)).to eq(" is a ")
294
- end
295
-
296
- it "should always remain open" do
297
- expect(@buffer).to be_open
298
- @buffer.close
299
- expect(@buffer).to be_open
300
- end
301
-
302
- it "should respond to peek and available" do
303
- @buffer.write "some data"
304
- expect(@buffer.peek).to be_truthy
305
- expect(@buffer.available).to eq(9)
306
- @buffer.read(4)
307
- expect(@buffer.peek).to be_truthy
308
- expect(@buffer.available).to eq(5)
309
- @buffer.read(5)
310
- expect(@buffer.peek).to be_falsey
311
- expect(@buffer.available).to eq(0)
312
- end
313
-
314
- it "should be able to reset the buffer" do
315
- @buffer.write "test data"
316
- @buffer.reset_buffer("foobar")
317
- expect(@buffer.available).to eq(6)
318
- expect(@buffer.read(@buffer.available)).to eq("foobar")
319
- @buffer.reset_buffer
320
- expect(@buffer.available).to eq(0)
321
- end
322
-
323
- it "should copy the given string when resetting the buffer" do
324
- s = "this is a test"
325
- @buffer.reset_buffer(s)
326
- expect(@buffer.available).to eq(14)
327
- @buffer.read(10)
328
- expect(@buffer.available).to eq(4)
329
- expect(s).to eq("this is a test")
330
- end
331
-
332
- it "should return from read what was given in write" do
333
- @buffer.write "test data"
334
- expect(@buffer.read(4)).to eq("test")
335
- expect(@buffer.read(@buffer.available)).to eq(" data")
336
- @buffer.write "foo"
337
- @buffer.write " bar"
338
- expect(@buffer.read(@buffer.available)).to eq("foo bar")
339
- end
340
-
341
- it "should throw an EOFError when there isn't enough data in the buffer" do
342
- @buffer.reset_buffer("")
343
- expect{ @buffer.read(1) }.to raise_error(EOFError)
344
-
345
- @buffer.reset_buffer("1234")
346
- expect{ @buffer.read(5) }.to raise_error(EOFError)
347
- end
348
- end
349
-
350
- describe Thrift::IOStreamTransport do
351
- before(:each) do
352
- @input = double("Input", :closed? => false)
353
- @output = double("Output", :closed? => false)
354
- @trans = Thrift::IOStreamTransport.new(@input, @output)
355
- end
356
-
357
- it "should provide a reasonable to_s" do
358
- expect(@input).to receive(:to_s).and_return("mock_input")
359
- expect(@output).to receive(:to_s).and_return("mock_output")
360
- expect(@trans.to_s).to eq("iostream(input=mock_input,output=mock_output)")
361
- end
362
-
363
- it "should be open as long as both input or output are open" do
364
- expect(@trans).to be_open
365
- allow(@input).to receive(:closed?).and_return(true)
366
- expect(@trans).to be_open
367
- allow(@input).to receive(:closed?).and_return(false)
368
- allow(@output).to receive(:closed?).and_return(true)
369
- expect(@trans).to be_open
370
- allow(@input).to receive(:closed?).and_return(true)
371
- expect(@trans).not_to be_open
372
- end
373
-
374
- it "should pass through read/write to input/output" do
375
- expect(@input).to receive(:read).with(17).and_return("+ read")
376
- expect(@output).to receive(:write).with("foobar").and_return("+ write")
377
- expect(@trans.read(17)).to eq("+ read")
378
- expect(@trans.write("foobar")).to eq("+ write")
379
- end
380
-
381
- it "should close both input and output when closed" do
382
- expect(@input).to receive(:close)
383
- expect(@output).to receive(:close)
384
- @trans.close
385
- end
386
- end
387
- end
@@ -1,46 +0,0 @@
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
- require 'spec_helper'
21
- require File.expand_path("#{File.dirname(__FILE__)}/binary_protocol_spec_shared")
22
-
23
- if defined? Thrift::BinaryProtocolAccelerated
24
-
25
- describe 'BinaryProtocolAccelerated' do
26
- # since BinaryProtocolAccelerated should be directly equivalent to
27
- # BinaryProtocol, we don't need any custom specs!
28
- it_should_behave_like 'a binary protocol'
29
-
30
- def protocol_class
31
- Thrift::BinaryProtocolAccelerated
32
- end
33
-
34
- describe Thrift::BinaryProtocolAcceleratedFactory do
35
- it "should create a BinaryProtocolAccelerated" do
36
- expect(Thrift::BinaryProtocolAcceleratedFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::BinaryProtocolAccelerated)
37
- end
38
-
39
- it "should provide a reasonable to_s" do
40
- expect(Thrift::BinaryProtocolAcceleratedFactory.new.to_s).to eq("binary-accel")
41
- end
42
- end
43
- end
44
- else
45
- puts "skipping BinaryProtocolAccelerated spec because it is not defined."
46
- end
@@ -1,72 +0,0 @@
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
- require 'spec_helper'
21
- require File.expand_path("#{File.dirname(__FILE__)}/binary_protocol_spec_shared")
22
-
23
- describe 'BinaryProtocol' do
24
- it_should_behave_like 'a binary protocol'
25
-
26
- def protocol_class
27
- Thrift::BinaryProtocol
28
- end
29
-
30
- describe Thrift::BinaryProtocol do
31
- before(:each) do
32
- @trans = Thrift::MemoryBufferTransport.new
33
- @prot = protocol_class.new(@trans)
34
- end
35
-
36
- it "should read a message header" do
37
- @trans.write([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY].pack('N'))
38
- @trans.write([42].pack('N'))
39
- expect(@prot).to receive(:read_string).and_return('testMessage')
40
- expect(@prot.read_message_begin).to eq(['testMessage', Thrift::MessageTypes::REPLY, 42])
41
- end
42
-
43
- it "should raise an exception if the message header has the wrong version" do
44
- expect(@prot).to receive(:read_i32).and_return(-1)
45
- expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
46
- e.type == Thrift::ProtocolException::BAD_VERSION
47
- end
48
- end
49
-
50
- it "should raise an exception if the message header does not exist and strict_read is enabled" do
51
- expect(@prot).to receive(:read_i32).and_return(42)
52
- expect(@prot).to receive(:strict_read).and_return(true)
53
- expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|
54
- e.type == Thrift::ProtocolException::BAD_VERSION
55
- end
56
- end
57
-
58
- it "should provide a reasonable to_s" do
59
- expect(@prot.to_s).to eq("binary(memory)")
60
- end
61
- end
62
-
63
- describe Thrift::BinaryProtocolFactory do
64
- it "should create a BinaryProtocol" do
65
- expect(Thrift::BinaryProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::BinaryProtocol)
66
- end
67
-
68
- it "should provide a reasonable to_s" do
69
- expect(Thrift::BinaryProtocolFactory.new.to_s).to eq("binary")
70
- end
71
- end
72
- end