thrift 0.8.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/{README → README.md} +0 -0
  3. data/ext/binary_protocol_accelerated.c +33 -14
  4. data/ext/bytes.c +36 -0
  5. data/ext/bytes.h +31 -0
  6. data/ext/compact_protocol.c +27 -8
  7. data/ext/constants.h +8 -5
  8. data/ext/extconf.rb +5 -1
  9. data/ext/memory_buffer.c +12 -9
  10. data/ext/protocol.c +0 -185
  11. data/ext/protocol.h +0 -20
  12. data/ext/strlcpy.h +7 -3
  13. data/ext/struct.c +27 -7
  14. data/ext/thrift_native.c +16 -11
  15. data/lib/thrift.rb +10 -4
  16. data/lib/thrift/bytes.rb +131 -0
  17. data/lib/thrift/client.rb +13 -4
  18. data/lib/thrift/exceptions.rb +3 -0
  19. data/lib/thrift/multiplexed_processor.rb +76 -0
  20. data/lib/thrift/processor.rb +24 -6
  21. data/lib/thrift/protocol/base_protocol.rb +109 -12
  22. data/lib/thrift/protocol/binary_protocol.rb +22 -7
  23. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  24. data/lib/thrift/protocol/compact_protocol.rb +23 -6
  25. data/lib/thrift/protocol/json_protocol.rb +786 -0
  26. data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
  27. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  28. data/lib/thrift/server/base_server.rb +8 -2
  29. data/lib/thrift/server/mongrel_http_server.rb +2 -0
  30. data/lib/thrift/server/simple_server.rb +5 -1
  31. data/lib/thrift/server/thin_http_server.rb +91 -0
  32. data/lib/thrift/server/thread_pool_server.rb +5 -1
  33. data/lib/thrift/server/threaded_server.rb +5 -1
  34. data/lib/thrift/struct.rb +1 -1
  35. data/lib/thrift/struct_union.rb +2 -2
  36. data/lib/thrift/transport/base_server_transport.rb +1 -1
  37. data/lib/thrift/transport/base_transport.rb +30 -20
  38. data/lib/thrift/transport/buffered_transport.rb +25 -11
  39. data/lib/thrift/transport/framed_transport.rb +20 -11
  40. data/lib/thrift/transport/http_client_transport.rb +16 -6
  41. data/lib/thrift/transport/io_stream_transport.rb +5 -2
  42. data/lib/thrift/transport/memory_buffer_transport.rb +10 -6
  43. data/lib/thrift/transport/server_socket.rb +6 -1
  44. data/lib/thrift/transport/socket.rb +23 -17
  45. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  46. data/lib/thrift/transport/ssl_socket.rb +51 -0
  47. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  48. data/lib/thrift/transport/unix_socket.rb +5 -1
  49. data/lib/thrift/union.rb +3 -6
  50. data/spec/BaseService.thrift +27 -0
  51. data/spec/ExtendedService.thrift +25 -0
  52. data/spec/Referenced.thrift +44 -0
  53. data/spec/ThriftNamespacedSpec.thrift +53 -0
  54. data/spec/ThriftSpec.thrift +52 -1
  55. data/spec/base_protocol_spec.rb +158 -93
  56. data/spec/base_transport_spec.rb +194 -157
  57. data/spec/binary_protocol_accelerated_spec.rb +14 -14
  58. data/spec/binary_protocol_spec.rb +29 -16
  59. data/spec/binary_protocol_spec_shared.rb +148 -65
  60. data/spec/bytes_spec.rb +160 -0
  61. data/spec/client_spec.rb +45 -47
  62. data/spec/compact_protocol_spec.rb +36 -22
  63. data/spec/exception_spec.rb +79 -80
  64. data/spec/flat_spec.rb +62 -0
  65. data/spec/http_client_spec.rb +91 -16
  66. data/spec/json_protocol_spec.rb +552 -0
  67. data/spec/namespaced_spec.rb +67 -0
  68. data/spec/nonblocking_server_spec.rb +26 -28
  69. data/spec/processor_spec.rb +29 -32
  70. data/spec/serializer_spec.rb +31 -33
  71. data/spec/server_socket_spec.rb +32 -28
  72. data/spec/server_spec.rb +112 -84
  73. data/spec/socket_spec.rb +27 -20
  74. data/spec/socket_spec_shared.rb +32 -32
  75. data/spec/spec_helper.rb +17 -11
  76. data/spec/ssl_server_socket_spec.rb +34 -0
  77. data/spec/ssl_socket_spec.rb +78 -0
  78. data/spec/struct_nested_containers_spec.rb +191 -0
  79. data/spec/struct_spec.rb +159 -161
  80. data/spec/thin_http_server_spec.rb +141 -0
  81. data/spec/types_spec.rb +71 -69
  82. data/spec/union_spec.rb +97 -76
  83. data/spec/unix_socket_spec.rb +49 -41
  84. metadata +268 -188
  85. data/CHANGELOG +0 -1
  86. data/benchmark/gen-rb/benchmark_constants.rb +0 -10
  87. data/benchmark/gen-rb/benchmark_service.rb +0 -80
  88. data/benchmark/gen-rb/benchmark_types.rb +0 -9
  89. data/spec/gen-rb/nonblocking_service.rb +0 -272
  90. data/spec/gen-rb/thrift_spec_constants.rb +0 -10
  91. data/spec/gen-rb/thrift_spec_types.rb +0 -345
  92. data/spec/mongrel_http_server_spec.rb +0 -117
  93. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -273
  94. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -760
  95. data/test/debug_proto/gen-rb/empty_service.rb +0 -24
  96. data/test/debug_proto/gen-rb/inherited.rb +0 -79
  97. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
  98. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
  99. 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 File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
