thrift 0.11.0.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/lib/thrift/protocol/base_protocol.rb +11 -3
  3. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  4. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  5. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  6. data/lib/thrift/protocol/json_protocol.rb +8 -0
  7. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  8. data/lib/thrift/server/base_server.rb +8 -2
  9. data/lib/thrift/server/simple_server.rb +5 -1
  10. data/lib/thrift/server/thread_pool_server.rb +5 -1
  11. data/lib/thrift/server/threaded_server.rb +5 -1
  12. data/lib/thrift/transport/base_server_transport.rb +1 -1
  13. data/lib/thrift/transport/base_transport.rb +8 -0
  14. data/lib/thrift/transport/buffered_transport.rb +9 -1
  15. data/lib/thrift/transport/framed_transport.rb +9 -1
  16. data/lib/thrift/transport/http_client_transport.rb +4 -0
  17. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  18. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  19. data/lib/thrift/transport/server_socket.rb +6 -1
  20. data/lib/thrift/transport/socket.rb +4 -2
  21. data/lib/thrift/transport/ssl_server_socket.rb +4 -0
  22. data/lib/thrift/transport/ssl_socket.rb +4 -0
  23. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  24. data/lib/thrift/transport/unix_socket.rb +5 -1
  25. data/spec/base_protocol_spec.rb +79 -71
  26. data/spec/base_transport_spec.rb +155 -117
  27. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  28. data/spec/binary_protocol_spec.rb +16 -8
  29. data/spec/binary_protocol_spec_shared.rb +73 -70
  30. data/spec/bytes_spec.rb +38 -38
  31. data/spec/client_spec.rb +41 -42
  32. data/spec/compact_protocol_spec.rb +23 -8
  33. data/spec/exception_spec.rb +54 -54
  34. data/spec/flat_spec.rb +5 -5
  35. data/spec/http_client_spec.rb +42 -38
  36. data/spec/json_protocol_spec.rb +146 -138
  37. data/spec/namespaced_spec.rb +5 -5
  38. data/spec/nonblocking_server_spec.rb +16 -16
  39. data/spec/processor_spec.rb +26 -26
  40. data/spec/serializer_spec.rb +20 -20
  41. data/spec/server_socket_spec.rb +27 -22
  42. data/spec/server_spec.rb +91 -52
  43. data/spec/socket_spec.rb +23 -16
  44. data/spec/socket_spec_shared.rb +31 -31
  45. data/spec/ssl_server_socket_spec.rb +34 -0
  46. data/spec/ssl_socket_spec.rb +26 -22
  47. data/spec/struct_nested_containers_spec.rb +24 -24
  48. data/spec/struct_spec.rb +120 -120
  49. data/spec/thin_http_server_spec.rb +18 -18
  50. data/spec/types_spec.rb +56 -53
  51. data/spec/union_spec.rb +42 -43
  52. data/spec/unix_socket_spec.rb +43 -34
  53. metadata +134 -154
  54. data/benchmark/gen-rb/benchmark_constants.rb +0 -11
  55. data/benchmark/gen-rb/benchmark_service.rb +0 -80
  56. data/benchmark/gen-rb/benchmark_types.rb +0 -10
  57. data/spec/gen-rb/base/base_service.rb +0 -80
  58. data/spec/gen-rb/base/base_service_constants.rb +0 -11
  59. data/spec/gen-rb/base/base_service_types.rb +0 -26
  60. data/spec/gen-rb/extended/extended_service.rb +0 -78
  61. data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
  62. data/spec/gen-rb/extended/extended_service_types.rb +0 -12
  63. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -272
  64. data/spec/gen-rb/flat/referenced_constants.rb +0 -11
  65. data/spec/gen-rb/flat/referenced_types.rb +0 -17
  66. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
  67. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
  68. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -272
  69. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
  70. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
  71. data/spec/gen-rb/nonblocking_service.rb +0 -272
  72. data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
  73. data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
  74. data/spec/gen-rb/thrift_spec_constants.rb +0 -11
  75. data/spec/gen-rb/thrift_spec_types.rb +0 -538
  76. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -278
  77. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -781
  78. data/test/debug_proto/gen-rb/empty_service.rb +0 -28
  79. data/test/debug_proto/gen-rb/inherited.rb +0 -83
  80. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -86
  81. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -85
  82. data/test/debug_proto/gen-rb/srv.rb +0 -395
