thrift-mavericks 0.8.0 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/ext/binary_protocol_accelerated.c +21 -2
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +24 -7
- data/ext/constants.h +5 -5
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +11 -8
- data/ext/protocol.c +0 -185
- data/ext/protocol.h +0 -20
- data/ext/struct.c +0 -3
- data/ext/thrift_native.c +10 -11
- data/lib/thrift.rb +3 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/exceptions.rb +3 -0
- data/lib/thrift/protocol/base_protocol.rb +96 -9
- data/lib/thrift/protocol/binary_protocol.rb +15 -7
- data/lib/thrift/protocol/compact_protocol.rb +14 -6
- data/lib/thrift/protocol/json_protocol.rb +766 -0
- data/lib/thrift/server/mongrel_http_server.rb +2 -0
- data/lib/thrift/server/thin_http_server.rb +91 -0
- data/lib/thrift/struct.rb +1 -1
- data/lib/thrift/struct_union.rb +2 -2
- data/lib/thrift/transport/base_transport.rb +22 -20
- data/lib/thrift/transport/buffered_transport.rb +16 -10
- data/lib/thrift/transport/framed_transport.rb +11 -10
- data/lib/thrift/transport/http_client_transport.rb +11 -6
- data/lib/thrift/transport/io_stream_transport.rb +1 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
- data/lib/thrift/transport/socket.rb +4 -2
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +108 -51
- data/spec/base_transport_spec.rb +49 -50
- data/spec/binary_protocol_accelerated_spec.rb +9 -13
- data/spec/binary_protocol_spec.rb +15 -10
- data/spec/binary_protocol_spec_shared.rb +92 -12
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +13 -14
- data/spec/compact_protocol_spec.rb +4 -5
- data/spec/exception_spec.rb +39 -40
- data/spec/gen-rb/thrift_spec_types.rb +192 -0
- data/spec/http_client_spec.rb +65 -9
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/nonblocking_server_spec.rb +18 -20
- data/spec/processor_spec.rb +13 -16
- data/spec/serializer_spec.rb +17 -19
- data/spec/server_socket_spec.rb +6 -7
- data/spec/server_spec.rb +46 -58
- data/spec/socket_spec.rb +11 -11
- data/spec/socket_spec_shared.rb +1 -1
- data/spec/spec_helper.rb +13 -10
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +84 -86
- data/spec/thin_http_server_spec.rb +140 -0
- data/spec/types_spec.rb +65 -66
- data/spec/union_spec.rb +57 -47
- data/spec/unix_socket_spec.rb +8 -9
- metadata +72 -14
- data/spec/mongrel_http_server_spec.rb +0 -117
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
#
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
@@ -17,7 +18,7 @@
|
|
17
18
|
# under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
+
require 'spec_helper'
|
21
22
|
|
22
23
|
describe Thrift::CompactProtocol do
|
23
24
|
TESTS = {
|
@@ -25,7 +26,7 @@ describe Thrift::CompactProtocol do
|
|
25
26
|
:i16 => (0..14).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
26
27
|
:i32 => (0..30).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
27
28
|
:i64 => (0..62).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
28
|
-
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "1" * 127, "1" * 3000],
|
29
|
+
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "unicode characters: \u20AC \u20AD", "1" * 127, "1" * 3000],
|
29
30
|
:binary => ["", "\001", "\001" * 5, "\001" * 14, "\001" * 15, "\001" * 127, "\001" * 3000],
|
30
31
|
:double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
|
31
32
|
:bool => [true, false]
|
@@ -133,12 +134,10 @@ describe Thrift::CompactProtocol do
|
|
133
134
|
end
|
134
135
|
|
135
136
|
def writer(sym)
|
136
|
-
sym = sym == :binary ? :string : sym
|
137
137
|
"write_#{sym.to_s}"
|
138
138
|
end
|
139
139
|
|
140
140
|
def reader(sym)
|
141
|
-
sym = sym == :binary ? :string : sym
|
142
141
|
"read_#{sym.to_s}"
|
143
142
|
end
|
144
|
-
end
|
143
|
+
end
|
data/spec/exception_spec.rb
CHANGED
@@ -17,29 +17,28 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Exception' do
|
24
23
|
|
25
|
-
describe Exception do
|
24
|
+
describe Thrift::Exception do
|
26
25
|
it "should have an accessible message" do
|
27
|
-
e = Exception.new("test message")
|
26
|
+
e = Thrift::Exception.new("test message")
|
28
27
|
e.message.should == "test message"
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe ApplicationException do
|
31
|
+
describe Thrift::ApplicationException do
|
33
32
|
it "should inherit from Thrift::Exception" do
|
34
|
-
ApplicationException.superclass.should == Exception
|
33
|
+
Thrift::ApplicationException.superclass.should == Thrift::Exception
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should have an accessible type and message" do
|
38
|
-
e = ApplicationException.new
|
39
|
-
e.type.should == ApplicationException::UNKNOWN
|
37
|
+
e = Thrift::ApplicationException.new
|
38
|
+
e.type.should == Thrift::ApplicationException::UNKNOWN
|
40
39
|
e.message.should be_nil
|
41
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
42
|
-
e.type.should == ApplicationException::UNKNOWN_METHOD
|
40
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
41
|
+
e.type.should == Thrift::ApplicationException::UNKNOWN_METHOD
|
43
42
|
e.message.should == "test message"
|
44
43
|
end
|
45
44
|
|
@@ -47,79 +46,79 @@ class ThriftExceptionSpec < Spec::ExampleGroup
|
|
47
46
|
prot = mock("MockProtocol")
|
48
47
|
prot.should_receive(:read_struct_begin).ordered
|
49
48
|
prot.should_receive(:read_field_begin).exactly(3).times.and_return(
|
50
|
-
["message", Types::STRING, 1],
|
51
|
-
["type", Types::I32, 2],
|
52
|
-
[nil, Types::STOP, 0]
|
49
|
+
["message", Thrift::Types::STRING, 1],
|
50
|
+
["type", Thrift::Types::I32, 2],
|
51
|
+
[nil, Thrift::Types::STOP, 0]
|
53
52
|
)
|
54
53
|
prot.should_receive(:read_string).ordered.and_return "test message"
|
55
|
-
prot.should_receive(:read_i32).ordered.and_return ApplicationException::BAD_SEQUENCE_ID
|
54
|
+
prot.should_receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
|
56
55
|
prot.should_receive(:read_field_end).exactly(2).times
|
57
56
|
prot.should_receive(:read_struct_end).ordered
|
58
57
|
|
59
|
-
e = ApplicationException.new
|
58
|
+
e = Thrift::ApplicationException.new
|
60
59
|
e.read(prot)
|
61
60
|
e.message.should == "test message"
|
62
|
-
e.type.should == ApplicationException::BAD_SEQUENCE_ID
|
61
|
+
e.type.should == Thrift::ApplicationException::BAD_SEQUENCE_ID
|
63
62
|
end
|
64
63
|
|
65
64
|
it "should skip bad fields when reading a struct" do
|
66
65
|
prot = mock("MockProtocol")
|
67
66
|
prot.should_receive(:read_struct_begin).ordered
|
68
67
|
prot.should_receive(:read_field_begin).exactly(5).times.and_return(
|
69
|
-
["type", Types::I32, 2],
|
70
|
-
["type", Types::STRING, 2],
|
71
|
-
["message", Types::MAP, 1],
|
72
|
-
["message", Types::STRING, 3],
|
73
|
-
[nil, Types::STOP, 0]
|
68
|
+
["type", Thrift::Types::I32, 2],
|
69
|
+
["type", Thrift::Types::STRING, 2],
|
70
|
+
["message", Thrift::Types::MAP, 1],
|
71
|
+
["message", Thrift::Types::STRING, 3],
|
72
|
+
[nil, Thrift::Types::STOP, 0]
|
74
73
|
)
|
75
|
-
prot.should_receive(:read_i32).and_return ApplicationException::INVALID_MESSAGE_TYPE
|
76
|
-
prot.should_receive(:skip).with(Types::STRING).twice
|
77
|
-
prot.should_receive(:skip).with(Types::MAP)
|
74
|
+
prot.should_receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
75
|
+
prot.should_receive(:skip).with(Thrift::Types::STRING).twice
|
76
|
+
prot.should_receive(:skip).with(Thrift::Types::MAP)
|
78
77
|
prot.should_receive(:read_field_end).exactly(4).times
|
79
78
|
prot.should_receive(:read_struct_end).ordered
|
80
79
|
|
81
|
-
e = ApplicationException.new
|
80
|
+
e = Thrift::ApplicationException.new
|
82
81
|
e.read(prot)
|
83
82
|
e.message.should be_nil
|
84
|
-
e.type.should == ApplicationException::INVALID_MESSAGE_TYPE
|
83
|
+
e.type.should == Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should write a Thrift::ApplicationException struct to the oprot" do
|
88
87
|
prot = mock("MockProtocol")
|
89
88
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
90
|
-
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
89
|
+
prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
91
90
|
prot.should_receive(:write_string).with("test message").ordered
|
92
|
-
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
93
|
-
prot.should_receive(:write_i32).with(ApplicationException::UNKNOWN_METHOD).ordered
|
91
|
+
prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
92
|
+
prot.should_receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
|
94
93
|
prot.should_receive(:write_field_end).twice
|
95
94
|
prot.should_receive(:write_field_stop).ordered
|
96
95
|
prot.should_receive(:write_struct_end).ordered
|
97
96
|
|
98
|
-
e = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, "test message")
|
97
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
99
98
|
e.write(prot)
|
100
99
|
end
|
101
100
|
|
102
101
|
it "should skip nil fields when writing to the oprot" do
|
103
102
|
prot = mock("MockProtocol")
|
104
103
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
105
|
-
prot.should_receive(:write_field_begin).with("message", Types::STRING, 1).ordered
|
104
|
+
prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
106
105
|
prot.should_receive(:write_string).with("test message").ordered
|
107
106
|
prot.should_receive(:write_field_end).ordered
|
108
107
|
prot.should_receive(:write_field_stop).ordered
|
109
108
|
prot.should_receive(:write_struct_end).ordered
|
110
109
|
|
111
|
-
e = ApplicationException.new(nil, "test message")
|
110
|
+
e = Thrift::ApplicationException.new(nil, "test message")
|
112
111
|
e.write(prot)
|
113
112
|
|
114
113
|
prot = mock("MockProtocol")
|
115
114
|
prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
116
|
-
prot.should_receive(:write_field_begin).with("type", Types::I32, 2).ordered
|
117
|
-
prot.should_receive(:write_i32).with(ApplicationException::BAD_SEQUENCE_ID).ordered
|
115
|
+
prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
116
|
+
prot.should_receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
|
118
117
|
prot.should_receive(:write_field_end).ordered
|
119
118
|
prot.should_receive(:write_field_stop).ordered
|
120
119
|
prot.should_receive(:write_struct_end).ordered
|
121
120
|
|
122
|
-
e = ApplicationException.new(ApplicationException::BAD_SEQUENCE_ID)
|
121
|
+
e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
123
122
|
e.write(prot)
|
124
123
|
|
125
124
|
prot = mock("MockProtocol")
|
@@ -127,15 +126,15 @@ class ThriftExceptionSpec < Spec::ExampleGroup
|
|
127
126
|
prot.should_receive(:write_field_stop).ordered
|
128
127
|
prot.should_receive(:write_struct_end).ordered
|
129
128
|
|
130
|
-
e = ApplicationException.new(nil)
|
129
|
+
e = Thrift::ApplicationException.new(nil)
|
131
130
|
e.write(prot)
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
describe ProtocolException do
|
134
|
+
describe Thrift::ProtocolException do
|
136
135
|
it "should have an accessible type" do
|
137
|
-
prot = ProtocolException.new(ProtocolException::SIZE_LIMIT, "message")
|
138
|
-
prot.type.should == ProtocolException::SIZE_LIMIT
|
136
|
+
prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
|
137
|
+
prot.type.should == Thrift::ProtocolException::SIZE_LIMIT
|
139
138
|
prot.message.should == "message"
|
140
139
|
end
|
141
140
|
end
|
@@ -343,4 +343,196 @@ module SpecNamespace
|
|
343
343
|
::Thrift::Struct.generate_accessors self
|
344
344
|
end
|
345
345
|
|
346
|
+
class NestedListInList
|
347
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
348
|
+
VALUE = 1
|
349
|
+
|
350
|
+
FIELDS = {
|
351
|
+
VALUE => {:type => ::Thrift::Types::LIST, :name => 'value', :element => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::BYTE}}}
|
352
|
+
}
|
353
|
+
|
354
|
+
def struct_fields; FIELDS; end
|
355
|
+
|
356
|
+
def validate
|
357
|
+
end
|
358
|
+
|
359
|
+
::Thrift::Struct.generate_accessors self
|
360
|
+
end
|
361
|
+
|
362
|
+
class NestedListInSet
|
363
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
364
|
+
VALUE = 1
|
365
|
+
|
366
|
+
FIELDS = {
|
367
|
+
VALUE => {:type => ::Thrift::Types::SET, :name => 'value', :element => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::BYTE}}}
|
368
|
+
}
|
369
|
+
|
370
|
+
def struct_fields; FIELDS; end
|
371
|
+
|
372
|
+
def validate
|
373
|
+
end
|
374
|
+
|
375
|
+
::Thrift::Struct.generate_accessors self
|
376
|
+
end
|
377
|
+
|
378
|
+
class NestedListInMapKey
|
379
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
380
|
+
VALUE = 1
|
381
|
+
|
382
|
+
FIELDS = {
|
383
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::BYTE}}, :value => {:type => ::Thrift::Types::BYTE}}
|
384
|
+
}
|
385
|
+
|
386
|
+
def struct_fields; FIELDS; end
|
387
|
+
|
388
|
+
def validate
|
389
|
+
end
|
390
|
+
|
391
|
+
::Thrift::Struct.generate_accessors self
|
392
|
+
end
|
393
|
+
|
394
|
+
class NestedListInMapValue
|
395
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
396
|
+
VALUE = 1
|
397
|
+
|
398
|
+
FIELDS = {
|
399
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::BYTE}}}
|
400
|
+
}
|
401
|
+
|
402
|
+
def struct_fields; FIELDS; end
|
403
|
+
|
404
|
+
def validate
|
405
|
+
end
|
406
|
+
|
407
|
+
::Thrift::Struct.generate_accessors self
|
408
|
+
end
|
409
|
+
|
410
|
+
class NestedSetInList
|
411
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
412
|
+
VALUE = 1
|
413
|
+
|
414
|
+
FIELDS = {
|
415
|
+
VALUE => {:type => ::Thrift::Types::LIST, :name => 'value', :element => {:type => ::Thrift::Types::SET, :element => {:type => ::Thrift::Types::BYTE}}}
|
416
|
+
}
|
417
|
+
|
418
|
+
def struct_fields; FIELDS; end
|
419
|
+
|
420
|
+
def validate
|
421
|
+
end
|
422
|
+
|
423
|
+
::Thrift::Struct.generate_accessors self
|
424
|
+
end
|
425
|
+
|
426
|
+
class NestedSetInSet
|
427
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
428
|
+
VALUE = 1
|
429
|
+
|
430
|
+
FIELDS = {
|
431
|
+
VALUE => {:type => ::Thrift::Types::SET, :name => 'value', :element => {:type => ::Thrift::Types::SET, :element => {:type => ::Thrift::Types::BYTE}}}
|
432
|
+
}
|
433
|
+
|
434
|
+
def struct_fields; FIELDS; end
|
435
|
+
|
436
|
+
def validate
|
437
|
+
end
|
438
|
+
|
439
|
+
::Thrift::Struct.generate_accessors self
|
440
|
+
end
|
441
|
+
|
442
|
+
class NestedSetInMapKey
|
443
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
444
|
+
VALUE = 1
|
445
|
+
|
446
|
+
FIELDS = {
|
447
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::SET, :element => {:type => ::Thrift::Types::BYTE}}, :value => {:type => ::Thrift::Types::BYTE}}
|
448
|
+
}
|
449
|
+
|
450
|
+
def struct_fields; FIELDS; end
|
451
|
+
|
452
|
+
def validate
|
453
|
+
end
|
454
|
+
|
455
|
+
::Thrift::Struct.generate_accessors self
|
456
|
+
end
|
457
|
+
|
458
|
+
class NestedSetInMapValue
|
459
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
460
|
+
VALUE = 1
|
461
|
+
|
462
|
+
FIELDS = {
|
463
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::SET, :element => {:type => ::Thrift::Types::BYTE}}}
|
464
|
+
}
|
465
|
+
|
466
|
+
def struct_fields; FIELDS; end
|
467
|
+
|
468
|
+
def validate
|
469
|
+
end
|
470
|
+
|
471
|
+
::Thrift::Struct.generate_accessors self
|
472
|
+
end
|
473
|
+
|
474
|
+
class NestedMapInList
|
475
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
476
|
+
VALUE = 1
|
477
|
+
|
478
|
+
FIELDS = {
|
479
|
+
VALUE => {:type => ::Thrift::Types::LIST, :name => 'value', :element => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::BYTE}}}
|
480
|
+
}
|
481
|
+
|
482
|
+
def struct_fields; FIELDS; end
|
483
|
+
|
484
|
+
def validate
|
485
|
+
end
|
486
|
+
|
487
|
+
::Thrift::Struct.generate_accessors self
|
488
|
+
end
|
489
|
+
|
490
|
+
class NestedMapInSet
|
491
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
492
|
+
VALUE = 1
|
493
|
+
|
494
|
+
FIELDS = {
|
495
|
+
VALUE => {:type => ::Thrift::Types::SET, :name => 'value', :element => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::BYTE}}}
|
496
|
+
}
|
497
|
+
|
498
|
+
def struct_fields; FIELDS; end
|
499
|
+
|
500
|
+
def validate
|
501
|
+
end
|
502
|
+
|
503
|
+
::Thrift::Struct.generate_accessors self
|
504
|
+
end
|
505
|
+
|
506
|
+
class NestedMapInMapKey
|
507
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
508
|
+
VALUE = 2
|
509
|
+
|
510
|
+
FIELDS = {
|
511
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::BYTE}}, :value => {:type => ::Thrift::Types::BYTE}}
|
512
|
+
}
|
513
|
+
|
514
|
+
def struct_fields; FIELDS; end
|
515
|
+
|
516
|
+
def validate
|
517
|
+
end
|
518
|
+
|
519
|
+
::Thrift::Struct.generate_accessors self
|
520
|
+
end
|
521
|
+
|
522
|
+
class NestedMapInMapValue
|
523
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
524
|
+
VALUE = 2
|
525
|
+
|
526
|
+
FIELDS = {
|
527
|
+
VALUE => {:type => ::Thrift::Types::MAP, :name => 'value', :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::BYTE}, :value => {:type => ::Thrift::Types::BYTE}}}
|
528
|
+
}
|
529
|
+
|
530
|
+
def struct_fields; FIELDS; end
|
531
|
+
|
532
|
+
def validate
|
533
|
+
end
|
534
|
+
|
535
|
+
::Thrift::Struct.generate_accessors self
|
536
|
+
end
|
537
|
+
|
346
538
|
end
|
data/spec/http_client_spec.rb
CHANGED
@@ -17,14 +17,13 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Thrift::HTTPClientTransport' do
|
24
23
|
|
25
|
-
describe HTTPClientTransport do
|
24
|
+
describe Thrift::HTTPClientTransport do
|
26
25
|
before(:each) do
|
27
|
-
@client = HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
26
|
+
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
28
27
|
end
|
29
28
|
|
30
29
|
it "should always be open" do
|
@@ -37,9 +36,13 @@ class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
|
|
37
36
|
@client.write "a test"
|
38
37
|
@client.write " frame"
|
39
38
|
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
40
|
-
mock("Net::HTTP").
|
39
|
+
mock("Net::HTTP").tap do |http|
|
41
40
|
http.should_receive(:use_ssl=).with(false)
|
42
|
-
http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return
|
41
|
+
http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
|
42
|
+
mock("Net::HTTPOK").tap do |response|
|
43
|
+
response.should_receive(:body).and_return "data"
|
44
|
+
end
|
45
|
+
end
|
43
46
|
end
|
44
47
|
end
|
45
48
|
@client.flush
|
@@ -53,12 +56,65 @@ class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
|
|
53
56
|
|
54
57
|
@client.add_headers(custom_headers)
|
55
58
|
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
56
|
-
mock("Net::HTTP").
|
59
|
+
mock("Net::HTTP").tap do |http|
|
57
60
|
http.should_receive(:use_ssl=).with(false)
|
58
|
-
http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return
|
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
|
59
66
|
end
|
60
67
|
end
|
61
68
|
@client.flush
|
62
69
|
end
|
63
70
|
end
|
71
|
+
|
72
|
+
describe 'ssl enabled' do
|
73
|
+
before(:each) do
|
74
|
+
@service_path = "/path/to/service?param=value"
|
75
|
+
@server_uri = "https://my.domain.com"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should use SSL for https" do
|
79
|
+
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}")
|
80
|
+
|
81
|
+
client.write "test"
|
82
|
+
|
83
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
|
84
|
+
mock("Net::HTTP").tap do |http|
|
85
|
+
http.should_receive(:use_ssl=).with(true)
|
86
|
+
http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
87
|
+
http.should_receive(:post).with(@service_path, "test",
|
88
|
+
"Content-Type" => "application/x-thrift").and_return do
|
89
|
+
mock("Net::HTTPOK").tap do |response|
|
90
|
+
response.should_receive(:body).and_return "data"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
client.flush
|
96
|
+
client.read(4).should == "data"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should set SSL verify mode when specified" do
|
100
|
+
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}",
|
101
|
+
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
102
|
+
|
103
|
+
client.write "test"
|
104
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 443).and_return do
|
105
|
+
mock("Net::HTTP").tap do |http|
|
106
|
+
http.should_receive(:use_ssl=).with(true)
|
107
|
+
http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
108
|
+
http.should_receive(:post).with(@service_path, "test",
|
109
|
+
"Content-Type" => "application/x-thrift").and_return do
|
110
|
+
mock("Net::HTTPOK").tap do |response|
|
111
|
+
response.should_receive(:body).and_return "data"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
client.flush
|
117
|
+
client.read(4).should == "data"
|
118
|
+
end
|
119
|
+
end
|
64
120
|
end
|