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.
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
@@ -16,144 +16,172 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  #
19
- require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
19
+ require 'spec_helper'
20
20
 
21
- class ThriftServerSpec < Spec::ExampleGroup
22
- include Thrift
21
+ describe 'Server' do
22
+
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
23
31
 
24
- describe BaseServer do
25
32
  it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do
26
- server = BaseServer.new(mock("Processor"), mock("BaseServerTransport"))
27
- server.instance_variable_get(:'@transport_factory').should be_an_instance_of(BaseTransportFactory)
28
- server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(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)
29
36
  end
30
37
 
31
- # 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
32
48
  end
33
49
 
34
- shared_examples_for "servers" do
50
+ describe Thrift::SimpleServer do
35
51
  before(:each) do
36
- @processor = mock("Processor")
37
- @serverTrans = mock("ServerTransport")
38
- @trans = mock("BaseTransport")
39
- @prot = mock("BaseProtocol")
40
- @client = mock("Client")
41
- @server = server_type.new(@processor, @serverTrans, @trans, @prot)
52
+ @processor = double("Processor")
53
+ @serverTrans = double("ServerTransport")
54
+ @trans = double("BaseTransport")
55
+ @prot = double("BaseProtocol")
56
+ @client = double("Client")
57
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
42
58
  end
43
- end
44
-
45
- describe SimpleServer do
46
- it_should_behave_like "servers"
47
-
48
- def server_type
49
- SimpleServer
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))))")
50
65
  end
51
-
66
+
52
67
  it "should serve in the main thread" do
53
- @serverTrans.should_receive(:listen).ordered
54
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
55
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
56
- @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)
57
72
  x = 0
58
- @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
59
74
  case (x += 1)
60
75
  when 1 then raise Thrift::TransportException
61
76
  when 2 then raise Thrift::ProtocolException
62
77
  when 3 then throw :stop
63
78
  end
64
79
  end
65
- @trans.should_receive(:close).exactly(3).times
66
- @serverTrans.should_receive(:close).ordered
67
- 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)
68
83
  end
69
84
  end
70
85
 
71
- describe ThreadedServer do
72
- it_should_behave_like "servers"
73
-
74
- def server_type
75
- ThreadedServer
86
+ describe Thrift::ThreadedServer do
87
+ before(:each) do
88
+ @processor = double("Processor")
89
+ @serverTrans = double("ServerTransport")
90
+ @trans = double("BaseTransport")
91
+ @prot = double("BaseProtocol")
92
+ @client = double("Client")
93
+ @server = described_class.new(@processor, @serverTrans, @trans, @prot)
76
94
  end
77
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
+
78
103
  it "should serve using threads" do
79
- @serverTrans.should_receive(:listen).ordered
80
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
81
- @trans.should_receive(:get_transport).exactly(3).times.with(@client).and_return(@trans)
82
- @prot.should_receive(:get_protocol).exactly(3).times.with(@trans).and_return(@prot)
83
- 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)
84
109
  x = 0
85
- @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
86
111
  case (x += 1)
87
112
  when 1 then raise Thrift::TransportException
88
113
  when 2 then raise Thrift::ProtocolException
89
114
  when 3 then throw :stop
90
115
  end
91
116
  end
92
- @trans.should_receive(:close).exactly(3).times
93
- @serverTrans.should_receive(:close).ordered
94
- 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)
95
120
  end
96
121
  end
97
122
 
98
- describe ThreadPoolServer do
99
- it_should_behave_like "servers"
100
-
101
- def server_type
102
- # put this stuff here so it runs before the server is created
103
- @threadQ = mock("SizedQueue")
104
- SizedQueue.should_receive(:new).with(20).and_return(@threadQ)
105
- @excQ = mock("Queue")
106
- Queue.should_receive(:new).and_return(@excQ)
107
- ThreadPoolServer
123
+ describe Thrift::ThreadPoolServer do
124
+ before(:each) do
125
+ @processor = double("Processor")
126
+ @server_trans = double("ServerTransport")
127
+ @trans = double("BaseTransport")
128
+ @prot = double("BaseProtocol")
129
+ @client = double("Client")
130
+ @server = described_class.new(@processor, @server_trans, @trans, @prot)
131
+ sleep(0.15)
108
132
  end
109
133
 
110
- it "should set up the queues" do
111
- @server.instance_variable_get(:'@thread_q').should be(@threadQ)
112
- @server.instance_variable_get(:'@exception_q').should be(@excQ)
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))))")
113
139
  end
114
-
140
+
115
141
  it "should serve inside a thread" do