@@ -32,7 +32,7 @@ describe 'namespaced generation' do
32
32
  "other_namespace/referenced_constants.rb",
33
33
  "other_namespace/referenced_types.rb"
34
34
  ].each do |name|
35
- File.exist?(File.join(prefix, name)).should be_true
35
+ expect(File.exist?(File.join(prefix, name))).to be_truthy
36
36
  end
37
37
  end
38
38
 
@@ -44,20 +44,20 @@ describe 'namespaced generation' do
44
44
  "referenced_constants.rb",
45
45
  "referenced_types.rb"
46
46
  ].each do |name|
47
- File.exist?(File.join(prefix, name)).should_not be_true
47
+ expect(File.exist?(File.join(prefix, name))).not_to be_truthy
48
48
  end
49
49
  end
50
50
 
51
51
  it "has a service class in the right place" do
52
- defined?(NamespacedSpecNamespace::NamespacedNonblockingService).should be_true
52
+ expect(defined?(NamespacedSpecNamespace::NamespacedNonblockingService)).to be_truthy
53
53
  end
54
54
 
55
55
  it "has a struct in the right place" do
56
- defined?(NamespacedSpecNamespace::Hello).should be_true
56
+ expect(defined?(NamespacedSpecNamespace::Hello)).to be_truthy
57
57
  end
58
58
 
59
59
  it "required an included file" do
60
- defined?(OtherNamespace::SomeEnum).should be_true
60
+ expect(defined?(OtherNamespace::SomeEnum)).to be_truthy
61
61
  end
62
62
 
63
63
  it "extended a service" do
@@ -176,8 +176,8 @@ describe 'NonblockingServer' do
176
176
 
177
177
  it "should handle basic message passing" do
178
178
  client = setup_client
179
- client.greeting(true).should == SpecNamespace::Hello.new
180
- client.greeting(false).should == SpecNamespace::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!'))
181
181
  @server.shutdown
182
182
  end
183
183
 
@@ -195,7 +195,7 @@ describe 'NonblockingServer' do
195
195
  end
196
196
  4.times { trans_queue.pop }
197
197
  setup_client.unblock(4)
198
- 4.times { queue.pop.should be_true }
198
+ 4.times { expect(queue.pop).to be_truthy }
199
199
  @server.shutdown
200
200
  end
201
201
 
@@ -212,15 +212,15 @@ describe 'NonblockingServer' do
212
212
  queues[4] << :hello
213
213
  queues[5] << :hello
214
214
  queues[6] << :hello
215
- 3.times { result.pop.should == SpecNamespace::Hello.new }
216
- client.greeting(true).should == SpecNamespace::Hello.new
215
+ 3.times { expect(result.pop).to eq(SpecNamespace::Hello.new) }
216
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
217
217
  queues[5] << [:unblock, 4]
218
- 4.times { result.pop.should be_true }
218
+ 4.times { expect(result.pop).to be_truthy }
219
219
  queues[2] << :hello
220
- result.pop.should == SpecNamespace::Hello.new
221
- client.greeting(false).should == SpecNamespace::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!'))
222
222
  7.times { queues.shift << :exit }
223
- client.greeting(true).should == SpecNamespace::Hello.new
223
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
224
224
  @server.shutdown
225
225
  end
226
226
 
@@ -229,7 +229,7 @@ describe 'NonblockingServer' do
229
229
  client = setup_client
