upfluence-thrift 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +43 -0
  3. data/benchmark/Benchmark.thrift +24 -0
  4. data/benchmark/benchmark.rb +271 -0
  5. data/benchmark/client.rb +74 -0
  6. data/benchmark/gen-rb/benchmark_constants.rb +11 -0
  7. data/benchmark/gen-rb/benchmark_service.rb +80 -0
  8. data/benchmark/gen-rb/benchmark_types.rb +10 -0
  9. data/benchmark/server.rb +82 -0
  10. data/benchmark/thin_server.rb +44 -0
  11. data/ext/binary_protocol_accelerated.c +460 -0
  12. data/ext/binary_protocol_accelerated.h +20 -0
  13. data/ext/bytes.c +36 -0
  14. data/ext/bytes.h +31 -0
  15. data/ext/compact_protocol.c +637 -0
  16. data/ext/compact_protocol.h +20 -0
  17. data/ext/constants.h +99 -0
  18. data/ext/extconf.rb +34 -0
  19. data/ext/macros.h +41 -0
  20. data/ext/memory_buffer.c +134 -0
  21. data/ext/memory_buffer.h +20 -0
  22. data/ext/protocol.c +0 -0
  23. data/ext/protocol.h +0 -0
  24. data/ext/strlcpy.c +41 -0
  25. data/ext/strlcpy.h +34 -0
  26. data/ext/struct.c +707 -0
  27. data/ext/struct.h +25 -0
  28. data/ext/thrift_native.c +201 -0
  29. data/lib/thrift.rb +68 -0
  30. data/lib/thrift/bytes.rb +131 -0
  31. data/lib/thrift/client.rb +71 -0
  32. data/lib/thrift/core_ext.rb +23 -0
  33. data/lib/thrift/core_ext/fixnum.rb +29 -0
  34. data/lib/thrift/exceptions.rb +87 -0
  35. data/lib/thrift/multiplexed_processor.rb +76 -0
  36. data/lib/thrift/processor.rb +57 -0
  37. data/lib/thrift/protocol/base_protocol.rb +379 -0
  38. data/lib/thrift/protocol/binary_protocol.rb +237 -0
  39. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  40. data/lib/thrift/protocol/compact_protocol.rb +435 -0
  41. data/lib/thrift/protocol/json_protocol.rb +769 -0
  42. data/lib/thrift/protocol/multiplexed_protocol.rb +40 -0
  43. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  44. data/lib/thrift/serializer/deserializer.rb +33 -0
  45. data/lib/thrift/serializer/serializer.rb +34 -0
  46. data/lib/thrift/server/base_server.rb +31 -0
  47. data/lib/thrift/server/mongrel_http_server.rb +60 -0
  48. data/lib/thrift/server/nonblocking_server.rb +305 -0
  49. data/lib/thrift/server/rack_application.rb +61 -0
  50. data/lib/thrift/server/simple_server.rb +43 -0
  51. data/lib/thrift/server/thin_http_server.rb +51 -0
  52. data/lib/thrift/server/thread_pool_server.rb +75 -0
  53. data/lib/thrift/server/threaded_server.rb +47 -0
  54. data/lib/thrift/struct.rb +237 -0
  55. data/lib/thrift/struct_union.rb +192 -0
  56. data/lib/thrift/thrift_native.rb +24 -0
  57. data/lib/thrift/transport/base_server_transport.rb +37 -0
  58. data/lib/thrift/transport/base_transport.rb +109 -0
  59. data/lib/thrift/transport/buffered_transport.rb +114 -0
  60. data/lib/thrift/transport/framed_transport.rb +117 -0
  61. data/lib/thrift/transport/http_client_transport.rb +56 -0
  62. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  63. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  64. data/lib/thrift/transport/server_socket.rb +63 -0
  65. data/lib/thrift/transport/socket.rb +139 -0
  66. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  67. data/lib/thrift/transport/unix_socket.rb +40 -0
  68. data/lib/thrift/types.rb +101 -0
  69. data/lib/thrift/union.rb +179 -0
  70. data/spec/BaseService.thrift +27 -0
  71. data/spec/ExtendedService.thrift +25 -0
  72. data/spec/Referenced.thrift +44 -0
  73. data/spec/ThriftNamespacedSpec.thrift +53 -0
  74. data/spec/ThriftSpec.thrift +183 -0
  75. data/spec/base_protocol_spec.rb +217 -0
  76. data/spec/base_transport_spec.rb +350 -0
  77. data/spec/binary_protocol_accelerated_spec.rb +42 -0
  78. data/spec/binary_protocol_spec.rb +66 -0
  79. data/spec/binary_protocol_spec_shared.rb +455 -0
  80. data/spec/bytes_spec.rb +160 -0
  81. data/spec/client_spec.rb +99 -0
  82. data/spec/compact_protocol_spec.rb +143 -0
  83. data/spec/exception_spec.rb +141 -0
  84. data/spec/flat_spec.rb +62 -0
  85. data/spec/gen-rb/base/base_service.rb +80 -0
  86. data/spec/gen-rb/base/base_service_constants.rb +11 -0
  87. data/spec/gen-rb/base/base_service_types.rb +26 -0
  88. data/spec/gen-rb/extended/extended_service.rb +78 -0
  89. data/spec/gen-rb/extended/extended_service_constants.rb +11 -0
  90. data/spec/gen-rb/extended/extended_service_types.rb +12 -0
  91. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +272 -0
  92. data/spec/gen-rb/flat/referenced_constants.rb +11 -0
  93. data/spec/gen-rb/flat/referenced_types.rb +17 -0
  94. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
  95. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +28 -0
  96. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +272 -0
  97. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
  98. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +28 -0
  99. data/spec/gen-rb/nonblocking_service.rb +272 -0
  100. data/spec/gen-rb/other_namespace/referenced_constants.rb +11 -0
  101. data/spec/gen-rb/other_namespace/referenced_types.rb +17 -0
  102. data/spec/gen-rb/thrift_spec_constants.rb +11 -0
  103. data/spec/gen-rb/thrift_spec_types.rb +538 -0
  104. data/spec/http_client_spec.rb +120 -0
  105. data/spec/json_protocol_spec.rb +513 -0
  106. data/spec/namespaced_spec.rb +67 -0
  107. data/spec/nonblocking_server_spec.rb +263 -0
  108. data/spec/processor_spec.rb +80 -0
  109. data/spec/serializer_spec.rb +67 -0
  110. data/spec/server_socket_spec.rb +79 -0
  111. data/spec/server_spec.rb +147 -0
  112. data/spec/socket_spec.rb +61 -0
  113. data/spec/socket_spec_shared.rb +104 -0
  114. data/spec/spec_helper.rb +64 -0
  115. data/spec/struct_nested_containers_spec.rb +191 -0
  116. data/spec/struct_spec.rb +293 -0
  117. data/spec/thin_http_server_spec.rb +141 -0
  118. data/spec/types_spec.rb +115 -0
  119. data/spec/union_spec.rb +203 -0
  120. data/spec/unix_socket_spec.rb +107 -0
  121. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
  122. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
  123. data/test/debug_proto/gen-rb/empty_service.rb +24 -0
  124. data/test/debug_proto/gen-rb/inherited.rb +79 -0
  125. data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
  126. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
  127. data/test/debug_proto/gen-rb/srv.rb +330 -0
  128. metadata +388 -0
