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
@@ -56,5 +56,9 @@ module Thrift
56
56
  end
57
57
 
58
58
  alias to_io handle
59
+
60
+ def to_s
61
+ "domain(#{@path})"
62
+ end
59
63
  end
60
- end
64
+ end
@@ -36,5 +36,9 @@ module Thrift
36
36
  raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
37
37
  end
38
38
  end
39
+
40
+ def to_s
41
+ "domain(#{@path})"
42
+ end
39
43
  end
40
- end
44
+ end
@@ -87,12 +87,9 @@ module Thrift
87
87
  end
88
88
 
89
89
  def ==(other)
90
- other != nil && @setfield == other.get_set_field && @value == other.get_value
91
- end
92
-
93
- def eql?(other)
94
- self.class == other.class && self == other
90
+ other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
95
91
  end
92
+ alias_method :eql?, :==
96
93
 
97
94
  def hash
98
95
  [self.class.name, @setfield, @value].hash
@@ -176,4 +173,4 @@ module Thrift
176
173
  end
177
174
  end
178
175
  end
179
- end
176
+ end
@@ -0,0 +1,27 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+
19
+ namespace rb Base
20
+
21
+ struct Hello {
22
+ 1: string greeting = "hello world"
23
+ }
24
+
25
+ service BaseService {
26
+ Hello greeting(1:bool english)
27
+ }
@@ -0,0 +1,25 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+
19
+ namespace rb Extended
20
+
21
+ include "BaseService.thrift"
22
+
23
+ service ExtendedService extends BaseService.BaseService {
24
+ void ping()
25
+ }
@@ -0,0 +1,44 @@
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
+ #
21
+ # Licensed to the Apache Software Foundation (ASF) under one
22
+ # or more contributor license agreements. See the NOTICE file
23
+ # distributed with this work for additional information
24
+ # regarding copyright ownership. The ASF licenses this file
25
+ # to you under the Apache License, Version 2.0 (the
26
+ # "License"); you may not use this file except in compliance
27
+ # with the License. You may obtain a copy of the License at
28
+ #
29
+ # http://www.apache.org/licenses/LICENSE-2.0
30
+ #
31
+ # Unless required by applicable law or agreed to in writing,
32
+ # software distributed under the License is distributed on an
33
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34
+ # KIND, either express or implied. See the License for the
35
+ # specific language governing permissions and limitations
36
+ # under the License.
37
+ #
38
+
39
+ namespace rb OtherNamespace
40
+
41
+ enum SomeEnum {
42
+ ONE
43
+ TWO
44
+ }
@@ -0,0 +1,53 @@
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
+ #
21
+ # Licensed to the Apache Software Foundation (ASF) under one
22
+ # or more contributor license agreements. See the NOTICE file
23
+ # distributed with this work for additional information
24
+ # regarding copyright ownership. The ASF licenses this file
25
+ # to you under the Apache License, Version 2.0 (the
26
+ # "License"); you may not use this file except in compliance
27
+ # with the License. You may obtain a copy of the License at
28
+ #
29
+ # http://www.apache.org/licenses/LICENSE-2.0
30
+ #
31
+ # Unless required by applicable law or agreed to in writing,
32
+ # software distributed under the License is distributed on an
33
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34
+ # KIND, either express or implied. See the License for the
35
+ # specific language governing permissions and limitations
36
+ # under the License.
37
+ #
38
+
39
+ namespace rb NamespacedSpecNamespace
40
+
41
+ include "Referenced.thrift"
42
+
43
+ struct Hello {
44
+ 1: string greeting = "hello world"
45
+ }
46
+
47
+ service NamespacedNonblockingService {
48
+ Hello greeting(1:bool english)
49
+ bool block()
50
+ oneway void unblock(1:i32 n)
51
+ oneway void shutdown()
52
+ void sleep(1:double seconds)
53
+ }
@@ -129,4 +129,55 @@ struct Struct_with_union {
129
129
 
130
130
  struct StructWithEnumMap {
131
131
  1: map<SomeEnum, list<SomeEnum>> my_map;
132
- }
132
+ }
133
+
134
+ # Nested lists
135
+ struct NestedListInList {
136
+ 1: list<list<byte>> value
137
+ }
138
+
139
+ struct NestedListInSet {
140
+ 1: set<list<byte>> value
141
+ }
142
+
143
+ struct NestedListInMapKey {
144
+ 1: map<list<byte>, byte> value
145
+ }
146
+
147
+ struct NestedListInMapValue {
148
+ 1: map<byte, list<byte>> value
149
+ }
150
+
151
+ # Nested sets
152
+ struct NestedSetInList {
153
+ 1: list<set<byte>> value
154
+ }
155
+
156
+ struct NestedSetInSet {
157
+ 1: set<set<byte>> value
158
+ }
159
+
160
+ struct NestedSetInMapKey {
161
+ 1: map<set<byte>, byte> value
162
+ }
163
+
164
+ struct NestedSetInMapValue {
165
+ 1: map<byte, set<byte>> value
166
+ }
167
+
168
+ # Nested maps
169
+ struct NestedMapInList {
170
+ 1: list<map<byte, byte>> value
171
+ }
172
+
173
+ struct NestedMapInSet {
174
+ 1: set<map<byte, byte>> value
175
+ }
176
+
177
+ struct NestedMapInMapKey {
178
+ 2: map<map<byte, byte>, byte> value
179
+ }
180
+
181
+ struct NestedMapInMapValue {
182
+ 2: map<byte, map<byte, byte>> value
183
+ }
@@ -17,144 +17,209 @@
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 ThriftBaseProtocolSpec < Spec::ExampleGroup
23
- include Thrift
22
+ describe 'BaseProtocol' do
24
23
 