116
- Thread.should_receive(:new).and_return do |block|
117
- @server.should_receive(:serve)
118
- block.call
119
- @server.rspec_verify
142
+ exception_q = @server.instance_variable_get(:@exception_q)
143
+ expect_any_instance_of(described_class).to receive(:serve) do
144
+ exception_q.push(StandardError.new('ERROR'))
120
145
  end
121
- @excQ.should_receive(:pop).and_throw(:popped)
122
- lambda { @server.rescuable_serve }.should throw_symbol(:popped)
146
+ expect { @server.rescuable_serve }.to(raise_error('ERROR'))
147
+ sleep(0.15)
123
148
  end
124
149
 
125
150
  it "should avoid running the server twice when retrying rescuable_serve" do
126
- Thread.should_receive(:new).and_return do |block|
127
- @server.should_receive(:serve)
128
- block.call
129
- @server.rspec_verify
151
+ exception_q = @server.instance_variable_get(:@exception_q)
152
+ expect_any_instance_of(described_class).to receive(:serve) do
153
+ exception_q.push(StandardError.new('ERROR1'))
154
+ exception_q.push(StandardError.new('ERROR2'))
130
155
  end
131
- @excQ.should_receive(:pop).twice.and_throw(:popped)
132
- lambda { @server.rescuable_serve }.should throw_symbol(:popped)
133
- lambda { @server.rescuable_serve }.should throw_symbol(:popped)
156
+ expect { @server.rescuable_serve }.to(raise_error('ERROR1'))
157
+ expect { @server.rescuable_serve }.to(raise_error('ERROR2'))
134
158
  end
135
159
 
136
160
  it "should serve using a thread pool" do
137
- @serverTrans.should_receive(:listen).ordered
138
- @threadQ.should_receive(:push).with(:token)
139
- @threadQ.should_receive(:pop)
140
- Thread.should_receive(:new).and_yield
141
- @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client)
142
- @trans.should_receive(:get_transport).exactly(3).times.and_return(@trans)
143
- @prot.should_receive(:get_protocol).exactly(3).times.and_return(@prot)
161
+ thread_q = double("SizedQueue")
162
+ exception_q = double("Queue")
163
+ @server.instance_variable_set(:@thread_q, thread_q)
164
+ @server.instance_variable_set(:@exception_q, exception_q)
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)
144
172
  x = 0
145
173
  error = RuntimeError.new("Stopped")
146
- @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
147
175
  case (x += 1)
148
176
  when 1 then raise Thrift::TransportException
149
177
  when 2 then raise Thrift::ProtocolException
150
178
  when 3 then raise error
151
179
  end
152
180
  end
153
- @trans.should_receive(:close).exactly(3).times
154
- @excQ.should_receive(:push).with(error).and_throw(:stop)
155
- @serverTrans.should_receive(:close)
156
- lambda { @server.serve }.should throw_symbol(:stop)
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)
184
+ expect { @server.serve }.to(throw_symbol(:stop))
157
185
  end
158
186
  end
159
187
  end
@@ -17,45 +17,52 @@
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 ThriftSocketSpec < Spec::ExampleGroup
24
- include Thrift
23
+ describe 'Socket' do
25
24
 
26
- describe Socket do
25
+ describe Thrift::Socket do
27
26
  before(:each) do
28
- @socket = Socket.new
29
- @handle = mock("Handle", :closed? => false)
30
- @handle.stub!(:close)
31
- @handle.stub!(:connect_nonblock)
32
- ::Socket.stub!(:new).and_return(@handle)
27
+ @socket = Thrift::Socket.new
28
+ @handle = double("Handle", :closed? => false)
29
+ allow(@handle).to receive(:close)
30
+ allow(@handle).to receive(:connect_nonblock)
31
+ allow(@handle).to receive(:setsockopt)
32
+ allow(::Socket).to receive(:new).and_return(@handle)
33
33
  end
34
34
 
35
35
  it_should_behave_like "a socket"
36
36
 
37
37
  it "should raise a TransportException when it cannot open a socket" do
38
- ::Socket.should_receive(:new).and_raise(StandardError)
39
- lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
38
+ expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
39
+ expect { @socket.open }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
40
40
  end
41
41
 
42
42
  it "should open a ::Socket with default args" do
43
- ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true))
44
- ::Socket.should_receive(:getaddrinfo).with("localhost", 9090).and_return([[]])
45
- ::Socket.should_receive(:sockaddr_in)
43
+ expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
44
+ expect(::Socket).to receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
45
+ expect(::Socket).to receive(:sockaddr_in)
46
+ @socket.to_s == "socket(localhost:9090)"
46
47
  @socket.open