20
+ require 'spec_helper'
21
21
 
22
- class ThriftNonblockingServerSpec < Spec::ExampleGroup
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).should == Hello.new
182
- client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
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.should be_true }
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.should == Hello.new }
218
- client.greeting(true).should == Hello.new
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.should be_true }
218
+ 4.times { expect(result.pop).to be_truthy }
221
219
  queues[2] << :hello
222
- result.pop.should == Hello.new
223
- client.greeting(false).should == Hello.new(:greeting => 'Aloha!')
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).should == Hello.new
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).should be_an_instance_of(Thread)
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).should be_an_instance_of(Thread)
244
- result.pop.should == :slept
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).should_not be_nil
255
- result.should be_empty
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).should == Hello.new
258
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
261
259
  client.shutdown
262
- @server_thread.join(2).should_not be_nil
260
+ expect(@server_thread.join(2)).not_to be_nil
263
261
  end
264
262
  end
265
263
  end
@@ -17,65 +17,62 @@
17
17
  # under the License.
18
18
  #
19
19
 
20
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
20
+ require 'spec_helper'
21
21
 
22
- class ThriftProcessorSpec < Spec::ExampleGroup
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 "Processor" do
28
+ describe Thrift::Processor do
30
29
  before(:each) do
31
- @processor = ProcessorSpec.new(mock("MockHandler"))
32
- @prot = mock("MockProtocol")
30
+ @processor = ProcessorSpec.new(double("MockHandler"))
31
+ @prot = double("MockProtocol")
33
32
  end
34
33
 
35
34
  def mock_trans(obj)
