thrift 0.9.2.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/ext/binary_protocol_accelerated.c +12 -12
  3. data/ext/struct.c +5 -1
  4. data/lib/thrift.rb +8 -4
  5. data/lib/thrift/multiplexed_processor.rb +76 -0
  6. data/lib/thrift/processor.rb +24 -6
  7. data/lib/thrift/protocol/base_protocol.rb +11 -3
  8. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  9. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  10. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  11. data/lib/thrift/protocol/json_protocol.rb +21 -4
  12. data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
  13. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  14. data/lib/thrift/server/base_server.rb +8 -2
  15. data/lib/thrift/server/simple_server.rb +5 -1
  16. data/lib/thrift/server/thread_pool_server.rb +5 -1
  17. data/lib/thrift/server/threaded_server.rb +5 -1
  18. data/lib/thrift/transport/base_server_transport.rb +1 -1
  19. data/lib/thrift/transport/base_transport.rb +8 -0
  20. data/lib/thrift/transport/buffered_transport.rb +9 -1
  21. data/lib/thrift/transport/framed_transport.rb +9 -1
  22. data/lib/thrift/transport/http_client_transport.rb +7 -0
  23. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  24. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  25. data/lib/thrift/transport/server_socket.rb +6 -1
  26. data/lib/thrift/transport/socket.rb +21 -17
  27. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  28. data/lib/thrift/transport/ssl_socket.rb +51 -0
  29. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  30. data/lib/thrift/transport/unix_socket.rb +5 -1
  31. data/lib/thrift/union.rb +3 -6
  32. data/spec/BaseService.thrift +27 -0
  33. data/spec/ExtendedService.thrift +25 -0
  34. data/spec/base_protocol_spec.rb +79 -71
  35. data/spec/base_transport_spec.rb +155 -117
  36. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  37. data/spec/binary_protocol_spec.rb +16 -8
  38. data/spec/binary_protocol_spec_shared.rb +75 -72
  39. data/spec/bytes_spec.rb +38 -38
  40. data/spec/client_spec.rb +41 -42
  41. data/spec/compact_protocol_spec.rb +32 -17
  42. data/spec/exception_spec.rb +54 -54
  43. data/spec/flat_spec.rb +62 -0
  44. data/spec/http_client_spec.rb +74 -33
  45. data/spec/json_protocol_spec.rb +170 -131
  46. data/spec/namespaced_spec.rb +10 -5
  47. data/spec/nonblocking_server_spec.rb +16 -16
  48. data/spec/processor_spec.rb +26 -26
  49. data/spec/serializer_spec.rb +20 -20
  50. data/spec/server_socket_spec.rb +27 -22
  51. data/spec/server_spec.rb +91 -51
  52. data/spec/socket_spec.rb +23 -16
  53. data/spec/socket_spec_shared.rb +31 -31
  54. data/spec/spec_helper.rb +4 -1
  55. data/spec/ssl_server_socket_spec.rb +34 -0
  56. data/spec/ssl_socket_spec.rb +78 -0
  57. data/spec/struct_nested_containers_spec.rb +24 -24
  58. data/spec/struct_spec.rb +120 -120
  59. data/spec/thin_http_server_spec.rb +18 -18
  60. data/spec/types_spec.rb +56 -53
  61. data/spec/union_spec.rb +51 -40
  62. data/spec/unix_socket_spec.rb +43 -34
  63. metadata +191 -143
data/spec/bytes_spec.rb CHANGED
@@ -25,33 +25,33 @@ describe Thrift::Bytes do
25
25
  describe '.empty_byte_buffer' do
26
26
  it 'should create an empty buffer' do
27
27
  b = Thrift::Bytes.empty_byte_buffer
28
- b.length.should == 0
29
- b.encoding.should == Encoding::BINARY
28
+ expect(b.length).to eq(0)
29
+ expect(b.encoding).to eq(Encoding::BINARY)
30
30
  end
31
31
 
32
32
  it 'should create an empty buffer of given size' do
33
33
  b = Thrift::Bytes.empty_byte_buffer 2
34
- b.length.should == 2
35
- b.getbyte(0).should == 0
36
- b.getbyte(1).should == 0
37
- b.encoding.should == Encoding::BINARY
34
+ expect(b.length).to eq(2)
35
+ expect(b.getbyte(0)).to eq(0)
36
+ expect(b.getbyte(1)).to eq(0)
37
+ expect(b.encoding).to eq(Encoding::BINARY)
38
38
  end
