thrift 0.0.751142 → 0.0.810255.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -1
- data/Manifest +47 -44
- data/README +19 -6
- data/Rakefile +1 -1
- data/benchmark/Benchmark.thrift +19 -0
- data/benchmark/benchmark.rb +20 -3
- data/benchmark/client.rb +20 -2
- data/benchmark/server.rb +22 -4
- data/benchmark/thin_server.rb +22 -4
- data/ext/binary_protocol_accelerated.c +32 -21
- data/ext/binary_protocol_accelerated.h +19 -0
- data/ext/compact_protocol.c +665 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +19 -1
- data/ext/extconf.rb +19 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +29 -5
- data/ext/memory_buffer.h +19 -0
- data/ext/protocol.c +20 -1
- data/ext/protocol.h +19 -0
- data/ext/struct.c +115 -83
- data/ext/struct.h +19 -0
- data/ext/thrift_native.c +23 -2
- data/lib/thrift/client.rb +19 -1
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/exceptions.rb +19 -2
- data/lib/thrift/processor.rb +19 -1
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
- data/lib/thrift/protocol/compact_protocol.rb +422 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/{httpserver.rb → mongrel_http_server.rb} +19 -5
- data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +73 -47
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +70 -0
- data/lib/thrift/transport/buffered_transport.rb +77 -0
- data/lib/thrift/transport/framed_transport.rb +90 -0
- data/lib/thrift/transport/http_client_transport.rb +45 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +22 -53
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +20 -2
- data/lib/thrift.rb +50 -19
- data/script/proto_benchmark.rb +121 -0
- data/script/read_struct.rb +43 -0
- data/script/write_struct.rb +30 -0
- data/spec/ThriftSpec.thrift +40 -2
- data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
- data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
- data/spec/binary_protocol_accelerated_spec.rb +41 -0
- data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
- data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
- data/spec/client_spec.rb +23 -4
- data/spec/compact_protocol_spec.rb +117 -0
- data/spec/exception_spec.rb +19 -0
- data/spec/http_client_spec.rb +49 -0
- data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
- data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
- data/spec/processor_spec.rb +19 -0
- data/spec/serializer_spec.rb +27 -10
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +35 -16
- data/spec/socket_spec.rb +19 -55
- data/spec/socket_spec_shared.rb +19 -0
- data/spec/spec_helper.rb +34 -9
- data/spec/struct_spec.rb +26 -18
- data/spec/types_spec.rb +19 -1
- data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
- data/thrift.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +80 -70
- metadata.gz.sig +0 -0
- data/COPYING +0 -14
- data/LICENSE +0 -14
- data/Makefile.am +0 -15
- data/benchmark/gen-rb/BenchmarkService.rb +0 -81
- data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/Benchmark_types.rb +0 -10
- data/lib/thrift/deprecation.rb +0 -155
- data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
- data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
- data/lib/thrift/protocol/tprotocol.rb +0 -2
- data/lib/thrift/protocol.rb +0 -270
- data/lib/thrift/serializer.rb +0 -27
- data/lib/thrift/server/thttpserver.rb +0 -2
- data/lib/thrift/server/tserver.rb +0 -2
- data/lib/thrift/server.rb +0 -135
- data/lib/thrift/thrift.rb +0 -14
- data/lib/thrift/transport/httpclient.rb +0 -29
- data/lib/thrift/transport/thttpclient.rb +0 -2
- data/lib/thrift/transport/tsocket.rb +0 -2
- data/lib/thrift/transport/ttransport.rb +0 -2
- data/lib/thrift/transport/unixsocket.rb +0 -58
- data/lib/thrift/transport.rb +0 -319
- data/spec/backwards_compatibility_spec.rb +0 -136
- data/spec/binaryprotocolaccelerated_spec.rb +0 -101
- data/spec/deprecation_spec.rb +0 -443
- data/spec/gen-rb/NonblockingService.rb +0 -268
- data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
- data/spec/gen-rb/ThriftSpec_types.rb +0 -134
- data/spec/httpclient_spec.rb +0 -31
@@ -0,0 +1,117 @@
|
|
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 File.dirname(__FILE__) + '/spec_helper'
|
21
|
+
|
22
|
+
describe Thrift::CompactProtocol do
|
23
|
+
TESTS = {
|
24
|
+
:byte => (-127..127).to_a,
|
25
|
+
:i16 => (0..14).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
26
|
+
:i32 => (0..30).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
27
|
+
:i64 => (0..62).map {|shift| [1 << shift, -(1 << shift)]}.flatten.sort,
|
28
|
+
:string => ["", "1", "short", "fourteen123456", "fifteen12345678", "1" * 127, "1" * 3000],
|
29
|
+
:binary => ["", "\001", "\001" * 5, "\001" * 14, "\001" * 15, "\001" * 127, "\001" * 3000],
|
30
|
+
:double => [0.0, 1.0, -1.0, 1.1, -1.1, 10000000.1, 1.0/0.0, -1.0/0.0],
|
31
|
+
:bool => [true, false]
|
32
|
+
}
|
33
|
+
|
34
|
+
it "should encode and decode naked primitives correctly" do
|
35
|
+
TESTS.each_pair do |primitive_type, test_values|
|
36
|
+
test_values.each do |value|
|
37
|
+
# puts "testing #{value}" if primitive_type == :i64
|
38
|
+
trans = Thrift::MemoryBufferTransport.new
|
39
|
+
proto = Thrift::CompactProtocol.new(trans)
|
40
|
+
|
41
|
+
proto.send(writer(primitive_type), value)
|
42
|
+
# puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
|
43
|
+
read_back = proto.send(reader(primitive_type))
|
44
|
+
read_back.should == value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should encode and decode primitives in fields correctly" do
|
50
|
+
TESTS.each_pair do |primitive_type, test_values|
|
51
|
+
final_primitive_type = primitive_type == :binary ? :string : primitive_type
|
52
|
+
thrift_type = Thrift::Types.const_get(final_primitive_type.to_s.upcase)
|
53
|
+
# puts primitive_type
|
54
|
+
test_values.each do |value|
|
55
|
+
trans = Thrift::MemoryBufferTransport.new
|
56
|
+
proto = Thrift::CompactProtocol.new(trans)
|
57
|
+
|
58
|
+
proto.write_field_begin(nil, thrift_type, 15)
|
59
|
+
proto.send(writer(primitive_type), value)
|
60
|
+
proto.write_field_end
|
61
|
+
|
62
|
+
proto = Thrift::CompactProtocol.new(trans)
|
63
|
+
name, type, id = proto.read_field_begin
|
64
|
+
type.should == thrift_type
|
65
|
+
id.should == 15
|
66
|
+
read_back = proto.send(reader(primitive_type))
|
67
|
+
read_back.should == value
|
68
|
+
proto.read_field_end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should encode and decode a monster struct correctly" do
|
74
|
+
trans = Thrift::MemoryBufferTransport.new
|
75
|
+
proto = Thrift::CompactProtocol.new(trans)
|
76
|
+
|
77
|
+
struct = CompactProtoTestStruct.new
|
78
|
+
# sets and maps don't hash well... not sure what to do here.
|
79
|
+
struct.write(proto)
|
80
|
+
|
81
|
+
struct2 = CompactProtoTestStruct.new
|
82
|
+
struct2.read(proto)
|
83
|
+
struct2.should == struct
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should make method calls correctly" do
|
87
|
+
client_out_trans = Thrift::MemoryBufferTransport.new
|
88
|
+
client_out_proto = Thrift::CompactProtocol.new(client_out_trans)
|
89
|
+
|
90
|
+
client_in_trans = Thrift::MemoryBufferTransport.new
|
91
|
+
client_in_proto = Thrift::CompactProtocol.new(client_in_trans)
|
92
|
+
|
93
|
+
processor = Srv::Processor.new(JankyHandler.new)
|
94
|
+
|
95
|
+
client = Srv::Client.new(client_in_proto, client_out_proto)
|
96
|
+
client.send_Janky(1)
|
97
|
+
# puts client_out_trans.inspect_buffer
|
98
|
+
processor.process(client_out_proto, client_in_proto)
|
99
|
+
client.recv_Janky.should == 2
|
100
|
+
end
|
101
|
+
|
102
|
+
class JankyHandler
|
103
|
+
def Janky(i32arg)
|
104
|
+
i32arg * 2
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def writer(sym)
|
109
|
+
sym = sym == :binary ? :string : sym
|
110
|
+
"write_#{sym.to_s}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def reader(sym)
|
114
|
+
sym = sym == :binary ? :string : sym
|
115
|
+
"read_#{sym.to_s}"
|
116
|
+
end
|
117
|
+
end
|
data/spec/exception_spec.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
21
|
|
3
22
|
class ThriftExceptionSpec < Spec::ExampleGroup
|
@@ -0,0 +1,49 @@
|
|
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 File.dirname(__FILE__) + '/spec_helper'
|
21
|
+
|
22
|
+
class ThriftHTTPClientTransportSpec < Spec::ExampleGroup
|
23
|
+
include Thrift
|
24
|
+
|
25
|
+
describe HTTPClientTransport do
|
26
|
+
before(:each) do
|
27
|
+
@client = HTTPClientTransport.new("http://my.domain.com/path/to/service")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should always be open" do
|
31
|
+
@client.should be_open
|
32
|
+
@client.close
|
33
|
+
@client.should be_open
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should post via HTTP and return the results" do
|
37
|
+
@client.write "a test"
|
38
|
+
@client.write " frame"
|
39
|
+
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
|
40
|
+
mock("Net::HTTP").tee do |http|
|
41
|
+
http.should_receive(:use_ssl=).with(false)
|
42
|
+
http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@client.flush
|
46
|
+
@client.read(10).should == "data"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,12 +1,31 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'thrift/server/
|
21
|
+
require 'thrift/server/mongrel_http_server'
|
3
22
|
|
4
23
|
class ThriftHTTPServerSpec < Spec::ExampleGroup
|
5
24
|
include Thrift
|
6
25
|
|
7
|
-
Handler =
|
26
|
+
Handler = MongrelHTTPServer::Handler
|
8
27
|
|
9
|
-
describe
|
28
|
+
describe MongrelHTTPServer do
|
10
29
|
it "should have appropriate defaults" do
|
11
30
|
mock_factory = mock("BinaryProtocolFactory")
|
12
31
|
mock_proc = mock("Processor")
|
@@ -18,7 +37,7 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
|
|
18
37
|
mock.should_receive(:register).with("/", handler)
|
19
38
|
end
|
20
39
|
end
|
21
|
-
|
40
|
+
MongrelHTTPServer.new(mock_proc)
|
22
41
|
end
|
23
42
|
|
24
43
|
it "should understand :ip, :port, :path, and :protocol_factory" do
|
@@ -31,7 +50,7 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
|
|
31
50
|
mock.should_receive(:register).with("/foo", handler)
|
32
51
|
end
|
33
52
|
end
|
34
|
-
|
53
|
+
MongrelHTTPServer.new(mock_proc, :ip => "1.2.3.4", :port => 1234, :path => "foo",
|
35
54
|
:protocol_factory => mock_factory)
|
36
55
|
end
|
37
56
|
|
@@ -48,11 +67,11 @@ class ThriftHTTPServerSpec < Spec::ExampleGroup
|
|
48
67
|
end
|
49
68
|
end
|
50
69
|
end
|
51
|
-
|
70
|
+
MongrelHTTPServer.new(nil).serve
|
52
71
|
end
|
53
72
|
end
|
54
73
|
|
55
|
-
describe
|
74
|
+
describe MongrelHTTPServer::Handler do
|
56
75
|
before(:each) do
|
57
76
|
@processor = mock("Processor")
|
58
77
|
@factory = mock("ProtocolFactory")
|
@@ -1,6 +1,23 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'thrift/server/nonblockingserver'
|
3
|
-
require File.dirname(__FILE__) + '/gen-rb/NonblockingService'
|
4
21
|
|
5
22
|
class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
6
23
|
include Thrift
|
@@ -38,7 +55,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
41
|
-
class SpecTransport <
|
58
|
+
class SpecTransport < BaseTransport
|
42
59
|
def initialize(transport, queue)
|
43
60
|
@transport = transport
|
44
61
|
@queue = queue
|
@@ -91,10 +108,10 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
91
108
|
processor = NonblockingService::Processor.new(handler)
|
92
109
|
queue = Queue.new
|
93
110
|
@transport = SpecServerSocket.new('localhost', @port, queue)
|
94
|
-
|
111
|
+
transport_factory = FramedTransportFactory.new
|
95
112
|
logger = Logger.new(STDERR)
|
96
113
|
logger.level = Logger::WARN
|
97
|
-
@server = NonblockingServer.new(processor, @transport,
|
114
|
+
@server = NonblockingServer.new(processor, @transport, transport_factory, nil, 5, logger)
|
98
115
|
handler.server = @server
|
99
116
|
@server_thread = Thread.new(Thread.current) do |master_thread|
|
100
117
|
begin
|
@@ -163,6 +180,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
163
180
|
client = setup_client
|
164
181
|
client.greeting(true).should == Hello.new
|
165
182
|
client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
|
183
|
+
@server.shutdown
|
166
184
|
end
|
167
185
|
|
168
186
|
it "should handle concurrent clients" do
|
@@ -180,6 +198,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
180
198
|
4.times { trans_queue.pop }
|
181
199
|
setup_client.unblock(4)
|
182
200
|
4.times { queue.pop.should be_true }
|
201
|
+
@server.shutdown
|
183
202
|
end
|
184
203
|
|
185
204
|
it "should handle messages from more than 5 long-lived connections" do
|
@@ -204,6 +223,7 @@ class ThriftNonblockingServerSpec < Spec::ExampleGroup
|
|
204
223
|
client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
|
205
224
|
7.times { queues.shift << :exit }
|
206
225
|
client.greeting(true).should == Hello.new
|
226
|
+
@server.shutdown
|
207
227
|
end
|
208
228
|
|
209
229
|
it "should shut down when asked" do
|
data/spec/processor_spec.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
21
|
|
3
22
|
class ThriftProcessorSpec < Spec::ExampleGroup
|
data/spec/serializer_spec.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'thrift/serializer'
|
3
|
-
require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types'
|
4
21
|
|
5
22
|
class ThriftSerializerSpec < Spec::ExampleGroup
|
6
23
|
include Thrift
|
@@ -14,16 +31,16 @@ class ThriftSerializerSpec < Spec::ExampleGroup
|
|
14
31
|
end
|
15
32
|
|
16
33
|
it "should serialize structs to the given protocol" do
|
17
|
-
protocol =
|
34
|
+
protocol = BaseProtocol.new(mock("transport"))
|
18
35
|
protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
|
19
36
|
protocol.should_receive(:write_field_begin).with("greeting", Types::STRING, 1)
|
20
37
|
protocol.should_receive(:write_string).with("Good day")
|
21
38
|
protocol.should_receive(:write_field_end)
|
22
39
|
protocol.should_receive(:write_field_stop)
|
23
40
|
protocol.should_receive(:write_struct_end)
|
24
|
-
|
25
|
-
|
26
|
-
serializer = Serializer.new(
|
41
|
+
protocol_factory = mock("ProtocolFactory")
|
42
|
+
protocol_factory.stub!(:get_protocol).and_return(protocol)
|
43
|
+
serializer = Serializer.new(protocol_factory)
|
27
44
|
serializer.serialize(Hello.new(:greeting => "Good day"))
|
28
45
|
end
|
29
46
|
end
|
@@ -36,16 +53,16 @@ class ThriftSerializerSpec < Spec::ExampleGroup
|
|
36
53
|
end
|
37
54
|
|
38
55
|
it "should deserialize structs from the given protocol" do
|
39
|
-
protocol =
|
56
|
+
protocol = BaseProtocol.new(mock("transport"))
|
40
57
|
protocol.should_receive(:read_struct_begin).and_return("SpecNamespace::Hello")
|
41
58
|
protocol.should_receive(:read_field_begin).and_return(["greeting", Types::STRING, 1],
|
42
59
|
[nil, Types::STOP, 0])
|
43
60
|
protocol.should_receive(:read_string).and_return("Good day")
|
44
61
|
protocol.should_receive(:read_field_end)
|
45
62
|
protocol.should_receive(:read_struct_end)
|
46
|
-
|
47
|
-
|
48
|
-
deserializer = Deserializer.new(
|
63
|
+
protocol_factory = mock("ProtocolFactory")
|
64
|
+
protocol_factory.stub!(:get_protocol).and_return(protocol)
|
65
|
+
deserializer = Deserializer.new(protocol_factory)
|
49
66
|
deserializer.deserialize(Hello.new, "").should == Hello.new(:greeting => "Good day")
|
50
67
|
end
|
51
68
|
end
|
@@ -0,0 +1,80 @@
|
|
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 File.dirname(__FILE__) + '/spec_helper'
|
21
|
+
require File.dirname(__FILE__) + "/socket_spec_shared"
|
22
|
+
|
23
|
+
class ThriftServerSocketSpec < Spec::ExampleGroup
|
24
|
+
include Thrift
|
25
|
+
|
26
|
+
describe ServerSocket do
|
27
|
+
before(:each) do
|
28
|
+
@socket = ServerSocket.new(1234)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create a handle when calling listen" do
|
32
|
+
TCPServer.should_receive(:new).with(nil, 1234)
|
33
|
+
@socket.listen
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should accept an optional host argument" do
|
37
|
+
@socket = ServerSocket.new('localhost', 1234)
|
38
|
+
TCPServer.should_receive(:new).with('localhost', 1234)
|
39
|
+
@socket.listen
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create a Thrift::Socket to wrap accepted sockets" do
|
43
|
+
handle = mock("TCPServer")
|
44
|
+
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
|
45
|
+
@socket.listen
|
46
|
+
sock = mock("sock")
|
47
|
+
handle.should_receive(:accept).and_return(sock)
|
48
|
+
trans = mock("Socket")
|
49
|
+
Socket.should_receive(:new).and_return(trans)
|
50
|
+
trans.should_receive(:handle=).with(sock)
|
51
|
+
@socket.accept.should == trans
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should close the handle when closed" do
|
55
|
+
handle = mock("TCPServer", :closed? => false)
|
56
|
+
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
|
57
|
+
@socket.listen
|
58
|
+
handle.should_receive(:close)
|
59
|
+
@socket.close
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return nil when accepting if there is no handle" do
|
63
|
+
@socket.accept.should be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return true for closed? when appropriate" do
|
67
|
+
handle = mock("TCPServer", :closed? => false)
|
68
|
+
TCPServer.stub!(:new).and_return(handle)
|
69
|
+
@socket.listen
|
70
|
+
@socket.should_not be_closed
|
71
|
+
handle.stub!(:close)
|
72
|
+
@socket.close
|
73
|
+
@socket.should be_closed
|
74
|
+
@socket.listen
|
75
|
+
@socket.should_not be_closed
|
76
|
+
handle.stub!(:closed?).and_return(true)
|
77
|
+
@socket.should be_closed
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/server_spec.rb
CHANGED
@@ -1,13 +1,32 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
21
|
|
3
22
|
class ThriftServerSpec < Spec::ExampleGroup
|
4
23
|
include Thrift
|
5
24
|
|
6
|
-
describe
|
7
|
-
it "should default to
|
8
|
-
server =
|
9
|
-
server.instance_variable_get(:'@
|
10
|
-
server.instance_variable_get(:'@
|
25
|
+
describe BaseServer do
|
26
|
+
it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
|
27
|
+
server = BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
|
28
|
+
server.instance_variable_get(:'@transport_factory').should be_an_instance_of(BaseTransportFactory)
|
29
|
+
server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(BinaryProtocolFactory)
|
11
30
|
end
|
12
31
|
|
13
32
|
# serve is a noop, so can't test that
|
@@ -17,8 +36,8 @@ class ThriftServerSpec < Spec::ExampleGroup
|
|
17
36
|
before(:each) do
|
18
37
|
@processor = mock("Processor")
|
19
38
|
@serverTrans = mock("ServerTransport")
|
20
|
-
@trans = mock("
|
21
|
-
@prot = mock("
|
39
|
+
@trans = mock("BaseTransport")
|
40
|
+
@prot = mock("BaseProtocol")
|
22
41
|
@client = mock("Client")
|
23
42
|
@server = server_type.new(@processor, @serverTrans, @trans, @prot)
|
24
43
|
end
|
@@ -39,9 +58,9 @@ class ThriftServerSpec < Spec::ExampleGroup
|
|
39
58
|
x = 0
|
40
59
|
@processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
|
41
60
|
case (x += 1)
|
42
|
-
when 1
|
43
|
-
when 2
|
44
|
-
when 3
|
61
|
+
when 1 then raise Thrift::TransportException
|
62
|
+
when 2 then raise Thrift::ProtocolException
|
63
|
+
when 3 then throw :stop
|
45
64
|
end
|
46
65
|
end
|
47
66
|
@trans.should_receive(:close).exactly(3).times
|
@@ -66,9 +85,9 @@ class ThriftServerSpec < Spec::ExampleGroup
|
|
66
85
|
x = 0
|
67
86
|
@processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
|
68
87
|
case (x += 1)
|
69
|
-
when 1
|
70
|
-
when 2
|
71
|
-
when 3
|
88
|
+
when 1 then raise Thrift::TransportException
|
89
|
+
when 2 then raise Thrift::ProtocolException
|
90
|
+
when 3 then throw :stop
|
72
91
|
end
|
73
92
|
end
|
74
93
|
@trans.should_receive(:close).exactly(3).times
|
@@ -127,9 +146,9 @@ class ThriftServerSpec < Spec::ExampleGroup
|
|
127
146
|
error = RuntimeError.new("Stopped")
|
128
147
|
@processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
|
129
148
|
case (x += 1)
|
130
|
-
when 1
|
131
|
-
when 2
|
132
|
-
when 3
|
149
|
+
when 1 then raise Thrift::TransportException
|
150
|
+
when 2 then raise Thrift::ProtocolException
|
151
|
+
when 3 then raise error
|
133
152
|
end
|
134
153
|
end
|
135
154
|
@trans.should_receive(:close).exactly(3).times
|
data/spec/socket_spec.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
21
|
require File.dirname(__FILE__) + "/socket_spec_shared"
|
3
22
|
|
@@ -39,59 +58,4 @@ class ThriftSocketSpec < Spec::ExampleGroup
|
|
39
58
|
Socket.new('localhost', 8080, 5).timeout.should == 5
|
40
59
|
end
|
41
60
|
end
|
42
|
-
|
43
|
-
describe ServerSocket do
|
44
|
-
before(:each) do
|
45
|
-
@socket = ServerSocket.new(1234)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should create a handle when calling listen" do
|
49
|
-
TCPServer.should_receive(:new).with(nil, 1234)
|
50
|
-
@socket.listen
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should accept an optional host argument" do
|
54
|
-
@socket = ServerSocket.new('localhost', 1234)
|
55
|
-
TCPServer.should_receive(:new).with('localhost', 1234)
|
56
|
-
@socket.listen
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should create a Thrift::Socket to wrap accepted sockets" do
|
60
|
-
handle = mock("TCPServer")
|
61
|
-
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
|
62
|
-
@socket.listen
|
63
|
-
sock = mock("sock")
|
64
|
-
handle.should_receive(:accept).and_return(sock)
|
65
|
-
trans = mock("Socket")
|
66
|
-
Socket.should_receive(:new).and_return(trans)
|
67
|
-
trans.should_receive(:handle=).with(sock)
|
68
|
-
@socket.accept.should == trans
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should close the handle when closed" do
|
72
|
-
handle = mock("TCPServer", :closed? => false)
|
73
|
-
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
|
74
|
-
@socket.listen
|
75
|
-
handle.should_receive(:close)
|
76
|
-
@socket.close
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should return nil when accepting if there is no handle" do
|
80
|
-
@socket.accept.should be_nil
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should return true for closed? when appropriate" do
|
84
|
-
handle = mock("TCPServer", :closed? => false)
|
85
|
-
TCPServer.stub!(:new).and_return(handle)
|
86
|
-
@socket.listen
|
87
|
-
@socket.should_not be_closed
|
88
|
-
handle.stub!(:close)
|
89
|
-
@socket.close
|
90
|
-
@socket.should be_closed
|
91
|
-
@socket.listen
|
92
|
-
@socket.should_not be_closed
|
93
|
-
handle.stub!(:closed?).and_return(true)
|
94
|
-
@socket.should be_closed
|
95
|
-
end
|
96
|
-
end
|
97
61
|
end
|