25
24
  before(:each) do
26
- @trans = mock("MockTransport")
27
- @prot = BaseProtocol.new(@trans)
25
+ @trans = double("MockTransport")
26
+ @prot = Thrift::BaseProtocol.new(@trans)
28
27
  end
29
28
 
30
- describe BaseProtocol do
29
+ describe Thrift::BaseProtocol do
31
30
  # most of the methods are stubs, so we can ignore them
32
31
 
32
+ it "should provide a reasonable to_s" do
33
+ expect(@trans).to receive(:to_s).once.and_return("trans")
34
+ expect(@prot.to_s).to eq("trans")
35
+ end
36
+
33
37
  it "should make trans accessible" do
34
- @prot.trans.should eql(@trans)
38
+ expect(@prot.trans).to eql(@trans)
35
39
  end
36
40
 
37
- it "should write out a field nicely" do
38
- @prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
39
- @prot.should_receive(:write_type).with('type', 'value').ordered
40
- @prot.should_receive(:write_field_end).ordered
41
+ it 'should write out a field nicely (deprecated write_field signature)' do
42
+ expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
43
+ expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
44
+ expect(@prot).to receive(:write_field_end).ordered
41
45
  @prot.write_field('field', 'type', 'fid', 'value')
42
46
  end
43
47
 