230
230
  client.greeting(false) # force a message pass
231
231
  @server.shutdown
232
- @server_thread.join(2).should be_an_instance_of(Thread)
232
+ expect(@server_thread.join(2)).to be_an_instance_of(Thread)
233
233
  end
234
234
 
235
235
  it "should continue processing active messages when shutting down" do
@@ -238,8 +238,8 @@ describe 'NonblockingServer' do
238
238
  client << :sleep
239
239
  sleep 0.1 # give the server time to start processing the client's message
240
240
  @server.shutdown
241
- @server_thread.join(2).should be_an_instance_of(Thread)
242
- result.pop.should == :slept
241
+ expect(@server_thread.join(2)).to be_an_instance_of(Thread)
242
+ expect(result.pop).to eq(:slept)
243
243
  end
244
244
 
245
245
  it "should kill active messages when they don't expire while shutting down" do
@@ -249,15 +249,15 @@ describe 'NonblockingServer' do
249
249
  sleep 0.1 # start processing the client's message
250
250
  @server.shutdown(1)
251
251
  @catch_exceptions = true
252
- @server_thread.join(3).should_not be_nil
253
- result.should be_empty
252
+ expect(@server_thread.join(3)).not_to be_nil
253
+ expect(result).to be_empty
254
254
  end
255
255
 
256
256
  it "should allow shutting down in response to a message" do
257
257
  client = setup_client
258
- client.greeting(true).should == SpecNamespace::Hello.new
258
+ expect(client.greeting(true)).to eq(SpecNamespace::Hello.new)
259
259
  client.shutdown
260
- @server_thread.join(2).should_not be_nil
260
+ expect(@server_thread.join(2)).not_to be_nil
261
261
  end
262
262
  end
263
263
  end
@@ -27,52 +27,52 @@ describe 'Processor' do
27
27
 
28
28
  describe Thrift::Processor do
29
29
  before(:each) do
30
- @processor = ProcessorSpec.new(mock("MockHandler"))
31
- @prot = mock("MockProtocol")
30
+ @processor = ProcessorSpec.new(double("MockHandler"))
31
+ @prot = double("MockProtocol")
32
32
  end
33
33
 
34
34
  def mock_trans(obj)
35
- obj.should_receive(:trans).ordered.and_return do
36
- mock("trans").tap do |trans|
37
- 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
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
42
  it "should call process_<message> when it receives that message" do
43
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 17]
44
- @processor.should_receive(:process_testMessage).with(17, @prot, @prot).ordered
45
- @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)
46
46
  end
47
47
 
48
48
  it "should raise an ApplicationException when the received message cannot be processed" do
49
- @prot.should_receive(:read_message_begin).ordered.and_return ['testMessage', Thrift::MessageTypes::CALL, 4]
50
- @prot.should_receive(:skip).with(Thrift::Types::STRUCT).ordered
51
- @prot.should_receive(:read_message_end).ordered
52
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::EXCEPTION, 4).ordered
53
- e = mock(Thrift::ApplicationException)
54
- e.should_receive(:write).with(@prot).ordered
55
- Thrift::ApplicationException.should_receive(:new).with(Thrift::ApplicationException::UNKNOWN_METHOD, "Unknown function testMessage").and_return(e)
56
- @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
57
57
  mock_trans(@prot)
58
58
  @processor.process(@prot, @prot)
59
59
  end
60
60
 
61
61
  it "should pass args off to the args class" do
62
- args_class = mock("MockArgsClass")
63
- args = mock("#<MockArgsClass:mock>").tap do |args|
64
- 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
65
65
  end
66
- args_class.should_receive(:new).and_return args
67
- @prot.should_receive(:read_message_end).ordered
68
- @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)
69
69
  end
70
70
 
71
71
  it "should write out a reply when asked" do
72
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::REPLY, 23).ordered
73
- result = mock("MockResult")
74
- result.should_receive(:write).with(@prot).ordered
75
- @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
76
76
  mock_trans(@prot)
