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,552 +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 'JsonProtocol' do
24
- describe Thrift::JsonProtocol do
25
- before(:each) do
26
- @trans = Thrift::MemoryBufferTransport.new
27
- @prot = Thrift::JsonProtocol.new(@trans)
28
- end
29
-
30
- it "should write json escaped char" do
31
- @prot.write_json_escape_char("\n")
32
- expect(@trans.read(@trans.available)).to eq('\u000a')
33
-
34
- @prot.write_json_escape_char(" ")
35
- expect(@trans.read(@trans.available)).to eq('\u0020')
36
- end
37
-
38
- it "should write json char" do
39
- @prot.write_json_char("\n")
40
- expect(@trans.read(@trans.available)).to eq('\\n')
41
-
42
- @prot.write_json_char(" ")
43
- expect(@trans.read(@trans.available)).to eq(' ')
44
-
45
- @prot.write_json_char("\\")
46
- expect(@trans.read(@trans.available)).to eq("\\\\")
47
-
48
- @prot.write_json_char("@")
49
- expect(@trans.read(@trans.available)).to eq('@')
50
- end
51
-
52
- it "should write json string" do
53
- @prot.write_json_string("this is a \\ json\nstring")
54
- expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"")
55
- end
56
-
57
- it "should write json base64" do
58
- @prot.write_json_base64("this is a base64 string")
59
- expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
60
- end
61
-
62
- it "should write json integer" do
63
- @prot.write_json_integer(45)
64
- expect(@trans.read(@trans.available)).to eq("45")
65
-
66
- @prot.write_json_integer(33000)
67
- expect(@trans.read(@trans.available)).to eq("33000")
68
-
69
- @prot.write_json_integer(3000000000)
70
- expect(@trans.read(@trans.available)).to eq("3000000000")
71
-
72
- @prot.write_json_integer(6000000000)
73
- expect(@trans.read(@trans.available)).to eq("6000000000")
74
- end
75
-
76
- it "should write json double" do
77
- @prot.write_json_double(12.3)
78
- expect(@trans.read(@trans.available)).to eq("12.3")
79
-
80
- @prot.write_json_double(-3.21)
81
- expect(@trans.read(@trans.available)).to eq("-3.21")
82
-
83
- @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
84
- expect(@trans.read(@trans.available)).to eq("\"NaN\"")
85
-
86
- @prot.write_json_double((+1.0/0.0))
87
- expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
88
-
89
- @prot.write_json_double((-1.0/0.0))
90
- expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
91
- end
92
-
93
- it "should write json object start" do
94
- @prot.write_json_object_start
95
- expect(@trans.read(@trans.available)).to eq("{")
96
- end
97
-
98
- it "should write json object end" do
99
- @prot.write_json_object_end
100
- expect(@trans.read(@trans.available)).to eq("}")
101
- end
102
-
103
- it "should write json array start" do
104
- @prot.write_json_array_start
105
- expect(@trans.read(@trans.available)).to eq("[")
106
- end
107
-
108
- it "should write json array end" do
109
- @prot.write_json_array_end
110
- expect(@trans.read(@trans.available)).to eq("]")
111
- end
112
-
113
- it "should write message begin" do
114
- @prot.write_message_begin("name", 12, 32)
115
- expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32")
116
- end
117
-
118
- it "should write message end" do
119
- @prot.write_message_end
120
- expect(@trans.read(@trans.available)).to eq("]")
121
- end
122
-
123
- it "should write struct begin" do
124
- @prot.write_struct_begin("name")
125
- expect(@trans.read(@trans.available)).to eq("{")
126
- end
127
-
128
- it "should write struct end" do
129
- @prot.write_struct_end
130
- expect(@trans.read(@trans.available)).to eq("}")
131
- end
132
-
133
- it "should write field begin" do
134
- @prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
135
- expect(@trans.read(@trans.available)).to eq("32{\"rec\"")
136
- end
137
-
138
- it "should write field end" do
139
- @prot.write_field_end
140
- expect(@trans.read(@trans.available)).to eq("}")
141
- end
142
-
143
- it "should write field stop" do
144
- @prot.write_field_stop
145
- expect(@trans.read(@trans.available)).to eq("")
146
- end
147
-
148
- it "should write map begin" do
149
- @prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
150
- expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{")
151
- end
152
-
153
- it "should write map end" do
154
- @prot.write_map_end
155
- expect(@trans.read(@trans.available)).to eq("}]")
156
- end
157
-
158
- it "should write list begin" do
159
- @prot.write_list_begin(Thrift::Types::STRUCT, 32)
160
- expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
161
- end
162
-
163
- it "should write list end" do
164
- @prot.write_list_end
165
- expect(@trans.read(@trans.available)).to eq("]")
166
- end
167
-
168
- it "should write set begin" do
169
- @prot.write_set_begin(Thrift::Types::STRUCT, 32)
170
- expect(@trans.read(@trans.available)).to eq("[\"rec\",32")
171
- end
172
-
173
- it "should write set end" do
174
- @prot.write_set_end
175
- expect(@trans.read(@trans.available)).to eq("]")
176
- end
177
-
178
- it "should write bool" do
179
- @prot.write_bool(true)
180
- expect(@trans.read(@trans.available)).to eq("1")
181
-
182
- @prot.write_bool(false)
183
- expect(@trans.read(@trans.available)).to eq("0")
184
- end
185
-
186
- it "should write byte" do
187
- @prot.write_byte(100)
188
- expect(@trans.read(@trans.available)).to eq("100")
189
- end
190
-
191
- it "should write i16" do
192
- @prot.write_i16(1000)
193
- expect(@trans.read(@trans.available)).to eq("1000")
194
- end
195
-
196
- it "should write i32" do
197
- @prot.write_i32(3000000000)
198
- expect(@trans.read(@trans.available)).to eq("3000000000")
199
- end
200
-
201
- it "should write i64" do
202
- @prot.write_i64(6000000000)
203
- expect(@trans.read(@trans.available)).to eq("6000000000")
204
- end
205
-
206
- it "should write double" do
207
- @prot.write_double(1.23)
208
- expect(@trans.read(@trans.available)).to eq("1.23")
209
-
210
- @prot.write_double(-32.1)
211
- expect(@trans.read(@trans.available)).to eq("-32.1")
212
-
213
- @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
214
- expect(@trans.read(@trans.available)).to eq("\"NaN\"")
215
-
216
- @prot.write_double((+1.0/0.0))
217
- expect(@trans.read(@trans.available)).to eq("\"Infinity\"")
218
-
219
- @prot.write_double((-1.0/0.0))
220
- expect(@trans.read(@trans.available)).to eq("\"-Infinity\"")
221
- end
222
-
223
- it 'should write string' do
224
- @prot.write_string('this is a test string')
225
- a = @trans.read(@trans.available)
226
- expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY))
227
- expect(a.encoding).to eq(Encoding::BINARY)
228
- end
229
-
230
- it 'should write string with unicode characters' do
231
- @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD")
232
- a = @trans.read(@trans.available)
233
- expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY))
234
- expect(a.encoding).to eq(Encoding::BINARY)
235
- end
236
-
237
- it "should write binary" do
238
- @prot.write_binary("this is a base64 string")
239
- expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"")
240
- end
241
-
242
- it "should write long binary" do
243
- @prot.write_binary((0...256).to_a.pack('C*'))
244
- expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
245
- end
246
-
247
- it "should write a uuid" do
248
- @prot.write_uuid("00112233-4455-6677-8899-aabbccddeeff")
249
- expect(@trans.read(@trans.available)).to eq("\"00112233-4455-6677-8899-aabbccddeeff\"")
250
- end
251
-
252
- it "should get type name for type id" do
253
- expect { @prot.get_type_name_for_type_id(Thrift::Types::STOP) }.to raise_error(NotImplementedError)
254
- expect { @prot.get_type_name_for_type_id(Thrift::Types::VOID) }.to raise_error(NotImplementedError)
255
- expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf")
256
- expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8")
257
- expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl")
258
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16")
259
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32")
260
- expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64")
261
- expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str")
262
- expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec")
263
- expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map")
264
- expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set")
265
- expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst")
266
- end
267
-
268
- it "should get type id for type name" do
269
- expect { @prot.get_type_id_for_type_name("pp") }.to raise_error(NotImplementedError)
270
- expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL)
271
- expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE)
272
- expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE)
273
- expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16)
274
- expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32)
275
- expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64)
276
- expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING)
277
- expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT)
278
- expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP)
279
- expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET)
280
- expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST)
281
- end
282
-
283
- it "should read json syntax char" do
284
- @trans.write('F')
285
- expect { @prot.read_json_syntax_char('G') }.to raise_error(Thrift::ProtocolException)
286
- @trans.write('H')
287
- @prot.read_json_syntax_char('H')
288
- end
289
-
290
- it "should read json escape char" do
291
- @trans.write('0054')
292
- expect(@prot.read_json_escape_char).to eq('T')
293
-
294
- @trans.write("\"\\\"\"")
295
- expect(@prot.read_json_string(false)).to eq("\"")
296
-
297
- @trans.write("\"\\\\\"")
298
- expect(@prot.read_json_string(false)).to eq("\\")
299
-
300
- @trans.write("\"\\/\"")
301
- expect(@prot.read_json_string(false)).to eq("\/")
302
-
303
- @trans.write("\"\\b\"")
304
- expect(@prot.read_json_string(false)).to eq("\b")
305
-
306
- @trans.write("\"\\f\"")
307
- expect(@prot.read_json_string(false)).to eq("\f")
308
-
309
- @trans.write("\"\\n\"")
310
- expect(@prot.read_json_string(false)).to eq("\n")
311
-
312
- @trans.write("\"\\r\"")
313
- expect(@prot.read_json_string(false)).to eq("\r")
314
-
315
- @trans.write("\"\\t\"")
316
- expect(@prot.read_json_string(false)).to eq("\t")
317
- end
318
-
319
- it "should read json string" do
320
- @trans.write("\"\\P")
321
- expect { @prot.read_json_string(false) }.to raise_error(Thrift::ProtocolException)
322
-
323
- @trans.write("\"this is a test string\"")
324
- expect(@prot.read_json_string).to eq("this is a test string")
325
- end
326
-
327
- it "should read json base64" do
328
- @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
329
- expect(@prot.read_json_base64).to eq("this is a test string")
330
- end
331
-
332
- it "should is json numeric" do
333
- expect(@prot.is_json_numeric("A")).to eq(false)
334
- expect(@prot.is_json_numeric("+")).to eq(true)
335
- expect(@prot.is_json_numeric("-")).to eq(true)
336
- expect(@prot.is_json_numeric(".")).to eq(true)
337
- expect(@prot.is_json_numeric("0")).to eq(true)
338
- expect(@prot.is_json_numeric("1")).to eq(true)
339
- expect(@prot.is_json_numeric("2")).to eq(true)
340
- expect(@prot.is_json_numeric("3")).to eq(true)
341
- expect(@prot.is_json_numeric("4")).to eq(true)
342
- expect(@prot.is_json_numeric("5")).to eq(true)
343
- expect(@prot.is_json_numeric("6")).to eq(true)
344
- expect(@prot.is_json_numeric("7")).to eq(true)
345
- expect(@prot.is_json_numeric("8")).to eq(true)
346
- expect(@prot.is_json_numeric("9")).to eq(true)
347
- expect(@prot.is_json_numeric("E")).to eq(true)
348
- expect(@prot.is_json_numeric("e")).to eq(true)
349
- end
350
-
351
- it "should read json numeric chars" do
352
- @trans.write("1.453E45T")
353
- expect(@prot.read_json_numeric_chars).to eq("1.453E45")
354
- end
355
-
356
- it "should read json integer" do
357
- @trans.write("1.45\"\"")
358
- expect { @prot.read_json_integer }.to raise_error(Thrift::ProtocolException)
359
- @prot.read_string
360
-
361
- @trans.write("1453T")
362
- expect(@prot.read_json_integer).to eq(1453)
363
- end
364
-
365
- it "should read json double" do
366
- @trans.write("1.45e3e01\"\"")
367
- expect { @prot.read_json_double }.to raise_error(Thrift::ProtocolException)
368
- @prot.read_string
369
-
370
- @trans.write("\"1.453e01\"")
371
- expect { @prot.read_json_double }.to raise_error(Thrift::ProtocolException)
372
-
373
- @trans.write("1.453e01\"\"")
374
- expect(@prot.read_json_double).to eq(14.53)
375
- @prot.read_string
376
-
377
- @trans.write("\"NaN\"")
378
- expect(@prot.read_json_double.nan?).to eq(true)
379
-
380
- @trans.write("\"Infinity\"")
381
- expect(@prot.read_json_double).to eq(+1.0/0.0)
382
-
383
- @trans.write("\"-Infinity\"")
384
- expect(@prot.read_json_double).to eq(-1.0/0.0)
385
- end
386
-
387
- it "should read json object start" do
388
- @trans.write("{")
389
- expect(@prot.read_json_object_start).to eq(nil)
390
- end
391
-
392
- it "should read json object end" do
393
- @trans.write("}")
394
- expect(@prot.read_json_object_end).to eq(nil)
395
- end
396
-
397
- it "should read json array start" do
398
- @trans.write("[")
399
- expect(@prot.read_json_array_start).to eq(nil)
400
- end
401
-
402
- it "should read json array end" do
403
- @trans.write("]")
404
- expect(@prot.read_json_array_end).to eq(nil)
405
- end
406
-
407
- it "should read_message_begin" do
408
- @trans.write("[2,")
409
- expect { @prot.read_message_begin }.to raise_error(Thrift::ProtocolException)
410
-
411
- @trans.write("[1,\"name\",12,32\"\"")
412
- expect(@prot.read_message_begin).to eq(["name", 12, 32])
413
- end
414
-
415
- it "should read message end" do
416
- @trans.write("]")
417
- expect(@prot.read_message_end).to eq(nil)
418
- end
419
-
420
- it "should read struct begin" do
421
- @trans.write("{")
422
- expect(@prot.read_struct_begin).to eq(nil)
423
- end
424
-
425
- it "should read struct end" do
426
- @trans.write("}")
427
- expect(@prot.read_struct_end).to eq(nil)
428
- end
429
-
430
- it "should read field begin" do
431
- @trans.write("1{\"rec\"")
432
- expect(@prot.read_field_begin).to eq([nil, 12, 1])
433
- end
434
-
435
- it "should read field end" do
436
- @trans.write("}")
437
- expect(@prot.read_field_end).to eq(nil)
438
- end
439
-
440
- it "should read map begin" do
441
- @trans.write("[\"rec\",\"lst\",2,{")
442
- expect(@prot.read_map_begin).to eq([12, 15, 2])
443
- end
444
-
445
- it "should read map end" do
446
- @trans.write("}]")
447
- expect(@prot.read_map_end).to eq(nil)
448
- end
449
-
450
- it "should read list begin" do
451
- @trans.write("[\"rec\",2\"\"")
452
- expect(@prot.read_list_begin).to eq([12, 2])
453
- end
454
-
455
- it "should read list end" do
456
- @trans.write("]")
457
- expect(@prot.read_list_end).to eq(nil)
458
- end
459
-
460
- it "should read set begin" do
461
- @trans.write("[\"rec\",2\"\"")
462
- expect(@prot.read_set_begin).to eq([12, 2])
463
- end
464
-
465
- it "should read set end" do
466
- @trans.write("]")
467
- expect(@prot.read_set_end).to eq(nil)
468
- end
469
-
470
- it "should read bool" do
471
- @trans.write("0\"\"")
472
- expect(@prot.read_bool).to eq(false)
473
- @prot.read_string
474
-
475
- @trans.write("1\"\"")
476
- expect(@prot.read_bool).to eq(true)
477
- end
478
-
479
- it "should read byte" do
480
- @trans.write("60\"\"")
481
- expect(@prot.read_byte).to eq(60)
482
- end
483
-
484
- it "should read i16" do
485
- @trans.write("1000\"\"")
486
- expect(@prot.read_i16).to eq(1000)
487
- end
488
-
489
- it "should read i32" do
490
- @trans.write("3000000000\"\"")
491
- expect(@prot.read_i32).to eq(3000000000)
492
- end
493
-
494
- it "should read i64" do
495
- @trans.write("6000000000\"\"")
496
- expect(@prot.read_i64).to eq(6000000000)
497
- end
498
-
499
- it "should read double" do
500
- @trans.write("12.23\"\"")
501
- expect(@prot.read_double).to eq(12.23)
502
- end
503
-
504
- it 'should read string' do
505
- @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY))
506
- a = @prot.read_string
507
- expect(a).to eq('this is a test string')
508
- expect(a.encoding).to eq(Encoding::UTF_8)
509
- end
510
-
511
- it 'should read string with unicode characters' do
512
- @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY))
513
- a = @prot.read_string
514
- expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD")
515
- expect(a.encoding).to eq(Encoding::UTF_8)
516
- end
517
-
518
- it "should read binary" do
519
- @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
520
- expect(@prot.read_binary).to eq("this is a test string")
521
- end
522
-
523
- it "should read long binary" do
524
- @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"")
525
- expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a)
526
- end
527
-
528
- it "should read a uuid" do
529
- @trans.write("\"00112233-4455-6677-8899-aabbccddeeff\"")
530
- expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff")
531
- end
532
-
533
- it "should normalize uppercase uuid on read" do
534
- @trans.write("\"00112233-4455-6677-8899-AABBCCDDEEFF\"")
535
- expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff")
536
- end
537
-
538
- it "should provide a reasonable to_s" do
539
- expect(@prot.to_s).to eq("json(memory)")
540
- end
541
- end
542
-
543
- describe Thrift::JsonProtocolFactory do
544
- it "should create a JsonProtocol" do
545
- expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol)
546
- end
547
-
548
- it "should provide a reasonable to_s" do
549
- expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json")
550
- end
551
- end
552
- end
@@ -1,66 +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 'namespaced generation' do
23
- before do
24
- require 'namespaced_spec_namespace/namespaced_nonblocking_service'
25
- end
26
-
27
- it "generated the right files" do
28
- prefix = File.expand_path("../gen-rb", __FILE__)
29
- ["namespaced_spec_namespace/namespaced_nonblocking_service.rb",
30
- "namespaced_spec_namespace/thrift_namespaced_spec_constants.rb",
31
- "namespaced_spec_namespace/thrift_namespaced_spec_types.rb",
32
- "other_namespace/referenced_constants.rb",
33
- "other_namespace/referenced_types.rb"
34
- ].each do |name|
35
- expect(File.exist?(File.join(prefix, name))).to be_truthy
36
- end
37
- end
38
-
39
- it "did not generate the wrong files" do
40
- prefix = File.expand_path("../gen-rb", __FILE__)
41
- ["namespaced_nonblocking_service.rb",
42
- "thrift_namespaced_spec_constants.rb",
43
- "thrift_namespaced_spec_types.rb",
44
- "referenced_constants.rb",
45
- "referenced_types.rb"
46
- ].each do |name|
47
- expect(File.exist?(File.join(prefix, name))).not_to be_truthy
48
- end
49
- end
50
-
51
- it "has a service class in the right place" do
52
- expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
53
- end
54
-
55
- it "has a struct in the right place" do
56
- expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
57
- end
58
-
59
- it "required an included file" do
60
- expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
61
- end
62
-
63
- it "extended a service" do
64
- require "extended/extended_service"
65
- end
66
- end