39
39
  end
40
40
 
41
41
  describe '.force_binary_encoding' do
42
42
  it 'should change encoding' do
43
43
  e = 'STRING'.encode('UTF-8')
44
- e.encoding.should_not == Encoding::BINARY
44
+ expect(e.encoding).not_to eq(Encoding::BINARY)
45
45
  a = Thrift::Bytes.force_binary_encoding e
46
- a.encoding.should == Encoding::BINARY
46
+ expect(a.encoding).to eq(Encoding::BINARY)
47
47
  end
48
48
  end
49
49
 
50
50
  describe '.get_string_byte' do
51
51
  it 'should get the byte at index' do
52
52
  s = "\x41\x42"
53
- Thrift::Bytes.get_string_byte(s, 0).should == 0x41
54
- Thrift::Bytes.get_string_byte(s, 1).should == 0x42
53
+ expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
54
+ expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
55
55
  end
56
56
  end
57
57
 
@@ -59,42 +59,42 @@ describe Thrift::Bytes do
59
59
  it 'should set byte value at index' do
60
60
  s = "\x41\x42"
61
61
  Thrift::Bytes.set_string_byte(s, 0, 0x43)
62
- s.getbyte(0).should == 0x43
63
- s.should == 'CB'
62
+ expect(s.getbyte(0)).to eq(0x43)
63
+ expect(s).to eq('CB')
64
64
  end
65
65
  end
66
66
 
67
67
  describe '.convert_to_utf8_byte_buffer' do
68
68
  it 'should convert UTF-8 String to byte buffer' do
69
69
  e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
70
- e.length.should == 1
70
+ expect(e.length).to eq(1)
71
71
 
72
72
  a = Thrift::Bytes.convert_to_utf8_byte_buffer e
73
- a.encoding.should == Encoding::BINARY
74
- a.length.should == 3
75
- a.unpack('C*').should == [0xE2, 0x82, 0xAC]
73
+ expect(a.encoding).to eq(Encoding::BINARY)
74
+ expect(a.length).to eq(3)
75
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
76
76
  end
77
77
 
78
78
  it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
79
79
  # Assumptions
80
80
  e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
81
- e.length.should == 1
82
- e.unpack('C*').should == [0xA4] # euro sign is a different code point in ISO-8859-15
81
+ expect(e.length).to eq(1)
82
+ expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
83
83
 
84
84
  a = Thrift::Bytes.convert_to_utf8_byte_buffer e
85
- a.encoding.should == Encoding::BINARY
86
- a.length.should == 3
87
- a.unpack('C*').should == [0xE2, 0x82, 0xAC]
85
+ expect(a.encoding).to eq(Encoding::BINARY)
86
+ expect(a.length).to eq(3)
87
+ expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
88
88
  end
89
89
  end
90
90
 
91
91
  describe '.convert_to_string' do
92
92
  it 'should convert UTF-8 byte buffer to a UTF-8 String' do
93
93
  e = [0xE2, 0x82, 0xAC].pack("C*")
94
- e.encoding.should == Encoding::BINARY
94
+ expect(e.encoding).to eq(Encoding::BINARY)
95
95
  a = Thrift::Bytes.convert_to_string e
96
- a.encoding.should == Encoding::UTF_8
97
- a.should == "\u20AC"
96
+ expect(a.encoding).to eq(Encoding::UTF_8)
97
+ expect(a).to eq("\u20AC")
98
98
  end
99
99
  end
100
100
 
@@ -102,14 +102,14 @@ describe Thrift::Bytes do
102
102
  describe '.empty_byte_buffer' do
103
103
  it 'should create an empty buffer' do
104
104
  b = Thrift::Bytes.empty_byte_buffer
105
- b.length.should == 0
105
+ expect(b.length).to eq(0)
106
106
  end
107
107
 
108
108
  it 'should create an empty buffer of given size' do
109
109
  b = Thrift::Bytes.empty_byte_buffer 2
110
- b.length.should == 2
111
- b[0].should == 0
112
- b[1].should == 0
110
+ expect(b.length).to eq(2)
111
+ expect(b[0]).to eq(0)
112
+ expect(b[1]).to eq(0)
113
113
  end
114
114
  end
115
115
 
@@ -117,16 +117,16 @@ describe Thrift::Bytes do
117
117
  it 'should be a no-op' do
