upfluence-thrift 1.1.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/extconf.rb +1 -4
  3. data/lib/thrift/client.rb +31 -1
  4. data/lib/thrift/definition.rb +64 -0
  5. data/lib/thrift/exceptions.rb +5 -5
  6. data/lib/thrift/middleware.rb +50 -0
  7. data/lib/thrift/processor.rb +3 -3
  8. data/lib/thrift/struct.rb +10 -10
  9. data/lib/thrift/transport/base_transport.rb +9 -7
  10. data/lib/thrift/transport/server_socket.rb +6 -6
  11. data/lib/thrift/types/known/any.rb +179 -0
  12. data/lib/thrift/types/known/any_constants.rb +17 -0
  13. data/lib/thrift/types/known/any_types.rb +43 -0
  14. data/lib/thrift/types/known/duration.rb +27 -0
  15. data/lib/thrift/types/known/duration_constants.rb +17 -0
  16. data/lib/thrift/types/known/duration_types.rb +43 -0
  17. data/lib/thrift/types/known/timestamp.rb +31 -0
  18. data/lib/thrift/types/known/timestamp_constants.rb +17 -0
  19. data/lib/thrift/types/known/timestamp_types.rb +43 -0
  20. data/lib/thrift/types/value.rb +114 -0
  21. data/lib/thrift/types/value_constants.rb +15 -0
  22. data/lib/thrift/types/value_types.rb +213 -0
  23. data/lib/thrift/types.rb +4 -4
  24. data/lib/thrift.rb +6 -4
  25. data/spec/binary_protocol_spec_shared.rb +57 -60
  26. data/spec/client_spec.rb +2 -2
  27. data/spec/compact_protocol_spec.rb +26 -20
  28. data/spec/http_client_spec.rb +7 -20
  29. data/spec/nonblocking_server_spec.rb +1 -1
  30. data/spec/processor_spec.rb +1 -1
  31. data/spec/struct_spec.rb +2 -2
  32. data/spec/types/known/any_spec.rb +44 -0
  33. data/spec/types/known/duration_spec.rb +20 -0
  34. data/spec/types/known/timestamp_spec.rb +17 -0
  35. data/spec/types/value_spec.rb +43 -0
  36. data/spec/types_spec.rb +2 -2
  37. metadata +114 -150
  38. data/benchmark/gen-rb/benchmark_constants.rb +0 -11
  39. data/benchmark/gen-rb/benchmark_service.rb +0 -91
  40. data/benchmark/gen-rb/benchmark_types.rb +0 -10
  41. data/spec/gen-rb/base/base_service.rb +0 -91
  42. data/spec/gen-rb/base/base_service_constants.rb +0 -11
  43. data/spec/gen-rb/base/base_service_types.rb +0 -26
  44. data/spec/gen-rb/extended/extended_service.rb +0 -89
  45. data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
  46. data/spec/gen-rb/extended/extended_service_types.rb +0 -12
  47. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -299
  48. data/spec/gen-rb/flat/referenced_constants.rb +0 -11
  49. data/spec/gen-rb/flat/referenced_types.rb +0 -17
  50. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
  51. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
  52. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -299
  53. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
  54. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
  55. data/spec/gen-rb/nonblocking_service.rb +0 -299
  56. data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
  57. data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
  58. data/spec/gen-rb/thrift_spec_constants.rb +0 -11
  59. data/spec/gen-rb/thrift_spec_types.rb +0 -538
  60. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -274
  61. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -761
  62. data/test/debug_proto/gen-rb/empty_service.rb +0 -31
  63. data/test/debug_proto/gen-rb/inherited.rb +0 -90
  64. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -93
  65. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -92
  66. data/test/debug_proto/gen-rb/srv.rb +0 -361
@@ -38,25 +38,25 @@ shared_examples_for 'a binary protocol' do
38
38
 
39
39
  it "should make strict_write readable" do