44
- it "should write out the different types" do
45
- @prot.should_receive(:write_bool).with('bool').ordered
46
- @prot.should_receive(:write_byte).with('byte').ordered
47
- @prot.should_receive(:write_double).with('double').ordered
48
- @prot.should_receive(:write_i16).with('i16').ordered
49
- @prot.should_receive(:write_i32).with('i32').ordered
50
- @prot.should_receive(:write_i64).with('i64').ordered
51
- @prot.should_receive(:write_string).with('string').ordered
52
- struct = mock('Struct')
53
- struct.should_receive(:write).with(@prot).ordered
54
- @prot.write_type(Types::BOOL, 'bool')
55
- @prot.write_type(Types::BYTE, 'byte')
56
- @prot.write_type(Types::DOUBLE, 'double')
57
- @prot.write_type(Types::I16, 'i16')
58
- @prot.write_type(Types::I32, 'i32')
59
- @prot.write_type(Types::I64, 'i64')
60
- @prot.write_type(Types::STRING, 'string')
61
- @prot.write_type(Types::STRUCT, struct)
48
+ it 'should write out a field nicely' do
49
+ expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
50
+ expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
51
+ expect(@prot).to receive(:write_field_end).ordered
52
+ @prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
53
+ end
54
+
55
+ it 'should write out the different types (deprecated write_type signature)' do
56
+ expect(@prot).to receive(:write_bool).with('bool').ordered
57
+ expect(@prot).to receive(:write_byte).with('byte').ordered
58
+ expect(@prot).to receive(:write_double).with('double').ordered
59
+ expect(@prot).to receive(:write_i16).with('i16').ordered
60
+ expect(@prot).to receive(:write_i32).with('i32').ordered
61
+ expect(@prot).to receive(:write_i64).with('i64').ordered
62
+ expect(@prot).to receive(:write_string).with('string').ordered
63
+ struct = double('Struct')
64
+ expect(struct).to receive(:write).with(@prot).ordered
65
+ @prot.write_type(Thrift::Types::BOOL, 'bool')
66
+ @prot.write_type(Thrift::Types::BYTE, 'byte')
67
+ @prot.write_type(Thrift::Types::DOUBLE, 'double')
68
+ @prot.write_type(Thrift::Types::I16, 'i16')
69
+ @prot.write_type(Thrift::Types::I32, 'i32')
70
+ @prot.write_type(Thrift::Types::I64, 'i64')
71
+ @prot.write_type(Thrift::Types::STRING, 'string')
72
+ @prot.write_type(Thrift::Types::STRUCT, struct)
73
+ # all other types are not implemented
74
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
75
+ expect { @prot.write_type(type, type.to_s) }.to raise_error(NotImplementedError)
76
+ end
77
+ end
78
+
79
+ it 'should write out the different types' do
80
+ expect(@prot).to receive(:write_bool).with('bool').ordered
81
+ expect(@prot).to receive(:write_byte).with('byte').ordered
82
+ expect(@prot).to receive(:write_double).with('double').ordered
83
+ expect(@prot).to receive(:write_i16).with('i16').ordered
84
+ expect(@prot).to receive(:write_i32).with('i32').ordered
85
+ expect(@prot).to receive(:write_i64).with('i64').ordered
86
+ expect(@prot).to receive(:write_string).with('string').ordered
87
+ expect(@prot).to receive(:write_binary).with('binary').ordered
88
+ struct = double('Struct')
89
+ expect(struct).to receive(:write).with(@prot).ordered
90
+ @prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
91
+ @prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
92
+ @prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
93
+ @prot.write_type({:type => Thrift::Types::I16}, 'i16')
94
+ @prot.write_type({:type => Thrift::Types::I32}, 'i32')
95
+ @prot.write_type({:type => Thrift::Types::I64}, 'i64')
96
+ @prot.write_type({:type => Thrift::Types::STRING}, 'string')
97
+ @prot.write_type({:type => Thrift::Types::STRING, :binary => true}, 'binary')
98
+ @prot.write_type({:type => Thrift::Types::STRUCT}, struct)
62
99
  # all other types are not implemented
63
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
64
- lambda { @prot.write_type(type, type.to_s) }.should raise_error(NotImplementedError)
100
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
101
+ expect { @prot.write_type({:type => type}, type.to_s) }.to raise_error(NotImplementedError)
65
102
  end
66
103
  end
67
104
 
68
- it "should read the different types" do
69
- @prot.should_receive(:read_bool).ordered
70
- @prot.should_receive(:read_byte).ordered
71
- @prot.should_receive(:read_i16).ordered
72
- @prot.should_receive(:read_i32).ordered
73
- @prot.should_receive(:read_i64).ordered
74
- @prot.should_receive(:read_double).ordered
75
- @prot.should_receive(:read_string).ordered
76
- @prot.read_type(Types::BOOL)
77
- @prot.read_type(Types::BYTE)
78
- @prot.read_type(Types::I16)
79
- @prot.read_type(Types::I32)
80
- @prot.read_type(Types::I64)
81
- @prot.read_type(Types::DOUBLE)
82
- @prot.read_type(Types::STRING)
105
+ it 'should read the different types (deprecated read_type signature)' do
106
+ expect(@prot).to receive(:read_bool).ordered
107
+ expect(@prot).to receive(:read_byte).ordered
108
+ expect(@prot).to receive(:read_i16).ordered
109
+ expect(@prot).to receive(:read_i32).ordered
110
+ expect(@prot).to receive(:read_i64).ordered
111
+ expect(@prot).to receive(:read_double).ordered
112
+ expect(@prot).to receive(:read_string).ordered
113
+ @prot.read_type(Thrift::Types::BOOL)
114
+ @prot.read_type(Thrift::Types::BYTE)
115
+ @prot.read_type(Thrift::Types::I16)
116
+ @prot.read_type(Thrift::Types::I32)
117
+ @prot.read_type(Thrift::Types::I64)
118
+ @prot.read_type(Thrift::Types::DOUBLE)
119
+ @prot.read_type(Thrift::Types::STRING)
83
120
  # all other types are not implemented