77
77
  @processor.write_result(result, @prot, 'testMessage', 23)
78
78
  end
@@ -25,19 +25,19 @@ describe 'Serializer' do
25
25
  it "should serialize structs to binary by default" do
26
26
  serializer = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
27
27
  data = serializer.serialize(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
28
- data.should == "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
28
+ expect(data).to eq("\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00")
29
29
  end
30
30
 
31
31
  it "should serialize structs to the given protocol" do
32
- protocol = Thrift::BaseProtocol.new(mock("transport"))
33
- protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
34
- protocol.should_receive(:write_field_begin).with("greeting", Thrift::Types::STRING, 1)
35
- protocol.should_receive(:write_string).with("Good day")
36
- protocol.should_receive(:write_field_end)
37
- protocol.should_receive(:write_field_stop)
38
- protocol.should_receive(:write_struct_end)
39
- protocol_factory = mock("ProtocolFactory")
40
- protocol_factory.stub!(:get_protocol).and_return(protocol)
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
41
  serializer = Thrift::Serializer.new(protocol_factory)
42
42
  serializer.serialize(SpecNamespace::Hello.new(:greeting => "Good day"))
43
43
  end
@@ -47,21 +47,21 @@ describe 'Serializer' do
47
47
  it "should deserialize structs from binary by default" do
48
48
  deserializer = Thrift::Deserializer.new
49
49
  data = "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
50
- deserializer.deserialize(SpecNamespace::Hello.new, data).should == SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!")
50
+ expect(deserializer.deserialize(SpecNamespace::Hello.new, data)).to eq(SpecNamespace::Hello.new(:greeting => "'Ello guv'nor!"))
51
51
  end
52
52
 
53
53
  it "should deserialize structs from the given protocol" do
54
- protocol = Thrift::BaseProtocol.new(mock("transport"))
55
- protocol.should_receive(:read_struct_begin).and_return("SpecNamespace::Hello")
56
- protocol.should_receive(:read_field_begin).and_return(["greeting", Thrift::Types::STRING, 1],
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
57
  [nil, Thrift::Types::STOP, 0])
58
- protocol.should_receive(:read_string).and_return("Good day")
59
- protocol.should_receive(:read_field_end)
60
- protocol.should_receive(:read_struct_end)
61
- protocol_factory = mock("ProtocolFactory")
62
- protocol_factory.stub!(:get_protocol).and_return(protocol)
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
63
  deserializer = Thrift::Deserializer.new(protocol_factory)
64
- deserializer.deserialize(SpecNamespace::Hello.new, "").should == SpecNamespace::Hello.new(:greeting => "Good day")
64
+ expect(deserializer.deserialize(SpecNamespace::Hello.new, "")).to eq(SpecNamespace::Hello.new(:greeting => "Good day"))
65
65
  end
66
66
  end
67
67
  end
@@ -28,52 +28,57 @@ describe 'Thrift::ServerSocket' do
28
28
  end
29
29
 
30
30
  it "should create a handle when calling listen" do
31
- TCPServer.should_receive(:new).with(nil, 1234)
31
+ expect(TCPServer).to receive(:new).with(nil, 1234)
32
32
  @socket.listen
33
33
  end
34
34
 
35
35
  it "should accept an optional host argument" do
36
36
  @socket = Thrift::ServerSocket.new('localhost', 1234)
37
- TCPServer.should_receive(:new).with('localhost', 1234)
37
+ expect(TCPServer).to receive(:new).with('localhost', 1234)
38
+ @socket.to_s == "server(localhost:1234)"
38
39
  @socket.listen
39
40
  end
40
41
 
41
42
  it "should create a Thrift::Socket to wrap accepted sockets" do
42
- handle = mock("TCPServer")
43
- 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)
44
45
  @socket.listen