47
48
  end
48
49
 
49
50
  it "should accept host/port options" do
50
- ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true))
51
- ::Socket.should_receive(:getaddrinfo).with("my.domain", 1234).and_return([[]])
52
- ::Socket.should_receive(:sockaddr_in)
53
- Socket.new('my.domain', 1234).open
51
+ expect(::Socket).to receive(:new).and_return(double("Handle", :connect_nonblock => true, :setsockopt => nil))
52
+ expect(::Socket).to receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]])
53
+ expect(::Socket).to receive(:sockaddr_in)
54
+ @socket = Thrift::Socket.new('my.domain', 1234).open
55
+ @socket.to_s == "socket(my.domain:1234)"
54
56
  end
55
57
 
56
58
  it "should accept an optional timeout" do
57
- ::Socket.stub!(:new)
58
- Socket.new('localhost', 8080, 5).timeout.should == 5
59
+ allow(::Socket).to receive(:new)
60
+ expect(Thrift::Socket.new('localhost', 8080, 5).timeout).to eq(5)
61
+ end
62
+
63
+ it "should provide a reasonable to_s" do
64
+ allow(::Socket).to receive(:new)
65
+ expect(Thrift::Socket.new('myhost', 8090).to_s).to eq("socket(myhost:8090)")
59
66
  end
60
67
  end
61
68
  end
@@ -17,88 +17,88 @@
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
22
  shared_examples_for "a socket" do
23
23
  it "should open a socket" do
24
- @socket.open.should == @handle
24
+ expect(@socket.open).to eq(@handle)
25
25
  end
26
26
 
27
27
  it "should be open whenever it has a handle" do
28
- @socket.should_not be_open
28
+ expect(@socket).not_to be_open
29
29
  @socket.open
30
- @socket.should be_open
30
+ expect(@socket).to be_open
31
31
  @socket.handle = nil
32
- @socket.should_not be_open
32
+ expect(@socket).not_to be_open
33
33
  @socket.handle = @handle
34
34
  @socket.close
35
- @socket.should_not be_open
35
+ expect(@socket).not_to be_open
36
36
  end
37
37
 
38
38
  it "should write data to the handle" do
39
39
  @socket.open
40
- @handle.should_receive(:write).with("foobar")
40
+ expect(@handle).to receive(:write).with("foobar")
41
41
  @socket.write("foobar")
42
- @handle.should_receive(:write).with("fail").and_raise(StandardError)
43
- lambda { @socket.write("fail") }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
42
+ expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
43
+ expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
44
44
  end
45
45
 
46
46
  it "should raise an error when it cannot read from the handle" do
47
47
  @socket.open
48
- @handle.should_receive(:readpartial).with(17).and_raise(StandardError)
49
- lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
48
+ expect(@handle).to receive(:readpartial).with(17).and_raise(StandardError)
49
+ expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
50
50
  end
51
51
 
52
52
  it "should return the data read when reading from the handle works" do
53
53
  @socket.open
54
- @handle.should_receive(:readpartial).with(17).and_return("test data")
55
- @socket.read(17).should == "test data"
54
+ expect(@handle).to receive(:readpartial).with(17).and_return("test data")
55
+ expect(@socket.read(17)).to eq("test data")
56
56
  end
57
57
 
58
58
  it "should declare itself as closed when it has an error" do
59
59
  @socket.open
60
- @handle.should_receive(:write).with("fail").and_raise(StandardError)
61
- @socket.should be_open
62
- lambda { @socket.write("fail") }.should raise_error
63
- @socket.should_not be_open
60
+ expect(@handle).to receive(:write).with("fail").and_raise(StandardError)
61
+ expect(@socket).to be_open
62
+ expect { @socket.write("fail") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::NOT_OPEN) }
63
+ expect(@socket).not_to be_open
64
64
  end
65
65
 
66
66
  it "should raise an error when the stream is closed" do
67
67
  @socket.open
68
- @handle.stub!(:closed?).and_return(true)
69
- @socket.should_not be_open
70
- lambda { @socket.write("fail") }.should raise_error(IOError, "closed stream")
71
- lambda { @socket.read(10) }.should raise_error(IOError, "closed stream")
68
+ allow(@handle).to receive(:closed?).and_return(true)
69
+ expect(@socket).not_to be_open
70
+ expect { @socket.write("fail") }.to raise_error(IOError, "closed stream")
71
+ expect { @socket.read(10) }.to raise_error(IOError, "closed stream")
72
72
  end
73
73
 
74
74
  it "should support the timeout accessor for read" do
