thrift 0.8.0 → 0.13.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 +7 -0
- data/{README → README.md} +0 -0
- data/ext/binary_protocol_accelerated.c +33 -14
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +27 -8
- data/ext/constants.h +8 -5
- data/ext/extconf.rb +5 -1
- data/ext/memory_buffer.c +12 -9
- data/ext/protocol.c +0 -185
- data/ext/protocol.h +0 -20
- data/ext/strlcpy.h +7 -3
- data/ext/struct.c +27 -7
- data/ext/thrift_native.c +16 -11
- data/lib/thrift.rb +10 -4
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +13 -4
- data/lib/thrift/exceptions.rb +3 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +24 -6
- data/lib/thrift/protocol/base_protocol.rb +109 -12
- data/lib/thrift/protocol/binary_protocol.rb +22 -7
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +23 -6
- data/lib/thrift/protocol/json_protocol.rb +786 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/mongrel_http_server.rb +2 -0
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thin_http_server.rb +91 -0
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/struct.rb +1 -1
- data/lib/thrift/struct_union.rb +2 -2
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +30 -20
- data/lib/thrift/transport/buffered_transport.rb +25 -11
- data/lib/thrift/transport/framed_transport.rb +20 -11
- data/lib/thrift/transport/http_client_transport.rb +16 -6
- data/lib/thrift/transport/io_stream_transport.rb +5 -2
- data/lib/thrift/transport/memory_buffer_transport.rb +10 -6
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +23 -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/union.rb +3 -6
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- data/spec/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +158 -93
- data/spec/base_transport_spec.rb +194 -157
- data/spec/binary_protocol_accelerated_spec.rb +14 -14
- data/spec/binary_protocol_spec.rb +29 -16
- data/spec/binary_protocol_spec_shared.rb +148 -65
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +45 -47
- data/spec/compact_protocol_spec.rb +36 -22
- data/spec/exception_spec.rb +79 -80
- data/spec/flat_spec.rb +62 -0
- data/spec/http_client_spec.rb +91 -16
- data/spec/json_protocol_spec.rb +552 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +26 -28
- data/spec/processor_spec.rb +29 -32
- data/spec/serializer_spec.rb +31 -33
- data/spec/server_socket_spec.rb +32 -28
- data/spec/server_spec.rb +112 -84
- data/spec/socket_spec.rb +27 -20
- data/spec/socket_spec_shared.rb +32 -32
- data/spec/spec_helper.rb +17 -11
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +159 -161
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +71 -69
- data/spec/union_spec.rb +97 -76
- data/spec/unix_socket_spec.rb +49 -41
- metadata +268 -188
- data/CHANGELOG +0 -1
- data/benchmark/gen-rb/benchmark_constants.rb +0 -10
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -9
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/thrift_spec_constants.rb +0 -10
- data/spec/gen-rb/thrift_spec_types.rb +0 -345
- data/spec/mongrel_http_server_spec.rb +0 -117
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -273
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -760
- data/test/debug_proto/gen-rb/empty_service.rb +0 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
@@ -0,0 +1,67 @@
|
|
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
|
+
|
22
|
+
describe 'namespaced generation' do
|
23
|
+
before do
|
24
|
+
require 'namespaced_spec_namespace/namespaced_nonblocking_service'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "generated the right files" do
|
28
|
+
prefix = File.expand_path("../gen-rb", __FILE__)
|
29
|
+
["namespaced_spec_namespace/namespaced_nonblocking_service.rb",
|
30
|
+
"namespaced_spec_namespace/thrift_namespaced_spec_constants.rb",
|
31
|
+
"namespaced_spec_namespace/thrift_namespaced_spec_types.rb",
|
32
|
+
"other_namespace/referenced_constants.rb",
|
33
|
+
"other_namespace/referenced_types.rb"
|
34
|
+
].each do |name|
|
35
|
+
expect(File.exist?(File.join(prefix, name))).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "did not generate the wrong files" do
|
40
|
+
prefix = File.expand_path("../gen-rb", __FILE__)
|
41
|
+
["namespaced_nonblocking_service.rb",
|
42
|
+
"thrift_namespaced_spec_constants.rb",
|
43
|
+
"thrift_namespaced_spec_types.rb",
|
44
|
+
"referenced_constants.rb",
|
45
|
+
"referenced_types.rb"
|
46
|
+
].each do |name|
|
47
|
+
expect(File.exist?(File.join(prefix, name))).not_to be_truthy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has a service class in the right place" do
|
52
|
+
expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has a struct in the right place" do
|
56
|
+
expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
|
57
|
+
end
|
58
|
+
|
59
|
+
it "required an included file" do
|
60
|
+
expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
|
61
|
+
end
|
62
|
+
|
63
|
+
it "extended a service" do
|
64
|
+
require "extended/extended_service"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -17,11 +17,9 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
24
|
-
include SpecNamespace
|
22
|
+
describe 'NonblockingServer' do
|
25
23
|
|
26
24
|
class Handler
|
27
25
|
def initialize
|
@@ -55,7 +53,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
|
-
class SpecTransport < BaseTransport
|
56
|
+
class SpecTransport < Thrift::BaseTransport
|
59
57
|
def initialize(transport, queue)
|
60
58
|
@transport = transport
|
61
59
|
@queue = queue
|
@@ -89,7 +87,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
class SpecServerSocket < ServerSocket
|
90
|
+
class SpecServerSocket < Thrift::ServerSocket
|
93
91
|
def initialize(host, port, queue)
|
94
92
|
super(host, port)
|
95
93
|
@queue = queue
|
@@ -105,13 +103,13 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
105
103
|
before(:each) do
|
106
104
|
@port = 43251
|
107
105
|
handler = Handler.new
|
108
|
-
processor = NonblockingService::Processor.new(handler)
|
106
|
+
processor = SpecNamespace::NonblockingService::Processor.new(handler)
|
109
107
|
queue = Queue.new
|
110
108
|
@transport = SpecServerSocket.new('localhost', @port, queue)
|
111
|
-
transport_factory = FramedTransportFactory.new
|
109
|
+
transport_factory = Thrift::FramedTransportFactory.new
|
112
110
|
logger = Logger.new(STDERR)
|
113
111
|
logger.level = Logger::WARN
|
114
|
-
@server = NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
|
112
|
+
@server = Thrift::NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
|
115
113
|
handler.server = @server
|
116
114
|
@server_thread = Thread.new(Thread.current) do |master_thread|
|
117
115
|
begin
|
@@ -136,9 +134,9 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
136
134
|
end
|
137
135
|
|
138
136
|
def setup_client(queue = nil)
|
139
|
-
transport = SpecTransport.new(FramedTransport.new(Socket.new('localhost', @port)), queue)
|
140
|
-
protocol = BinaryProtocol.new(transport)
|
141
|
-
client = NonblockingService::Client.new(protocol)
|
137
|
+
transport = SpecTransport.new(Thrift::FramedTransport.new(Thrift::Socket.new('localhost', @port)), queue)
|
138
|
+
protocol = Thrift::BinaryProtocol.new(transport)
|
139
|
+
client = SpecNamespace::NonblockingService::Client.new(protocol)
|
142
140
|
transport.open
|
143
141
|
@clients << [client, transport]
|
144
142
|
client
|
@@ -178,8 +176,8 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
178
176
|
|
179
177
|
it "should handle basic message passing" do
|
180
178
|
client = setup_client
|
181
|
-
client.greeting(true).
|
182
|
-
client.greeting(false).
|
179
|
+
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
180
|
+
expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
|
183
181
|
@server.shutdown
|
184
182
|
end
|
185
183
|
|
@@ -197,7 +195,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
197
195
|
end
|
198
196
|
4.times { trans_queue.pop }
|
199
197
|
setup_client.unblock(4)
|
200
|
-
4.times { queue.pop.
|
198
|
+
4.times { expect(queue.pop).to be_truthy }
|
201
199
|
@server.shutdown
|
202
200
|
end
|
203
201
|
|
@@ -214,15 +212,15 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
214
212
|
queues[4] << :hello
|
215
213
|
queues[5] << :hello
|
216
214
|
queues[6] << :hello
|
217
|
-
3.times { result.pop.
|
218
|
-
client.greeting(true).
|
215
|
+
3.times { expect(result.pop).to eq(SpecNamespace::Hello.new) }
|
216
|
+
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
219
217
|
queues[5] << [:unblock, 4]
|
220
|
-
4.times { result.pop.
|
218
|
+
4.times { expect(result.pop).to be_truthy }
|
221
219
|
queues[2] << :hello
|
222
|
-
result.pop.
|
223
|
-
client.greeting(false).
|
220
|
+
expect(result.pop).to eq(SpecNamespace::Hello.new)
|
221
|
+
expect(client.greeting(false)).to eq(SpecNamespace::Hello.new(:greeting => 'Aloha!'))
|
224
222
|
7.times { queues.shift << :exit }
|
225
|
-
client.greeting(true).
|
223
|
+
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
226
224
|
@server.shutdown
|
227
225
|
end
|
228
226
|
|
@@ -231,7 +229,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
231
229
|
client = setup_client
|
232
230
|
client.greeting(false) # force a message pass
|
233
231
|
@server.shutdown
|
234
|
-
@server_thread.join(2).
|
232
|
+
expect(@server_thread.join(2)).to be_an_instance_of(Thread)
|
235
233
|
end
|
236
234
|
|
237
235
|
it "should continue processing active messages when shutting down" do
|
@@ -240,8 +238,8 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
240
238
|
client << :sleep
|
241
239
|
sleep 0.1 # give the server time to start processing the client's message
|
242
240
|
@server.shutdown
|
243
|
-
@server_thread.join(2).
|
244
|
-
result.pop.
|
241
|
+
expect(@server_thread.join(2)).to be_an_instance_of(Thread)
|
242
|
+
expect(result.pop).to eq(:slept)
|
245
243
|
end
|
246
244
|
|
247
245
|
it "should kill active messages when they don't expire while shutting down" do
|
@@ -251,15 +249,15 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
251
249
|
sleep 0.1 # start processing the client's message
|
252
250
|
@server.shutdown(1)
|
253
251
|
@catch_exceptions = true
|
254
|
-
@server_thread.join(3).
|
255
|
-
result.
|
252
|
+
expect(@server_thread.join(3)).not_to be_nil
|
253
|
+
expect(result).to be_empty
|
256
254
|
end
|
257
255
|
|
258
256
|
it "should allow shutting down in response to a message" do
|
259
257
|
client = setup_client
|
260
|
-
client.greeting(true).
|
258
|
+
expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
|
261
259
|
client.shutdown
|
262
|
-
@server_thread.join(2).
|
260
|
+
expect(@server_thread.join(2)).not_to be_nil
|
263
261
|
end
|
264
262
|
end
|
265
263
|
end
|
data/spec/processor_spec.rb
CHANGED
@@ -17,65 +17,62 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
22
|
+
describe 'Processor' do
|
24
23
|
|
25
24
|
class ProcessorSpec
|
26
25
|
include Thrift::Processor
|
27
26
|
end
|
28
27
|
|
29
|
-
describe
|
28
|
+
describe Thrift::Processor do
|
30
29
|
before(:each) do
|
31
|
-
@processor = ProcessorSpec.new(
|
32
|
-
@prot =
|
30
|
+
@processor = ProcessorSpec.new(double("MockHandler"))
|
31
|
+
@prot = double("MockProtocol")
|
33
32
|
end
|
34
33
|
|
35
34
|
def mock_trans(obj)
|
36
|
-
obj.
|
37
|
-
|
38
|
-
trans.
|
35
|
+
expect(obj).to receive(:trans).ordered do
|
36
|
+
double("trans").tap do |trans|
|
37
|
+
expect(trans).to receive(:flush).ordered
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
it "should call process_<message> when it receives that message" do
|
44
|
-
@prot.
|
45
|
-
@processor.
|
46
|
-
@processor.process(@prot, @prot).
|
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)
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should raise an ApplicationException when the received message cannot be processed" do
|
50
|
-
@prot.
|
51
|
-
@prot.
|
52
|
-
@prot.
|
53
|
-
@prot.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
@prot.should_receive(:write_message_end).ordered
|
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
|
60
57
|
mock_trans(@prot)
|
61
58
|
@processor.process(@prot, @prot)
|
62
59
|
end
|
63
60
|
|
64
61
|
it "should pass args off to the args class" do
|
65
|
-
args_class =
|
66
|
-
args =
|
67
|
-
args.
|
62
|
+
args_class = double("MockArgsClass")
|
63
|
+
args = double("#<MockArgsClass:mock>").tap do |args|
|
64
|
+
expect(args).to receive(:read).with(@prot).ordered
|
68
65
|
end
|
69
|
-
args_class.
|
70
|
-
@prot.
|
71
|
-
@processor.read_args(@prot, args_class).
|
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)
|
72
69
|
end
|
73
70
|
|
74
71
|
it "should write out a reply when asked" do
|
75
|
-
@prot.
|
76
|
-
result =
|
77
|
-
result.
|
78
|
-
@prot.
|
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
|
79
76
|
mock_trans(@prot)
|
80
77
|
@processor.write_result(result, @prot, 'testMessage', 23)
|
81
78
|
end
|
data/spec/serializer_spec.rb
CHANGED
@@ -17,53 +17,51 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
|
22
|
-
|
23
|
-
include Thrift
|
24
|
-
include SpecNamespace
|
22
|
+
describe 'Serializer' do
|
25
23
|
|
26
|
-
describe Serializer do
|
24
|
+
describe Thrift::Serializer do
|
27
25
|
it "should serialize structs to binary by default" do
|
28
|
-
serializer = Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
|
29
|
-
data = serializer.serialize(Hello.new(:greeting => "'Ello guv'nor!"))
|
30
|
-
data.
|
26
|
+
serializer = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
|
27
|
+
data = serializer.serialize(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
|
28
|
+
expect(data).to eq("\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00")
|
31
29
|
end
|
32
30
|
|
33
31
|
it "should serialize structs to the given protocol" do
|
34
|
-
protocol = BaseProtocol.new(
|
35
|
-
protocol.
|
36
|
-
protocol.
|
37
|
-
protocol.
|
38
|
-
protocol.
|
39
|
-
protocol.
|
40
|
-
protocol.
|
41
|
-
protocol_factory =
|
42
|
-
protocol_factory.
|
43
|
-
serializer = Serializer.new(protocol_factory)
|
44
|
-
serializer.serialize(Hello.new(:greeting => "Good day"))
|
32
|
+
protocol = Thrift::BaseProtocol.new(double("transport"))
|
33
|
+
expect(protocol).to receive(:write_struct_begin).with("SpecNamespace::Hello")
|
34
|
+
expect(protocol).to receive(:write_field_begin).with("greeting", Thrift::Types::STRING, 1)
|
35
|
+
expect(protocol).to receive(:write_string).with("Good day")
|
36
|
+
expect(protocol).to receive(:write_field_end)
|
37
|
+
expect(protocol).to receive(:write_field_stop)
|
38
|
+
expect(protocol).to receive(:write_struct_end)
|
39
|
+
protocol_factory = double("ProtocolFactory")
|
40
|
+
allow(protocol_factory).to receive(:get_protocol).and_return(protocol)
|
41
|
+
serializer = Thrift::Serializer.new(protocol_factory)
|
42
|
+
serializer.serialize(SpecNamespace::Hello.new(:greeting => "Good day"))
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
describe Deserializer do
|
46
|
+
describe Thrift::Deserializer do
|
49
47
|
it "should deserialize structs from binary by default" do
|
50
|
-
deserializer = Deserializer.new
|
48
|
+
deserializer = Thrift::Deserializer.new
|
51
49
|
data = "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
|
52
|
-
deserializer.deserialize(Hello.new, data).
|
50
|
+
expect(deserializer.deserialize(SpecNamespace::Hello.new, data)).to eq(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
|
53
51
|
end
|
54
52
|
|
55
53
|
it "should deserialize structs from the given protocol" do
|
56
|
-
protocol = BaseProtocol.new(
|
57
|
-
protocol.
|
58
|
-
protocol.
|
59
|
-
[nil, Types::STOP, 0])
|
60
|
-
protocol.
|
61
|
-
protocol.
|
62
|
-
protocol.
|
63
|
-
protocol_factory =
|
64
|
-
protocol_factory.
|
65
|
-
deserializer = Deserializer.new(protocol_factory)
|
66
|
-
deserializer.deserialize(Hello.new, "").
|
54
|
+
protocol = Thrift::BaseProtocol.new(double("transport"))
|
55
|
+
expect(protocol).to receive(:read_struct_begin).and_return("SpecNamespace::Hello")
|
56
|
+
expect(protocol).to receive(:read_field_begin).and_return(["greeting", Thrift::Types::STRING, 1],
|
57
|
+
[nil, Thrift::Types::STOP, 0])
|
58
|
+
expect(protocol).to receive(:read_string).and_return("Good day")
|
59
|
+
expect(protocol).to receive(:read_field_end)
|
60
|
+
expect(protocol).to receive(:read_struct_end)
|
61
|
+
protocol_factory = double("ProtocolFactory")
|
62
|
+
allow(protocol_factory).to receive(:get_protocol).and_return(protocol)
|
63
|
+
deserializer = Thrift::Deserializer.new(protocol_factory)
|
64
|
+
expect(deserializer.deserialize(SpecNamespace::Hello.new, "")).to eq(SpecNamespace::Hello.new(:greeting => "Good day"))
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
data/spec/server_socket_spec.rb
CHANGED
@@ -17,64 +17,68 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require 'spec_helper'
|
21
21
|
require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
|
22
22
|
|
23
|
-
|
24
|
-
include Thrift
|
23
|
+
describe 'Thrift::ServerSocket' do
|
25
24
|
|
26
|
-
describe ServerSocket do
|
25
|
+
describe Thrift::ServerSocket do
|
27
26
|
before(:each) do
|
28
|
-
@socket = ServerSocket.new(1234)
|
27
|
+
@socket = Thrift::ServerSocket.new(1234)
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should create a handle when calling listen" do
|
32
|
-
TCPServer.
|
31
|
+
expect(TCPServer).to receive(:new).with(nil, 1234)
|
33
32
|
@socket.listen
|
34
33
|
end
|
35
34
|
|
36
35
|
it "should accept an optional host argument" do
|
37
|
-
@socket = ServerSocket.new('localhost', 1234)
|
38
|
-
TCPServer.
|
36
|
+
@socket = Thrift::ServerSocket.new('localhost', 1234)
|
37
|
+
expect(TCPServer).to receive(:new).with('localhost', 1234)
|
38
|
+
@socket.to_s == "server(localhost:1234)"
|
39
39
|
@socket.listen
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should create a Thrift::Socket to wrap accepted sockets" do
|
43
|
-
handle =
|
44
|
-
TCPServer.
|
43
|
+
handle = double("TCPServer")
|
44
|
+
expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
|
45
45
|
@socket.listen
|
46
|
-
sock =
|
47
|
-
handle.
|
48
|
-
trans =
|
49
|
-
|
50
|
-
trans.
|
51
|
-
@socket.accept.
|
46
|
+
sock = double("sock")
|
47
|
+
expect(handle).to receive(:accept).and_return(sock)
|
48
|
+
trans = double("Socket")
|
49
|
+
expect(Thrift::Socket).to receive(:new).and_return(trans)
|
50
|
+
expect(trans).to receive(:handle=).with(sock)
|
51
|
+
expect(@socket.accept).to eq(trans)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should close the handle when closed" do
|
55
|
-
handle =
|
56
|
-
TCPServer.
|
55
|
+
handle = double("TCPServer", :closed? => false)
|
56
|
+
expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
|
57
57
|
@socket.listen
|
58
|
-
handle.
|
58
|
+
expect(handle).to receive(:close)
|
59
59
|
@socket.close
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should return nil when accepting if there is no handle" do
|
63
|
-
@socket.accept.
|
63
|
+
expect(@socket.accept).to be_nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should return true for closed? when appropriate" do
|
67
|
-
handle =
|
68
|
-
TCPServer.
|
67
|
+
handle = double("TCPServer", :closed? => false)
|
68
|
+
allow(TCPServer).to receive(:new).and_return(handle)
|
69
69
|
@socket.listen
|
70
|
-
@socket.
|
71
|
-
handle.
|
70
|
+
expect(@socket).not_to be_closed
|
71
|
+
allow(handle).to receive(:close)
|
72
72
|
@socket.close
|
73
|
-
@socket.
|
73
|
+
expect(@socket).to be_closed
|
74
74
|
@socket.listen
|
75
|
-
@socket.
|
76
|
-
handle.
|
77
|
-
@socket.
|
75
|
+
expect(@socket).not_to be_closed
|
76
|
+
allow(handle).to receive(:closed?).and_return(true)
|
77
|
+
expect(@socket).to be_closed
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should provide a reasonable to_s" do
|
81
|
+
expect(@socket.to_s).to eq("socket(:1234)")
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|