45
- sock = mock("sock")
46
- handle.should_receive(:accept).and_return(sock)
47
- trans = mock("Socket")
48
- Thrift::Socket.should_receive(:new).and_return(trans)
49
- trans.should_receive(:handle=).with(sock)
50
- @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)
51
52
  end
52
53
 
53
54
  it "should close the handle when closed" do
54
- handle = mock("TCPServer", :closed? => false)
55
- 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)
56
57
  @socket.listen
57
- handle.should_receive(:close)
58
+ expect(handle).to receive(:close)
58
59
  @socket.close
59
60
  end
60
61
 
61
62
  it "should return nil when accepting if there is no handle" do
62
- @socket.accept.should be_nil
63
+ expect(@socket.accept).to be_nil
63
64
  end
64
65
 
65
66
  it "should return true for closed? when appropriate" do
66
- handle = mock("TCPServer", :closed? => false)
67
- TCPServer.stub!(:new).and_return(handle)
67
+ handle = double("TCPServer", :closed? => false)
68
+ allow(TCPServer).to receive(:new).and_return(handle)
68
69
  @socket.listen
69
- @socket.should_not be_closed
70
- handle.stub!(:close)
70
+ expect(@socket).not_to be_closed
71
+ allow(handle).to receive(:close)
71
72
  @socket.close
72
- @socket.should be_closed
73
+ expect(@socket).to be_closed
73
74
  @socket.listen
74
- @socket.should_not be_closed
75
- handle.stub!(:closed?).and_return(true)
76
- @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)")
77
82
  end
78
83
  end
79
84
  end
@@ -21,96 +21,135 @@ require 'spec_helper'
21
21
  describe 'Server' do
22
22
 
23
23
  describe Thrift::BaseServer do
24
+ before(:each) do
25
+ @processor = double("Processor")
26
+ @serverTrans = double("ServerTransport")
27
+ @trans = double("BaseTransport")
28
+ @prot = double("BaseProtocol")
29
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
30
+ end
31
+
24
32
  it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
25
- server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
26
- server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory)
27
- server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory)
33
+ @server = Thrift::BaseServer.new(double("Processor"), double("BaseServerTransport"))
34
+ expect(@server.instance_variable_get(:'@transport_factory')).to be_an_instance_of(Thrift::BaseTransportFactory)
35
+ expect(@server.instance_variable_get(:'@protocol_factory')).to be_an_instance_of(Thrift::BinaryProtocolFactory)
28
36
  end
29
37
 
30
- # serve is a noop, so can't test that
38
+ it "should not serve" do
39
+ expect { @server.serve()}.to raise_error(NotImplementedError)
40
+ end
41
+
42
+ it "should provide a reasonable to_s" do
43
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
44
+ expect(@trans).to receive(:to_s).once.and_return("trans")
45
+ expect(@prot).to receive(:to_s).once.and_return("prot")
46
+ expect(@server.to_s).to eq("server(prot(trans(serverTrans)))")
47
+ end
31
48
  end
32
49
 
33
50
  describe Thrift::SimpleServer do
34
51
  before(:each) do
35
- @processor = mock("Processor")
36
- @serverTrans = mock("ServerTransport")
37
- @trans = mock("BaseTransport")
38
- @prot = mock("BaseProtocol")
39
- @client = mock("Client")
52
+ @processor = double("Processor")
53
+ @serverTrans = double("ServerTransport")
54
+ @trans = double("BaseTransport")
55
+ @prot = double("BaseProtocol")
56
+ @client = double("Client")
40
57
  @server = described_class.new(@processor, @serverTrans, @trans, @prot)
41
58
  end
42
59
 
60
+ it "should provide a reasonable to_s" do
61
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
62
+ expect(@trans).to receive(:to_s).once.and_return("trans")
63
+ expect(@prot).to receive(:to_s).once.and_return("prot")
64
+ expect(@server.to_s).to eq("simple(server(prot(trans(serverTrans))))")
65
+ end
66
+
43
67
  it "should serve in the main thread" do