75
75
  @socket.timeout = 3
76
76
  @socket.open
77
- IO.should_receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
78
- @handle.should_receive(:readpartial).with(17).and_return("test data")
79
- @socket.read(17).should == "test data"
77
+ expect(IO).to receive(:select).with([@handle], nil, nil, 3).and_return([[@handle], [], []])
78
+ expect(@handle).to receive(:readpartial).with(17).and_return("test data")
79
+ expect(@socket.read(17)).to eq("test data")
80
80
  end
81
81
 
82
82
  it "should support the timeout accessor for write" do
83
83
  @socket.timeout = 3
84
84
  @socket.open
85
- IO.should_receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
86
- @handle.should_receive(:write_nonblock).with("test data").and_return(4)
87
- @handle.should_receive(:write_nonblock).with(" data").and_return(5)
88
- @socket.write("test data").should == 9
85
+ expect(IO).to receive(:select).with(nil, [@handle], nil, 3).twice.and_return([[], [@handle], []])
86
+ expect(@handle).to receive(:write_nonblock).with("test data").and_return(4)
87
+ expect(@handle).to receive(:write_nonblock).with(" data").and_return(5)
88
+ expect(@socket.write("test data")).to eq(9)
89
89
  end
90
90
 
91
91
  it "should raise an error when read times out" do
92
92
  @socket.timeout = 0.5
93
93
  @socket.open
94
- IO.should_receive(:select).once {sleep(0.5); nil}
95
- lambda { @socket.read(17) }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
94
+ expect(IO).to receive(:select).once {sleep(0.5); nil}
95
+ expect { @socket.read(17) }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
96
96
  end
97
97
 
98
98
  it "should raise an error when write times out" do
99
99
  @socket.timeout = 0.5
100
100
  @socket.open
101
- IO.should_receive(:select).with(nil, [@handle], nil, 0.5).any_number_of_times.and_return(nil)
102
- lambda { @socket.write("test data") }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::TIMED_OUT }
101
+ allow(IO).to receive(:select).with(nil, [@handle], nil, 0.5).and_return(nil)
102
+ expect { @socket.write("test data") }.to raise_error(Thrift::TransportException) { |e| expect(e.type).to eq(Thrift::TransportException::TIMED_OUT) }
103
103
  end
104
104
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  #
2
3
  # Licensed to the Apache Software Foundation (ASF) under one
3
4
  # or more contributor license agreements. See the NOTICE file
@@ -18,7 +19,7 @@
18
19
  #
19
20
 
20
21
  require 'rubygems'
21
- require 'spec'
22
+ require 'rspec'
22
23
 
23
24
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
24
25
 
@@ -26,33 +27,38 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
26
27
  # will get screwed up
27
28
  # $" << 'fastthread.bundle'
28
29
 
29
- require File.dirname(__FILE__) + '/../lib/thrift'
30
+ require 'thrift'
30
31
 
31
- class Object
32
- # tee is a useful method, so let's let our tests have it
33
- def tee(&block)
34
- block.call(self)
35
- self
32
+ unless Object.method_defined? :tap
33
+ # if Object#tap isn't defined, then add it; this should only happen in Ruby < 1.8.7
34
+ class Object
35
+ def tap(&block)
36
+ block.call(self)
37
+ self
38
+ end
36
39
  end
37
40
  end
38
41
 
39
- Spec::Runner.configure do |configuration|
42
+ RSpec.configure do |configuration|
40
43
  configuration.before(:each) do
41
44
  Thrift.type_checking = true
42
45
  end
43
46
  end
44
47
 
45
48
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. test debug_proto gen-rb])
46
- require "srv"
47
- require "debug_proto_test_constants"
49
+ require 'srv'
50
+ require 'debug_proto_test_constants'
48
51
 
49
52
  $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb])
50
53
  require 'thrift_spec_types'
51
54
  require 'nonblocking_service'
52
55
 
53
56
  module Fixtures
54
- COMPACT_PROTOCOL_TEST_STRUCT = COMPACT_TEST.dup
57
+ COMPACT_PROTOCOL_TEST_STRUCT = Thrift::Test::COMPACT_TEST.dup
55
58
  COMPACT_PROTOCOL_TEST_STRUCT.a_binary = [0,1,2,3,4,5,6,7,8].pack('c*')
56
59
  COMPACT_PROTOCOL_TEST_STRUCT.set_byte_map = nil
57
60
  COMPACT_PROTOCOL_TEST_STRUCT.map_byte_map = nil
58
61
  end
62
+
63
+ $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb/flat])
64
+