thrift 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +107 -4
- data/ext/binary_protocol_accelerated.c +52 -17
- data/ext/compact_protocol.c +135 -70
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +4 -4
- data/ext/macros.h +11 -0
- data/ext/memory_buffer.c +35 -17
- data/ext/struct.c +185 -64
- data/ext/thrift_native.c +6 -0
- data/lib/thrift/bytes.rb +2 -2
- data/lib/thrift/client.rb +31 -22
- data/lib/thrift/exceptions.rb +10 -8
- data/lib/thrift/multiplexed_processor.rb +5 -6
- data/lib/thrift/processor.rb +24 -3
- data/lib/thrift/protocol/base_protocol.rb +53 -27
- data/lib/thrift/protocol/binary_protocol.rb +54 -40
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
- data/lib/thrift/protocol/compact_protocol.rb +193 -88
- data/lib/thrift/protocol/header_protocol.rb +14 -3
- data/lib/thrift/protocol/json_protocol.rb +146 -104
- data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
- data/lib/thrift/protocol/protocol_decorator.rb +5 -2
- data/lib/thrift/serializer/serializer.rb +6 -0
- data/lib/thrift/server/base_server.rb +10 -2
- data/lib/thrift/server/nonblocking_server.rb +49 -26
- data/lib/thrift/server/rack_application.rb +69 -0
- data/lib/thrift/server/simple_server.rb +27 -23
- data/lib/thrift/server/thin_http_server.rb +20 -44
- data/lib/thrift/server/thread_pool_server.rb +20 -17
- data/lib/thrift/server/threaded_server.rb +22 -26
- data/lib/thrift/struct.rb +33 -18
- data/lib/thrift/struct_union.rb +36 -30
- data/lib/thrift/transport/base_transport.rb +23 -5
- data/lib/thrift/transport/buffered_transport.rb +4 -4
- data/lib/thrift/transport/framed_transport.rb +32 -7
- data/lib/thrift/transport/header_transport.rb +130 -50
- data/lib/thrift/transport/http_client_transport.rb +27 -14
- data/lib/thrift/transport/io_stream_transport.rb +2 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
- data/lib/thrift/transport/server_socket.rb +4 -5
- data/lib/thrift/transport/socket.rb +20 -22
- data/lib/thrift/transport/ssl_server_socket.rb +64 -4
- data/lib/thrift/transport/ssl_socket.rb +32 -5
- data/lib/thrift/transport/unix_server_socket.rb +1 -1
- data/lib/thrift/transport/unix_socket.rb +4 -6
- data/lib/thrift/types.rb +22 -22
- data/lib/thrift/union.rb +20 -11
- data/lib/thrift/uuid.rb +8 -8
- data/lib/thrift.rb +39 -39
- metadata +5 -230
- data/benchmark/Benchmark.thrift +0 -24
- data/benchmark/benchmark.rb +0 -286
- data/benchmark/client.rb +0 -118
- data/benchmark/server.rb +0 -121
- data/benchmark/thin_server.rb +0 -46
- data/lib/thrift/server/mongrel_http_server.rb +0 -61
- data/spec/BaseService.thrift +0 -27
- data/spec/ExtendedService.thrift +0 -25
- data/spec/Referenced.thrift +0 -44
- data/spec/ThriftNamespacedSpec.thrift +0 -53
- data/spec/ThriftSpec.thrift +0 -203
- data/spec/base_protocol_spec.rb +0 -244
- data/spec/base_transport_spec.rb +0 -428
- data/spec/binary_protocol_accelerated_spec.rb +0 -47
- data/spec/binary_protocol_spec.rb +0 -73
- data/spec/binary_protocol_spec_shared.rb +0 -509
- data/spec/bytes_spec.rb +0 -117
- data/spec/client_spec.rb +0 -167
- data/spec/compact_protocol_spec.rb +0 -295
- data/spec/constants_demo_spec.rb +0 -102
- data/spec/exception_spec.rb +0 -141
- data/spec/flat_spec.rb +0 -63
- data/spec/header_protocol_spec.rb +0 -476
- data/spec/header_transport_spec.rb +0 -431
- data/spec/http_client_spec.rb +0 -160
- data/spec/json_protocol_spec.rb +0 -574
- data/spec/multiplexed_processor_spec.rb +0 -75
- data/spec/namespaced_spec.rb +0 -67
- data/spec/nonblocking_server_spec.rb +0 -429
- data/spec/processor_spec.rb +0 -80
- data/spec/recursion_depth_spec.rb +0 -223
- data/spec/serializer_spec.rb +0 -67
- data/spec/server_socket_spec.rb +0 -121
- data/spec/server_spec.rb +0 -238
- data/spec/socket_spec.rb +0 -174
- data/spec/socket_spec_shared.rb +0 -168
- data/spec/spec_helper.rb +0 -70
- data/spec/ssl_server_socket_spec.rb +0 -85
- data/spec/ssl_socket_spec.rb +0 -248
- data/spec/struct_nested_containers_spec.rb +0 -191
- data/spec/struct_spec.rb +0 -398
- data/spec/support/header_protocol_helper.rb +0 -55
- data/spec/thin_http_server_spec.rb +0 -127
- data/spec/types_spec.rb +0 -118
- data/spec/union_spec.rb +0 -273
- data/spec/unix_socket_spec.rb +0 -131
- data/spec/uuid_validation_spec.rb +0 -239
- data/test/fuzz/Makefile +0 -779
- data/test/fuzz/Makefile.am +0 -173
- data/test/fuzz/Makefile.in +0 -775
- data/test/fuzz/README.md +0 -149
- data/test/fuzz/fuzz_common.rb +0 -96
- data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_tracer.rb +0 -29
data/spec/namespaced_spec.rb
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
#
|
|
3
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
-
# or more contributor license agreements. See the NOTICE file
|
|
5
|
-
# distributed with this work for additional information
|
|
6
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
7
|
-
# to you under the Apache License, Version 2.0 (the
|
|
8
|
-
# "License"); you may not use this file except in compliance
|
|
9
|
-
# with the License. You may obtain a copy of the License at
|
|
10
|
-
#
|
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
#
|
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
|
14
|
-
# software distributed under the License is distributed on an
|
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
-
# KIND, either express or implied. See the License for the
|
|
17
|
-
# specific language governing permissions and limitations
|
|
18
|
-
# under the License.
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
require 'spec_helper'
|
|
22
|
-
|
|
23
|
-
describe 'namespaced generation' do
|
|
24
|
-
before do
|
|
25
|
-
require 'namespaced_spec_namespace/namespaced_nonblocking_service'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "generated the right files" do
|
|
29
|
-
prefix = File.expand_path("../gen-rb", __FILE__)
|
|
30
|
-
["namespaced_spec_namespace/namespaced_nonblocking_service.rb",
|
|
31
|
-
"namespaced_spec_namespace/thrift_namespaced_spec_constants.rb",
|
|
32
|
-
"namespaced_spec_namespace/thrift_namespaced_spec_types.rb",
|
|
33
|
-
"other_namespace/referenced_constants.rb",
|
|
34
|
-
"other_namespace/referenced_types.rb"
|
|
35
|
-
].each do |name|
|
|
36
|
-
expect(File.exist?(File.join(prefix, name))).to be_truthy
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "did not generate the wrong files" do
|
|
41
|
-
prefix = File.expand_path("../gen-rb", __FILE__)
|
|
42
|
-
["namespaced_nonblocking_service.rb",
|
|
43
|
-
"thrift_namespaced_spec_constants.rb",
|
|
44
|
-
"thrift_namespaced_spec_types.rb",
|
|
45
|
-
"referenced_constants.rb",
|
|
46
|
-
"referenced_types.rb"
|
|
47
|
-
].each do |name|
|
|
48
|
-
expect(File.exist?(File.join(prefix, name))).not_to be_truthy
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "has a service class in the right place" do
|
|
53
|
-
expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "has a struct in the right place" do
|
|
57
|
-
expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "required an included file" do
|
|
61
|
-
expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "extended a service" do
|
|
65
|
-
require "extended/extended_service"
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
#
|
|
3
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
-
# or more contributor license agreements. See the NOTICE file
|
|
5
|
-
# distributed with this work for additional information
|
|
6
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
7
|
-
# to you under the Apache License, Version 2.0 (the
|
|
8
|
-
# "License"); you may not use this file except in compliance
|
|
9
|
-
# with the License. You may obtain a copy of the License at
|
|
10
|
-
#
|
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
#
|
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
|
14
|
-
# software distributed under the License is distributed on an
|
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
-
# KIND, either express or implied. See the License for the
|
|
17
|
-
# specific language governing permissions and limitations
|
|
18
|
-
# under the License.
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
require 'spec_helper'
|
|
22
|
-
require 'timeout'
|
|
23
|
-
|
|
24
|
-
describe 'NonblockingServer' do
|
|
25
|
-
class Handler
|
|
26
|
-
def initialize
|
|
27
|
-
@queue = Queue.new
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
attr_accessor :server
|
|
31
|
-
|
|
32
|
-
def greeting(english)
|
|
33
|
-
if english
|
|
34
|
-
SpecNamespace::Hello.new
|
|
35
|
-
else
|
|
36
|
-
SpecNamespace::Hello.new(:greeting => "Aloha!")
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def block
|
|
41
|
-
@queue.pop
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def unblock(n)
|
|
45
|
-
n.times { @queue.push true }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def sleep(time)
|
|
49
|
-
Kernel.sleep time
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def shutdown
|
|
53
|
-
@server.shutdown(0, false)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class SpecTransport < Thrift::BaseTransport
|
|
58
|
-
def initialize(transport, queue)
|
|
59
|
-
@transport = transport
|
|
60
|
-
@queue = queue
|
|
61
|
-
@flushed = false
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def open?
|
|
65
|
-
@transport.open?
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def open
|
|
69
|
-
@transport.open
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def close
|
|
73
|
-
@transport.close
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def read(sz)
|
|
77
|
-
@transport.read(sz)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def write(buf, sz = nil)
|
|
81
|
-
@transport.write(buf, sz)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def flush
|
|
85
|
-
@queue.push :flushed unless @flushed or @queue.nil?
|
|
86
|
-
@flushed = true
|
|
87
|
-
@transport.flush
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
class SpecServerSocket < Thrift::ServerSocket
|
|
92
|
-
def initialize(host, port, queue)
|
|
93
|
-
super(host, port)
|
|
94
|
-
@queue = queue
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def listen
|
|
98
|
-
super
|
|
99
|
-
@queue.push :listen
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
describe Thrift::NonblockingServer do
|
|
104
|
-
before(:each) do
|
|
105
|
-
@port = available_port
|
|
106
|
-
handler = Handler.new
|
|
107
|
-
processor = SpecNamespace::NonblockingService::Processor.new(handler)
|
|
108
|
-
queue = Queue.new
|
|
109
|
-
@transport = SpecServerSocket.new('localhost', @port, queue)
|
|
110
|
-
transport_factory = Thrift::FramedTransportFactory.new
|
|
111
|
-
logger = Logger.new(STDERR)
|
|
112
|
-
logger.level = Logger::WARN
|
|
113
|
-
@server = Thrift::NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
|
|
114
|
-
handler.server = @server
|
|
115
|
-
@server_thread = Thread.new(Thread.current) do |master_thread|
|
|
116
|
-
begin
|
|
117
|
-
@server.serve
|
|
118
|
-
rescue => e
|
|
119
|
-
p e
|
|
120
|
-
puts e.backtrace * "\n"
|
|
121
|
-
master_thread.raise e
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
queue.pop
|
|
125
|
-
wait_until_listening(@transport, @server_thread)
|
|
126
|
-
|
|
127
|
-
@clients = []
|
|
128
|
-
@catch_exceptions = false
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
after(:each) do
|
|
132
|
-
@clients.each { |client, trans| trans.close }
|
|
133
|
-
@server.shutdown(1, false) if @server
|
|
134
|
-
@server_thread.join(2) if @server_thread
|
|
135
|
-
@server_thread.kill if @server_thread && @server_thread.alive?
|
|
136
|
-
@server_thread.join(2) if @server_thread
|
|
137
|
-
@transport.close if @transport
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def setup_client(queue = nil)
|
|
141
|
-
transport = SpecTransport.new(Thrift::FramedTransport.new(Thrift::Socket.new('localhost', @port)), queue)
|
|
142
|
-
protocol = Thrift::BinaryProtocol.new(transport)
|
|
143
|
-
client = SpecNamespace::NonblockingService::Client.new(protocol)
|
|
144
|
-
transport.open
|
|
145
|
-
@clients << [client, transport]
|
|
146
|
-
client
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def setup_client_thread(result)
|
|
150
|
-
queue = Queue.new
|
|
151
|
-
Thread.new do
|
|
152
|
-
begin
|
|
153
|
-
client = setup_client
|
|
154
|
-
while (cmd = queue.pop)
|
|
155
|
-
msg, *args = cmd
|
|
156
|
-
case msg
|
|
157
|
-
when :block
|
|
158
|
-
result << client.block
|
|
159
|
-
when :unblock
|
|
160
|
-
client.unblock(args.first)
|
|
161
|
-
when :hello
|
|
162
|
-
result << client.greeting(true) # ignore result
|
|
163
|
-
when :sleep
|
|
164
|
-
client.sleep(args[0] || 0.5)
|
|
165
|
-
result << :slept
|
|
166
|
-
when :shutdown
|
|
167
|
-
client.shutdown
|
|
168
|
-
when :exit
|
|
169
|
-
result << :done
|
|
170
|
-
break
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
@clients.each { |c, t| t.close and break if c == client } # close the transport
|
|
174
|
-
rescue => e
|
|
175
|
-
raise e unless @catch_exceptions
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
queue
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it "should handle basic message passing" do
|
|
182
|
-
client = setup_client
|
|
183
|
-
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
|
184
|
-
expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
|
|
185
|
-
@server.shutdown
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
it "should handle concurrent clients" do
|
|
189
|
-
queue = Queue.new
|
|
190
|
-
trans_queue = Queue.new
|
|
191
|
-
4.times do
|
|
192
|
-
Thread.new(Thread.current) do |main_thread|
|
|
193
|
-
begin
|
|
194
|
-
queue.push setup_client(trans_queue).block
|
|
195
|
-
rescue => e
|
|
196
|
-
main_thread.raise e
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
4.times { trans_queue.pop }
|
|
201
|
-
setup_client.unblock(4)
|
|
202
|
-
4.times { expect(queue.pop).to be_truthy }
|
|
203
|
-
@server.shutdown
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
it "should handle messages from more than 5 long-lived connections" do
|
|
207
|
-
queues = []
|
|
208
|
-
result = Queue.new
|
|
209
|
-
7.times do |i|
|
|
210
|
-
queues << setup_client_thread(result)
|
|
211
|
-
Thread.pass if i == 4 # give the server time to accept connections
|
|
212
|
-
end
|
|
213
|
-
client = setup_client
|
|
214
|
-
# block 4 connections
|
|
215
|
-
4.times { |i| queues[i] << :block }
|
|
216
|
-
queues[4] << :hello
|
|
217
|
-
queues[5] << :hello
|
|
218
|
-
queues[6] << :hello
|
|
219
|
-
3.times { expect(result.pop).to eq(SpecNamespace::Hello.new) }
|
|
220
|
-
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
|
221
|
-
queues[5] << [:unblock, 4]
|
|
222
|
-
4.times { expect(result.pop).to be_truthy }
|
|
223
|
-
queues[2] << :hello
|
|
224
|
-
expect(result.pop).to eq(SpecNamespace::Hello.new)
|
|
225
|
-
expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
|
|
226
|
-
7.times { queues.shift << :exit }
|
|
227
|
-
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
|
228
|
-
@server.shutdown
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it "should shut down when asked" do
|
|
232
|
-
# connect first to ensure it's running
|
|
233
|
-
client = setup_client
|
|
234
|
-
client.greeting(false) # force a message pass
|
|
235
|
-
@server.shutdown
|
|
236
|
-
expect(@server_thread.join(2)).to be_an_instance_of(Thread)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it "should continue processing active messages when shutting down" do
|
|
240
|
-
result = Queue.new
|
|
241
|
-
client = setup_client_thread(result)
|
|
242
|
-
client << :sleep
|
|
243
|
-
sleep 0.1 # give the server time to start processing the client's message
|
|
244
|
-
@server.shutdown
|
|
245
|
-
expect(@server_thread.join(2)).to be_an_instance_of(Thread)
|
|
246
|
-
expect(result.pop).to eq(:slept)
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
it "should kill active messages when they don't expire while shutting down" do
|
|
250
|
-
result = Queue.new
|
|
251
|
-
client = setup_client_thread(result)
|
|
252
|
-
client << [:sleep, 10.0]
|
|
253
|
-
sleep 0.1 # start processing the client's message
|
|
254
|
-
@server.shutdown(1)
|
|
255
|
-
@catch_exceptions = true
|
|
256
|
-
expect(@server_thread.join(3)).not_to be_nil
|
|
257
|
-
expect(result).to be_empty
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
it "should allow shutting down in response to a message" do
|
|
261
|
-
client = setup_client
|
|
262
|
-
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
|
263
|
-
client.shutdown
|
|
264
|
-
expect(@server_thread.join(2)).not_to be_nil
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
describe Thrift::NonblockingServer::IOManager do
|
|
269
|
-
def build_io_manager
|
|
270
|
-
logger = Logger.new(IO::NULL)
|
|
271
|
-
logger.level = Logger::FATAL
|
|
272
|
-
Thrift::NonblockingServer::IOManager.new(
|
|
273
|
-
double('processor'),
|
|
274
|
-
double('server_transport'),
|
|
275
|
-
Thrift::BaseTransportFactory.new,
|
|
276
|
-
Thrift::BinaryProtocolFactory.new,
|
|
277
|
-
1,
|
|
278
|
-
logger
|
|
279
|
-
)
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
it "closes tracked connections and signal pipes during forced cleanup" do
|
|
283
|
-
io_manager = build_io_manager
|
|
284
|
-
connection = double('connection', :close => nil)
|
|
285
|
-
pipe_a = double('pipe_a', :closed? => false, :close => nil)
|
|
286
|
-
pipe_b = double('pipe_b', :closed? => false, :close => nil)
|
|
287
|
-
|
|
288
|
-
io_manager.instance_variable_set(:@connections, [connection])
|
|
289
|
-
io_manager.instance_variable_set(:@buffers, { connection => 'frame' })
|
|
290
|
-
io_manager.instance_variable_set(:@signal_pipes, [pipe_a, pipe_b])
|
|
291
|
-
io_manager.instance_variable_set(:@worker_threads, [])
|
|
292
|
-
|
|
293
|
-
io_manager.ensure_closed
|
|
294
|
-
|
|
295
|
-
expect(connection).to have_received(:close)
|
|
296
|
-
expect(pipe_a).to have_received(:close)
|
|
297
|
-
expect(pipe_b).to have_received(:close)
|
|
298
|
-
expect(io_manager.instance_variable_get(:@connections)).to be_empty
|
|
299
|
-
expect(io_manager.instance_variable_get(:@buffers)).to be_empty
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
it "continues closing remaining signal pipes when one close raises" do
|
|
303
|
-
io_manager = build_io_manager
|
|
304
|
-
pipe_a = double('pipe_a', :closed? => false)
|
|
305
|
-
pipe_b = double('pipe_b', :closed? => false, :close => nil)
|
|
306
|
-
|
|
307
|
-
allow(pipe_a).to receive(:close).and_raise(IOError)
|
|
308
|
-
|
|
309
|
-
io_manager.instance_variable_set(:@signal_pipes, [pipe_a, pipe_b])
|
|
310
|
-
io_manager.instance_variable_set(:@worker_threads, [])
|
|
311
|
-
|
|
312
|
-
io_manager.send(:close_signal_pipes)
|
|
313
|
-
|
|
314
|
-
expect(pipe_a).to have_received(:close)
|
|
315
|
-
expect(pipe_b).to have_received(:close)
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
it "drops removed connections from bookkeeping" do
|
|
319
|
-
io_manager = build_io_manager
|
|
320
|
-
connection = double('connection', :close => nil)
|
|
321
|
-
|
|
322
|
-
io_manager.instance_variable_set(:@connections, [connection])
|
|
323
|
-
io_manager.instance_variable_set(:@buffers, { connection => 'frame' })
|
|
324
|
-
|
|
325
|
-
io_manager.send(:remove_connection, connection)
|
|
326
|
-
|
|
327
|
-
expect(io_manager.instance_variable_get(:@connections)).to be_empty
|
|
328
|
-
expect(io_manager.instance_variable_get(:@buffers)).to be_empty
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
describe "#{Thrift::NonblockingServer} with TLS transport" do
|
|
333
|
-
before(:each) do
|
|
334
|
-
@port = available_port
|
|
335
|
-
handler = Handler.new
|
|
336
|
-
processor = SpecNamespace::NonblockingService::Processor.new(handler)
|
|
337
|
-
@transport = Thrift::SSLServerSocket.new('localhost', @port, create_server_ssl_context)
|
|
338
|
-
transport_factory = Thrift::FramedTransportFactory.new
|
|
339
|
-
logger = Logger.new(STDERR)
|
|
340
|
-
logger.level = Logger::WARN
|
|
341
|
-
@server = Thrift::NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
|
|
342
|
-
handler.server = @server
|
|
343
|
-
|
|
344
|
-
@server_thread = Thread.new(Thread.current) do |master_thread|
|
|
345
|
-
begin
|
|
346
|
-
@server.serve
|
|
347
|
-
rescue => e
|
|
348
|
-
master_thread.raise e
|
|
349
|
-
end
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
@clients = []
|
|
353
|
-
wait_until_listening(@transport, @server_thread)
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
after(:each) do
|
|
357
|
-
@clients.each(&:close)
|
|
358
|
-
@server.shutdown if @server
|
|
359
|
-
@server_thread.join(2) if @server_thread
|
|
360
|
-
@transport.close if @transport
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
it "should handle requests over TLS" do
|
|
364
|
-
expect(@server_thread).to be_alive
|
|
365
|
-
|
|
366
|
-
client = setup_tls_client
|
|
367
|
-
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
|
368
|
-
|
|
369
|
-
@server.shutdown
|
|
370
|
-
expect(@server_thread.join(2)).to be_an_instance_of(Thread)
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
def setup_tls_client
|
|
374
|
-
transport = Thrift::FramedTransport.new(
|
|
375
|
-
Thrift::SSLSocket.new('localhost', @port, nil, create_client_ssl_context)
|
|
376
|
-
)
|
|
377
|
-
protocol = Thrift::BinaryProtocol.new(transport)
|
|
378
|
-
client = SpecNamespace::NonblockingService::Client.new(protocol)
|
|
379
|
-
transport.open
|
|
380
|
-
@clients << transport
|
|
381
|
-
client
|
|
382
|
-
end
|
|
383
|
-
|
|
384
|
-
def ssl_keys_dir
|
|
385
|
-
File.expand_path('../../../test/keys', __dir__)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
def create_server_ssl_context
|
|
389
|
-
OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
|
390
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
391
|
-
if ctx.respond_to?(:min_version=) && OpenSSL::SSL.const_defined?(:TLS1_2_VERSION)
|
|
392
|
-
ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
393
|
-
end
|
|
394
|
-
ctx.ca_file = File.join(ssl_keys_dir, 'CA.pem')
|
|
395
|
-
ctx.cert = OpenSSL::X509::Certificate.new(File.read(File.join(ssl_keys_dir, 'server.crt')))
|
|
396
|
-
ctx.cert_store = OpenSSL::X509::Store.new
|
|
397
|
-
ctx.cert_store.add_file(File.join(ssl_keys_dir, 'client.pem'))
|
|
398
|
-
ctx.key = OpenSSL::PKey::RSA.new(File.read(File.join(ssl_keys_dir, 'server.key')))
|
|
399
|
-
end
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
def create_client_ssl_context
|
|
403
|
-
OpenSSL::SSL::SSLContext.new.tap do |ctx|
|
|
404
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
405
|
-
if ctx.respond_to?(:min_version=) && OpenSSL::SSL.const_defined?(:TLS1_2_VERSION)
|
|
406
|
-
ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
407
|
-
end
|
|
408
|
-
ctx.ca_file = File.join(ssl_keys_dir, 'CA.pem')
|
|
409
|
-
ctx.cert = OpenSSL::X509::Certificate.new(File.read(File.join(ssl_keys_dir, 'client.crt')))
|
|
410
|
-
ctx.cert_store = OpenSSL::X509::Store.new
|
|
411
|
-
ctx.cert_store.add_file(File.join(ssl_keys_dir, 'server.pem'))
|
|
412
|
-
ctx.key = OpenSSL::PKey::RSA.new(File.read(File.join(ssl_keys_dir, 'client.key')))
|
|
413
|
-
end
|
|
414
|
-
end
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
def wait_until_listening(server_transport, server_thread)
|
|
418
|
-
Timeout.timeout(2) do
|
|
419
|
-
until server_transport.handle
|
|
420
|
-
raise "Server thread exited unexpectedly" unless server_thread.alive?
|
|
421
|
-
sleep 0.01
|
|
422
|
-
end
|
|
423
|
-
end
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
def available_port
|
|
427
|
-
TCPServer.open('localhost', 0) { |server| server.addr[1] }
|
|
428
|
-
end
|
|
429
|
-
end
|
data/spec/processor_spec.rb
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
#
|
|
3
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
-
# or more contributor license agreements. See the NOTICE file
|
|
5
|
-
# distributed with this work for additional information
|
|
6
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
7
|
-
# to you under the Apache License, Version 2.0 (the
|
|
8
|
-
# "License"); you may not use this file except in compliance
|
|
9
|
-
# with the License. You may obtain a copy of the License at
|
|
10
|
-
#
|
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
#
|
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
|
14
|
-
# software distributed under the License is distributed on an
|
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
-
# KIND, either express or implied. See the License for the
|
|
17
|
-
# specific language governing permissions and limitations
|
|
18
|
-
# under the License.
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
require 'spec_helper'
|
|
22
|
-
|
|
23
|
-
describe 'Processor' do
|
|
24
|
-
class ProcessorSpec
|
|
25
|
-
include Thrift::Processor
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe Thrift::Processor do
|
|
29
|
-
before(:each) do
|
|
30
|
-
@processor = ProcessorSpec.new(double("MockHandler"))
|
|
31
|
-
@prot = double("MockProtocol")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def mock_trans(obj)
|
|
35
|
-
expect(obj).to receive(:trans).ordered do
|
|
36
|
-
double("trans").tap do |trans|
|
|
37
|
-
expect(trans).to receive(:flush).ordered
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should call process_<message> when it receives that message" do
|
|
43
|
-
expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 17]
|
|
44
|
-
expect(@processor).to receive(:process_testMessage).with(17, @prot, @prot).ordered
|
|
45
|
-
expect(@processor.process(@prot, @prot)).to eq(true)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "should raise an ApplicationException when the received message cannot be processed" do
|
|
49
|
-
expect(@prot).to receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
|
|
50
|
-
expect(@prot).to receive(:skip).with(Thrift::Types::STRUCT).ordered
|
|
51
|
-
expect(@prot).to receive(:read_message_end).ordered
|
|
52
|
-
expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::EXCEPTION, 4).ordered
|
|
53
|
-
e = double(Thrift::ApplicationException)
|
|
54
|
-
expect(e).to receive(:write).with(@prot).ordered
|
|
55
|
-
expect(Thrift::ApplicationException).to receive(:new).with(Thrift::ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return(e)
|
|
56
|
-
expect(@prot).to receive(:write_message_end).ordered
|
|
57
|
-
mock_trans(@prot)
|
|
58
|
-
@processor.process(@prot, @prot)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should pass args off to the args class" do
|
|
62
|
-
args_class = double("MockArgsClass")
|
|
63
|
-
args = double("#<MockArgsClass:mock>").tap do |args|
|
|
64
|
-
expect(args).to receive(:read).with(@prot).ordered
|
|
65
|
-
end
|
|
66
|
-
expect(args_class).to receive(:new).and_return args
|
|
67
|
-
expect(@prot).to receive(:read_message_end).ordered
|
|
68
|
-
expect(@processor.read_args(@prot, args_class)).to eql(args)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "should write out a reply when asked" do
|
|
72
|
-
expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::REPLY, 23).ordered
|
|
73
|
-
result = double("MockResult")
|
|
74
|
-
expect(result).to receive(:write).with(@prot).ordered
|
|
75
|
-
expect(@prot).to receive(:write_message_end).ordered
|
|
76
|
-
mock_trans(@prot)
|
|
77
|
-
@processor.write_result(result, @prot, 'testMessage', 23)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|