36
- obj.should_receive(:trans).ordered.and_return do
37
- mock("trans").tee do |trans|
38
- trans.should_receive(:flush).ordered
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.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 17]
45
- @processor.should_receive(:process_testMessage).with(17, @prot, @prot).ordered
46
- @processor.process(@prot, @prot).should == true
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.should_receive(:read_message_begin).ordered.and_return ['testMessage', MessageTypes::CALL, 4]
51
- @prot.should_receive(:skip).with(Types::STRUCT).ordered
52
- @prot.should_receive(:read_message_end).ordered
53
- @prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::EXCEPTION, 4).ordered
54
- ApplicationException.should_receive(:new).with(ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return do
55
- mock(ApplicationException).tee do |e|
56
- e.should_receive(:write).with(@prot).ordered
57
- end
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 = mock("MockArgsClass")
66
- args = mock("#<MockArgsClass:mock>").tee do |args|
67
- args.should_receive(:read).with(@prot).ordered
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.should_receive(:new).and_return args
70
- @prot.should_receive(:read_message_end).ordered
71
- @processor.read_args(@prot, args_class).should eql(args)
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.should_receive(:write_message_begin).with('testMessage', MessageTypes::REPLY, 23).ordered
76
- result = mock("MockResult")
77
- result.should_receive(:write).with(@prot).ordered
78
- @prot.should_receive(:write_message_end).ordered
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
@@ -17,53 +17,51 @@
17
17
  # under the License.
18
18
  #
19
19
 
20
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
20
+ require 'spec_helper'
21
21
 
22
- class ThriftSerializerSpec < Spec::ExampleGroup
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.should == "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
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(mock("transport"))
35
- protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
36
- protocol.should_receive(:write_field_begin).with("greeting", Types::STRING, 1)
37
- protocol.should_receive(:write_string).with("Good day")
38
- protocol.should_receive(:write_field_end)
39
- protocol.should_receive(:write_field_stop)
40
- protocol.should_receive(:write_struct_end)
41
- protocol_factory = mock("ProtocolFactory")
42
- protocol_factory.stub!(:get_protocol).and_return(protocol)
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).should == Hello.new(:greeting => "'Ello guv'nor!")
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(mock("transport"))
57
- protocol.should_receive(:read_struct_begin).and_return("SpecNamespace::Hello")
58
- protocol.should_receive(:read_field_begin).and_return(["greeting", Types::STRING, 1],
59
- [nil, Types::STOP, 0])
60
- protocol.should_receive(:read_string).and_return("Good day")
61
- protocol.should_receive(:read_field_end)
62
- protocol.should_receive(:read_struct_end)
63
- protocol_factory = mock("ProtocolFactory")
64
- protocol_factory.stub!(:get_protocol).and_return(protocol)
65
- deserializer = Deserializer.new(protocol_factory)
66
- deserializer.deserialize(Hello.new, "").should == Hello.new(:greeting => "Good day")
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
@@ -17,64 +17,68 @@
17
17
  # under the License.
18
18
  #
19
19
 
20
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
20
+ require 'spec_helper'
21
21
  require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared")
22
22
 
23
- class ThriftServerSocketSpec < Spec::ExampleGroup
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.should_receive(:new).with(nil, 1234)
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.should_receive(:new).with('localhost', 1234)
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 = mock("TCPServer")
44
- TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
43
+ handle = double("TCPServer")
44
+ expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
45
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
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 = mock("TCPServer", :closed? => false)
56
- TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
55
+ handle = double("TCPServer", :closed? => false)
56
+ expect(TCPServer).to receive(:new).with(nil, 1234).and_return(handle)
57
57
  @socket.listen
58
- handle.should_receive(:close)
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.should be_nil
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 = mock("TCPServer", :closed? => false)
68
- TCPServer.stub!(:new).and_return(handle)
67
+ handle = double("TCPServer", :closed? => false)
68
+ allow(TCPServer).to receive(:new).and_return(handle)
69
69
  @socket.listen
70
- @socket.should_not be_closed
71
- handle.stub!(:close)
70
+ expect(@socket).not_to be_closed
71
+ allow(handle).to receive(:close)
72
72
  @socket.close
73
- @socket.should be_closed
73
+ expect(@socket).to be_closed
74
74
  @socket.listen
75
- @socket.should_not be_closed
76
- handle.stub!(:closed?).and_return(true)
77
- @socket.should be_closed
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