84
- [Types::STOP, Types::VOID, Types::MAP, Types::SET, Types::LIST].each do |type|
85
- lambda { @prot.read_type(type) }.should raise_error(NotImplementedError)
121
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
122
+ Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
123
+ expect { @prot.read_type(type) }.to raise_error(NotImplementedError)
124
+ end
125
+ end
126
+
127
+ it 'should read the different types' do
128
+ expect(@prot).to receive(:read_bool).ordered
129
+ expect(@prot).to receive(:read_byte).ordered
130
+ expect(@prot).to receive(:read_i16).ordered
131
+ expect(@prot).to receive(:read_i32).ordered
132
+ expect(@prot).to receive(:read_i64).ordered
133
+ expect(@prot).to receive(:read_double).ordered
134
+ expect(@prot).to receive(:read_string).ordered
135
+ expect(@prot).to receive(:read_binary).ordered
136
+ @prot.read_type({:type => Thrift::Types::BOOL})
137
+ @prot.read_type({:type => Thrift::Types::BYTE})
138
+ @prot.read_type({:type => Thrift::Types::I16})
139
+ @prot.read_type({:type => Thrift::Types::I32})
140
+ @prot.read_type({:type => Thrift::Types::I64})
141
+ @prot.read_type({:type => Thrift::Types::DOUBLE})
142
+ @prot.read_type({:type => Thrift::Types::STRING})
143
+ @prot.read_type({:type => Thrift::Types::STRING, :binary => true})
144
+ # all other types are not implemented
145
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
146
+ Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
147
+ expect { @prot.read_type({:type => type}) }.to raise_error(NotImplementedError)
86
148
  end
87
149
  end
88
150
 
89
151
  it "should skip the basic types" do
90
- @prot.should_receive(:read_bool).ordered
91
- @prot.should_receive(:read_byte).ordered
92
- @prot.should_receive(:read_i16).ordered
93
- @prot.should_receive(:read_i32).ordered
94
- @prot.should_receive(:read_i64).ordered
95
- @prot.should_receive(:read_double).ordered
96
- @prot.should_receive(:read_string).ordered
97
- @prot.skip(Types::BOOL)
98
- @prot.skip(Types::BYTE)
99
- @prot.skip(Types::I16)
100
- @prot.skip(Types::I32)
101
- @prot.skip(Types::I64)
102
- @prot.skip(Types::DOUBLE)
103
- @prot.skip(Types::STRING)
104
- @prot.skip(Types::STOP) # should do absolutely nothing
152
+ expect(@prot).to receive(:read_bool).ordered
153
+ expect(@prot).to receive(:read_byte).ordered
154
+ expect(@prot).to receive(:read_i16).ordered
155
+ expect(@prot).to receive(:read_i32).ordered
156
+ expect(@prot).to receive(:read_i64).ordered
157
+ expect(@prot).to receive(:read_double).ordered
158
+ expect(@prot).to receive(:read_string).ordered
159
+ @prot.skip(Thrift::Types::BOOL)
160
+ @prot.skip(Thrift::Types::BYTE)
161
+ @prot.skip(Thrift::Types::I16)
162
+ @prot.skip(Thrift::Types::I32)
163
+ @prot.skip(Thrift::Types::I64)
164
+ @prot.skip(Thrift::Types::DOUBLE)
165
+ @prot.skip(Thrift::Types::STRING)
105
166
  end
106
167
 
107
168
  it "should skip structs" do
108
169
  real_skip = @prot.method(:skip)
