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,445 +0,0 @@
1
- # encoding: ascii-8bit
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
-
23
- shared_examples_for 'a binary protocol' do
24
- before(:each) do
25
- @trans = Thrift::MemoryBufferTransport.new
26
- @prot = protocol_class.new(@trans)
27
- end
28
-
29
- it "should define the proper VERSION_1, VERSION_MASK AND TYPE_MASK" do
30
- expect(protocol_class.const_get(:VERSION_MASK)).to eq(0xffff0000)
31
- expect(protocol_class.const_get(:VERSION_1)).to eq(0x80010000)
32
- expect(protocol_class.const_get(:TYPE_MASK)).to eq(0x000000ff)
33
- end
34
-
35
- it "should make strict_read readable" do
36
- expect(@prot.strict_read).to eql(true)
37
- end
38
-
39
- it "should make strict_write readable" do
40
- expect(@prot.strict_write).to eql(true)
41
- end
42
-
43
- it "should write the message header" do
44
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
45
- expect(@trans.read(@trans.available)).to eq([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N"))
46
- end
47
-
48
- it "should write the message header without version when writes are not strict" do
49
- @prot = protocol_class.new(@trans, true, false) # no strict write
50
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
51
- expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
52
- end
53
-
54
- it "should write the message header with a version when writes are strict" do
55
- @prot = protocol_class.new(@trans) # strict write
56
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
57
- expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
58
- end
59
-
60
- # message footer is a noop
61
-
62
- it "should write the field header" do
63
- @prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
64
- expect(@trans.read(@trans.available)).to eq([Thrift::Types::DOUBLE, 3].pack("cn"))
65
- end
66
-
67
- # field footer is a noop
68
-
69
- it "should write the STOP field" do
70
- @prot.write_field_stop
71
- expect(@trans.read(1)).to eq("\000")
72
- end
73
-
74
- it "should write the map header" do
75
- @prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
76
- expect(@trans.read(@trans.available)).to eq([Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN"));
77
- end
78
-
79
- # map footer is a noop
80
-
81
- it "should write the list header" do
82
- @prot.write_list_begin(Thrift::Types::I16, 42)
83
- expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
84
- end
85
-
86
- # list footer is a noop
87
-
88
- it "should write the set header" do
89
- @prot.write_set_begin(Thrift::Types::I16, 42)
90
- expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
91
- end
92
-
93
- it "should write a bool" do
94
- @prot.write_bool(true)
95
- @prot.write_bool(false)
96
- expect(@trans.read(@trans.available)).to eq("\001\000")
97
- end
98
-
99
- it "should treat a nil bool as false" do
100
- @prot.write_bool(nil)
101
- expect(@trans.read(1)).to eq("\000")
102
- end
103
-
104
- it "should write a byte" do
105
- # byte is small enough, let's check -128..127
106
- (-128..127).each do |i|
107
- @prot.write_byte(i)
108
- expect(@trans.read(1)).to eq([i].pack('c'))
109
- end
110
- end
111
-
112
- it "should clip numbers out of signed range" do
113
- (128..255).each do |i|
114
- @prot.write_byte(i)
115
- expect(@trans.read(1)).to eq([i].pack('c'))
116
- end
117
- end
118
-
119
- it "errors out with a Bignum" do
120
- expect { @prot.write_byte(2**65) }.to raise_error(RangeError)
121
- end
122
-
123
- it "should error gracefully when trying to write a nil byte" do
124
- expect { @prot.write_byte(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
125
- end
126
-
127
- it "should write an i16" do
128
- # try a random scattering of values
129
- # include the signed i16 minimum/maximum
130
- [-2**15, -1024, 17, 0, -10000, 1723, 2**15-1].each do |i|
131
- @prot.write_i16(i)
132
- end
133
- # and try something out of signed range, it should clip
134
- @prot.write_i16(2**15 + 5)
135
-
136
- expect(@trans.read(@trans.available)).to eq("\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005")
137
-
138
- # a Bignum should error
139
- # lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
140
- end
141
-
142
- it "should error gracefully when trying to write a nil i16" do
143
- expect { @prot.write_i16(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
144
- end
145
-
146
- it "should write an i32" do
147
- # try a random scattering of values
148
- # include the signed i32 minimum/maximum
149
- [-2**31, -123123, -2532, -3, 0, 2351235, 12331, 2**31-1].each do |i|
150
- @prot.write_i32(i)
151
- end
152
- # try something out of signed range, it should clip
153
- expect(@trans.read(@trans.available)).to eq("\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377")
154
- [2 ** 31 + 5, 2 ** 65 + 5].each do |i|
155
- expect { @prot.write_i32(i) }.to raise_error(RangeError)
156
- end
157
- end
158
-
159
- it "should error gracefully when trying to write a nil i32" do
160
- expect { @prot.write_i32(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
161
- end
162
-
163
- it "should write an i64" do
164
- # try a random scattering of values
165
- # try the signed i64 minimum/maximum
166
- [-2**63, -12356123612323, -23512351, -234, 0, 1231, 2351236, 12361236213, 2**63-1].each do |i|
167
- @prot.write_i64(i)
168
- end
169
- # try something out of signed range, it should clip
170
- expect(@trans.read(@trans.available)).to eq(["\200\000\000\000\000\000\000\000",
171
- "\377\377\364\303\035\244+]",
172
- "\377\377\377\377\376\231:\341",
173
- "\377\377\377\377\377\377\377\026",
174
- "\000\000\000\000\000\000\000\000",
175
- "\000\000\000\000\000\000\004\317",
176
- "\000\000\000\000\000#\340\204",
177
- "\000\000\000\002\340\311~\365",
178
- "\177\377\377\377\377\377\377\377"].join(""))
179
- expect { @prot.write_i64(2 ** 65 + 5) }.to raise_error(RangeError)
180
- end
181
-
182
- it "should error gracefully when trying to write a nil i64" do
183
- expect { @prot.write_i64(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
184
- end
185
-
186
- it "should write a double" do
187
- # try a random scattering of values, including min/max
188
- values = [Float::MIN, -1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
189
- values.each do |f|
190
- @prot.write_double(f)
191
- expect(@trans.read(@trans.available)).to eq([f].pack("G"))
192
- end
193
- end
194
-
195
- it "should error gracefully when trying to write a nil double" do
196
- expect { @prot.write_double(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
197
- end
198
-
199
- it 'should write a string' do
200
- str = 'abc'
201
- @prot.write_string(str)
202
- a = @trans.read(@trans.available)
203
- expect(a.encoding).to eq(Encoding::BINARY)
204
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
205
- end
206
-
207
- it 'should write a string with unicode characters' do
208
- str = "abc \u20AC \u20AD".encode('UTF-8')
209
- @prot.write_string(str)
210
- a = @trans.read(@trans.available)
211
- expect(a.encoding).to eq(Encoding::BINARY)
212
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
213
- 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
214
- end
215
-
216
- it 'should write should write a string with unicode characters and transcoding' do
217
- str = "abc \u20AC".encode('ISO-8859-15')
218
- @prot.write_string(str)
219
- a = @trans.read(@trans.available)
220
- expect(a.encoding).to eq(Encoding::BINARY)
221
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
222
- end
223
-
224
- it 'should write a binary string' do
225
- buffer = [0, 1, 2, 3].pack('C*')
226
- @prot.write_binary(buffer)
227
- a = @trans.read(@trans.available)
228
- expect(a.encoding).to eq(Encoding::BINARY)
229
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
230
- end
231
-
232
- it "should error gracefully when trying to write a nil string" do
233
- expect { @prot.write_string(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
234
- end
235
-
236
- it "should error gracefully when trying to write a nil binary" do
237
- expect { @prot.write_binary(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
238
- end
239
-
240
- it "should write a uuid" do
241
- @prot.write_uuid("00112233-4455-6677-8899-aabbccddeeff")
242
- a = @trans.read(@trans.available)
243
- expect(a.unpack('C*')).to eq([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff])
244
- end
245
-
246
- it "should read a uuid" do
247
- @trans.write([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff].pack('C*'))
248
- uuid = @prot.read_uuid
249
- expect(uuid).to eq("00112233-4455-6677-8899-aabbccddeeff")
250
- end
251
-
252
- it "should error gracefully when trying to write an invalid uuid" do
253
- expect { @prot.write_uuid("invalid") }.to raise_error(Thrift::ProtocolException)
254
- end
255
-
256
- it "should write the message header without version when writes are not strict" do
257
- @prot = protocol_class.new(@trans, true, false) # no strict write
258
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
259
- expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
260
- end
261
-
262
- it "should write the message header with a version when writes are strict" do
263
- @prot = protocol_class.new(@trans) # strict write
264
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
265
- expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
266
- end
267
-
268
- # message footer is a noop
269
-
270
- it "should read a field header" do
271
- @trans.write([Thrift::Types::STRING, 3].pack("cn"))
272
- expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STRING, 3])
273
- end
274
-
275
- # field footer is a noop
276
-
277
- it "should read a stop field" do
278
- @trans.write([Thrift::Types::STOP].pack("c"));
279
- expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STOP, 0])
280
- end
281
-
282
- it "should read a map header" do
283
- @trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
284
- expect(@prot.read_map_begin).to eq([Thrift::Types::DOUBLE, Thrift::Types::I64, 42])
285
- end
286
-
287
- # map footer is a noop
288
-
289
- it "should read a list header" do
290
- @trans.write([Thrift::Types::STRING, 17].pack("cN"))
291
- expect(@prot.read_list_begin).to eq([Thrift::Types::STRING, 17])
292
- end
293
-
294
- # list footer is a noop
295
-
296
- it "should read a set header" do
297
- @trans.write([Thrift::Types::STRING, 17].pack("cN"))
298
- expect(@prot.read_set_begin).to eq([Thrift::Types::STRING, 17])
299
- end
300
-
301
- # set footer is a noop
302
-
303
- it "should read a bool" do
304
- @trans.write("\001\000");
305
- expect(@prot.read_bool).to eq(true)
306
- expect(@prot.read_bool).to eq(false)
307
- end
308
-
309
- it "should read a byte" do
310
- [-128, -57, -3, 0, 17, 24, 127].each do |i|
311
- @trans.write([i].pack("c"))
312
- expect(@prot.read_byte).to eq(i)
313
- end
314
- end
315
-
316
- it "should read an i16" do
317
- # try a scattering of values, including min/max
318
- [-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
319
- @trans.write([i].pack("n"));
320
- expect(@prot.read_i16).to eq(i)
321
- end
322
- end
323
-
324
- it "should read an i32" do
325
- # try a scattering of values, including min/max
326
- [-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
327
- @trans.write([i].pack("N"))
328
- expect(@prot.read_i32).to eq(i)
329
- end
330
- end
331
-
332
- it "should read an i64" do
333
- # try a scattering of values, including min/max
334
- [-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
335
- @trans.write([i >> 32, i & 0xFFFFFFFF].pack("NN"))
336
- expect(@prot.read_i64).to eq(i)
337
- end
338
- end
339
-
340
- it "should read a double" do
341
- # try a random scattering of values, including min/max
342
- [Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
343
- @trans.write([f].pack("G"));
344
- expect(@prot.read_double).to eq(f)
345
- end
346
- end
347
-
348
- it 'should read a string' do
349
- # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
350
- buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
351
- @trans.write(buffer)
352
- a = @prot.read_string
353
- expect(a).to eq('abc'.encode('UTF-8'))
354
- expect(a.encoding).to eq(Encoding::UTF_8)
355
- end
356
-
357
- it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
358
- # i32 of value 3, followed by one character U+20AC made up of three bytes
359
- buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
360
- @trans.write(buffer)
361
- a = @prot.read_string
362
- expect(a).to eq("\u20AC".encode('UTF-8'))
363
- expect(a.encoding).to eq(Encoding::UTF_8)
364
- end
365
-
366
- it 'should read a binary string' do
367
- buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
368
- @trans.write(buffer)
369
- a = @prot.read_binary
370
- expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
371
- expect(a.encoding).to eq(Encoding::BINARY)
372
- end
373
-
374
- it "should perform a complete rpc with no args or return" do
375
- srv_test(
376
- proc { |client| client.send_voidMethod() },
377
- proc { |client| expect(client.recv_voidMethod).to eq(nil) }
378
- )
379
- end
380
-
381
- it "should perform a complete rpc with a primitive return type" do
382
- srv_test(
383
- proc { |client| client.send_primitiveMethod() },
384
- proc { |client| expect(client.recv_primitiveMethod).to eq(1) }
385
- )
386
- end
387
-
388
- it "should perform a complete rpc with a struct return type" do
389
- srv_test(
390
- proc { |client| client.send_structMethod() },
391
- proc { |client|
392
- result = client.recv_structMethod
393
- result.set_byte_map = nil
394
- result.map_byte_map = nil
395
- expect(result).to eq(Fixtures::COMPACT_PROTOCOL_TEST_STRUCT)
396
- }
397
- )
398
- end
399
-
400
- def get_socket_connection
401
- server = Thrift::ServerSocket.new("localhost", 9090)
402
- server.listen
403
-
404
- clientside = Thrift::Socket.new("localhost", 9090)
405
- clientside.open
406
- serverside = server.accept
407
- [clientside, serverside, server]
408
- end
409
-
410
- def srv_test(firstblock, secondblock)
411
- clientside, serverside, server = get_socket_connection
412
-
413
- clientproto = protocol_class.new(clientside)
414
- serverproto = protocol_class.new(serverside)
415
-
416
- processor = Thrift::Test::Srv::Processor.new(SrvHandler.new)
417
-
418
- client = Thrift::Test::Srv::Client.new(clientproto, clientproto)
419
-
420
- # first block
421
- firstblock.call(client)
422
-
423
- processor.process(serverproto, serverproto)
424
-
425
- # second block
426
- secondblock.call(client)
427
- ensure
428
- clientside.close
429
- serverside.close
430
- server.close
431
- end
432
-
433
- class SrvHandler
434
- def voidMethod()
435
- end
436
-
437
- def primitiveMethod
438
- 1
439
- end
440
-
441
- def structMethod
442
- Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
443
- end
444
- end
445
- end
data/spec/bytes_spec.rb DELETED
@@ -1,99 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
-
23
- describe Thrift::Bytes do
24
- describe '.empty_byte_buffer' do
25
- it 'should create an empty buffer' do
26
- b = Thrift::Bytes.empty_byte_buffer
27
- expect(b.length).to eq(0)
28
- expect(b.encoding).to eq(Encoding::BINARY)
29
- end
30
-
31
- it 'should create an empty buffer of given size' do
32
- b = Thrift::Bytes.empty_byte_buffer 2
33
- expect(b.length).to eq(2)
34
- expect(b.getbyte(0)).to eq(0)
35
- expect(b.getbyte(1)).to eq(0)
36
- expect(b.encoding).to eq(Encoding::BINARY)
37
- end
38
- end
39
-
40
- describe '.force_binary_encoding' do
41
- it 'should change encoding' do
42
- e = 'STRING'.encode('UTF-8')
43
- expect(e.encoding).not_to eq(Encoding::BINARY)
44
- a = Thrift::Bytes.force_binary_encoding e
45
- expect(a.encoding).to eq(Encoding::BINARY)
46
- end
47
- end
48
-
49
- describe '.get_string_byte' do
50
- it 'should get the byte at index' do
51
- s = "\x41\x42"
52
- expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
53
- expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
54
- end
55
- end
56
-
57
- describe '.set_string_byte' do
58
- it 'should set byte value at index' do
59
- s = "\x41\x42"
60
- Thrift::Bytes.set_string_byte(s, 0, 0x43)
61
- expect(s.getbyte(0)).to eq(0x43)
62
- expect(s).to eq('CB')
63
- end
64
- end
65
-
66
- describe '.convert_to_utf8_byte_buffer' do
67
- it 'should convert UTF-8 String to byte buffer' do
68
- e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
69
- expect(e.length).to eq(1)
70
-
71
- a = Thrift::Bytes.convert_to_utf8_byte_buffer e
72
- expect(a.encoding).to eq(Encoding::BINARY)
73
- expect(a.length).to eq(3)
74
- expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
75
- end
76
-
77
- it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
78
- # Assumptions
79
- e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
80
- expect(e.length).to eq(1)
81
- expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
82
-
83
- a = Thrift::Bytes.convert_to_utf8_byte_buffer e
84
- expect(a.encoding).to eq(Encoding::BINARY)
85
- expect(a.length).to eq(3)
86
- expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
87
- end
88
- end
89
-
90
- describe '.convert_to_string' do
91
- it 'should convert UTF-8 byte buffer to a UTF-8 String' do
92
- e = [0xE2, 0x82, 0xAC].pack("C*")
93
- expect(e.encoding).to eq(Encoding::BINARY)
94
- a = Thrift::Bytes.convert_to_string e
95
- expect(a.encoding).to eq(Encoding::UTF_8)
96
- expect(a).to eq("\u20AC")
97
- end
98
- end
99
- end