thrift 0.24.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 +107 -4
  3. data/ext/binary_protocol_accelerated.c +52 -17
  4. data/ext/compact_protocol.c +135 -70
  5. data/ext/constants.h +3 -0
  6. data/ext/extconf.rb +4 -4
  7. data/ext/macros.h +11 -0
  8. data/ext/memory_buffer.c +35 -17
  9. data/ext/struct.c +185 -64
  10. data/ext/thrift_native.c +6 -0
  11. data/lib/thrift/bytes.rb +2 -2
  12. data/lib/thrift/client.rb +31 -22
  13. data/lib/thrift/exceptions.rb +10 -8
  14. data/lib/thrift/multiplexed_processor.rb +5 -6
  15. data/lib/thrift/processor.rb +24 -3
  16. data/lib/thrift/protocol/base_protocol.rb +53 -27
  17. data/lib/thrift/protocol/binary_protocol.rb +54 -40
  18. data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
  19. data/lib/thrift/protocol/compact_protocol.rb +193 -88
  20. data/lib/thrift/protocol/header_protocol.rb +14 -3
  21. data/lib/thrift/protocol/json_protocol.rb +146 -104
  22. data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
  23. data/lib/thrift/protocol/protocol_decorator.rb +5 -2
  24. data/lib/thrift/serializer/serializer.rb +6 -0
  25. data/lib/thrift/server/base_server.rb +10 -2
  26. data/lib/thrift/server/nonblocking_server.rb +49 -26
  27. data/lib/thrift/server/rack_application.rb +69 -0
  28. data/lib/thrift/server/simple_server.rb +27 -23
  29. data/lib/thrift/server/thin_http_server.rb +20 -44
  30. data/lib/thrift/server/thread_pool_server.rb +20 -17
  31. data/lib/thrift/server/threaded_server.rb +22 -26
  32. data/lib/thrift/struct.rb +33 -18
  33. data/lib/thrift/struct_union.rb +36 -30
  34. data/lib/thrift/transport/base_transport.rb +23 -5
  35. data/lib/thrift/transport/buffered_transport.rb +4 -4
  36. data/lib/thrift/transport/framed_transport.rb +32 -7
  37. data/lib/thrift/transport/header_transport.rb +130 -50
  38. data/lib/thrift/transport/http_client_transport.rb +27 -14
  39. data/lib/thrift/transport/io_stream_transport.rb +2 -1
  40. data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
  41. data/lib/thrift/transport/server_socket.rb +4 -5
  42. data/lib/thrift/transport/socket.rb +20 -22
  43. data/lib/thrift/transport/ssl_server_socket.rb +64 -4
  44. data/lib/thrift/transport/ssl_socket.rb +32 -5
  45. data/lib/thrift/transport/unix_server_socket.rb +1 -1
  46. data/lib/thrift/transport/unix_socket.rb +4 -6
  47. data/lib/thrift/types.rb +22 -22
  48. data/lib/thrift/union.rb +20 -11
  49. data/lib/thrift/uuid.rb +8 -8
  50. data/lib/thrift.rb +39 -39
  51. metadata +5 -230
  52. data/benchmark/Benchmark.thrift +0 -24
  53. data/benchmark/benchmark.rb +0 -286
  54. data/benchmark/client.rb +0 -118
  55. data/benchmark/server.rb +0 -121
  56. data/benchmark/thin_server.rb +0 -46
  57. data/lib/thrift/server/mongrel_http_server.rb +0 -61
  58. data/spec/BaseService.thrift +0 -27
  59. data/spec/ExtendedService.thrift +0 -25
  60. data/spec/Referenced.thrift +0 -44
  61. data/spec/ThriftNamespacedSpec.thrift +0 -53
  62. data/spec/ThriftSpec.thrift +0 -203
  63. data/spec/base_protocol_spec.rb +0 -244
  64. data/spec/base_transport_spec.rb +0 -428
  65. data/spec/binary_protocol_accelerated_spec.rb +0 -47
  66. data/spec/binary_protocol_spec.rb +0 -73
  67. data/spec/binary_protocol_spec_shared.rb +0 -509
  68. data/spec/bytes_spec.rb +0 -117
  69. data/spec/client_spec.rb +0 -167
  70. data/spec/compact_protocol_spec.rb +0 -295
  71. data/spec/constants_demo_spec.rb +0 -102
  72. data/spec/exception_spec.rb +0 -141
  73. data/spec/flat_spec.rb +0 -63
  74. data/spec/header_protocol_spec.rb +0 -476
  75. data/spec/header_transport_spec.rb +0 -431
  76. data/spec/http_client_spec.rb +0 -160
  77. data/spec/json_protocol_spec.rb +0 -574
  78. data/spec/multiplexed_processor_spec.rb +0 -75
  79. data/spec/namespaced_spec.rb +0 -67
  80. data/spec/nonblocking_server_spec.rb +0 -429
  81. data/spec/processor_spec.rb +0 -80
  82. data/spec/recursion_depth_spec.rb +0 -223
  83. data/spec/serializer_spec.rb +0 -67
  84. data/spec/server_socket_spec.rb +0 -121
  85. data/spec/server_spec.rb +0 -238
  86. data/spec/socket_spec.rb +0 -174
  87. data/spec/socket_spec_shared.rb +0 -168
  88. data/spec/spec_helper.rb +0 -70
  89. data/spec/ssl_server_socket_spec.rb +0 -85
  90. data/spec/ssl_socket_spec.rb +0 -248
  91. data/spec/struct_nested_containers_spec.rb +0 -191
  92. data/spec/struct_spec.rb +0 -398
  93. data/spec/support/header_protocol_helper.rb +0 -55
  94. data/spec/thin_http_server_spec.rb +0 -127
  95. data/spec/types_spec.rb +0 -118
  96. data/spec/union_spec.rb +0 -273
  97. data/spec/unix_socket_spec.rb +0 -131
  98. data/spec/uuid_validation_spec.rb +0 -239
  99. data/test/fuzz/Makefile +0 -779
  100. data/test/fuzz/Makefile.am +0 -173
  101. data/test/fuzz/Makefile.in +0 -775
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -96
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
  120. data/test/fuzz/fuzz_tracer.rb +0 -29
