upfluence-thrift 2.6.8 → 2.7.4
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 +4 -4
- data/benchmark/{gen-rb/benchmark_constants.rb → benchmark_constants.rb} +1 -1
- data/benchmark/{gen-rb/benchmark_service.rb → benchmark_service.rb} +2 -2
- data/benchmark/{gen-rb/benchmark_types.rb → benchmark_types.rb} +1 -1
- data/ext/struct.c +5 -1
- data/lib/thrift/base_stream.rb +85 -0
- data/lib/thrift/bidi_stream.rb +183 -0
- data/lib/thrift/client.rb +84 -17
- data/lib/thrift/inbound_stream.rb +72 -0
- data/lib/thrift/middleware.rb +42 -0
- data/lib/thrift/outbound_stream.rb +52 -0
- data/lib/thrift/processor.rb +287 -47
- data/lib/thrift/protocol/base_protocol.rb +35 -33
- 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 +21 -4
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/nonblocking_server.rb +5 -4
- 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 +4 -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 +5 -0
- data/lib/thrift/transport/socket.rb +21 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
- data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
- data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
- data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
- data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
- data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
- data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
- data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
- data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
- data/lib/thrift/types/core/core_constants.rb +15 -0
- data/lib/thrift/types/core/core_types.rb +58 -0
- data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
- data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
- data/lib/thrift/types/known/any/any_constants.rb +1 -1
- data/lib/thrift/types/known/any/any_types.rb +2 -2
- data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
- data/lib/thrift/types/known/duration/duration_types.rb +2 -2
- data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
- data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
- data/lib/thrift/types/plugin/plugin.rb +139 -0
- data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
- data/lib/thrift/types/plugin/plugin_types.rb +106 -0
- data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
- data/lib/thrift/types/program_definition/program_definition_types.rb +137 -0
- data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
- data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
- data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
- data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
- data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
- data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
- data/lib/thrift/types/value/value_constants.rb +1 -1
- data/lib/thrift/types/value/value_types.rb +50 -51
- data/lib/thrift/types.rb +11 -3
- data/lib/thrift/union.rb +3 -6
- data/lib/thrift.rb +6 -0
- data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
- data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
- data/lib/types/annotation/naming/naming_constants.rb +16 -0
- data/lib/types/annotation/naming/naming_types.rb +57 -0
- data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
- data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
- data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
- data/lib/types/constant_definition/constant_definition_types.rb +290 -0
- data/lib/types/core/core_constants.rb +14 -0
- data/lib/types/core/core_types.rb +56 -0
- data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
- data/lib/types/enum_definition/enum_definition_types.rb +104 -0
- data/lib/types/known/any/any_constants.rb +16 -0
- data/lib/types/known/any/any_types.rb +59 -0
- data/lib/types/known/duration/duration_constants.rb +16 -0
- data/lib/types/known/duration/duration_types.rb +59 -0
- data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
- data/lib/types/known/timestamp/timestamp_types.rb +59 -0
- data/lib/types/plugin/plugin.rb +137 -0
- data/lib/types/plugin/plugin_constants.rb +14 -0
- data/lib/types/plugin/plugin_types.rb +104 -0
- data/lib/types/program_definition/program_definition_constants.rb +14 -0
- data/lib/types/program_definition/program_definition_types.rb +135 -0
- data/lib/types/service_definition/service_definition_constants.rb +14 -0
- data/lib/types/service_definition/service_definition_types.rb +158 -0
- data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
- data/lib/types/struct_definition/struct_definition_types.rb +155 -0
- data/lib/types/type_definition/type_definition_constants.rb +14 -0
- data/lib/types/type_definition/type_definition_types.rb +240 -0
- data/lib/types/value/value_constants.rb +14 -0
- data/lib/types/value/value_types.rb +330 -0
- data/spec/{gen-rb/base → base}/base_service.rb +2 -2
- data/spec/{gen-rb/base → base}/base_service_constants.rb +1 -1
- data/spec/{gen-rb/base → base}/base_service_types.rb +1 -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 +77 -77
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +48 -50
- data/spec/compact_protocol_spec.rb +59 -46
- data/spec/exception_spec.rb +54 -54
- data/spec/{gen-rb/extended → extended}/extended_service.rb +2 -2
- data/spec/{gen-rb/extended → extended}/extended_service_constants.rb +1 -1
- data/spec/{gen-rb/extended → extended}/extended_service_types.rb +1 -1
- data/spec/flat_spec.rb +5 -5
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +4 -4
- data/spec/gen-rb/flat/referenced_constants.rb +1 -1
- data/spec/gen-rb/flat/referenced_types.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +1 -1
- data/spec/http_client_spec.rb +96 -43
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +24 -27
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/namespaced_nonblocking_service.rb +4 -4
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_types.rb +1 -1
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/{gen-rb/nonblocking_service.rb → nonblocking_service.rb} +4 -4
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_constants.rb +1 -1
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_types.rb +1 -1
- data/spec/processor_spec.rb +42 -31
- data/spec/rack_application_spec.rb +22 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/spec_helper.rb +1 -1
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/streaming_spec.rb +442 -0
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +71 -28
- data/spec/{gen-rb/thrift_spec_constants.rb → thrift_spec_constants.rb} +1 -1
- data/spec/{gen-rb/thrift_spec_types.rb → thrift_spec_types.rb} +16 -16
- data/spec/types/known/any_spec.rb +2 -2
- data/spec/types/known/duration_spec.rb +1 -1
- data/spec/types/known/timestamp_spec.rb +1 -1
- data/spec/types/value_spec.rb +2 -1
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +51 -40
- data/spec/unix_socket_spec.rb +43 -34
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +267 -260
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +1481 -1416
- data/test/debug_proto/gen-rb/empty_service.rb +31 -27
- data/test/debug_proto/gen-rb/inherited.rb +102 -98
- data/test/debug_proto/gen-rb/reverse_order_service.rb +112 -108
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +99 -95
- data/test/debug_proto/gen-rb/srv.rb +525 -406
- metadata +178 -41
data/spec/server_spec.rb
CHANGED
|
@@ -21,95 +21,135 @@ require 'spec_helper'
|
|
|
21
21
|
describe 'Server' do
|
|
22
22
|
|
|
23
23
|
describe Thrift::BaseServer do
|
|
24
|
+
before(:each) do
|
|
25
|
+
@processor = double("Processor")
|
|
26
|
+
@serverTrans = double("ServerTransport")
|
|
27
|
+
@trans = double("BaseTransport")
|
|
28
|
+
@prot = double("BaseProtocol")
|
|
29
|
+
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
|
|
30
|
+
end
|
|
31
|
+
|
|
24
32
|
it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
|
|
25
|
-
server = Thrift::BaseServer.new(
|
|
26
|
-
server.instance_variable_get(:'@transport_factory').
|
|
27
|
-
server.instance_variable_get(:'@protocol_factory').
|
|
33
|
+
@server = Thrift::BaseServer.new(double("Processor"), double("BaseServerTransport"))
|
|
34
|
+
expect(@server.instance_variable_get(:'@transport_factory')).to be_an_instance_of(Thrift::BaseTransportFactory)
|
|
35
|
+
expect(@server.instance_variable_get(:'@protocol_factory')).to be_an_instance_of(Thrift::BinaryProtocolFactory)
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
it "should not serve" do
|
|
39
|
+
expect { @server.serve()}.to raise_error(NotImplementedError)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should provide a reasonable to_s" do
|
|
43
|
+
expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
|
|
44
|
+
expect(@trans).to receive(:to_s).once.and_return("trans")
|
|
45
|
+
expect(@prot).to receive(:to_s).once.and_return("prot")
|
|
46
|
+
expect(@server.to_s).to eq("server(prot(trans(serverTrans)))")
|
|
47
|
+
end
|
|
31
48
|
end
|
|
32
49
|
|
|
33
50
|
describe Thrift::SimpleServer do
|
|
34
51
|
before(:each) do
|
|
35
|
-
@processor =
|
|
36
|
-
@serverTrans =
|
|
37
|
-
@trans =
|
|
38
|
-
@prot =
|
|
39
|
-
@client =
|
|
52
|
+
@processor = double("Processor")
|
|
53
|
+
@serverTrans = double("ServerTransport")
|
|
54
|
+
@trans = double("BaseTransport")
|
|
55
|
+
@prot = double("BaseProtocol")
|
|
56
|
+
@client = double("Client")
|
|
40
57
|
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
|
|
41
58
|
end
|
|
42
59
|
|
|
60
|
+
it "should provide a reasonable to_s" do
|
|
61
|
+
expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
|
|
62
|
+
expect(@trans).to receive(:to_s).once.and_return("trans")
|
|
63
|
+
expect(@prot).to receive(:to_s).once.and_return("prot")
|
|
64
|
+
expect(@server.to_s).to eq("simple(server(prot(trans(serverTrans))))")
|
|
65
|
+
end
|
|
66
|
+
|
|
43
67
|
it "should serve in the main thread" do
|
|
44
|
-
@serverTrans.
|
|
45
|
-
@serverTrans.
|
|
46
|
-
@trans.
|
|
47
|
-
@prot.
|
|
68
|
+
expect(@serverTrans).to receive(:listen).ordered
|
|
69
|
+
expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
|
|
70
|
+
expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
|
|
71
|
+
expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
|
|
48
72
|
x = 0
|
|
49
|
-
@processor.
|
|
73
|
+
expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
|
|
50
74
|
case (x += 1)
|
|
51
75
|
when 1 then raise Thrift::TransportException
|
|
52
76
|
when 2 then raise Thrift::ProtocolException
|
|
53
77
|
when 3 then throw :stop
|
|
54
78
|
end
|
|
55
79
|
end
|
|
56
|
-
@trans.
|
|
57
|
-
@serverTrans.
|
|
58
|
-
|
|
80
|
+
expect(@trans).to receive(:close).exactly(3).times
|
|
81
|
+
expect(@serverTrans).to receive(:close).ordered
|
|
82
|
+
expect { @server.serve }.to throw_symbol(:stop)
|
|
59
83
|
end
|
|
60
84
|
end
|
|
61
85
|
|
|
62
86
|
describe Thrift::ThreadedServer do
|
|
63
87
|
before(:each) do
|
|
64
|
-
@processor =
|
|
65
|
-
@serverTrans =
|
|
66
|
-
@trans =
|
|
67
|
-
@prot =
|
|
68
|
-
@client =
|
|
88
|
+
@processor = double("Processor")
|
|
89
|
+
@serverTrans = double("ServerTransport")
|
|
90
|
+
@trans = double("BaseTransport")
|
|
91
|
+
@prot = double("BaseProtocol")
|
|
92
|
+
@client = double("Client")
|
|
69
93
|
@server = described_class.new(@processor, @serverTrans, @trans, @prot)
|
|
70
94
|
end
|
|
71
95
|
|
|
96
|
+
it "should provide a reasonable to_s" do
|
|
97
|
+
expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
|
|
98
|
+
expect(@trans).to receive(:to_s).once.and_return("trans")
|
|
99
|
+
expect(@prot).to receive(:to_s).once.and_return("prot")
|
|
100
|
+
expect(@server.to_s).to eq("threaded(server(prot(trans(serverTrans))))")
|
|
101
|
+
end
|
|
102
|
+
|
|
72
103
|
it "should serve using threads" do
|
|
73
|
-
@serverTrans.
|
|
74
|
-
@serverTrans.
|
|
75
|
-
@trans.
|
|
76
|
-
@prot.
|
|
77
|
-
Thread.
|
|
104
|
+
expect(@serverTrans).to receive(:listen).ordered
|
|
105
|
+
expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
|
|
106
|
+
expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
|
|
107
|
+
expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
|
|
108
|
+
expect(Thread).to receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
|
|
78
109
|
x = 0
|
|
79
|
-
@processor.
|
|
110
|
+
expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
|
|
80
111
|
case (x += 1)
|
|
81
112
|
when 1 then raise Thrift::TransportException
|
|
82
113
|
when 2 then raise Thrift::ProtocolException
|
|
83
114
|
when 3 then throw :stop
|
|
84
115
|
end
|
|
85
116
|
end
|
|
86
|
-
@trans.
|
|
87
|
-
@serverTrans.
|
|
88
|
-
|
|
117
|
+
expect(@trans).to receive(:close).exactly(3).times
|
|
118
|
+
expect(@serverTrans).to receive(:close).ordered
|
|
119
|
+
expect { @server.serve }.to throw_symbol(:stop)
|
|
89
120
|
end
|
|
90
121
|
end
|
|
91
122
|
|
|
92
123
|
describe Thrift::ThreadPoolServer do
|
|
93
124
|
before(:each) do
|
|
94
|
-
@processor =
|
|
95
|
-
@server_trans =
|
|
96
|
-
@trans =
|
|
97
|
-
@prot =
|
|
98
|
-
@client =
|
|
125
|
+
@processor = double("Processor")
|
|
126
|
+
@server_trans = double("ServerTransport")
|
|
127
|
+
@trans = double("BaseTransport")
|
|
128
|
+
@prot = double("BaseProtocol")
|
|
129
|
+
@client = double("Client")
|
|
99
130
|
@server = described_class.new(@processor, @server_trans, @trans, @prot)
|
|
131
|
+
sleep(0.15)
|
|
100
132
|
end
|
|
101
133
|
|
|
134
|
+
it "should provide a reasonable to_s" do
|
|
135
|
+
expect(@server_trans).to receive(:to_s).once.and_return("server_trans")
|
|
136
|
+
expect(@trans).to receive(:to_s).once.and_return("trans")
|
|
137
|
+
expect(@prot).to receive(:to_s).once.and_return("prot")
|
|
138
|
+
expect(@server.to_s).to eq("threadpool(server(prot(trans(server_trans))))")
|
|
139
|
+
end
|
|
140
|
+
|
|
102
141
|
it "should serve inside a thread" do
|
|
103
142
|
exception_q = @server.instance_variable_get(:@exception_q)
|
|
104
|
-
described_class.
|
|
143
|
+
expect_any_instance_of(described_class).to receive(:serve) do
|
|
105
144
|
exception_q.push(StandardError.new('ERROR'))
|
|
106
145
|
end
|
|
107
146
|
expect { @server.rescuable_serve }.to(raise_error('ERROR'))
|
|
147
|
+
sleep(0.15)
|
|
108
148
|
end
|
|
109
149
|
|
|
110
150
|
it "should avoid running the server twice when retrying rescuable_serve" do
|
|
111
151
|
exception_q = @server.instance_variable_get(:@exception_q)
|
|
112
|
-
described_class.
|
|
152
|
+
expect_any_instance_of(described_class).to receive(:serve) do
|
|
113
153
|
exception_q.push(StandardError.new('ERROR1'))
|
|
114
154
|
exception_q.push(StandardError.new('ERROR2'))
|
|
115
155
|
end
|
|
@@ -118,29 +158,29 @@ describe 'Server' do
|
|
|
118
158
|
end
|
|
119
159
|
|
|
120
160
|
it "should serve using a thread pool" do
|
|
121
|
-
thread_q =
|
|
122
|
-
exception_q =
|
|
161
|
+
thread_q = double("SizedQueue")
|
|
162
|
+
exception_q = double("Queue")
|
|
123
163
|
@server.instance_variable_set(:@thread_q, thread_q)
|
|
124
164
|
@server.instance_variable_set(:@exception_q, exception_q)
|
|
125
|
-
@server_trans.
|
|
126
|
-
thread_q.
|
|
127
|
-
thread_q.
|
|
128
|
-
Thread.
|
|
129
|
-
@server_trans.
|
|
130
|
-
@trans.
|
|
131
|
-
@prot.
|
|
165
|
+
expect(@server_trans).to receive(:listen).ordered
|
|
166
|
+
expect(thread_q).to receive(:push).with(:token)
|
|
167
|
+
expect(thread_q).to receive(:pop)
|
|
168
|
+
expect(Thread).to receive(:new).and_yield
|
|
169
|
+
expect(@server_trans).to receive(:accept).exactly(3).times.and_return(@client)
|
|
170
|
+
expect(@trans).to receive(:get_transport).exactly(3).times.and_return(@trans)
|
|
171
|
+
expect(@prot).to receive(:get_protocol).exactly(3).times.and_return(@prot)
|
|
132
172
|
x = 0
|
|
133
173
|
error = RuntimeError.new("Stopped")
|
|
134
|
-
@processor.
|
|
174
|
+
expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
|
|
135
175
|
case (x += 1)
|
|
136
176
|
when 1 then raise Thrift::TransportException
|
|
137
177
|
when 2 then raise Thrift::ProtocolException
|
|
138
178
|
when 3 then raise error
|
|
139
179
|
end
|
|
140
180
|
end
|
|
141
|
-
@trans.
|
|
142
|
-
exception_q.
|
|
143
|
-
@server_trans.
|
|
181
|
+
expect(@trans).to receive(:close).exactly(3).times
|
|
182
|
+
expect(exception_q).to receive(:push).with(error).and_throw(:stop)
|
|
183
|
+
expect(@server_trans).to receive(:close)
|
|
144
184
|
expect { @server.serve }.to(throw_symbol(:stop))
|
|
145
185
|
end
|
|
146
186
|
end
|
data/spec/socket_spec.rb
CHANGED
|
@@ -25,37 +25,44 @@ describe 'Socket' do
|
|
|
25
25
|
describe Thrift::Socket do
|
|
26
26
|
before(:each) do
|
|
27
27
|
@socket = Thrift::Socket.new
|
|
28
|
-
@handle =
|
|
29
|
-
@handle.
|
|
30
|
-
@handle.
|
|
31
|
-
@handle.
|
|
32
|
-
::Socket.
|
|
28
|
+
@handle = double("Handle", :closed? => false)
|
|
29
|
+
allow(@handle).to receive(:close)
|
|
30
|
+
allow(@handle).to receive(:connect_nonblock)
|
|
31
|
+
allow(@handle).to receive(:setsockopt)
|
|
32
|
+
allow(::Socket).to receive(:new).and_return(@handle)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it_should_behave_like "a socket"
|
|
36
36
|
|
|
37
37
|
it "should raise a TransportException when it cannot open a socket" do
|
|
38
|
-
::Socket.
|
|
39
|
-
|
|
38
|
+
expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
|
|
39
|
+
expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "should open a ::Socket with default args" do
|
|
43
|
-
::Socket.
|
|
44
|
-
::Socket.
|
|
45
|
-
::Socket.
|
|
43
|
+
expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
|
|
44
|
+
expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
|
|
45
|
+
expect(::Socket).to receive(:sockaddr_in)
|
|
46
|
+
@socket.to_s == "socket(localhost:9090)"
|
|
46
47
|
@socket.open
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
it "should accept host/port options" do
|
|
50
|
-
::Socket.
|
|
51
|
-
::Socket.
|
|
52
|
-
::Socket.
|
|
53
|
-
Thrift::Socket.new('my.domain', 1234).open
|
|
51
|
+
expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
|
|
52
|
+
expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
|
|
53
|
+
expect(::Socket).to receive(:sockaddr_in)
|
|
54
|
+
@socket = Thrift::Socket.new('my.domain', 1234).open
|
|
55
|
+
@socket.to_s == "socket(my.domain:1234)"
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
it "should accept an optional timeout" do
|
|
57
|
-
::Socket.
|
|
58
|
-
Thrift::Socket.new('localhost', 8080, 5).timeout.
|
|
59
|
+
allow(::Socket).to receive(:new)
|
|
60
|
+
expect(Thrift::Socket.new('localhost', 8080, 5).timeout).to eq(5)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should provide a reasonable to_s" do
|
|
64
|
+
allow(::Socket).to receive(:new)
|
|
65
|
+
expect(Thrift::Socket.new('myhost', 8090).to_s).to eq("socket(myhost:8090)")
|
|
59
66
|
end
|
|
60
67
|
end
|
|
61
68
|
end
|
data/spec/socket_spec_shared.rb
CHANGED
|
@@ -21,84 +21,84 @@ require 'spec_helper'
|
|
|
21
21
|
|
|
22
22
|
shared_examples_for "a socket" do
|
|
23
23
|
it "should open a socket" do
|
|
24
|
-
@socket.open.
|
|
24
|
+
expect(@socket.open).to eq(@handle)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should be open whenever it has a handle" do
|
|
28
|
-
@socket.
|
|
28
|
+
expect(@socket).not_to be_open
|
|
29
29
|
@socket.open
|
|
30
|
-
@socket.
|
|
30
|
+
expect(@socket).to be_open
|
|
31
31
|
@socket.handle = nil
|
|
32
|
-
@socket.
|
|
32
|
+
expect(@socket).not_to be_open
|
|
33
33
|
@socket.handle = @handle
|
|
34
34
|
@socket.close
|
|
35
|
-
@socket.
|
|
35
|
+
expect(@socket).not_to be_open
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "should write data to the handle" do
|
|
39
39
|
@socket.open
|
|
40
|
-
@handle.
|
|
40
|
+
expect(@handle).to receive(:write).with("foobar")
|
|
41
41
|
@socket.write("foobar")
|
|
42
|
-
@handle.
|
|
43
|
-
|
|
42
|
+
expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
|
|
43
|
+
expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "should raise an error when it cannot read from the handle" do
|
|
47
47
|
@socket.open
|
|
48
|
-
@handle.
|
|
49
|
-
|
|
48
|
+
expect(@handle).to receive(:readpartial).with(17).and_raise(StandardError)
|
|
49
|
+
expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "should return the data read when reading from the handle works" do
|
|
53
53
|
@socket.open
|
|
54
|
-
@handle.
|
|
55
|
-
@socket.read(17).
|
|
54
|
+
expect(@handle).to receive(:readpartial).with(17).and_return("test data")
|
|
55
|
+
expect(@socket.read(17)).to eq("test data")
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "should declare itself as closed when it has an error" do
|
|
59
59
|
@socket.open
|
|
60
|
-
@handle.
|
|
61
|
-
@socket.
|
|
62
|
-
|
|
63
|
-
@socket.
|
|
60
|
+
expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
|
|
61
|
+
expect(@socket).to be_open
|
|
62
|
+
expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
|
|
63
|
+
expect(@socket).not_to be_open
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it "should raise an error when the stream is closed" do
|
|
67
67
|
@socket.open
|
|
68
|
-
@handle.
|
|
69
|
-
@socket.
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
allow(@handle).to receive(:closed?).and_return(true)
|
|
69
|
+
expect(@socket).not_to be_open
|
|
70
|
+
expect { @socket.write("fail") }.to raise_error(IOError, "closed stream")
|
|
71
|
+
expect { @socket.read(10) }.to raise_error(IOError, "closed stream")
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "should support the timeout accessor for read" do
|
|
75
75
|
@socket.timeout = 3
|
|
76
76
|
@socket.open
|
|
77
|
-
IO.
|
|
78
|
-
@handle.
|
|
79
|
-
@socket.read(17).
|
|
77
|
+
expect(IO).to receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
|
|
78
|
+
expect(@handle).to receive(:readpartial).with(17).and_return("test data")
|
|
79
|
+
expect(@socket.read(17)).to eq("test data")
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "should support the timeout accessor for write" do
|
|
83
83
|
@socket.timeout = 3
|
|
84
84
|
@socket.open
|
|
85
|
-
IO.
|
|
86
|
-
@handle.
|
|
87
|
-
@handle.
|
|
88
|
-
@socket.write("test data").
|
|
85
|
+
expect(IO).to receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
|
|
86
|
+
expect(@handle).to receive(:write_nonblock).with("test data").and_return(4)
|
|
87
|
+
expect(@handle).to receive(:write_nonblock).with(" data").and_return(5)
|
|
88
|
+
expect(@socket.write("test data")).to eq(9)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it "should raise an error when read times out" do
|
|
92
92
|
@socket.timeout = 0.5
|
|
93
93
|
@socket.open
|
|
94
|
-
IO.
|
|
95
|
-
|
|
94
|
+
expect(IO).to receive(:select).once {sleep(0.5); nil}
|
|
95
|
+
expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "should raise an error when write times out" do
|
|
99
99
|
@socket.timeout = 0.5
|
|
100
100
|
@socket.open
|
|
101
|
-
IO.
|
|
102
|
-
|
|
101
|
+
allow(IO).to receive(:select).with(nil, [@handle], nil, 0.5).and_return(nil)
|
|
102
|
+
expect { @socket.write("test data") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
|
|
103
103
|
end
|
|
104
104
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -54,7 +54,7 @@ require 'thrift_spec_types'
|
|
|
54
54
|
require 'nonblocking_service'
|
|
55
55
|
|
|
56
56
|
module Fixtures
|
|
57
|
-
COMPACT_PROTOCOL_TEST_STRUCT = COMPACT_TEST.dup
|
|
57
|
+
COMPACT_PROTOCOL_TEST_STRUCT = Thrift::Test::COMPACT_TEST.dup
|
|
58
58
|
COMPACT_PROTOCOL_TEST_STRUCT.a_binary = [0,1,2,3,4,5,6,7,8].pack('c*')
|
|
59
59
|
COMPACT_PROTOCOL_TEST_STRUCT.set_byte_map = nil
|
|
60
60
|
COMPACT_PROTOCOL_TEST_STRUCT.map_byte_map = nil
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
|
|
22
|
+
|
|
23
|
+
describe 'SSLServerSocket' do
|
|
24
|
+
|
|
25
|
+
describe Thrift::SSLServerSocket do
|
|
26
|
+
before(:each) do
|
|
27
|
+
@socket = Thrift::SSLServerSocket.new(1234)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should provide a reasonable to_s" do
|
|
31
|
+
expect(@socket.to_s).to eq("ssl(socket(:1234))")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
|
|
22
|
+
|
|
23
|
+
describe 'SSLSocket' do
|
|
24
|
+
|
|
25
|
+
describe Thrift::SSLSocket do
|
|
26
|
+
before(:each) do
|
|
27
|
+
@context = OpenSSL::SSL::SSLContext.new
|
|
28
|
+
@socket = Thrift::SSLSocket.new
|
|
29
|
+
@simple_socket_handle = double("Handle", :closed? => false)
|
|
30
|
+
allow(@simple_socket_handle).to receive(:close)
|
|
31
|
+
allow(@simple_socket_handle).to receive(:connect_nonblock)
|
|
32
|
+
allow(@simple_socket_handle).to receive(:setsockopt)
|
|
33
|
+
|
|
34
|
+
@handle = double(double("SSLHandle", :connect_nonblock => true, :post_connection_check => true), :closed? => false)
|
|
35
|
+
allow(@handle).to receive(:connect_nonblock)
|
|
36
|
+
allow(@handle).to receive(:close)
|
|
37
|
+
allow(@handle).to receive(:post_connection_check)
|
|
38
|
+
|
|
39
|
+
allow(::Socket).to receive(:new).and_return(@simple_socket_handle)
|
|
40
|
+
allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@handle)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it_should_behave_like "a socket"
|
|
44
|
+
|
|
45
|
+
it "should raise a TransportException when it cannot open a ssl socket" do
|
|
46
|
+
expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
|
|
47
|
+
expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should open a ::Socket with default args" do
|
|
51
|
+
expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(@simple_socket_handle, nil).and_return(@handle)
|
|
52
|
+
expect(@handle).to receive(:post_connection_check).with('localhost')
|
|
53
|
+
@socket.open
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should accept host/port options" do
|
|
57
|
+
handle = double("Handle", :connect_nonblock => true, :setsockopt => nil)
|
|
58
|
+
allow(::Socket).to receive(:new).and_return(handle)
|
|
59
|
+
expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
|
|
60
|
+
expect(::Socket).to receive(:sockaddr_in)
|
|
61
|
+
expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(handle, nil).and_return(@handle)
|
|
62
|
+
expect(@handle).to receive(:post_connection_check).with('my.domain')
|
|
63
|
+
Thrift::SSLSocket.new('my.domain', 1234, 6000, nil).open
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should accept an optional timeout" do
|
|
67
|
+
expect(Thrift::SSLSocket.new('localhost', 8080, 5).timeout).to eq(5)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should accept an optional context" do
|
|
71
|
+
expect(Thrift::SSLSocket.new('localhost', 8080, 5, @context).ssl_context).to eq(@context)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should provide a reasonable to_s" do
|
|
75
|
+
expect(Thrift::SSLSocket.new('myhost', 8090).to_s).to eq("ssl(socket(myhost:8090))")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|