118
118
  e = 'STRING'
119
119
  a = Thrift::Bytes.force_binary_encoding e
120
- a.should == e
121
- a.should be(e)
120
+ expect(a).to eq(e)
121
+ expect(a).to be(e)
122
122
  end
123
123
  end
124
124
 
125
125
  describe '.get_string_byte' do
126
126
  it 'should get the byte at index' do
127
127
  s = "\x41\x42"
128
- Thrift::Bytes.get_string_byte(s, 0).should == 0x41
129
- Thrift::Bytes.get_string_byte(s, 1).should == 0x42
128
+ expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
129
+ expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
130
130
  end
131
131
  end
132
132
 
@@ -134,8 +134,8 @@ describe Thrift::Bytes do
134
134
  it 'should set byte value at index' do
135
135
  s = "\x41\x42"
136
136
  Thrift::Bytes.set_string_byte(s, 0, 0x43)
137
- s[0].should == 0x43
138
- s.should == 'CB'
137
+ expect(s[0]).to eq(0x43)
138
+ expect(s).to eq('CB')
139
139
  end
140
140
  end
141
141
 
@@ -143,8 +143,8 @@ describe Thrift::Bytes do
143
143
  it 'should be a no-op' do
144
144
  e = 'STRING'
145
145
  a = Thrift::Bytes.convert_to_utf8_byte_buffer e
146
- a.should == e
147
- a.should be(e)
146
+ expect(a).to eq(e)
147
+ expect(a).to be(e)
148
148
  end
149
149
  end
150
150
 
@@ -152,8 +152,8 @@ describe Thrift::Bytes do
152
152
  it 'should be a no-op' do
153
153
  e = 'STRING'
154
154
  a = Thrift::Bytes.convert_to_string e
155
- a.should == e
156
- a.should be(e)
155
+ expect(a).to eq(e)
156
+ expect(a).to be(e)
157
157
  end
158
158
  end
159
159
  end
data/spec/client_spec.rb CHANGED
@@ -26,74 +26,73 @@ describe 'Client' do
26
26
  end
27
27
 
28
28
  before(:each) do
29
- @prot = mock("MockProtocol")
29
+ @prot = double("MockProtocol")
30
30
  @client = ClientSpec.new(@prot)
31
31
  end
32
32
 
33
33
  describe Thrift::Client do
34
34
  it "should re-use iprot for oprot if not otherwise specified" do
35
- @client.instance_variable_get(:'@iprot').should eql(@prot)
36
- @client.instance_variable_get(:'@oprot').should eql(@prot)
35
+ expect(@client.instance_variable_get(:'@iprot')).to eql(@prot)
36
+ expect(@client.instance_variable_get(:'@oprot')).to eql(@prot)
37
37
  end
38
38
 
39
39
  it "should send a test message" do
40
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
41
- mock_args = mock('#<TestMessage_args:mock>')
42
- mock_args.should_receive(:foo=).with('foo')
43
- mock_args.should_receive(:bar=).with(42)
44
- mock_args.should_receive(:write).with(@prot)
45
- @prot.should_receive(:write_message_end)
46
- @prot.should_receive(:trans) do
47
- mock('trans').tap do |trans|
48
- trans.should_receive(:flush)
40
+ expect(@prot).to receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0)
41
+ mock_args = double('#<TestMessage_args:mock>')
42
+ expect(mock_args).to receive(:foo=).with('foo')
43
+ expect(mock_args).to receive(:bar=).with(42)
44
+ expect(mock_args).to receive(:write).with(@prot)
45
+ expect(@prot).to receive(:write_message_end)
46
+ expect(@prot).to receive(:trans) do
47
+ double('trans').tap do |trans|
48
+ expect(trans).to receive(:flush)
49
49
  end
50
50
  end
51
- klass = stub("TestMessage_args", :new => mock_args)
51
+ klass = double("TestMessage_args", :new => mock_args)
52
52
  @client.send_message('testMessage', klass, :foo => 'foo', :bar => 42)
53
53
  end
54
54
 
55
55
  it "should increment the sequence id when sending messages" do