109
- @prot.should_receive(:read_struct_begin).ordered
110
- @prot.should_receive(:read_field_begin).exactly(4).times.and_return(
111
- ['field 1', Types::STRING, 1],
112
- ['field 2', Types::I32, 2],
113
- ['field 3', Types::MAP, 3],
114
- [nil, Types::STOP, 0]
170
+ expect(@prot).to receive(:read_struct_begin).ordered
171
+ expect(@prot).to receive(:read_field_begin).exactly(4).times.and_return(
172
+ ['field 1', Thrift::Types::STRING, 1],
173
+ ['field 2', Thrift::Types::I32, 2],
174
+ ['field 3', Thrift::Types::MAP, 3],
175
+ [nil, Thrift::Types::STOP, 0]
115
176
  )
116
- @prot.should_receive(:read_field_end).exactly(3).times
117
- @prot.should_receive(:read_string).exactly(3).times
118
- @prot.should_receive(:read_i32).ordered
119
- @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRING, 1])
177
+ expect(@prot).to receive(:read_field_end).exactly(3).times
178
+ expect(@prot).to receive(:read_string).exactly(3).times
179
+ expect(@prot).to receive(:read_i32).ordered
180
+ expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
120
181
  # @prot.should_receive(:read_string).exactly(2).times
121
- @prot.should_receive(:read_map_end).ordered
122
- @prot.should_receive(:read_struct_end).ordered
123
- real_skip.call(Types::STRUCT)
182
+ expect(@prot).to receive(:read_map_end).ordered
183
+ expect(@prot).to receive(:read_struct_end).ordered
184
+ real_skip.call(Thrift::Types::STRUCT)
124
185
  end
125
186
 
126
187
  it "should skip maps" do
127
188
  real_skip = @prot.method(:skip)
128
- @prot.should_receive(:read_map_begin).ordered.and_return([Types::STRING, Types::STRUCT, 1])
129
- @prot.should_receive(:read_string).ordered
130
- @prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
131
- @prot.should_receive(:read_field_begin).ordered.and_return([nil, Types::STOP, nil]);
132
- @prot.should_receive(:read_struct_end).ordered
133
- @prot.should_receive(:read_map_end).ordered
134
- real_skip.call(Types::MAP)
189
+ expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
190
+ expect(@prot).to receive(:read_string).ordered
191
+ expect(@prot).to receive(:read_struct_begin).ordered.and_return(["some_struct"])
192
+ expect(@prot).to receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
193
+ expect(@prot).to receive(:read_struct_end).ordered
194
+ expect(@prot).to receive(:read_map_end).ordered
195
+ real_skip.call(Thrift::Types::MAP)
135
196
  end
136
197
 
137
198
  it "should skip sets" do
138
199
  real_skip = @prot.method(:skip)
139
- @prot.should_receive(:read_set_begin).ordered.and_return([Types::I64, 9])
140
- @prot.should_receive(:read_i64).ordered.exactly(9).times
141
- @prot.should_receive(:read_set_end)
142
- real_skip.call(Types::SET)
200
+ expect(@prot).to receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
201
+ expect(@prot).to receive(:read_i64).ordered.exactly(9).times
202
+ expect(@prot).to receive(:read_set_end)
203
+ real_skip.call(Thrift::Types::SET)
143
204
  end
144
205
 
145
206
  it "should skip lists" do
146
207
  real_skip = @prot.method(:skip)
147
- @prot.should_receive(:read_list_begin).ordered.and_return([Types::DOUBLE, 11])
148
- @prot.should_receive(:read_double).ordered.exactly(11).times
149
- @prot.should_receive(:read_list_end)
150
- real_skip.call(Types::LIST)
208
+ expect(@prot).to receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
209
+ expect(@prot).to receive(:read_double).ordered.exactly(11).times
210
+ expect(@prot).to receive(:read_list_end)
211
+ real_skip.call(Thrift::Types::LIST)
151
212
  end
152
213
  end
153
214
 
154
- describe BaseProtocolFactory do
215
+ describe Thrift::BaseProtocolFactory do
155
216
  it "should raise NotImplementedError" do
156
217
  # returning nil since Protocol is just an abstract class
157
- lambda {BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
218
+ expect {Thrift::BaseProtocolFactory.new.get_protocol(double("MockTransport"))}.to raise_error(NotImplementedError)
219
+ end
220
+
221
+ it "should provide a reasonable to_s" do
222
+ expect(Thrift::BaseProtocolFactory.new.to_s).to eq("base")
158
223
  end
159
224
  end
160
225
  end