@@ -1,574 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
- #
4
- # Licensed to the Apache Software Foundation (ASF) under one
5
- # or more contributor license agreements. See the NOTICE file
6
- # distributed with this work for additional information
7
- # regarding copyright ownership. The ASF licenses this file
8
- # to you under the Apache License, Version 2.0 (the
9
- # "License"); you may not use this file except in compliance
10
- # with the License. You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing,
15
- # software distributed under the License is distributed on an
16
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
- # KIND, either express or implied. See the License for the
18
- # specific language governing permissions and limitations
19
- # under the License.
20
- #
21
-
22
- require 'spec_helper'
23
-
24
- describe 'JsonProtocol' do
25
- describe Thrift::JsonProtocol do
26
- before(:each) do
27
- @trans = Thrift::MemoryBufferTransport.new
28
- @prot = Thrift::JsonProtocol.new(@trans)
29
- end
30
-
31
- it "should write json escaped char" do
32
- @prot.write_json_escape_char("\n")
33
- expect(@trans.read(@trans.available)).to eq('\u000a')
34
-
35
- @prot.write_json_escape_char(" ")
36
- expect(@trans.read(@trans.available)).to eq('\u0020')
37
- end
38
-
39
- it "should write json char" do
40
- @prot.write_json_char("\n")
41
- expect(@trans.read(@trans.available)).to eq('\\n')
42
-
43
- @prot.write_json_char(" ")
44
- expect(@trans.read(@trans.available)).to eq(' ')
45
-
46
- @prot.write_json_char("\\")
47
- expect(@trans.read(@trans.available)).to eq("\\\\")
48
-
49
- @prot.write_json_char("@")
50
- expect(@trans.read(@trans.available)).to eq('@')
51
- end
52
-
53
- it "should write json string" do
54
- @prot.write_json_string("this is a \\ json\nstring")
55
- expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"")
56
- end
57
-
58
- it "should write json base64" do
59
- @prot.write_json_base64("this is a base64 string")
60
- expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
61
- end
62
-
63
- it "should write json integer" do
64
- @prot.write_json_integer(45)
65
- expect(@trans.read(@trans.available)).to eq("45")
66
-
67
- @prot.write_json_integer(33000)
68
- expect(@trans.read(@trans.available)).to eq("33000")
69
-
70
- @prot.write_json_integer(3000000000)
71
- expect(@trans.read(@trans.available)).to eq("3000000000")
72
-
73
- @prot.write_json_integer(6000000000)
74
- expect(@trans.read(@trans.available)).to eq("6000000000")
75
- end
76
-
77
- it "should write json double" do
78
- @prot.write_json_double(12.3)
79
- expect(@trans.read(@trans.available)).to eq("12.3")
80
-
81
- @prot.write_json_double(-3.21)
82
- expect(@trans.read(@trans.available)).to eq("-3.21")
83
-
84
- @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
85
- expect(@trans.read(@trans.available)).to eq("\"NaN\"")
86
-
87
- @prot.write_json_double((+1.0/0.0))
88
- expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
89
-
90
- @prot.write_json_double((-1.0/0.0))
91
- expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
92
- end
93
-
94
- it "should write json object start" do
95
- @prot.write_json_object_start
96
- expect(@trans.read(@trans.available)).to eq("{")
97
- end
98
-
99
- it "should write json object end" do
100
- @prot.write_json_object_end
101
- expect(@trans.read(@trans.available)).to eq("}")
102
- end
103
-
104
- it "should write json array start" do
105
- @prot.write_json_array_start
106
- expect(@trans.read(@trans.available)).to eq("[")
107
- end
108
-
109
- it "should write json array end" do
110
- @prot.write_json_array_end
111
- expect(@trans.read(@trans.available)).to eq("]")
112
- end
113
-
114
- it "should write message begin" do
115
- @prot.write_message_begin("name", 12, 32)
116
- expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32")
117
- end
118
-
119
- it "should write message end" do
120
- @prot.write_message_end
121
- expect(@trans.read(@trans.available)).to eq("]")
122
- end
123
-
124
- it "should write struct begin" do
125
- @prot.write_struct_begin("name")
126
- expect(@trans.read(@trans.available)).to eq("{")
127
- end
128
-
129
- it "should write struct end" do
130
- @prot.write_struct_end
131
- expect(@trans.read(@trans.available)).to eq("}")
132
- end
133
-
134
- it "should write field begin" do
135
- @prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
136
- expect(@trans.read(@trans.available)).to eq("32{\"rec\"")
137
- end
138
-
139
- it "should write field end" do
140
- @prot.write_field_end
141
- expect(@trans.read(@trans.available)).to eq("}")
142
- end
143
-
144
- it "should write field stop" do
145
- @prot.write_field_stop
146
- expect(@trans.read(@trans.available)).to eq("")
147
- end
148
-
149
- it "should write map begin" do
150
- @prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
151
- expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{")
152
- end
153
-
154
- it "should write map end" do
155
- @prot.write_map_end
156
- expect(@trans.read(@trans.available)).to eq("}]")
157
- end
158
-
159
- it "should write list begin" do
160
- @prot.write_list_begin(Thrift::Types::STRUCT, 32)
161
- expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
162
- end
163
-
164
- it "should write list end" do
165
- @prot.write_list_end
166
- expect(@trans.read(@trans.available)).to eq("]")
167
- end
168
-
169
- it "should write set begin" do
170
- @prot.write_set_begin(Thrift::Types::STRUCT, 32)
171
- expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
172
- end
173
-
174
- it "should write set end" do
175
- @prot.write_set_end
176
- expect(@trans.read(@trans.available)).to eq("]")
177
- end
178
-
179
- it "should write bool" do
180
- @prot.write_bool(true)
181
- expect(@trans.read(@trans.available)).to eq("1")
182
-
183
- @prot.write_bool(false)
184
- expect(@trans.read(@trans.available)).to eq("0")
185
- end
186
-
187
- it "should write byte" do
188
- @prot.write_byte(100)
189
- expect(@trans.read(@trans.available)).to eq("100")
190
- end
191
-
192
- it "should write i16" do
193
- @prot.write_i16(1000)
194
- expect(@trans.read(@trans.available)).to eq("1000")
195
- end
196
-
197
- it "should write i32" do
198
- @prot.write_i32(3000000000)
199
- expect(@trans.read(@trans.available)).to eq("3000000000")
200
- end
201
-
202
- it "should write i64" do
203
- @prot.write_i64(6000000000)
204
- expect(@trans.read(@trans.available)).to eq("6000000000")
205
- end
206
-
207
- it "should write double" do
208
- @prot.write_double(1.23)
209
- expect(@trans.read(@trans.available)).to eq("1.23")
210
-
211
- @prot.write_double(-32.1)
212
- expect(@trans.read(@trans.available)).to eq("-32.1")
213
-
214
- @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
215
- expect(@trans.read(@trans.available)).to eq("\"NaN\"")
216
-
217
- @prot.write_double((+1.0/0.0))
218
- expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
219
-
220
- @prot.write_double((-1.0/0.0))
221
- expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
222
- end
223
-
224
- it 'should write string' do
225
- @prot.write_string('this is a test string')
226
- a = @trans.read(@trans.available)
227
- expect(a).to eq('"this is a test string"'.b)
228
- expect(a.encoding).to eq(Encoding::BINARY)
229
- end
230
-
231
- it 'should write string with unicode characters' do
232
- @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
233
- a = @trans.read(@trans.available)
234
- expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".b)
235
- expect(a.encoding).to eq(Encoding::BINARY)
236
- end
237
-
238
- it "should write binary" do
239
- @prot.write_binary("this is a base64 string")
240
- expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
241
- end
242
-
243
- it "should write long binary" do
244
- @prot.write_binary((0...256).to_a.pack('C*'))
245
- expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
246
- end
247
-
248
- it "should write a uuid" do
249
- @prot.write_uuid("00112233-4455-6677-8899-aabbccddeeff")
250
- expect(@trans.read(@trans.available)).to eq("\"00112233-4455-6677-8899-aabbccddeeff\"")
251
- end
252
-
253
- it "should get type name for type id" do
254
- expect { @prot.get_type_name_for_type_id(Thrift::Types::STOP) }.to raise_error(NotImplementedError)
255
- expect { @prot.get_type_name_for_type_id(Thrift::Types::VOID) }.to raise_error(NotImplementedError)
256
- expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf")
257
- expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8")
258
- expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl")
259
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16")
260
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32")
261
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64")
262
- expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str")
263
- expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec")
264
- expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map")
265
- expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set")
266
- expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst")
267
- end
268
-
269
- it "should get type id for type name" do
270
- expect { @prot.get_type_id_for_type_name("pp") }.to raise_error(NotImplementedError)
271
- expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL)
272
- expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE)
273
- expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE)
274
- expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16)
275
- expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32)
276
- expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64)
277
- expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING)
278
- expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT)
279
- expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP)
280
- expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET)
281
- expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST)
282
- end
283
-
284
- it "should read json syntax char" do
285
- @trans.write('F')
286
- expect { @prot.read_json_syntax_char('G') }.to raise_error(Thrift::ProtocolException)
287
- @trans.write('H')
288
- @prot.read_json_syntax_char('H')
289
- end
290
-
291
- it "should read json escape char" do
292
- @trans.write('0054')
293
- expect(@prot.read_json_escape_char).to eq('T')
294
-
295
- @trans.write("\"\\\"\"")
296
- expect(@prot.read_json_string(false)).to eq("\"")
297
-
298
- @trans.write("\"\\\\\"")
299
- expect(@prot.read_json_string(false)).to eq("\\")
300
-
301
- @trans.write("\"\\/\"")
302
- expect(@prot.read_json_string(false)).to eq("\/")
303
-
304
- @trans.write("\"\\b\"")
305
- expect(@prot.read_json_string(false)).to eq("\b")
306
-
307
- @trans.write("\"\\f\"")
308
- expect(@prot.read_json_string(false)).to eq("\f")
309
-
310
- @trans.write("\"\\n\"")
311
- expect(@prot.read_json_string(false)).to eq("\n")
312
-
313
- @trans.write("\"\\r\"")
314
- expect(@prot.read_json_string(false)).to eq("\r")
315
-
316
- @trans.write("\"\\t\"")
317
- expect(@prot.read_json_string(false)).to eq("\t")
318
- end
319
-
320
- it "should read json string" do
321
- @trans.write("\"\\P")
322
- expect { @prot.read_json_string(false) }.to raise_error(Thrift::ProtocolException)
323
-
324
- @trans.write("\"this is a test string\"")
325
- expect(@prot.read_json_string).to eq("this is a test string")
326
- end
327
-
328
- it "should read json base64" do
329
- @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
330
- expect(@prot.read_json_base64).to eq("this is a test string")
331
- end
332
-
333
- it "should is json numeric" do
334
- expect(@prot.is_json_numeric("A")).to eq(false)
335
- expect(@prot.is_json_numeric("+")).to eq(true)
336
- expect(@prot.is_json_numeric("-")).to eq(true)
337
- expect(@prot.is_json_numeric(".")).to eq(true)
338
- expect(@prot.is_json_numeric("0")).to eq(true)
339
- expect(@prot.is_json_numeric("1")).to eq(true)
340
- expect(@prot.is_json_numeric("2")).to eq(true)
341
- expect(@prot.is_json_numeric("3")).to eq(true)
342
- expect(@prot.is_json_numeric("4")).to eq(true)
343
- expect(@prot.is_json_numeric("5")).to eq(true)
344
- expect(@prot.is_json_numeric("6")).to eq(true)
345
- expect(@prot.is_json_numeric("7")).to eq(true)
346
- expect(@prot.is_json_numeric("8")).to eq(true)
347
- expect(@prot.is_json_numeric("9")).to eq(true)
348
- expect(@prot.is_json_numeric("E")).to eq(true)
349
- expect(@prot.is_json_numeric("e")).to eq(true)
350
- end
351
-
352
- it "should read json numeric chars" do
353
- @trans.write("1.453E45T")
354
- expect(@prot.read_json_numeric_chars).to eq("1.453E45")
355
- end
356
-
357
- it "should read json integer" do
358
- @trans.write("1.45\"\"")
359
- expect { @prot.read_json_integer }.to raise_error(Thrift::ProtocolException)
360
- @prot.read_string
361
-
362
- @trans.write("1453T")
363
- expect(@prot.read_json_integer).to eq(1453)
364
- end
365
-
366
- it "should read json double" do
367
- @trans.write("1.45e3e01\"\"")
368
- expect { @prot.read_json_double }.to raise_error(Thrift::ProtocolException)
369
- @prot.read_string
370
-
371
- @trans.write("\"1.453e01\"")
372
- expect { @prot.read_json_double }.to raise_error(Thrift::ProtocolException)
373
-
374
- @trans.write("1.453e01\"\"")
375
- expect(@prot.read_json_double).to eq(14.53)
376
- @prot.read_string
377
-
378
- @trans.write("\"NaN\"")
379
- expect(@prot.read_json_double.nan?).to eq(true)
380
-
381
- @trans.write("\"Infinity\"")
382
- expect(@prot.read_json_double).to eq(+1.0/0.0)
383
-
384
- @trans.write("\"-Infinity\"")
385
- expect(@prot.read_json_double).to eq(-1.0/0.0)
386
- end
387
-
388
- it "should read json object start" do
389
- @trans.write("{")
390
- expect(@prot.read_json_object_start).to eq(nil)
391
- end
392
-
393
- it "should read json object end" do
394
- @trans.write("}")
395
- expect(@prot.read_json_object_end).to eq(nil)
396
- end
397
-
398
- it "should read json array start" do
399
- @trans.write("[")
400
- expect(@prot.read_json_array_start).to eq(nil)
401
- end
402
-
403
- it "should read json array end" do
404
- @trans.write("]")
405
- expect(@prot.read_json_array_end).to eq(nil)
406
- end
407
-
408
- it "should read_message_begin" do
409
- @trans.write("[2,")
410
- expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException)
411
-
412
- @trans.write("[1,\"name\",12,32\"\"")
413
- expect(@prot.read_message_begin).to eq(["name", 12, 32])
414
- end
415
-
416
- it "should read message end" do
417
- @trans.write("]")
418
- expect(@prot.read_message_end).to eq(nil)
419
- end
420
-
421
- it "should read struct begin" do
422
- @trans.write("{")
423
- expect(@prot.read_struct_begin).to eq(nil)
424
- end
425
-
426
- it "should read struct end" do
427
- @trans.write("}")
428
- expect(@prot.read_struct_end).to eq(nil)
429
- end
430
-
431
- it "should read field begin" do
432
- @trans.write("1{\"rec\"")
433
- expect(@prot.read_field_begin).to eq([nil, 12, 1])
434
- end
435
-
436
- it "should read field end" do
437
- @trans.write("}")
438
- expect(@prot.read_field_end).to eq(nil)
439
- end
440
-
441
- it "should read map begin" do
442
- @trans.write("[\"rec\",\"lst\",2,{")
443
- expect(@prot.read_map_begin).to eq([12, 15, 2])
444
- end
445
-
446
- it "should reject a negative map size" do
447
- @trans.write("[\"rec\",\"lst\",-1,{")
448
- expect { @prot.read_map_begin }.to raise_error(Thrift::ProtocolException, "Negative size") do |e|
449
- expect(e.type).to eq(Thrift::ProtocolException::NEGATIVE_SIZE)
450
- end
451
- end
452
-
453
- it "should read map end" do
454
- @trans.write("}]")
455
- expect(@prot.read_map_end).to eq(nil)
456
- end
457
-
458
- it "should read list begin" do
459
- @trans.write("[\"rec\",2\"\"")
460
- expect(@prot.read_list_begin).to eq([12, 2])
461
- end
462
-
463
- it "should reject a negative list size" do
464
- @trans.write("[\"rec\",-1\"\"")
465
- expect { @prot.read_list_begin }.to raise_error(Thrift::ProtocolException, "Negative size") do |e|
466
- expect(e.type).to eq(Thrift::ProtocolException::NEGATIVE_SIZE)
467
- end
468
- end
469
-
470
- it "should read list end" do
471
- @trans.write("]")
472
- expect(@prot.read_list_end).to eq(nil)
473
- end
474
-
475
- it "should read set begin" do
476
- @trans.write("[\"rec\",2\"\"")
477
- expect(@prot.read_set_begin).to eq([12, 2])
478
- end
479
-
480
- it "should reject a negative set size" do
481
- @trans.write("[\"rec\",-1\"\"")
482
- expect { @prot.read_set_begin }.to raise_error(Thrift::ProtocolException, "Negative size") do |e|
483
- expect(e.type).to eq(Thrift::ProtocolException::NEGATIVE_SIZE)
484
- end
485
- end
486
-
487
- it "should read set end" do
488
- @trans.write("]")
489
- expect(@prot.read_set_end).to eq(nil)
490
- end
491
-
492
- it "should read bool" do
493
- @trans.write("0\"\"")
494
- expect(@prot.read_bool).to eq(false)
495
- @prot.read_string
496
-
497
- @trans.write("1\"\"")
498
- expect(@prot.read_bool).to eq(true)
499
- end
500
-
501
- it "should read byte" do
502
- @trans.write("60\"\"")
503
- expect(@prot.read_byte).to eq(60)
504
- end
505
-
506
- it "should read i16" do
507
- @trans.write("1000\"\"")
508
- expect(@prot.read_i16).to eq(1000)
509
- end
510
-
511
- it "should read i32" do
512
- @trans.write("3000000000\"\"")
513
- expect(@prot.read_i32).to eq(3000000000)
514
- end
515
-
516
- it "should read i64" do
517
- @trans.write("6000000000\"\"")
518
- expect(@prot.read_i64).to eq(6000000000)
519
- end
520
-
521
- it "should read double" do
522
- @trans.write("12.23\"\"")
523
- expect(@prot.read_double).to eq(12.23)
524
- end
525
-
526
- it 'should read string' do
527
- @trans.write('"this is a test string"'.b)
528
- a = @prot.read_string
529
- expect(a).to eq('this is a test string')
530
- expect(a.encoding).to eq(Encoding::UTF_8)
531
- end
532
-
533
- it 'should read string with unicode characters' do
534
- @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.b)
535
- a = @prot.read_string
536
- expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
537
- expect(a.encoding).to eq(Encoding::UTF_8)
538
- end
539
-
540
- it "should read binary" do
541
- @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
542
- expect(@prot.read_binary).to eq("this is a test string")
543
- end
544
-
545
- it "should read long binary" do
546
- @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
547
- expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a)
548
- end
549
-
550
- it "should read a uuid" do
551
- @trans.write("\"00112233-4455-6677-8899-aabbccddeeff\"")
552
- expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff")
553
- end
554
-
555
- it "should normalize uppercase uuid on read" do
556
- @trans.write("\"00112233-4455-6677-8899-AABBCCDDEEFF\"")
557
- expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff")
558
- end
559
-
560
- it "should provide a reasonable to_s" do
561
- expect(@prot.to_s).to eq("json(memory)")
562
- end
563
- end
564
-
565
- describe Thrift::JsonProtocolFactory do
566
- it "should create a JsonProtocol" do
567
- expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol)
568
- end
569
-
570
- it "should provide a reasonable to_s" do
571
- expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json")
572
- end
573
- end
574
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
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::MultiplexedProcessor do
24
- before(:each) do
25
- @processor = Thrift::MultiplexedProcessor.new
26
- @iprot = double('MockInputProtocol')
27
- @oprot = double('MockOutputProtocol')
28
- end
29
-
30
- it 'dispatches multiplexed calls to the registered service processor' do
31
- actual_processor = double('ActualProcessor')
32
- @processor.register_processor('ThriftTest', actual_processor)
33
-
34
- expect(@iprot).to receive(:read_message_begin).and_return(['ThriftTest:testVoid', Thrift::MessageTypes::CALL, 1])
35
- expect(actual_processor).to receive(:process) do |stored_protocol, oprot|
36
- expect(stored_protocol.read_message_begin).to eq(['testVoid', Thrift::MessageTypes::CALL, 1])
37
- expect(oprot).to eq(@oprot)
38
- true
39
- end
40
-
41
- expect(@processor.process(@iprot, @oprot)).to eq(true)
42
- end
43
-
44
- it 'dispatches non-multiplexed calls to the default processor' do
45
- default_processor = double('DefaultProcessor')
46
- @processor.register_default(default_processor)
47
-
48
- expect(@iprot).to receive(:read_message_begin).and_return(['testVoid', Thrift::MessageTypes::CALL, 2])
49
- expect(default_processor).to receive(:process) do |stored_protocol, oprot|
50
- expect(stored_protocol.read_message_begin).to eq(['testVoid', Thrift::MessageTypes::CALL, 2])
51
- expect(oprot).to eq(@oprot)
52
- true
53
- end
54
-
55
- expect(@processor.process(@iprot, @oprot)).to eq(true)
56
- end
57
-
58
- it 'raises for non-multiplexed calls when no default processor is registered' do
59
- expect(@iprot).to receive(:read_message_begin).and_return(['testVoid', Thrift::MessageTypes::CALL, 3])
60
-
61
- expect { @processor.process(@iprot, @oprot) }.to raise_error(
62
- Thrift::Exception,
63
- 'Service name not found in message name: testVoid. Did you forget to use a Thrift::Protocol::MultiplexedProtocol in your client?'
64
- )
65
- end
66
-
67
- it 'raises for unknown multiplexed service names' do
68
- expect(@iprot).to receive(:read_message_begin).and_return(['Missing:testVoid', Thrift::MessageTypes::CALL, 4])
69
-
70
- expect { @processor.process(@iprot, @oprot) }.to raise_error(
71
- Thrift::Exception,
72
- 'Service name not found: Missing. Did you forget to call Thrift::MultiplexedProcessor#register_processor?'
73
- )
74
- end
75
- end