56
- pending "it seems sequence ids are completely ignored right now" do
57
- @prot.should_receive(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
58
- @prot.should_receive(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
59
- @prot.should_receive(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
60
- @prot.stub!(:write_message_end)
61
- @prot.stub!(:trans).and_return mock("trans").as_null_object
62
- @client.send_message('testMessage', mock("args class").as_null_object)
63
- @client.send_message('testMessage2', mock("args class").as_null_object)
64
- @client.send_message('testMessage3', mock("args class").as_null_object)
65
- end
56
+ pending "it seems sequence ids are completely ignored right now"
57
+ @prot.expect(:write_message_begin).with('testMessage', Thrift::MessageTypes::CALL, 0).ordered
58
+ @prot.expect(:write_message_begin).with('testMessage2', Thrift::MessageTypes::CALL, 1).ordered
59
+ @prot.expect(:write_message_begin).with('testMessage3', Thrift::MessageTypes::CALL, 2).ordered
60
+ @prot.stub!(:write_message_end)
61
+ @prot.stub!(:trans).and_return double("trans").as_null_object
62
+ @client.send_message('testMessage', double("args class").as_null_object)
63
+ @client.send_message('testMessage2', double("args class").as_null_object)
64
+ @client.send_message('testMessage3', double("args class").as_null_object)
66
65
  end
67
66
 
68
67
  it "should receive a test message" do
69
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
70
- @prot.should_receive(:read_message_end)
71
- mock_klass = mock("#<MockClass:mock>")
72
- mock_klass.should_receive(:read).with(@prot)
73
- @client.receive_message(stub("MockClass", :new => mock_klass))
68
+ expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::CALL, 0]
69
+ expect(@prot).to receive(:read_message_end)
70
+ mock_klass = double("#<MockClass:mock>")
71
+ expect(mock_klass).to receive(:read).with(@prot)
72
+ @client.receive_message(double("MockClass", :new => mock_klass))
74
73
  end
75
74
 
76
75
  it "should handle received exceptions" do
77
- @prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
78
- @prot.should_receive(:read_message_end)
79
- Thrift::ApplicationException.should_receive(:new).and_return do
76
+ expect(@prot).to receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
77
+ expect(@prot).to receive(:read_message_end)
78
+ expect(Thrift::ApplicationException).to receive(:new) do
80
79
  StandardError.new.tap do |mock_exc|
81
- mock_exc.should_receive(:read).with(@prot)
80
+ expect(mock_exc).to receive(:read).with(@prot)
82
81
  end
83
82
  end
84
- lambda { @client.receive_message(nil) }.should raise_error(StandardError)
83
+ expect { @client.receive_message(nil) }.to raise_error(StandardError)
85
84
  end
86
85
 
87
86
  it "should close the transport if an error occurs while sending a message" do
88
- @prot.stub!(:write_message_begin)
89
- @prot.should_not_receive(:write_message_end)
90
- mock_args = mock("#<TestMessage_args:mock>")
91
- mock_args.should_receive(:write).with(@prot).and_raise(StandardError)
92
- trans = mock("MockTransport")
93
- @prot.stub!(:trans).and_return(trans)
94
- trans.should_receive(:close)
95
- klass = mock("TestMessage_args", :new => mock_args)
96
- lambda { @client.send_message("testMessage", klass) }.should raise_error(StandardError)
87
+ allow(@prot).to receive(:write_message_begin)
88
+ expect(@prot).not_to receive(:write_message_end)
89
+ mock_args = double("#<TestMessage_args:mock>")
90
+ expect(mock_args).to receive(:write).with(@prot).and_raise(StandardError)
91
+ trans = double("MockTransport")
92
+ allow(@prot).to receive(:trans).and_return(trans)
93
+ expect(trans).to receive(:close)
94
+ klass = double("TestMessage_args", :new => mock_args)
95
+ expect { @client.send_message("testMessage", klass) }.to raise_error(StandardError)
97
96
  end
98
97
  end
99
98
  end
@@ -42,7 +42,7 @@ describe Thrift::CompactProtocol do
42
42
  proto.send(writer(primitive_type), value)
43
43
  # puts "buf: #{trans.inspect_buffer}" if primitive_type == :i64
44
44
  read_back = proto.send(reader(primitive_type))
45
- read_back.should == value
45
+ expect(read_back).to eq(value)
46
46
  end
47
47
  end
48
48
  end
@@ -62,10 +62,10 @@ describe Thrift::CompactProtocol do
62
62
 
63
63
  proto = Thrift::CompactProtocol.new(trans)
64
64
  name, type, id = proto.read_field_begin
65
- type.should == thrift_type
66
- id.should == 15
65
+ expect(type).to eq(thrift_type)
66
+ expect(id).to eq(15)
67
67
  read_back = proto.send(reader(primitive_type))
68
- read_back.should == value
68
+ expect(read_back).to eq(value)
69
69
  proto.read_field_end
70
70
  end
71
71
  end
@@ -75,13 +75,13 @@ describe Thrift::CompactProtocol do
75
75
  trans = Thrift::MemoryBufferTransport.new
76
76
  proto = Thrift::CompactProtocol.new(trans)
77
77
 
78
- struct = CompactProtoTestStruct.new
78
+ struct = Thrift::Test::CompactProtoTestStruct.new
79
79
  # sets and maps don't hash well... not sure what to do here.
80
80
  struct.write(proto)
81
81
 
82
- struct2 = CompactProtoTestStruct.new
82
+ struct2 = Thrift::Test::CompactProtoTestStruct.new
83
83
  struct2.read(proto)
84
- struct2.should == struct
84
+ expect(struct2).to eq(struct)
85
85
  end
86
86
 
87
87
  it "should make method calls correctly" do
@@ -91,19 +91,19 @@ describe Thrift::CompactProtocol do
91
91
  client_in_trans = Thrift::MemoryBufferTransport.new
92
92
  client_in_proto = Thrift::CompactProtocol.new(client_in_trans)
93
93
 
94
- processor = Srv::Processor.new(JankyHandler.new)
94
+ processor = Thrift::Test::Srv::Processor.new(JankyHandler.new)
95
95
 
96
- client = Srv::Client.new(client_in_proto, client_out_proto)
96
+ client = Thrift::Test::Srv::Client.new(client_in_proto, client_out_proto)
97
97
  client.send_Janky(1)
98
98
  # puts client_out_trans.inspect_buffer
99
99
  processor.process(client_out_proto, client_in_proto)
100
- client.recv_Janky.should == 2
100
+ expect(client.recv_Janky).to eq(2)
101
101
  end
102
102
 
103
103
  it "should deal with fields following fields that have non-delta ids" do
104
- brcp = BreaksRubyCompactProtocol.new(
104
+ brcp = Thrift::Test::BreaksRubyCompactProtocol.new(
105
105
  :field1 => "blah",
106
- :field2 => BigFieldIdStruct.new(
106
+ :field2 => Thrift::Test::BigFieldIdStruct.new(
107
107
  :field1 => "string1",
108
108
  :field2 => "string2"),
109
109
  :field3 => 3)
@@ -111,20 +111,25 @@ describe Thrift::CompactProtocol do
111
111
  bytes = ser.serialize(brcp)
112
112
 
113
113
  deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
114
- brcp2 = BreaksRubyCompactProtocol.new
114
+ brcp2 = Thrift::Test::BreaksRubyCompactProtocol.new
115
115
  deser.deserialize(brcp2, bytes)
116
- brcp2.should == brcp
116
+ expect(brcp2).to eq(brcp)
117
117
  end
118
118
 
119
119
  it "should deserialize an empty map to an empty hash" do
120
- struct = SingleMapTestStruct.new(:i32_map => {})
120
+ struct = Thrift::Test::SingleMapTestStruct.new(:i32_map => {})
121
121
  ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
122
122
  bytes = ser.serialize(struct)
123
123
 
124
124
  deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
125
- struct2 = SingleMapTestStruct.new
125
+ struct2 = Thrift::Test::SingleMapTestStruct.new
126
126
  deser.deserialize(struct2, bytes)
127
- struct.should == struct2
127
+ expect(struct).to eq(struct2)
128
+ end
129
+
130
+ it "should provide a reasonable to_s" do
131
+ trans = Thrift::MemoryBufferTransport.new
132
+ expect(Thrift::CompactProtocol.new(trans).to_s).to eq("compact(memory)")
128
133
  end
129
134
 
130
135
  class JankyHandler
@@ -141,3 +146,13 @@ describe Thrift::CompactProtocol do
141
146
  "read_#{sym.to_s}"
142
147
  end
143
148
  end
149
+
150
+ describe Thrift::CompactProtocolFactory do
151
+ it "should create a CompactProtocol" do
152
+ expect(Thrift::CompactProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::CompactProtocol)
153
+ end
154
+
155
+ it "should provide a reasonable to_s" do
156
+ expect(Thrift::CompactProtocolFactory.new.to_s).to eq("compact")
157
+ end
158
+ end
@@ -24,107 +24,107 @@ describe 'Exception' do
24
24
  describe Thrift::Exception do
25
25
  it "should have an accessible message" do
26
26
  e = Thrift::Exception.new("test message")
27
- e.message.should == "test message"
27
+ expect(e.message).to eq("test message")
28
28
  end
29
29
  end
30
30
 
31
31
  describe Thrift::ApplicationException do
32
32
  it "should inherit from Thrift::Exception" do
33
- Thrift::ApplicationException.superclass.should == Thrift::Exception
33
+ expect(Thrift::ApplicationException.superclass).to eq(Thrift::Exception)
34
34
  end
35
35
 
36
36
  it "should have an accessible type and message" do
37
37
  e = Thrift::ApplicationException.new
38
- e.type.should == Thrift::ApplicationException::UNKNOWN
39
- e.message.should be_nil
38
+ expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN)
39
+ expect(e.message).to be_nil
40
40
  e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
41
- e.type.should == Thrift::ApplicationException::UNKNOWN_METHOD
42
- e.message.should == "test message"
41
+ expect(e.type).to eq(Thrift::ApplicationException::UNKNOWN_METHOD)
42
+ expect(e.message).to eq("test message")
43
43
  end
44
44
 
45
45
  it "should read a struct off of a protocol" do
46
- prot = mock("MockProtocol")
47
- prot.should_receive(:read_struct_begin).ordered
48
- prot.should_receive(:read_field_begin).exactly(3).times.and_return(
46
+ prot = double("MockProtocol")
47
+ expect(prot).to receive(:read_struct_begin).ordered
48
+ expect(prot).to receive(:read_field_begin).exactly(3).times.and_return(
49
49
  ["message", Thrift::Types::STRING, 1],
50
50
  ["type", Thrift::Types::I32, 2],
51
51
  [nil, Thrift::Types::STOP, 0]
52
52
  )
53
- prot.should_receive(:read_string).ordered.and_return "test message"
54
- prot.should_receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
55
- prot.should_receive(:read_field_end).exactly(2).times
56
- prot.should_receive(:read_struct_end).ordered
53
+ expect(prot).to receive(:read_string).ordered.and_return "test message"
54
+ expect(prot).to receive(:read_i32).ordered.and_return Thrift::ApplicationException::BAD_SEQUENCE_ID
55
+ expect(prot).to receive(:read_field_end).exactly(2).times
56
+ expect(prot).to receive(:read_struct_end).ordered
57
57
 
58
58
  e = Thrift::ApplicationException.new
59
59
  e.read(prot)
60
- e.message.should == "test message"
61
- e.type.should == Thrift::ApplicationException::BAD_SEQUENCE_ID
60
+ expect(e.message).to eq("test message")
61
+ expect(e.type).to eq(Thrift::ApplicationException::BAD_SEQUENCE_ID)
62
62
  end
63
63
 
64
64
  it "should skip bad fields when reading a struct" do
65
- prot = mock("MockProtocol")
66
- prot.should_receive(:read_struct_begin).ordered
67
- prot.should_receive(:read_field_begin).exactly(5).times.and_return(
65
+ prot = double("MockProtocol")
66
+ expect(prot).to receive(:read_struct_begin).ordered
67
+ expect(prot).to receive(:read_field_begin).exactly(5).times.and_return(
68
68
  ["type", Thrift::Types::I32, 2],
69
69
  ["type", Thrift::Types::STRING, 2],
70
70
  ["message", Thrift::Types::MAP, 1],
71
71
  ["message", Thrift::Types::STRING, 3],
72
72
  [nil, Thrift::Types::STOP, 0]
73
73
  )
74
- prot.should_receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
75
- prot.should_receive(:skip).with(Thrift::Types::STRING).twice
76
- prot.should_receive(:skip).with(Thrift::Types::MAP)
77
- prot.should_receive(:read_field_end).exactly(4).times
78
- prot.should_receive(:read_struct_end).ordered
74
+ expect(prot).to receive(:read_i32).and_return Thrift::ApplicationException::INVALID_MESSAGE_TYPE
75
+ expect(prot).to receive(:skip).with(Thrift::Types::STRING).twice
76
+ expect(prot).to receive(:skip).with(Thrift::Types::MAP)
77
+ expect(prot).to receive(:read_field_end).exactly(4).times
78
+ expect(prot).to receive(:read_struct_end).ordered
79
79
 
80
80
  e = Thrift::ApplicationException.new
81
81
  e.read(prot)
82
- e.message.should be_nil
83
- e.type.should == Thrift::ApplicationException::INVALID_MESSAGE_TYPE
82
+ expect(e.message).to be_nil
83
+ expect(e.type).to eq(Thrift::ApplicationException::INVALID_MESSAGE_TYPE)
84
84
  end
85
85
 
86
86
  it "should write a Thrift::ApplicationException struct to the oprot" do
87
- prot = mock("MockProtocol")
88
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
89
- prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
90
- prot.should_receive(:write_string).with("test message").ordered
91
- prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
92
- prot.should_receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
93
- prot.should_receive(:write_field_end).twice
94
- prot.should_receive(:write_field_stop).ordered
95
- prot.should_receive(:write_struct_end).ordered
87
+ prot = double("MockProtocol")
88
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
89
+ expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
90
+ expect(prot).to receive(:write_string).with("test message").ordered
91
+ expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
92
+ expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::UNKNOWN_METHOD).ordered
93
+ expect(prot).to receive(:write_field_end).twice
94
+ expect(prot).to receive(:write_field_stop).ordered
95
+ expect(prot).to receive(:write_struct_end).ordered
96
96
 
97
97
  e = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, "test message")
98
98
  e.write(prot)
99
99
  end
100
100
 
101
101
  it "should skip nil fields when writing to the oprot" do
102
- prot = mock("MockProtocol")
103
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
104
- prot.should_receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
105
- prot.should_receive(:write_string).with("test message").ordered
106
- prot.should_receive(:write_field_end).ordered
107
- prot.should_receive(:write_field_stop).ordered
108
- prot.should_receive(:write_struct_end).ordered
102
+ prot = double("MockProtocol")
103
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
104
+ expect(prot).to receive(:write_field_begin).with("message", Thrift::Types::STRING, 1).ordered
105
+ expect(prot).to receive(:write_string).with("test message").ordered
106
+ expect(prot).to receive(:write_field_end).ordered
107
+ expect(prot).to receive(:write_field_stop).ordered
108
+ expect(prot).to receive(:write_struct_end).ordered
109
109
 
110
110
  e = Thrift::ApplicationException.new(nil, "test message")
111
111
  e.write(prot)
112
112
 
113
- prot = mock("MockProtocol")
114
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
115
- prot.should_receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
116
- prot.should_receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
117
- prot.should_receive(:write_field_end).ordered
118
- prot.should_receive(:write_field_stop).ordered
119
- prot.should_receive(:write_struct_end).ordered
113
+ prot = double("MockProtocol")
114
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
115
+ expect(prot).to receive(:write_field_begin).with("type", Thrift::Types::I32, 2).ordered
116
+ expect(prot).to receive(:write_i32).with(Thrift::ApplicationException::BAD_SEQUENCE_ID).ordered
117
+ expect(prot).to receive(:write_field_end).ordered
118
+ expect(prot).to receive(:write_field_stop).ordered
119
+ expect(prot).to receive(:write_struct_end).ordered
120
120
 
121
121
  e = Thrift::ApplicationException.new(Thrift::ApplicationException::BAD_SEQUENCE_ID)
122
122
  e.write(prot)
123
123
 
124
- prot = mock("MockProtocol")
125
- prot.should_receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
126
- prot.should_receive(:write_field_stop).ordered
127
- prot.should_receive(:write_struct_end).ordered
124
+ prot = double("MockProtocol")
125
+ expect(prot).to receive(:write_struct_begin).with("Thrift::ApplicationException").ordered
126
+ expect(prot).to receive(:write_field_stop).ordered
127
+ expect(prot).to receive(:write_struct_end).ordered
128
128
 
129
129
  e = Thrift::ApplicationException.new(nil)
130
130
  e.write(prot)
@@ -134,8 +134,8 @@ describe 'Exception' do
134
134
  describe Thrift::ProtocolException do
135
135
  it "should have an accessible type" do
136
136
  prot = Thrift::ProtocolException.new(Thrift::ProtocolException::SIZE_LIMIT, "message")
137
- prot.type.should == Thrift::ProtocolException::SIZE_LIMIT
138
- prot.message.should == "message"
137
+ expect(prot.type).to eq(Thrift::ProtocolException::SIZE_LIMIT)
138
+ expect(prot.message).to eq("message")
139
139
  end
140
140
  end
141
141
  end