44
- @serverTrans.should_receive(:listen).ordered
45
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
46
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
47
- @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
68
+ expect(@serverTrans).to receive(:listen).ordered
69
+ expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
70
+ expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
71
+ expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
48
72
  x = 0
49
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
73
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
50
74
  case (x += 1)
51
75
  when 1 then raise Thrift::TransportException
52
76
  when 2 then raise Thrift::ProtocolException
53
77
  when 3 then throw :stop
54
78
  end
55
79
  end
56
- @trans.should_receive(:close).exactly(3).times
57
- @serverTrans.should_receive(:close).ordered
58
- lambda { @server.serve }.should throw_symbol(:stop)
80
+ expect(@trans).to receive(:close).exactly(3).times
81
+ expect(@serverTrans).to receive(:close).ordered
82
+ expect { @server.serve }.to throw_symbol(:stop)
59
83
  end
60
84
  end
61
85
 
62
86
  describe Thrift::ThreadedServer do
63
87
  before(:each) do
64
- @processor = mock("Processor")
65
- @serverTrans = mock("ServerTransport")
66
- @trans = mock("BaseTransport")
67
- @prot = mock("BaseProtocol")
68
- @client = mock("Client")
88
+ @processor = double("Processor")
89
+ @serverTrans = double("ServerTransport")
90
+ @trans = double("BaseTransport")
91
+ @prot = double("BaseProtocol")
92
+ @client = double("Client")
69
93
  @server = described_class.new(@processor, @serverTrans, @trans, @prot)
70
94
  end
71
95
 
96
+ it "should provide a reasonable to_s" do
97
+ expect(@serverTrans).to receive(:to_s).once.and_return("serverTrans")
98
+ expect(@trans).to receive(:to_s).once.and_return("trans")
99
+ expect(@prot).to receive(:to_s).once.and_return("prot")
100
+ expect(@server.to_s).to eq("threaded(server(prot(trans(serverTrans))))")
101
+ end
102
+
72
103
  it "should serve using threads" do
73
- @serverTrans.should_receive(:listen).ordered
74
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
75
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
76
- @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
77
- Thread.should_receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
104
+ expect(@serverTrans).to receive(:listen).ordered
105
+ expect(@serverTrans).to receive(:accept).exactly(3).times.and_return(@client)
106
+ expect(@trans).to receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
107
+ expect(@prot).to receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
108
+ expect(Thread).to receive(:new).with(@prot, @trans).exactly(3).times.and_yield(@prot, @trans)
78
109
  x = 0
79
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
110
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
80
111
  case (x += 1)
81
112
  when 1 then raise Thrift::TransportException
82
113
  when 2 then raise Thrift::ProtocolException
83
114
  when 3 then throw :stop
84
115
  end
85
116
  end
86
- @trans.should_receive(:close).exactly(3).times
87
- @serverTrans.should_receive(:close).ordered
88
- lambda { @server.serve }.should throw_symbol(:stop)
117
+ expect(@trans).to receive(:close).exactly(3).times
118
+ expect(@serverTrans).to receive(:close).ordered
119
+ expect { @server.serve }.to throw_symbol(:stop)
89
120
  end
90
121
  end
91
122
 
92
123
  describe Thrift::ThreadPoolServer do
93
124
  before(:each) do
94
- @processor = mock("Processor")
95
- @server_trans = mock("ServerTransport")
96
- @trans = mock("BaseTransport")
97
- @prot = mock("BaseProtocol")
98
- @client = mock("Client")
125
+ @processor = double("Processor")
126
+ @server_trans = double("ServerTransport")
127
+ @trans = double("BaseTransport")
128
+ @prot = double("BaseProtocol")
129
+ @client = double("Client")
99
130
  @server = described_class.new(@processor, @server_trans, @trans, @prot)
