thrift 0.22.0 → 0.23.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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -17
  3. data/benchmark/benchmark.rb +22 -8
  4. data/benchmark/client.rb +49 -6
  5. data/benchmark/server.rb +45 -7
  6. data/benchmark/thin_server.rb +1 -0
  7. data/ext/binary_protocol_accelerated.c +76 -19
  8. data/ext/compact_protocol.c +80 -15
  9. data/ext/constants.h +12 -0
  10. data/ext/extconf.rb +10 -9
  11. data/ext/memory_buffer.c +7 -7
  12. data/ext/protocol.c +29 -0
  13. data/ext/protocol.h +35 -0
  14. data/ext/struct.c +36 -5
  15. data/ext/thrift_native.c +27 -3
  16. data/lib/thrift/bytes.rb +68 -101
  17. data/lib/thrift/client.rb +61 -9
  18. data/lib/thrift/exceptions.rb +5 -5
  19. data/lib/thrift/multiplexed_processor.rb +6 -6
  20. data/lib/thrift/processor.rb +6 -6
  21. data/lib/thrift/protocol/base_protocol.rb +37 -15
  22. data/lib/thrift/protocol/binary_protocol.rb +25 -9
  23. data/lib/thrift/protocol/binary_protocol_accelerated.rb +5 -5
  24. data/lib/thrift/protocol/compact_protocol.rb +61 -37
  25. data/lib/thrift/protocol/header_protocol.rb +320 -0
  26. data/lib/thrift/protocol/json_protocol.rb +26 -16
  27. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -5
  28. data/lib/thrift/protocol/protocol_decorator.rb +12 -4
  29. data/lib/thrift/serializer/deserializer.rb +5 -5
  30. data/lib/thrift/serializer/serializer.rb +4 -5
  31. data/lib/thrift/server/base_server.rb +4 -4
  32. data/lib/thrift/server/mongrel_http_server.rb +6 -6
  33. data/lib/thrift/server/nonblocking_server.rb +8 -8
  34. data/lib/thrift/server/simple_server.rb +4 -4
  35. data/lib/thrift/server/thin_http_server.rb +3 -3
  36. data/lib/thrift/server/thread_pool_server.rb +6 -6
  37. data/lib/thrift/server/threaded_server.rb +4 -4
  38. data/lib/thrift/struct.rb +11 -11
  39. data/lib/thrift/struct_union.rb +19 -9
  40. data/lib/thrift/thrift_native.rb +1 -1
  41. data/lib/thrift/transport/base_server_transport.rb +5 -5
  42. data/lib/thrift/transport/base_transport.rb +12 -12
  43. data/lib/thrift/transport/buffered_transport.rb +6 -6
  44. data/lib/thrift/transport/framed_transport.rb +7 -7
  45. data/lib/thrift/transport/header_transport.rb +516 -0
  46. data/lib/thrift/transport/http_client_transport.rb +1 -1
  47. data/lib/thrift/transport/io_stream_transport.rb +3 -3
  48. data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
  49. data/lib/thrift/transport/server_socket.rb +8 -5
  50. data/lib/thrift/transport/socket.rb +58 -31
  51. data/lib/thrift/transport/ssl_server_socket.rb +1 -1
  52. data/lib/thrift/transport/ssl_socket.rb +2 -2
  53. data/lib/thrift/transport/unix_server_socket.rb +4 -4
  54. data/lib/thrift/transport/unix_socket.rb +6 -6
  55. data/lib/thrift/types.rb +9 -6
  56. data/lib/thrift/union.rb +14 -8
  57. data/lib/thrift/uuid.rb +49 -0
  58. data/lib/thrift.rb +3 -1
  59. data/spec/ThriftSpec.thrift +5 -1
  60. data/spec/base_protocol_spec.rb +1 -2
  61. data/spec/base_transport_spec.rb +6 -7
  62. data/spec/binary_protocol_spec.rb +0 -2
  63. data/spec/binary_protocol_spec_shared.rb +129 -142
  64. data/spec/bytes_spec.rb +57 -118
  65. data/spec/client_spec.rb +85 -19
  66. data/spec/compact_protocol_spec.rb +54 -16
  67. data/spec/constants_demo_spec.rb +101 -0
  68. data/spec/exception_spec.rb +0 -1
  69. data/spec/header_protocol_spec.rb +475 -0
  70. data/spec/header_transport_spec.rb +386 -0
  71. data/spec/http_client_spec.rb +4 -6
  72. data/spec/json_protocol_spec.rb +47 -47
  73. data/spec/namespaced_spec.rb +0 -1
  74. data/spec/nonblocking_server_spec.rb +102 -4
  75. data/spec/processor_spec.rb +0 -1
  76. data/spec/serializer_spec.rb +0 -1
  77. data/spec/server_socket_spec.rb +1 -1
  78. data/spec/server_spec.rb +8 -9
  79. data/spec/socket_spec.rb +0 -1
  80. data/spec/socket_spec_shared.rb +72 -9
  81. data/spec/spec_helper.rb +1 -1
  82. data/spec/ssl_server_socket_spec.rb +12 -1
  83. data/spec/ssl_socket_spec.rb +10 -1
  84. data/spec/struct_nested_containers_spec.rb +1 -2
  85. data/spec/struct_spec.rb +113 -9
  86. data/spec/support/header_protocol_helper.rb +54 -0
  87. data/spec/thin_http_server_spec.rb +3 -18
  88. data/spec/types_spec.rb +25 -26
  89. data/spec/union_spec.rb +69 -11
  90. data/spec/unix_socket_spec.rb +1 -2
  91. data/spec/uuid_validation_spec.rb +238 -0
  92. data/test/fuzz/Makefile.am +173 -0
  93. data/test/fuzz/README.md +149 -0
  94. data/test/fuzz/fuzz_common.rb +95 -0
  95. data/{lib/thrift/core_ext.rb → test/fuzz/fuzz_parse_binary_protocol.rb} +3 -4
  96. data/{lib/thrift/core_ext/fixnum.rb → test/fuzz/fuzz_parse_binary_protocol_accelerated.rb} +6 -13
  97. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +22 -0
  98. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +22 -0
  99. data/test/fuzz/fuzz_parse_compact_protocol.rb +22 -0
  100. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +22 -0
  101. data/test/fuzz/fuzz_parse_json_protocol.rb +22 -0
  102. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +22 -0
  103. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +22 -0
  104. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +22 -0
  105. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +22 -0
  106. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +22 -0
  107. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +22 -0
  108. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +22 -0
  109. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +22 -0
  110. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +22 -0
  111. data/test/fuzz/fuzz_tracer.rb +28 -0
  112. metadata +106 -37
