thrift 0.11.0.0 → 0.14.2
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.
- checksums.yaml +5 -5
- data/lib/thrift/protocol/base_protocol.rb +11 -3
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +8 -0
- data/lib/thrift/protocol/json_protocol.rb +8 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +6 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +4 -2
- data/lib/thrift/transport/ssl_server_socket.rb +4 -0
- data/lib/thrift/transport/ssl_socket.rb +4 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +73 -70
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +41 -42
- data/spec/compact_protocol_spec.rb +23 -8
- data/spec/exception_spec.rb +54 -54
- data/spec/flat_spec.rb +5 -5
- data/spec/http_client_spec.rb +64 -38
- data/spec/json_protocol_spec.rb +146 -138
- data/spec/namespaced_spec.rb +5 -5
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/processor_spec.rb +26 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -52
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +26 -22
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +18 -18
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +42 -43
- data/spec/unix_socket_spec.rb +43 -34
- metadata +138 -158
- data/benchmark/gen-rb/benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -10
- data/spec/gen-rb/base/base_service.rb +0 -80
- data/spec/gen-rb/base/base_service_constants.rb +0 -11
- data/spec/gen-rb/base/base_service_types.rb +0 -26
- data/spec/gen-rb/extended/extended_service.rb +0 -78
- data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
- data/spec/gen-rb/extended/extended_service_types.rb +0 -12
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/flat/referenced_constants.rb +0 -11
- data/spec/gen-rb/flat/referenced_types.rb +0 -17
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
- data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
- data/spec/gen-rb/thrift_spec_constants.rb +0 -11
- data/spec/gen-rb/thrift_spec_types.rb +0 -538
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -278
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -781
- data/test/debug_proto/gen-rb/empty_service.rb +0 -28
- data/test/debug_proto/gen-rb/inherited.rb +0 -83
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -86
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -85
- data/test/debug_proto/gen-rb/srv.rb +0 -395
data/spec/client_spec.rb
CHANGED
@@ -26,74 +26,73 @@ describe 'Client' do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
before(:each) do
|
29
|
-
@prot =
|
29
|
+
@prot = double("MockProtocol")
|
30
30
|
@client = ClientSpec.new(@prot)
|
31
31
|
end
|
32
32
|
|
33
33
|
describe Thrift::Client do
|
34
34
|
it "should re-use iprot for oprot if not otherwise specified" do
|
35
|
-
@client.instance_variable_get(:'@iprot').
|
36
|
-
@client.instance_variable_get(:'@oprot').
|
35
|
+
expect(@client.instance_variable_get(:'@iprot')).to eql(@prot)
|
36
|
+
expect(@client.instance_variable_get(:'@oprot')).to eql(@prot)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should send a test message" do
|
40
|
-
@prot.
|
41
|
-
mock_args =
|
42
|
-
mock_args.
|
43
|
-
mock_args.
|
44
|
-
mock_args.
|
45
|
-
@prot.
|
46
|
-
@prot.
|
47
|
-
|
48
|
-
trans.
|
40
|
+
expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
|
41
|
+
mock_args = double('#<TestMessage_args:mock>')
|
42
|
+
expect(mock_args).to receive(:foo=).with('foo')
|
43
|
+
expect(mock_args).to receive(:bar=).with(42)
|
44
|
+
expect(mock_args).to receive(:write).with(@prot)
|
45
|
+
expect(@prot).to receive(:write_message_end)
|
46
|
+
expect(@prot).to receive(:trans) do
|
47
|
+
double('trans').tap do |trans|
|
48
|
+
expect(trans).to receive(:flush)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
klass =
|
51
|
+
klass = double("TestMessage_args", :new => mock_args)
|
52
52
|
@client.send_message('testMessage', klass, :foo => 'foo', :bar => 42)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should increment the sequence id when sending messages" do
|
56
|
-
pending "it seems sequence ids are completely ignored right now"
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
56
|
+
pending "it seems sequence ids are completely ignored right now"
|
57
|
+
@prot.expect(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
|
58
|
+
@prot.expect(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
|
59
|
+
@prot.expect(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
|
60
|
+
@prot.stub!(:write_message_end)
|
61
|
+
@prot.stub!(:trans).and_return double("trans").as_null_object
|
62
|
+
@client.send_message('testMessage', double("args class").as_null_object)
|
63
|
+
@client.send_message('testMessage2', double("args class").as_null_object)
|
64
|
+
@client.send_message('testMessage3', double("args class").as_null_object)
|
66
65
|
end
|
67
66
|
|
68
67
|
it "should receive a test message" do
|
69
|
-
@prot.
|
70
|
-
@prot.
|
71
|
-
mock_klass =
|
72
|
-
mock_klass.
|
73
|
-
@client.receive_message(
|
68
|
+
expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
|
69
|
+
expect(@prot).to receive(:read_message_end)
|
70
|
+
mock_klass = double("#<MockClass:mock>")
|
71
|
+
expect(mock_klass).to receive(:read).with(@prot)
|
72
|
+
@client.receive_message(double("MockClass", :new => mock_klass))
|
74
73
|
end
|
75
74
|
|
76
75
|
it "should handle received exceptions" do
|
77
|
-
@prot.
|
78
|
-
@prot.
|
79
|
-
Thrift::ApplicationException.
|
76
|
+
expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
|
77
|
+
expect(@prot).to receive(:read_message_end)
|
78
|
+
expect(Thrift::ApplicationException).to receive(:new) do
|
80
79
|
StandardError.new.tap do |mock_exc|
|
81
|
-
mock_exc.
|
80
|
+
expect(mock_exc).to receive(:read).with(@prot)
|
82
81
|
end
|
83
82
|
end
|
84
|
-
|
83
|
+
expect { @client.receive_message(nil) }.to raise_error(StandardError)
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should close the transport if an error occurs while sending a message" do
|
88
|
-
@prot.
|
89
|
-
@prot.
|
90
|
-
mock_args =
|
91
|
-
mock_args.
|
92
|
-
trans =
|
93
|
-
@prot.
|
94
|
-
trans.
|
95
|
-
klass =
|
96
|
-
|
87
|
+
allow(@prot).to receive(:write_message_begin)
|
88
|
+
expect(@prot).not_to receive(:write_message_end)
|
89
|
+
mock_args = double("#<TestMessage_args:mock>")
|
90
|
+
expect(mock_args).to receive(:write).with(@prot).and_raise(StandardError)
|
91
|
+
trans = double("MockTransport")
|
92
|
+
allow(@prot).to receive(:trans).and_return(trans)
|
93
|
+
expect(trans).to receive(:close)
|
94
|
+
klass = double("TestMessage_args", :new => mock_args)
|
95
|
+
expect { @client.send_message("testMessage", klass) }.to raise_error(StandardError)
|
97
96
|
end
|
98
97
|
end
|
99
98
|
end
|
@@ -42,7 +42,7 @@ describe Thrift::CompactProtocol do
|
|
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))
|
45
|
-
read_back.
|
45
|
+
expect(read_back).to eq(value)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -62,10 +62,10 @@ describe Thrift::CompactProtocol do
|
|
62
62
|
|
63
63
|
proto = Thrift::CompactProtocol.new(trans)
|
64
64
|
name, type, id = proto.read_field_begin
|
65
|
-
type.
|
66
|
-
id.
|
65
|
+
expect(type).to eq(thrift_type)
|
66
|
+
expect(id).to eq(15)
|
67
67
|
read_back = proto.send(reader(primitive_type))
|
68
|
-
read_back.
|
68
|
+
expect(read_back).to eq(value)
|
69
69
|
proto.read_field_end
|
70
70
|
end
|
71
71
|
end
|
@@ -81,7 +81,7 @@ describe Thrift::CompactProtocol do
|
|
81
81
|
|
82
82
|
struct2 = Thrift::Test::CompactProtoTestStruct.new
|
83
83
|
struct2.read(proto)
|
84
|
-
struct2.
|
84
|
+
expect(struct2).to eq(struct)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should make method calls correctly" do
|
@@ -97,7 +97,7 @@ describe Thrift::CompactProtocol do
|
|
97
97
|
client.send_Janky(1)
|
98
98
|
# puts client_out_trans.inspect_buffer
|
99
99
|
processor.process(client_out_proto, client_in_proto)
|
100
|
-
client.recv_Janky.
|
100
|
+
expect(client.recv_Janky).to eq(2)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should deal with fields following fields that have non-delta ids" do
|
@@ -113,7 +113,7 @@ describe Thrift::CompactProtocol do
|
|
113
113
|
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
|
114
114
|
brcp2 = Thrift::Test::BreaksRubyCompactProtocol.new
|
115
115
|
deser.deserialize(brcp2, bytes)
|
116
|
-
brcp2.
|
116
|
+
expect(brcp2).to eq(brcp)
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should deserialize an empty map to an empty hash" do
|
@@ -124,7 +124,12 @@ describe Thrift::CompactProtocol do
|
|
124
124
|
deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
|
125
125
|
struct2 = Thrift::Test::SingleMapTestStruct.new
|
126
126
|
deser.deserialize(struct2, bytes)
|
127
|
-
struct.
|
127
|
+
expect(struct).to eq(struct2)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should provide a reasonable to_s" do
|
131
|
+
trans = Thrift::MemoryBufferTransport.new
|
132
|
+
expect(Thrift::CompactProtocol.new(trans).to_s).to eq("compact(memory)")
|
128
133
|
end
|
129
134
|
|
130
135
|
class JankyHandler
|
@@ -141,3 +146,13 @@ describe Thrift::CompactProtocol do
|
|
141
146
|
"read_#{sym.to_s}"
|
142
147
|
end
|
143
148
|
end
|
149
|
+
|
150
|
+
describe Thrift::CompactProtocolFactory do
|
151
|
+
it "should create a CompactProtocol" do
|
152
|
+
expect(Thrift::CompactProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::CompactProtocol)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should provide a reasonable to_s" do
|
156
|
+
expect(Thrift::CompactProtocolFactory.new.to_s).to eq("compact")
|
157
|
+
end
|
158
|
+
end
|
data/spec/exception_spec.rb
CHANGED
@@ -24,107 +24,107 @@ describe 'Exception' do
|
|
24
24
|
describe Thrift::Exception do
|
25
25
|
it "should have an accessible message" do
|
26
26
|
e = Thrift::Exception.new("test message")
|
27
|
-
e.message.
|
27
|
+
expect(e.message).to eq("test message")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe Thrift::ApplicationException do
|
32
32
|
it "should inherit from Thrift::Exception" do
|
33
|
-
Thrift::ApplicationException.superclass.
|
33
|
+
expect(Thrift::ApplicationException.superclass).to eq(Thrift::Exception)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should have an accessible type and message" do
|
37
37
|
e = Thrift::ApplicationException.new
|
38
|
-
e.type.
|
39
|
-
e.message.
|
38
|
+
expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN)
|
39
|
+
expect(e.message).to be_nil
|
40
40
|
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
41
|
-
e.type.
|
42
|
-
e.message.
|
41
|
+
expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN_METHOD)
|
42
|
+
expect(e.message).to eq("test message")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should read a struct off of a protocol" do
|
46
|
-
prot =
|
47
|
-
prot.
|
48
|
-
prot.
|
46
|
+
prot = double("MockProtocol")
|
47
|
+
expect(prot).to receive(:read_struct_begin).ordered
|
48
|
+
expect(prot).to receive(:read_field_begin).exactly(3).times.and_return(
|
49
49
|
["message", Thrift::Types::STRING, 1],
|
50
50
|
["type", Thrift::Types::I32, 2],
|
51
51
|
[nil, Thrift::Types::STOP, 0]
|
52
52
|
)
|
53
|
-
prot.
|
54
|
-
prot.
|
55
|
-
prot.
|
56
|
-
prot.
|
53
|
+
expect(prot).to receive(:read_string).ordered.and_return "test message"
|
54
|
+
expect(prot).to receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
|
55
|
+
expect(prot).to receive(:read_field_end).exactly(2).times
|
56
|
+
expect(prot).to receive(:read_struct_end).ordered
|
57
57
|
|
58
58
|
e = Thrift::ApplicationException.new
|
59
59
|
e.read(prot)
|
60
|
-
e.message.
|
61
|
-
e.type.
|
60
|
+
expect(e.message).to eq("test message")
|
61
|
+
expect(e.type).to eq(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should skip bad fields when reading a struct" do
|
65
|
-
prot =
|
66
|
-
prot.
|
67
|
-
prot.
|
65
|
+
prot = double("MockProtocol")
|
66
|
+
expect(prot).to receive(:read_struct_begin).ordered
|
67
|
+
expect(prot).to receive(:read_field_begin).exactly(5).times.and_return(
|
68
68
|
["type", Thrift::Types::I32, 2],
|
69
69
|
["type", Thrift::Types::STRING, 2],
|
70
70
|
["message", Thrift::Types::MAP, 1],
|
71
71
|
["message", Thrift::Types::STRING, 3],
|
72
72
|
[nil, Thrift::Types::STOP, 0]
|
73
73
|
)
|
74
|
-
prot.
|
75
|
-
prot.
|
76
|
-
prot.
|
77
|
-
prot.
|
78
|
-
prot.
|
74
|
+
expect(prot).to receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
|
75
|
+
expect(prot).to receive(:skip).with(Thrift::Types::STRING).twice
|
76
|
+
expect(prot).to receive(:skip).with(Thrift::Types::MAP)
|
77
|
+
expect(prot).to receive(:read_field_end).exactly(4).times
|
78
|
+
expect(prot).to receive(:read_struct_end).ordered
|
79
79
|
|
80
80
|
e = Thrift::ApplicationException.new
|
81
81
|
e.read(prot)
|
82
|
-
e.message.
|
83
|
-
e.type.
|
82
|
+
expect(e.message).to be_nil
|
83
|
+
expect(e.type).to eq(Thrift::ApplicationException::INVALID_MESSAGE_TYPE)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should write a Thrift::ApplicationException struct to the oprot" do
|
87
|
-
prot =
|
88
|
-
prot.
|
89
|
-
prot.
|
90
|
-
prot.
|
91
|
-
prot.
|
92
|
-
prot.
|
93
|
-
prot.
|
94
|
-
prot.
|
95
|
-
prot.
|
87
|
+
prot = double("MockProtocol")
|
88
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
89
|
+
expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
90
|
+
expect(prot).to receive(:write_string).with("test message").ordered
|
91
|
+
expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
92
|
+
expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
|
93
|
+
expect(prot).to receive(:write_field_end).twice
|
94
|
+
expect(prot).to receive(:write_field_stop).ordered
|
95
|
+
expect(prot).to receive(:write_struct_end).ordered
|
96
96
|
|
97
97
|
e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
|
98
98
|
e.write(prot)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should skip nil fields when writing to the oprot" do
|
102
|
-
prot =
|
103
|
-
prot.
|
104
|
-
prot.
|
105
|
-
prot.
|
106
|
-
prot.
|
107
|
-
prot.
|
108
|
-
prot.
|
102
|
+
prot = double("MockProtocol")
|
103
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
104
|
+
expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
|
105
|
+
expect(prot).to receive(:write_string).with("test message").ordered
|
106
|
+
expect(prot).to receive(:write_field_end).ordered
|
107
|
+
expect(prot).to receive(:write_field_stop).ordered
|
108
|
+
expect(prot).to receive(:write_struct_end).ordered
|
109
109
|
|
110
110
|
e = Thrift::ApplicationException.new(nil, "test message")
|
111
111
|
e.write(prot)
|
112
112
|
|
113
|
-
prot =
|
114
|
-
prot.
|
115
|
-
prot.
|
116
|
-
prot.
|
117
|
-
prot.
|
118
|
-
prot.
|
119
|
-
prot.
|
113
|
+
prot = double("MockProtocol")
|
114
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
115
|
+
expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
|
116
|
+
expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
|
117
|
+
expect(prot).to receive(:write_field_end).ordered
|
118
|
+
expect(prot).to receive(:write_field_stop).ordered
|
119
|
+
expect(prot).to receive(:write_struct_end).ordered
|
120
120
|
|
121
121
|
e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
|
122
122
|
e.write(prot)
|
123
123
|
|
124
|
-
prot =
|
125
|
-
prot.
|
126
|
-
prot.
|
127
|
-
prot.
|
124
|
+
prot = double("MockProtocol")
|
125
|
+
expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
|
126
|
+
expect(prot).to receive(:write_field_stop).ordered
|
127
|
+
expect(prot).to receive(:write_struct_end).ordered
|
128
128
|
|
129
129
|
e = Thrift::ApplicationException.new(nil)
|
130
130
|
e.write(prot)
|
@@ -134,8 +134,8 @@ describe 'Exception' do
|
|
134
134
|
describe Thrift::ProtocolException do
|
135
135
|
it "should have an accessible type" do
|
136
136
|
prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
|
137
|
-
prot.type.
|
138
|
-
prot.message.
|
137
|
+
expect(prot.type).to eq(Thrift::ProtocolException::SIZE_LIMIT)
|
138
|
+
expect(prot.message).to eq("message")
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
data/spec/flat_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe 'generation' do
|
|
32
32
|
"other_namespace/referenced_constants.rb",
|
33
33
|
"other_namespace/referenced_types.rb"
|
34
34
|
].each do |name|
|
35
|
-
File.exist?(File.join(prefix, name)).
|
35
|
+
expect(File.exist?(File.join(prefix, name))).not_to be_truthy
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -44,19 +44,19 @@ describe 'generation' do
|
|
44
44
|
"referenced_constants.rb",
|
45
45
|
"referenced_types.rb"
|
46
46
|
].each do |name|
|
47
|
-
File.exist?(File.join(prefix, name)).
|
47
|
+
expect(File.exist?(File.join(prefix, name))).to be_truthy
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
it "has a service class in the right place" do
|
52
|
-
defined?(NamespacedSpecNamespace::NamespacedNonblockingService).
|
52
|
+
expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
|
53
53
|
end
|
54
54
|
|
55
55
|
it "has a struct in the right place" do
|
56
|
-
defined?(NamespacedSpecNamespace::Hello).
|
56
|
+
expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
|
57
57
|
end
|
58
58
|
|
59
59
|
it "required an included file" do
|
60
|
-
defined?(OtherNamespace::SomeEnum).
|
60
|
+
expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
|
61
61
|
end
|
62
62
|
end
|
data/spec/http_client_spec.rb
CHANGED
@@ -25,28 +25,33 @@ describe 'Thrift::HTTPClientTransport' do
|
|
25
25
|
before(:each) do
|
26
26
|
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
27
27
|
end
|
28
|
+
|
29
|
+
it "should provide a reasonable to_s" do
|
30
|
+
@client.to_s == "http://my.domain.com/path/to/service?param=value"
|
31
|
+
end
|
28
32
|
|
29
33
|
it "should always be open" do
|
30
|
-
@client.
|
34
|
+
expect(@client).to be_open
|
31
35
|
@client.close
|
32
|
-
@client.
|
36
|
+
expect(@client).to be_open
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should post via HTTP and return the results" do
|
36
40
|
@client.write "a test"
|
37
41
|
@client.write " frame"
|
38
|
-
Net::HTTP.
|
39
|
-
|
40
|
-
http.
|
41
|
-
http.
|
42
|
-
|
43
|
-
response.
|
42
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
43
|
+
double("Net::HTTP").tap do |http|
|
44
|
+
expect(http).to receive(:use_ssl=).with(false)
|
45
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}) do
|
46
|
+
double("Net::HTTPOK").tap do |response|
|
47
|
+
expect(response).to receive(:body).and_return "data"
|
48
|
+
expect(response).to receive(:code).and_return "200"
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
@client.flush
|
49
|
-
@client.read(10).
|
54
|
+
expect(@client.read(10)).to eq("data")
|
50
55
|
end
|
51
56
|
|
52
57
|
it "should send custom headers if defined" do
|
@@ -55,12 +60,13 @@ describe 'Thrift::HTTPClientTransport' do
|
|
55
60
|
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
|
56
61
|
|
57
62
|
@client.add_headers(custom_headers)
|
58
|
-
Net::HTTP.
|
59
|
-
|
60
|
-
http.
|
61
|
-
http.
|
62
|
-
|
63
|
-
response.
|
63
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
64
|
+
double("Net::HTTP").tap do |http|
|
65
|
+
expect(http).to receive(:use_ssl=).with(false)
|
66
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", headers) do
|
67
|
+
double("Net::HTTPOK").tap do |response|
|
68
|
+
expect(response).to receive(:body).and_return "data"
|
69
|
+
expect(response).to receive(:code).and_return "200"
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
@@ -71,15 +77,33 @@ describe 'Thrift::HTTPClientTransport' do
|
|
71
77
|
it 'should reset the outbuf on HTTP failures' do
|
72
78
|
@client.write "test"
|
73
79
|
|
74
|
-
Net::HTTP.
|
75
|
-
|
76
|
-
http.
|
77
|
-
http.
|
80
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
81
|
+
double("Net::HTTP").tap do |http|
|
82
|
+
expect(http).to receive(:use_ssl=).with(false)
|
83
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
81
87
|
@client.flush rescue
|
82
|
-
@client.instance_variable_get(:@outbuf).
|
88
|
+
expect(@client.instance_variable_get(:@outbuf)).to eq(Thrift::Bytes.empty_byte_buffer)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should raise TransportError on HTTP failures' do
|
92
|
+
@client.write "test"
|
93
|
+
|
94
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
95
|
+
double("Net::HTTP").tap do |http|
|
96
|
+
expect(http).to receive(:use_ssl=).with(false)
|
97
|
+
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) do
|
98
|
+
double("Net::HTTPOK").tap do |response|
|
99
|
+
expect(response).not_to receive(:body)
|
100
|
+
expect(response).to receive(:code).at_least(:once).and_return "503"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
expect { @client.flush }.to raise_error(Thrift::TransportException)
|
83
107
|
end
|
84
108
|
|
85
109
|
end
|
@@ -95,20 +119,21 @@ describe 'Thrift::HTTPClientTransport' do
|
|
95
119
|
|
96
120
|
client.write "test"
|
97
121
|
|
98
|
-
Net::HTTP.
|
99
|
-
|
100
|
-
http.
|
101
|
-
http.
|
102
|
-
http.
|
103
|
-
"Content-Type" => "application/x-thrift")
|
104
|
-
|
105
|
-
response.
|
122
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
123
|
+
double("Net::HTTP").tap do |http|
|
124
|
+
expect(http).to receive(:use_ssl=).with(true)
|
125
|
+
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
126
|
+
expect(http).to receive(:post).with(@service_path, "test",
|
127
|
+
"Content-Type" => "application/x-thrift") do
|
128
|
+
double("Net::HTTPOK").tap do |response|
|
129
|
+
expect(response).to receive(:body).and_return "data"
|
130
|
+
expect(response).to receive(:code).and_return "200"
|
106
131
|
end
|
107
132
|
end
|
108
133
|
end
|
109
134
|
end
|
110
135
|
client.flush
|
111
|
-
client.read(4).
|
136
|
+
expect(client.read(4)).to eq("data")
|
112
137
|
end
|
113
138
|
|
114
139
|
it "should set SSL verify mode when specified" do
|
@@ -116,20 +141,21 @@ describe 'Thrift::HTTPClientTransport' do
|
|
116
141
|
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
117
142
|
|
118
143
|
client.write "test"
|
119
|
-
Net::HTTP.
|
120
|
-
|
121
|
-
http.
|
122
|
-
http.
|
123
|
-
http.
|
124
|
-
"Content-Type" => "application/x-thrift")
|
125
|
-
|
126
|
-
response.
|
144
|
+
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
145
|
+
double("Net::HTTP").tap do |http|
|
146
|
+
expect(http).to receive(:use_ssl=).with(true)
|
147
|
+
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
148
|
+
expect(http).to receive(:post).with(@service_path, "test",
|
149
|
+
"Content-Type" => "application/x-thrift") do
|
150
|
+
double("Net::HTTPOK").tap do |response|
|
151
|
+
expect(response).to receive(:body).and_return "data"
|
152
|
+
expect(response).to receive(:code).and_return "200"
|
127
153
|
end
|
128
154
|
end
|
129
155
|
end
|
130
156
|
end
|
131
157
|
client.flush
|
132
|
-
client.read(4).
|
158
|
+
expect(client.read(4)).to eq("data")
|
133
159
|
end
|
134
160
|
end
|
135
161
|
end
|