100
- sleep(0.1)
131
+ sleep(0.15)
101
132
  end
102
133
 
134
+ it "should provide a reasonable to_s" do
135
+ expect(@server_trans).to receive(:to_s).once.and_return("server_trans")
136
+ expect(@trans).to receive(:to_s).once.and_return("trans")
137
+ expect(@prot).to receive(:to_s).once.and_return("prot")
138
+ expect(@server.to_s).to eq("threadpool(server(prot(trans(server_trans))))")
139
+ end
140
+
103
141
  it "should serve inside a thread" do
104
142
  exception_q = @server.instance_variable_get(:@exception_q)
105
- described_class.any_instance.should_receive(:serve) do
143
+ expect_any_instance_of(described_class).to receive(:serve) do
106
144
  exception_q.push(StandardError.new('ERROR'))
107
145
  end
108
146
  expect { @server.rescuable_serve }.to(raise_error('ERROR'))
147
+ sleep(0.15)
109
148
  end
110
149
 
111
150
  it "should avoid running the server twice when retrying rescuable_serve" do
112
151
  exception_q = @server.instance_variable_get(:@exception_q)
113
- described_class.any_instance.should_receive(:serve) do
152
+ expect_any_instance_of(described_class).to receive(:serve) do
114
153
  exception_q.push(StandardError.new('ERROR1'))
115
154
  exception_q.push(StandardError.new('ERROR2'))
116
155
  end
@@ -119,29 +158,29 @@ describe 'Server' do
119
158
  end
120
159
 
121
160
  it "should serve using a thread pool" do
122
- thread_q = mock("SizedQueue")
123
- exception_q = mock("Queue")
161
+ thread_q = double("SizedQueue")
162
+ exception_q = double("Queue")
124
163
  @server.instance_variable_set(:@thread_q, thread_q)
125
164
  @server.instance_variable_set(:@exception_q, exception_q)
126
- @server_trans.should_receive(:listen).ordered
127
- thread_q.should_receive(:push).with(:token)
128
- thread_q.should_receive(:pop)
129
- Thread.should_receive(:new).and_yield
130
- @server_trans.should_receive(:accept).exactly(3).times.and_return(@client)
131
- @trans.should_receive(:get_transport).exactly(3).times.and_return(@trans)
132
- @prot.should_receive(:get_protocol).exactly(3).times.and_return(@prot)
165
+ expect(@server_trans).to receive(:listen).ordered
166
+ expect(thread_q).to receive(:push).with(:token)
167
+ expect(thread_q).to receive(:pop)
168
+ expect(Thread).to receive(:new).and_yield
169
+ expect(@server_trans).to receive(:accept).exactly(3).times.and_return(@client)
170
+ expect(@trans).to receive(:get_transport).exactly(3).times.and_return(@trans)
171
+ expect(@prot).to receive(:get_protocol).exactly(3).times.and_return(@prot)
133
172
  x = 0
134
173
  error = RuntimeError.new("Stopped")
135
- @processor.should_receive(:process).exactly(3).times.with(@prot, @prot).and_return do
174
+ expect(@processor).to receive(:process).exactly(3).times.with(@prot, @prot) do
136
175
  case (x += 1)
137
176
  when 1 then raise Thrift::TransportException
138
177
  when 2 then raise Thrift::ProtocolException
139
178
  when 3 then raise error
140
179
  end
141
180
  end
142
- @trans.should_receive(:close).exactly(3).times
143
- exception_q.should_receive(:push).with(error).and_throw(:stop)
144
- @server_trans.should_receive(:close)
181
+ expect(@trans).to receive(:close).exactly(3).times
182
+ expect(exception_q).to receive(:push).with(error).and_throw(:stop)
183
+ expect(@server_trans).to receive(:close)
145
184
  expect { @server.serve }.to(throw_symbol(:stop))
146
185
  end
147
186
  end