@@ -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
+ }
@@ -0,0 +1,183 @@
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 SpecNamespace
40
+
41
+ struct Hello {
42
+ 1: string greeting = "hello world"
43
+ }
44
+
45
+ enum SomeEnum {
46
+ ONE
47
+ TWO
48
+ }
49
+
50
+ struct StructWithSomeEnum {
51
+ 1: SomeEnum some_enum;
52
+ }
53
+
54
+ union TestUnion {
55
+ /**
56
+ * A doc string
57
+ */
58
+ 1: string string_field;
59
+ 2: i32 i32_field;
60
+ 3: i32 other_i32_field;
61
+ 4: SomeEnum enum_field;
62
+ 5: binary binary_field;
63
+ }
64
+
65
+ struct Foo {
66
+ 1: i32 simple = 53,
67
+ 2: string words = "words",
68
+ 3: Hello hello = {'greeting' : "hello, world!"},
69
+ 4: list<i32> ints = [1, 2, 2, 3],
70
+ 5: map<i32, map<string, double>> complex,
71
+ 6: set<i16> shorts = [5, 17, 239],
72
+ 7: optional string opt_string
73
+ 8: bool my_bool
74
+ }
75
+
76
+ struct Foo2 {
77
+ 1: binary my_binary
78
+ }
79
+
80
+ struct BoolStruct {
81
+ 1: bool yesno = 1
82
+ }
83
+
84
+ struct SimpleList {
85
+ 1: list<bool> bools,
86
+ 2: list<byte> bytes,
87
+ 3: list<i16> i16s,
88
+ 4: list<i32> i32s,
89
+ 5: list<i64> i64s,
90
+ 6: list<double> doubles,
91
+ 7: list<string> strings,
92
+ 8: list<map<i16, i16>> maps,
93
+ 9: list<list<i16>> lists,
94
+ 10: list<set<i16>> sets,
95
+ 11: list<Hello> hellos
96
+ }
97
+
98
+ exception Xception {
99
+ 1: string message,
100
+ 2: i32 code = 1
101
+ }
102
+
103
+ service NonblockingService {
104
+ Hello greeting(1:bool english)
105
+ bool block()
106
+ oneway void unblock(1:i32 n)
107
+ oneway void shutdown()
108
+ void sleep(1:double seconds)
109
+ }
110
+
111
+ union My_union {
112
+ 1: bool im_true,
113
+ 2: byte a_bite,
114
+ 3: i16 integer16,
115
+ 4: i32 integer32,
116
+ 5: i64 integer64,
117
+ 6: double double_precision,
118
+ 7: string some_characters,
119
+ 8: i32 other_i32
120
+ 9: SomeEnum some_enum;
121
+ 10: map<SomeEnum, list<SomeEnum>> my_map;
122
+ }
123
+
124
+ struct Struct_with_union {
125
+ 1: My_union fun_union
126
+ 2: i32 integer32
127
+ 3: string some_characters
128
+ }
129
+
130
+ struct StructWithEnumMap {
131
+ 1: map<SomeEnum, list<SomeEnum>> my_map;
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
+ }
@@ -0,0 +1,217 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'spec_helper'
21
+
22
+ describe 'BaseProtocol' do
23
+
24
+ before(:each) do
25
+ @trans = mock("MockTransport")
26
+ @prot = Thrift::BaseProtocol.new(@trans)
27
+ end
28
+
29
+ describe Thrift::BaseProtocol do
30
+ # most of the methods are stubs, so we can ignore them
31
+
32
+ it "should make trans accessible" do
33
+ @prot.trans.should eql(@trans)
34
+ end
35
+
36
+ it 'should write out a field nicely (deprecated write_field signature)' do
37
+ @prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
38
+ @prot.should_receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
39
+ @prot.should_receive(:write_field_end).ordered
40
+ @prot.write_field('field', 'type', 'fid', 'value')
41
+ end
42
+
43
+ it 'should write out a field nicely' do
44
+ @prot.should_receive(:write_field_begin).with('field', 'type', 'fid').ordered
45
+ @prot.should_receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
46
+ @prot.should_receive(:write_field_end).ordered
47
+ @prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
48
+ end
49
+
50
+ it 'should write out the different types (deprecated write_type signature)' do
51
+ @prot.should_receive(:write_bool).with('bool').ordered
52
+ @prot.should_receive(:write_byte).with('byte').ordered
53
+ @prot.should_receive(:write_double).with('double').ordered
54
+ @prot.should_receive(:write_i16).with('i16').ordered
55
+ @prot.should_receive(:write_i32).with('i32').ordered
56
+ @prot.should_receive(:write_i64).with('i64').ordered
57
+ @prot.should_receive(:write_string).with('string').ordered
58
+ struct = mock('Struct')
59
+ struct.should_receive(:write).with(@prot).ordered
60
+ @prot.write_type(Thrift::Types::BOOL, 'bool')
61
+ @prot.write_type(Thrift::Types::BYTE, 'byte')
62
+ @prot.write_type(Thrift::Types::DOUBLE, 'double')
63
+ @prot.write_type(Thrift::Types::I16, 'i16')
64
+ @prot.write_type(Thrift::Types::I32, 'i32')
65
+ @prot.write_type(Thrift::Types::I64, 'i64')
66
+ @prot.write_type(Thrift::Types::STRING, 'string')
67
+ @prot.write_type(Thrift::Types::STRUCT, struct)
68
+ # all other types are not implemented
69
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
70
+ expect { @prot.write_type(type, type.to_s) }.to raise_error(NotImplementedError)
71
+ end
72
+ end
73
+
74
+ it 'should write out the different types' do
75
+ @prot.should_receive(:write_bool).with('bool').ordered
76
+ @prot.should_receive(:write_byte).with('byte').ordered
77
+ @prot.should_receive(:write_double).with('double').ordered
78
+ @prot.should_receive(:write_i16).with('i16').ordered
79
+ @prot.should_receive(:write_i32).with('i32').ordered
80
+ @prot.should_receive(:write_i64).with('i64').ordered
81
+ @prot.should_receive(:write_string).with('string').ordered
82
+ @prot.should_receive(:write_binary).with('binary').ordered
83
+ struct = mock('Struct')
84
+ struct.should_receive(:write).with(@prot).ordered
85
+ @prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
86
+ @prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
87
+ @prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
88
+ @prot.write_type({:type => Thrift::Types::I16}, 'i16')
89
+ @prot.write_type({:type => Thrift::Types::I32}, 'i32')
90
+ @prot.write_type({:type => Thrift::Types::I64}, 'i64')
91
+ @prot.write_type({:type => Thrift::Types::STRING}, 'string')
92
+ @prot.write_type({:type => Thrift::Types::STRING, :binary => true}, 'binary')
93
+ @prot.write_type({:type => Thrift::Types::STRUCT}, struct)
94
+ # all other types are not implemented
95
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
96
+ expect { @prot.write_type({:type => type}, type.to_s) }.to raise_error(NotImplementedError)
97
+ end
98
+ end
99
+
100
+ it 'should read the different types (deprecated read_type signature)' do
101
+ @prot.should_receive(:read_bool).ordered
102
+ @prot.should_receive(:read_byte).ordered
103
+ @prot.should_receive(:read_i16).ordered
104
+ @prot.should_receive(:read_i32).ordered
105
+ @prot.should_receive(:read_i64).ordered
106
+ @prot.should_receive(:read_double).ordered
107
+ @prot.should_receive(:read_string).ordered
108
+ @prot.read_type(Thrift::Types::BOOL)
109
+ @prot.read_type(Thrift::Types::BYTE)
110
+ @prot.read_type(Thrift::Types::I16)
111
+ @prot.read_type(Thrift::Types::I32)
112
+ @prot.read_type(Thrift::Types::I64)
113
+ @prot.read_type(Thrift::Types::DOUBLE)
114
+ @prot.read_type(Thrift::Types::STRING)
115
+ # all other types are not implemented
116
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
117
+ Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
118
+ expect { @prot.read_type(type) }.to raise_error(NotImplementedError)
119
+ end
120
+ end
121
+
122
+ it 'should read the different types' do
123
+ @prot.should_receive(:read_bool).ordered
124
+ @prot.should_receive(:read_byte).ordered
125
+ @prot.should_receive(:read_i16).ordered
126
+ @prot.should_receive(:read_i32).ordered
127
+ @prot.should_receive(:read_i64).ordered
128
+ @prot.should_receive(:read_double).ordered
129
+ @prot.should_receive(:read_string).ordered
130
+ @prot.should_receive(:read_binary).ordered
131
+ @prot.read_type({:type => Thrift::Types::BOOL})
132
+ @prot.read_type({:type => Thrift::Types::BYTE})
133
+ @prot.read_type({:type => Thrift::Types::I16})
134
+ @prot.read_type({:type => Thrift::Types::I32})
135
+ @prot.read_type({:type => Thrift::Types::I64})
136
+ @prot.read_type({:type => Thrift::Types::DOUBLE})
137
+ @prot.read_type({:type => Thrift::Types::STRING})
138
+ @prot.read_type({:type => Thrift::Types::STRING, :binary => true})
139
+ # all other types are not implemented
140
+ [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
141
+ Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
142
+ expect { @prot.read_type({:type => type}) }.to raise_error(NotImplementedError)
143
+ end
144
+ end
145
+
146
+ it "should skip the basic types" do
147
+ @prot.should_receive(:read_bool).ordered
148
+ @prot.should_receive(:read_byte).ordered
149
+ @prot.should_receive(:read_i16).ordered
150
+ @prot.should_receive(:read_i32).ordered
151
+ @prot.should_receive(:read_i64).ordered
152
+ @prot.should_receive(:read_double).ordered
153
+ @prot.should_receive(:read_string).ordered
154
+ @prot.skip(Thrift::Types::BOOL)
155
+ @prot.skip(Thrift::Types::BYTE)
156
+ @prot.skip(Thrift::Types::I16)
157
+ @prot.skip(Thrift::Types::I32)
158
+ @prot.skip(Thrift::Types::I64)
159
+ @prot.skip(Thrift::Types::DOUBLE)
160
+ @prot.skip(Thrift::Types::STRING)
161
+ @prot.skip(Thrift::Types::STOP) # should do absolutely nothing
162
+ end
163
+
164
+ it "should skip structs" do
165
+ real_skip = @prot.method(:skip)
166
+ @prot.should_receive(:read_struct_begin).ordered
167
+ @prot.should_receive(:read_field_begin).exactly(4).times.and_return(
168
+ ['field 1', Thrift::Types::STRING, 1],
169
+ ['field 2', Thrift::Types::I32, 2],
170
+ ['field 3', Thrift::Types::MAP, 3],
171
+ [nil, Thrift::Types::STOP, 0]
172
+ )
173
+ @prot.should_receive(:read_field_end).exactly(3).times
174
+ @prot.should_receive(:read_string).exactly(3).times
175
+ @prot.should_receive(:read_i32).ordered
176
+ @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
177
+ # @prot.should_receive(:read_string).exactly(2).times
178
+ @prot.should_receive(:read_map_end).ordered
179
+ @prot.should_receive(:read_struct_end).ordered
180
+ real_skip.call(Thrift::Types::STRUCT)
181
+ end
182
+
183
+ it "should skip maps" do
184
+ real_skip = @prot.method(:skip)
185
+ @prot.should_receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
186
+ @prot.should_receive(:read_string).ordered
187
+ @prot.should_receive(:read_struct_begin).ordered.and_return(["some_struct"])
188
+ @prot.should_receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
189
+ @prot.should_receive(:read_struct_end).ordered
190
+ @prot.should_receive(:read_map_end).ordered
191
+ real_skip.call(Thrift::Types::MAP)
192
+ end
193
+
194
+ it "should skip sets" do
195
+ real_skip = @prot.method(:skip)
196
+ @prot.should_receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
197
+ @prot.should_receive(:read_i64).ordered.exactly(9).times
198
+ @prot.should_receive(:read_set_end)
199
+ real_skip.call(Thrift::Types::SET)
200
+ end
201
+
202
+ it "should skip lists" do
203
+ real_skip = @prot.method(:skip)
204
+ @prot.should_receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
205
+ @prot.should_receive(:read_double).ordered.exactly(11).times
206
+ @prot.should_receive(:read_list_end)
207
+ real_skip.call(Thrift::Types::LIST)
208
+ end
209
+ end
210
+
211
+ describe Thrift::BaseProtocolFactory do
212
+ it "should raise NotImplementedError" do
213
+ # returning nil since Protocol is just an abstract class
214
+ lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError)
215
+ end
216
+ end
217
+ end