40
40
  @prot.strict_write.should 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
  @trans.read(@trans.available).should == [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
  @trans.read(@trans.available).should == "\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
  @trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
58
58
  end
59
-
59
+
60
60
 
61
61
  # message footer is a noop
62
62
 
@@ -64,44 +64,44 @@ shared_examples_for 'a binary protocol' do
64
64
  @prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
65
65
  @trans.read(@trans.available).should == [Thrift::Types::DOUBLE, 3].pack("cn")
66
66
  end
67
-
67
+
68
68
  # field footer is a noop
69
-
69
+
70
70
  it "should write the STOP field" do
71
71
  @prot.write_field_stop
72
72
  @trans.read(1).should == "\000"
73
73
  end
74
-
74
+
75
75
  it "should write the map header" do
76
76
  @prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
77
77
  @trans.read(@trans.available).should == [Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN");
78
78
  end
79
-
79
+
80
80
  # map footer is a noop
81
-
81
+
82
82
  it "should write the list header" do
83
83
  @prot.write_list_begin(Thrift::Types::I16, 42)
84
84
  @trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
85
85
  end
86
-
86
+
87
87
  # list footer is a noop
88
-
88
+
89
89
  it "should write the set header" do
90
90
  @prot.write_set_begin(Thrift::Types::I16, 42)
91
91
  @trans.read(@trans.available).should == [Thrift::Types::I16, 42].pack("cN")
92
92
  end
93
-
93
+
94
94
  it "should write a bool" do
95
95
  @prot.write_bool(true)
96
96
  @prot.write_bool(false)
97
97
  @trans.read(@trans.available).should == "\001\000"
98
98
  end
99
-
99
+
100
100
  it "should treat a nil bool as false" do
101
101
  @prot.write_bool(nil)
102
102
  @trans.read(1).should == "\000"
103
103
  end
104
-
104
+
105
105
  it "should write a byte" do
106
106
  # byte is small enough, let's check -128..127
107
107
  (-128..127).each do |i|
@@ -117,11 +117,11 @@ shared_examples_for 'a binary protocol' do
117
117
  # and lastly, a Bignum is going to error out
118
118
  lambda { @prot.write_byte(2**65) }.should raise_error(RangeError)
119
119
  end
120
-
120
+
121
121
  it "should error gracefully when trying to write a nil byte" do
122
122
  lambda { @prot.write_byte(nil) }.should raise_error
123
123
  end
124
-
124
+
125
125
  it "should write an i16" do
126
126
  # try a random scattering of values
127
127
  # include the signed i16 minimum/maximum
@@ -130,17 +130,17 @@ shared_examples_for 'a binary protocol' do
130
130
  end
131
131
  # and try something out of signed range, it should clip
132
132
  @prot.write_i16(2**15 + 5)
133
-
133
+
134
134
  @trans.read(@trans.available).should == "\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005"
135
-
135
+
136
136
  # a Bignum should error
137
137
  # lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
138
138
  end
139
-
139
+
140
140
  it "should error gracefully when trying to write a nil i16" do
141
141
  lambda { @prot.write_i16(nil) }.should raise_error
142
142
  end
143
-
143
+
144
144
  it "should write an i32" do
145
145
  # try a random scattering of values
146
146
  # include the signed i32 minimum/maximum
@@ -150,14 +150,14 @@ shared_examples_for 'a binary protocol' do
150
150
  # try something out of signed range, it should clip
151
151
  @trans.read(@trans.available).should == "\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"
152
152
  [2 ** 31 + 5, 2 ** 65 + 5].each do |i|
153
- lambda { @prot.write_i32(i) }.should raise_error(RangeError)
153
+ lambda { @prot.write_i32(i) }.should raise_error(RangeError)
154
154
  end
155
155
  end
156
-
156
+
157
157
  it "should error gracefully when trying to write a nil i32" do
158
158
  lambda { @prot.write_i32(nil) }.should raise_error
159
159
  end
160
-
160
+
161
161
  it "should write an i64" do
162
162
  # try a random scattering of values
163
163
  # try the signed i64 minimum/maximum
@@ -176,11 +176,11 @@ shared_examples_for 'a binary protocol' do
176
176
  "\177\377\377\377\377\377\377\377"].join("")
177
177
  lambda { @prot.write_i64(2 ** 65 + 5) }.should raise_error(RangeError)
178
178
  end
179
-
179
+
180
180
  it "should error gracefully when trying to write a nil i64" do
181
181
  lambda { @prot.write_i64(nil) }.should raise_error
182
182
  end
183
-
183
+
184
184
  it "should write a double" do
185
185
  # try a random scattering of values, including min/max
186
186
  values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
@@ -189,7 +189,7 @@ shared_examples_for 'a binary protocol' do
189
189
  @trans.read(@trans.available).should == [f].pack("G")
190
190
  end
191
191
  end
192
-
192
+
193
193
  it "should error gracefully when trying to write a nil double" do
194
194
  lambda { @prot.write_double(nil) }.should raise_error
195
195
  end
@@ -246,28 +246,28 @@ shared_examples_for 'a binary protocol' do
246
246
  it "should error gracefully when trying to write a nil string" do
247
247
  lambda { @prot.write_string(nil) }.should raise_error
248
248
  end
249
-
249
+
250
250
  it "should write the message header without version when writes are not strict" do
251
251
  @prot = protocol_class.new(@trans, true, false) # no strict write
252
252
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
253
253
  @trans.read(@trans.available).should == "\000\000\000\vtestMessage\001\000\000\000\021"
254
254
  end
255
-
255
+
256
256
  it "should write the message header with a version when writes are strict" do
257
257
  @prot = protocol_class.new(@trans) # strict write
258
258
  @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
259
259
  @trans.read(@trans.available).should == "\200\001\000\001\000\000\000\vtestMessage\000\000\000\021"
260
260
  end
261
-
261
+
262
262
  # message footer is a noop
263
-
263
+
264
264
  it "should read a field header" do
265
265
  @trans.write([Thrift::Types::STRING, 3].pack("cn"))
266
266
  @prot.read_field_begin.should == [nil, Thrift::Types::STRING, 3]
267
267
  end
268
-
268
+
269
269
  # field footer is a noop
270
-
270
+
271
271
  it "should read a stop field" do
272
272
  @trans.write([Thrift::Types::STOP].pack("c"));
273
273
  @prot.read_field_begin.should == [nil, Thrift::Types::STOP, 0]
@@ -277,36 +277,36 @@ shared_examples_for 'a binary protocol' do
277
277
  @trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
278
278
  @prot.read_map_begin.should == [Thrift::Types::DOUBLE, Thrift::Types::I64, 42]
279
279
  end
280
-
280
+
281
281
  # map footer is a noop
282
-
282
+
283
283
  it "should read a list header" do
284
284
  @trans.write([Thrift::Types::STRING, 17].pack("cN"))
285
285
  @prot.read_list_begin.should == [Thrift::Types::STRING, 17]
286
286
  end
287
-
287
+
288
288
  # list footer is a noop
289
-
289
+
290
290
  it "should read a set header" do
291
291
  @trans.write([Thrift::Types::STRING, 17].pack("cN"))
292
292
  @prot.read_set_begin.should == [Thrift::Types::STRING, 17]
293
293
  end
294
-
294
+
295
295
  # set footer is a noop
296
-
296
+
297
297
  it "should read a bool" do
298
298
  @trans.write("\001\000");
299
299
  @prot.read_bool.should == true
300
300
  @prot.read_bool.should == false
301
301
  end
302
-
302
+
303
303
  it "should read a byte" do
304
304
  [-128, -57, -3, 0, 17, 24, 127].each do |i|
305
305
  @trans.write([i].pack("c"))
306
306
  @prot.read_byte.should == i
307
307
  end
308
308
  end
309
-
309
+
310
310
  it "should read an i16" do
311
311
  # try a scattering of values, including min/max
312
312
  [-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
@@ -314,7 +314,7 @@ shared_examples_for 'a binary protocol' do
314
314
  @prot.read_i16.should == i
315
315
  end
316
316
  end
317
-
317
+
318
318
  it "should read an i32" do
319
319
  # try a scattering of values, including min/max
320
320
  [-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
@@ -322,7 +322,7 @@ shared_examples_for 'a binary protocol' do
322
322
  @prot.read_i32.should == i
323
323
  end
324
324
  end
325
-
325
+
326
326
  it "should read an i64" do
327
327
  # try a scattering of values, including min/max
328
328
  [-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
@@ -330,7 +330,7 @@ shared_examples_for 'a binary protocol' do
330
330
  @prot.read_i64.should == i
331
331
  end
332
332
  end
333
-
333
+
334
334
  it "should read a double" do
335
335
  # try a random scattering of values, including min/max
336
336
  [Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
@@ -383,23 +383,20 @@ shared_examples_for 'a binary protocol' do
383
383
 
384
384
  it "should perform a complete rpc with no args or return" do
385
385
  srv_test(
386
- proc {|client| client.send_voidMethod()},
387
- proc {|client| client.recv_voidMethod.should == nil}
386
+ proc {|client| client.voidMethod().should == nil },
388
387
  )
389
388
  end
390
389
 
391
390
  it "should perform a complete rpc with a primitive return type" do
392
391
  srv_test(
393
- proc {|client| client.send_primitiveMethod()},
394
- proc {|client| client.recv_primitiveMethod.should == 1}
392
+ proc {|client| client.primitiveMethod.should == 1}
395
393
  )
396
394
  end
397
395
 
398
396
  it "should perform a complete rpc with a struct return type" do
399
397
  srv_test(
400
- proc {|client| client.send_structMethod()},
401
398
  proc {|client|
402
- result = client.recv_structMethod
399
+ result = client.structMethod
403
400
  result.set_byte_map = nil
404
401
  result.map_byte_map = nil
405
402
  result.should == Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
@@ -410,14 +407,14 @@ shared_examples_for 'a binary protocol' do
410
407
  def get_socket_connection
411
408
  server = Thrift::ServerSocket.new("localhost", 9090)
412
409
  server.listen
413
-
410
+
414
411
  clientside = Thrift::Socket.new("localhost", 9090)
415
412
  clientside.open
416
413
  serverside = server.accept
417
414
  [clientside, serverside, server]
418
415
  end
419
416
 
420
- def srv_test(firstblock, secondblock)
417
+ def srv_test(block)
421
418
  clientside, serverside, server = get_socket_connection
422
419
 
423
420
  clientproto = protocol_class.new(clientside)
@@ -425,29 +422,29 @@ shared_examples_for 'a binary protocol' do
425
422
 
426
423
  processor = Srv::Processor.new(SrvHandler.new)
427
424
 
428
- client = Srv::Client.new(clientproto, clientproto)
425
+ client = Srv::Client.new(clientproto)
426
+
427
+ t = Thread.new { processor.process(serverproto, serverproto) }
429
428
 
430
- # first block
431
- firstblock.call(client)
429
+ resp = block.call(client)
432
430
 
433
- processor.process(serverproto, serverproto)
431
+ t.join
434
432
 
435
- # second block
436
- secondblock.call(client)
433
+ resp
437
434
  ensure
438
435
  clientside.close
439
436
  serverside.close
440
437
  server.close
441
438
  end
442
439
 
443
- class SrvHandler
440
+ class SrvHandler
444
441
  def voidMethod()
445
442
  end
446
-
443
+
447
444
  def primitiveMethod
448
445
  1
449
446
  end
450
-
447
+
451
448
  def structMethod
452
449
  Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
453
450
  end
data/spec/client_spec.rb CHANGED
@@ -37,7 +37,7 @@ describe 'Client' do
37
37
  end
38
38
 
39
39
  it "should send a test message" do
40
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
40
+ @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 1)
41
41
  mock_args = mock('#<TestMessage_args:mock>')
42
42
  mock_args.should_receive(:foo=).with('foo')
43
43
  mock_args.should_receive(:bar=).with(42)
@@ -66,7 +66,7 @@ describe 'Client' do
66
66
  end
67
67
 
68
68
  it "should receive a test message" do
69
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
69
+ @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::REPLY, 0]
70
70
  @prot.should_receive(:read_message_end)
71
71
  mock_klass = mock("#<MockClass:mock>")
72
72
  mock_klass.should_receive(:read).with(@prot)
@@ -31,14 +31,14 @@ describe Thrift::CompactProtocol do
31
31
  :double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
32
32
  :bool => [true, false]
33
33
  }
34
-
34
+
35
35
  it "should encode and decode naked primitives correctly" do
36
36
  TESTS.each_pair do |primitive_type, test_values|
37
37
  test_values.each do |value|
38
38
  # puts "testing #{value}" if primitive_type == :i64
39
39
  trans = Thrift::MemoryBufferTransport.new
40
40
  proto = Thrift::CompactProtocol.new(trans)
41
-
41
+
42
42
  proto.send(writer(primitive_type), value)
43
43
  # puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
44
44
  read_back = proto.send(reader(primitive_type))
@@ -46,7 +46,7 @@ describe Thrift::CompactProtocol do
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  it "should encode and decode primitives in fields correctly" do
51
51
  TESTS.each_pair do |primitive_type, test_values|
52
52
  final_primitive_type = primitive_type == :binary ? :string : primitive_type
@@ -80,32 +80,38 @@ describe Thrift::CompactProtocol do
80
80
  struct.write(proto)
81
81
 
82
82
  struct2 = CompactProtoTestStruct.new
83
- struct2.read(proto)
83
+ struct2.read(proto)
84
84
  struct2.should == struct
85
85
  end
86
86
 
87
- it "should make method calls correctly" do
88
- client_out_trans = Thrift::MemoryBufferTransport.new
87
+ xit "should make method calls correctly" do
88
+ r1, w1 = IO.pipe
89
+ r2, w2 = IO.pipe
90
+ client_out_trans = Thrift::IOStreamTransport.new(r2, w1)
89
91
  client_out_proto = Thrift::CompactProtocol.new(client_out_trans)
90
92
 
91
- client_in_trans = Thrift::MemoryBufferTransport.new
93
+ client_in_trans = Thrift::IOStreamTransport.new(r1, w2)
92
94
  client_in_proto = Thrift::CompactProtocol.new(client_in_trans)
93
95
 
94
96
  processor = Srv::Processor.new(JankyHandler.new)
95
97
 
96
- client = Srv::Client.new(client_in_proto, client_out_proto)
97
- client.send_Janky(1)
98
- # puts client_out_trans.inspect_buffer
99
- processor.process(client_out_proto, client_in_proto)
100
- client.recv_Janky.should == 2
98
+ client = Srv::Client.new(
99
+ Thrift::BaseClient.new(client_in_proto, client_out_proto)
100
+ )
101
+
102
+ t = Thread.new { processor.process(client_in_proto, client_out_proto) }
103
+
104
+ client.Janky(1).should == 2
105
+
106
+ t.join
101
107
  end
102
-
108
+
103
109
  it "should deal with fields following fields that have non-delta ids" do
104
110
  brcp = BreaksRubyCompactProtocol.new(
105
- :field1 => "blah",
111
+ :field1 => "blah",
106
112
  :field2 => BigFieldIdStruct.new(
107
- :field1 => "string1",
108
- :field2 => "string2"),
113
+ :field1 => "string1",
114
+ :field2 => "string2"),
109
115
  :field3 => 3)
110
116
  ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
111
117
  bytes = ser.serialize(brcp)
@@ -115,7 +121,7 @@ describe Thrift::CompactProtocol do
115
121
  deser.deserialize(brcp2, bytes)
116
122
  brcp2.should == brcp
117
123
  end
118
-
124
+
119
125
  it "should deserialize an empty map to an empty hash" do
120
126
  struct = SingleMapTestStruct.new(:i32_map => {})
121
127
  ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
@@ -126,17 +132,17 @@ describe Thrift::CompactProtocol do
126
132
  deser.deserialize(struct2, bytes)
127
133
  struct.should == struct2
128
134
  end
129
-
135
+
130
136
  class JankyHandler
131
137
  def Janky(i32arg)
132
138
  i32arg * 2
133
139
  end
134
140
  end
135
-
141
+
136
142
  def writer(sym)
137
143
  "write_#{sym.to_s}"
138
144
  end
139
-
145
+
140
146
  def reader(sym)
141
147
  "read_#{sym.to_s}"
142
148
  end
@@ -23,7 +23,10 @@ describe 'Thrift::HTTPClientTransport' do
23
23
 
24
24
  describe Thrift::HTTPClientTransport do
25
25
  before(:each) do
26
- @client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
26
+ @client = Thrift::HTTPClientTransport.new(
27
+ "http://my.domain.com/path/to/service?param=value",
28
+ retries: 0
29
+ )
27
30
  end
28
31
 
29
32
  it "should always be open" do
@@ -41,6 +44,7 @@ describe 'Thrift::HTTPClientTransport' do
41
44
  http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
42
45
  mock("Net::HTTPOK").tap do |response|
43
46
  response.should_receive(:body).and_return "data"
47
+ response.should_receive(:value).and_return nil
44
48
  end
45
49
  end
46
50
  end
@@ -48,25 +52,6 @@ describe 'Thrift::HTTPClientTransport' do
48
52
  @client.flush
49
53
  @client.read(10).should == "data"
50
54
  end
51
-
52
- it "should send custom headers if defined" do
53
- @client.write "test"
54
- custom_headers = {"Cookie" => "Foo"}
55
- headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
56
-
57
- @client.add_headers(custom_headers)
58
- Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
59
- mock("Net::HTTP").tap do |http|
60
- http.should_receive(:use_ssl=).with(false)
61
- http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
62
- mock("Net::HTTPOK").tap do |response|
63
- response.should_receive(:body).and_return "data"
64
- end
65
- end
66
- end
67
- end
68
- @client.flush
69
- end
70
55
  end
71
56
 
72
57
  describe 'ssl enabled' do
@@ -88,6 +73,7 @@ describe 'Thrift::HTTPClientTransport' do
88
73
  "Content-Type" => "application/x-thrift").and_return do
89
74
  mock("Net::HTTPOK").tap do |response|
90
75
  response.should_receive(:body).and_return "data"
76
+ response.should_receive(:value).and_return nil
91
77
  end
92
78
  end
93
79
  end
@@ -109,6 +95,7 @@ describe 'Thrift::HTTPClientTransport' do
109
95
  "Content-Type" => "application/x-thrift").and_return do
110
96
  mock("Net::HTTPOK").tap do |response|
111
97
  response.should_receive(:body).and_return "data"
98
+ response.should_receive(:value).and_return nil
112
99
  end
113
100
  end
114
101
  end
@@ -157,7 +157,7 @@ describe 'NonblockingServer' do
157
157
  when :hello
158
158
  result << client.greeting(true) # ignore result
159
159
  when :sleep
160
- client.sleep(args[0] || 0.5)
160
+ client.sleep(args[0].to_f || 0.5)
161
161
  result << :slept
162
162
  when :shutdown
163
163
  client.shutdown
@@ -45,7 +45,7 @@ describe 'Processor' do
45
45
  @processor.process(@prot, @prot).should == true
46
46
  end
47
47
 
48
- it "should raise an ApplicationException when the received message cannot be processed" do
48
+ xit "should raise an ApplicationException when the received message cannot be processed" do
49
49
  @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
50
50
  @prot.should_receive(:skip).with(Thrift::Types::STRUCT).ordered
51
51
  @prot.should_receive(:read_message_end).ordered
data/spec/struct_spec.rb CHANGED
@@ -227,7 +227,7 @@ describe 'Struct' do
227
227
  it "should support optional type-checking in Thrift::Struct.new" do
228
228
  Thrift.type_checking = true
229
229
  begin
230
- lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
230
+ lambda { SpecNamespace::Hello.new(:greeting => 3) }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
231
231
  ensure
232
232
  Thrift.type_checking = false
233
233
  end
@@ -238,7 +238,7 @@ describe 'Struct' do
238
238
  Thrift.type_checking = true
239
239
  begin
240
240
  hello = SpecNamespace::Hello.new
241
- lambda { hello.greeting = 3 }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Fixnum for field greeting")
241
+ lambda { hello.greeting = 3 }.should raise_error(Thrift::TypeError, "Expected Types::STRING, received Integer for field greeting")
242
242
  ensure
243
243
  Thrift.type_checking = false
244
244
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/value'
3
+ require 'thrift/types/known/any'
4
+
5
+ describe 'Thrift::Types::Known::Any' do
6
+ describe 'encode' do
7
+ let(:codec) { '' }
8
+
9
+ shared_examples 'idempotent' do
10
+ it 'should be idempotent' do
11
+ Thrift::Types::Known::Any.from_object(obj, codec).to_object.should == obj
12
+ end
13
+ end
14
+
15
+ subject { Thrift::Types::Known::Any.from_object(obj, codec) }
16
+
17
+ context 'thrift struct' do
18
+ let(:obj) { Thrift::Types::Value.from_object("foo") }
19
+
20
+ it { subject.type.should == 'thrift/types.value.Value' }
21
+ it { subject.value.should == '{"2":{"str":"foo"}}' }
22
+
23
+ include_examples 'idempotent'
24
+
25
+ context 'yaml only' do
26
+ let(:codec) { 'yaml' }
27
+
28
+ it { subject.type.should == 'thrift-yaml/types.value.Value' }
29
+ it { subject.value.should == "string_value: foo\n" }
30
+
31
+ include_examples 'idempotent'
32
+ end
33
+
34
+ context 'json only' do
35
+ let(:codec) { 'json' }
36
+
37
+ it { subject.type.should == 'thrift-json/types.value.Value' }
38
+ it { subject.value.should == '{"string_value":"foo"}' }
39
+
40
+ include_examples 'idempotent'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/known/duration'
3
+
4
+ describe 'Thrift::Types::Known::Duration' do
5
+ context 'from_number' do
6
+ it 'from float' do
7
+ d = Thrift::Types::Known::Duration.from_number(2.0005)
8
+
9
+ d.seconds.should == 2
10
+ d.nanos.should == 500_000
11
+ end
12
+
13
+ it 'from int' do
14
+ d = Thrift::Types::Known::Duration.from_number(127)
15
+
16
+ d.seconds.should == 127
17
+ d.nanos.should == 0
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'thrift/types/known/timestamp'
3
+
4
+ describe 'Thrift::Types::Known::Timestamp' do
5
+ context 'from_time' do
6
+ it do
7
+ t = Time.at(137, 5, :nsec)
8
+
9
+ tt = Thrift::Types::Known::Timestamp.from_time(t)
10
+
11
+ tt.seconds.should == 137
12
+ tt.nanos.should == 5
13
+
14
+ tt.to_time.should == t
15
+ end
16
+ end
17
+ end