@@ -38,25 +38,24 @@ shared_examples_for 'a binary protocol' do
38
38
 
39
39
  it "should make strict_write readable" do
40
40
  expect(@prot.strict_write).to eql(true)
41
- end
41
+ end
42
42
 
43
43
  it "should write the message header" do
44
44
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
45
45
  expect(@trans.read(@trans.available)).to eq([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N"))
46
46
  end
47
-
47
+
48
48
  it "should write the message header without version when writes are not strict" do
49
49
  @prot = protocol_class.new(@trans, true, false) # no strict write
50
50
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
51
51
  expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
52
52
  end
53
-
53
+
54
54
  it "should write the message header with a version when writes are strict" do
55
55
  @prot = protocol_class.new(@trans) # strict write
56
56
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
57
57
  expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
58
58
  end
59
-
60
59
 
61
60
  # message footer is a noop
62
61
 
@@ -64,44 +63,44 @@ shared_examples_for 'a binary protocol' do
64
63
  @prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
65
64
  expect(@trans.read(@trans.available)).to eq([Thrift::Types::DOUBLE, 3].pack("cn"))
66
65
  end
67
-
66
+
68
67
  # field footer is a noop
69
-
68
+
70
69
  it "should write the STOP field" do
71
70
  @prot.write_field_stop
72
71
  expect(@trans.read(1)).to eq("\000")
73
72
  end
74
-
73
+
75
74
  it "should write the map header" do
76
75
  @prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
77
76
  expect(@trans.read(@trans.available)).to eq([Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN"));
78
77
  end
79
-
78
+
80
79
  # map footer is a noop
81
-
80
+
82
81
  it "should write the list header" do
83
82
  @prot.write_list_begin(Thrift::Types::I16, 42)
84
83
  expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
85
84
  end
86
-
85
+
87
86
  # list footer is a noop
88
-
87
+
89
88
  it "should write the set header" do
90
89
  @prot.write_set_begin(Thrift::Types::I16, 42)
91
90
  expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
92
91
  end
93
-
92
+
94
93
  it "should write a bool" do
95
94
  @prot.write_bool(true)
96
95
  @prot.write_bool(false)
97
96
  expect(@trans.read(@trans.available)).to eq("\001\000")
98
97
  end
99
-
98
+
100
99
  it "should treat a nil bool as false" do
101
100
  @prot.write_bool(nil)
102
101
  expect(@trans.read(1)).to eq("\000")
103
102
  end
104
-
103
+
105
104
  it "should write a byte" do
106
105
  # byte is small enough, let's check -128..127
107
106
  (-128..127).each do |i|
@@ -120,11 +119,11 @@ shared_examples_for 'a binary protocol' do
120
119
  it "errors out with a Bignum" do
121
120
  expect { @prot.write_byte(2**65) }.to raise_error(RangeError)
122
121
  end
123
-
122
+
124
123
  it "should error gracefully when trying to write a nil byte" do
125
- expect { @prot.write_byte(nil) }.to raise_error
124
+ expect { @prot.write_byte(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
126
125
  end
127
-
126
+
128
127
  it "should write an i16" do
129
128
  # try a random scattering of values
130
129
  # include the signed i16 minimum/maximum
@@ -133,17 +132,17 @@ shared_examples_for 'a binary protocol' do
133
132
  end
134
133
  # and try something out of signed range, it should clip
135
134
  @prot.write_i16(2**15 + 5)
136
-
135
+
137
136
  expect(@trans.read(@trans.available)).to eq("\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005")
138
-
137
+
139
138
  # a Bignum should error
140
139
  # lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
141
140
  end
142
-
141
+
143
142
  it "should error gracefully when trying to write a nil i16" do
144
- expect { @prot.write_i16(nil) }.to raise_error
143
+ expect { @prot.write_i16(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
145
144
  end
146
-
145
+
147
146
  it "should write an i32" do
148
147
  # try a random scattering of values
149
148
  # include the signed i32 minimum/maximum
@@ -153,14 +152,14 @@ shared_examples_for 'a binary protocol' do
153
152
  # try something out of signed range, it should clip
154
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")
155
154
  [2 ** 31 + 5, 2 ** 65 + 5].each do |i|
156
- expect { @prot.write_i32(i) }.to raise_error(RangeError)
155
+ expect { @prot.write_i32(i) }.to raise_error(RangeError)
157
156
  end
158
157
  end
159
-
158
+
160
159
  it "should error gracefully when trying to write a nil i32" do
161
- expect { @prot.write_i32(nil) }.to raise_error
160
+ expect { @prot.write_i32(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
162
161
  end
163
-
162
+
164
163
  it "should write an i64" do
165
164
  # try a random scattering of values
166
165
  # try the signed i64 minimum/maximum
@@ -179,98 +178,102 @@ shared_examples_for 'a binary protocol' do
179
178
  "\177\377\377\377\377\377\377\377"].join(""))
180
179
  expect { @prot.write_i64(2 ** 65 + 5) }.to raise_error(RangeError)
181
180
  end
182
-
181
+
183
182
  it "should error gracefully when trying to write a nil i64" do
184
- expect { @prot.write_i64(nil) }.to raise_error
183
+ expect { @prot.write_i64(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
185
184
  end
186
-
185
+
187
186
  it "should write a double" do
188
187
  # try a random scattering of values, including min/max
189
- values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
188
+ values = [Float::MIN, -1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
190
189
  values.each do |f|
191
190
  @prot.write_double(f)
192
191
  expect(@trans.read(@trans.available)).to eq([f].pack("G"))
193
192
  end
194
193
  end
195
-
194
+
196
195
  it "should error gracefully when trying to write a nil double" do
197
- expect { @prot.write_double(nil) }.to raise_error
196
+ expect { @prot.write_double(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
198
197
  end
199
198
 
200
- if RUBY_VERSION >= '1.9'
201
- it 'should write a string' do
202
- str = 'abc'
203
- @prot.write_string(str)
204
- a = @trans.read(@trans.available)
205
- expect(a.encoding).to eq(Encoding::BINARY)
206
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
207
- end
208
-
209
- it 'should write a string with unicode characters' do
210
- str = "abc \u20AC \u20AD".encode('UTF-8')
211
- @prot.write_string(str)
212
- a = @trans.read(@trans.available)
213
- expect(a.encoding).to eq(Encoding::BINARY)
214
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
215
- 0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
216
- end
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
217
206
 
218
- it 'should write should write a string with unicode characters and transcoding' do
219
- str = "abc \u20AC".encode('ISO-8859-15')
220
- @prot.write_string(str)
221
- a = @trans.read(@trans.available)
222
- expect(a.encoding).to eq(Encoding::BINARY)
223
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
224
- end
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
225
215
 
226
- it 'should write a binary string' do
227
- buffer = [0, 1, 2, 3].pack('C*')
228
- @prot.write_binary(buffer)
229
- a = @trans.read(@trans.available)
230
- expect(a.encoding).to eq(Encoding::BINARY)
231
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
232
- end
233
- else
234
- it 'should write a string' do
235
- str = 'abc'
236
- @prot.write_string(str)
237
- a = @trans.read(@trans.available)
238
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
239
- end
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
240
223
 
241
- it 'should write a binary string' do
242
- buffer = [0, 1, 2, 3].pack('C*')
243
- @prot.write_binary(buffer)
244
- a = @trans.read(@trans.available)
245
- expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
246
- end
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])
247
230
  end
248
231
 
249
232
  it "should error gracefully when trying to write a nil string" do
250
- expect { @prot.write_string(nil) }.to raise_error
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")
251
250
  end
252
-
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
+
253
256
  it "should write the message header without version when writes are not strict" do
254
257
  @prot = protocol_class.new(@trans, true, false) # no strict write
255
258
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
256
259
  expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
257
260
  end
258
-
261
+
259
262
  it "should write the message header with a version when writes are strict" do
260
263
  @prot = protocol_class.new(@trans) # strict write
261
264
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
262
265
  expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
263
266
  end
264
-
267
+
265
268
  # message footer is a noop
266
-
269
+
267
270
  it "should read a field header" do
268
271
  @trans.write([Thrift::Types::STRING, 3].pack("cn"))
269
272
  expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STRING, 3])
270
273
  end
271
-
274
+
272
275
  # field footer is a noop
273
-
276
+
274
277
  it "should read a stop field" do
275
278
  @trans.write([Thrift::Types::STOP].pack("c"));
276
279
  expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STOP, 0])
@@ -280,36 +283,36 @@ shared_examples_for 'a binary protocol' do
280
283
  @trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
281
284
  expect(@prot.read_map_begin).to eq([Thrift::Types::DOUBLE, Thrift::Types::I64, 42])
282
285
  end
283
-
286
+
284
287
  # map footer is a noop
285
-
288
+
286
289
  it "should read a list header" do
287
290
  @trans.write([Thrift::Types::STRING, 17].pack("cN"))
288
291
  expect(@prot.read_list_begin).to eq([Thrift::Types::STRING, 17])
289
292
  end
290
-
293
+
291
294
  # list footer is a noop
292
-
295
+
293
296
  it "should read a set header" do
294
297
  @trans.write([Thrift::Types::STRING, 17].pack("cN"))
295
298
  expect(@prot.read_set_begin).to eq([Thrift::Types::STRING, 17])
296
299
  end
297
-
300
+
298
301
  # set footer is a noop
299
-
302
+
300
303
  it "should read a bool" do
301
304
  @trans.write("\001\000");
302
305
  expect(@prot.read_bool).to eq(true)
303
306
  expect(@prot.read_bool).to eq(false)
304
307
  end
305
-
308
+
306
309
  it "should read a byte" do
307
310
  [-128, -57, -3, 0, 17, 24, 127].each do |i|
308
311
  @trans.write([i].pack("c"))
309
312
  expect(@prot.read_byte).to eq(i)
310
313
  end
311
314
  end
312
-
315
+
313
316
  it "should read an i16" do
314
317
  # try a scattering of values, including min/max
315
318
  [-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
@@ -317,7 +320,7 @@ shared_examples_for 'a binary protocol' do
317
320
  expect(@prot.read_i16).to eq(i)
318
321
  end
319
322
  end
320
-
323
+
321
324
  it "should read an i32" do
322
325
  # try a scattering of values, including min/max
323
326
  [-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
@@ -325,7 +328,7 @@ shared_examples_for 'a binary protocol' do
325
328
  expect(@prot.read_i32).to eq(i)
326
329
  end
327
330
  end
328
-
331
+
329
332
  it "should read an i64" do
330
333
  # try a scattering of values, including min/max
331
334
  [-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
@@ -333,7 +336,7 @@ shared_examples_for 'a binary protocol' do
333
336
  expect(@prot.read_i64).to eq(i)
334
337
  end
335
338
  end
336
-
339
+
337
340
  it "should read a double" do
338
341
  # try a random scattering of values, including min/max
339
342
  [Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
@@ -342,66 +345,50 @@ shared_examples_for 'a binary protocol' do
342
345
  end
343
346
  end
344
347
 
345
- if RUBY_VERSION >= '1.9'
346
- it 'should read a string' do
347
- # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
348
- buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
349
- @trans.write(buffer)
350
- a = @prot.read_string
351
- expect(a).to eq('abc'.encode('UTF-8'))
352
- expect(a.encoding).to eq(Encoding::UTF_8)
353
- end
354
-
355
- it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
356
- # i32 of value 3, followed by one character U+20AC made up of three bytes
357
- buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
358
- @trans.write(buffer)
359
- a = @prot.read_string
360
- expect(a).to eq("\u20AC".encode('UTF-8'))
361
- expect(a.encoding).to eq(Encoding::UTF_8)
362
- end
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
363
356
 
364
- it 'should read a binary string' do
365
- buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
366
- @trans.write(buffer)
367
- a = @prot.read_binary
368
- expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
369
- expect(a.encoding).to eq(Encoding::BINARY)
370
- end
371
- else
372
- it 'should read a string' do
373
- # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
374
- buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
375
- @trans.write(buffer)
376
- expect(@prot.read_string).to eq('abc')
377
- end
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
378
365
 
379
- it 'should read a binary string' do
380
- buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
381
- @trans.write(buffer)
382
- a = @prot.read_binary
383
- expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
384
- end
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)
385
372
  end
386
373
 
387
374
  it "should perform a complete rpc with no args or return" do
388
375
  srv_test(
389
- proc {|client| client.send_voidMethod()},
390
- proc {|client| expect(client.recv_voidMethod).to eq(nil)}
376
+ proc { |client| client.send_voidMethod() },
377
+ proc { |client| expect(client.recv_voidMethod).to eq(nil) }
391
378
  )
392
379
  end
393
380
 
394
381
  it "should perform a complete rpc with a primitive return type" do
395
382
  srv_test(
396
- proc {|client| client.send_primitiveMethod()},
397
- proc {|client| expect(client.recv_primitiveMethod).to eq(1)}
383
+ proc { |client| client.send_primitiveMethod() },
384
+ proc { |client| expect(client.recv_primitiveMethod).to eq(1) }
398
385
  )
399
386
  end
400
387
 
401
388
  it "should perform a complete rpc with a struct return type" do
402
389
  srv_test(
403
- proc {|client| client.send_structMethod()},
404
- proc {|client|
390
+ proc { |client| client.send_structMethod() },
391
+ proc { |client|
405
392
  result = client.recv_structMethod
406
393
  result.set_byte_map = nil
407
394
  result.map_byte_map = nil
@@ -413,7 +400,7 @@ shared_examples_for 'a binary protocol' do
413
400
  def get_socket_connection
414
401
  server = Thrift::ServerSocket.new("localhost", 9090)
415
402
  server.listen
416
-
403
+
417
404
  clientside = Thrift::Socket.new("localhost", 9090)
418
405
  clientside.open
419
406
  serverside = server.accept
@@ -443,14 +430,14 @@ shared_examples_for 'a binary protocol' do
443
430
  server.close
444
431
  end
445
432
 
446
- class SrvHandler
433
+ class SrvHandler
447
434
  def voidMethod()
448
435
  end
449
-
436
+
450
437
  def primitiveMethod
451
438
  1
452
439
  end
453
-
440
+
454
441
  def structMethod
455
442
  Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
456
443
  end