upfluence-thrift 2.6.8 → 2.7.4

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/benchmark/{gen-rb/benchmark_constants.rb → benchmark_constants.rb} +1 -1
  3. data/benchmark/{gen-rb/benchmark_service.rb → benchmark_service.rb} +2 -2
  4. data/benchmark/{gen-rb/benchmark_types.rb → benchmark_types.rb} +1 -1
  5. data/ext/struct.c +5 -1
  6. data/lib/thrift/base_stream.rb +85 -0
  7. data/lib/thrift/bidi_stream.rb +183 -0
  8. data/lib/thrift/client.rb +84 -17
  9. data/lib/thrift/inbound_stream.rb +72 -0
  10. data/lib/thrift/middleware.rb +42 -0
  11. data/lib/thrift/outbound_stream.rb +52 -0
  12. data/lib/thrift/processor.rb +287 -47
  13. data/lib/thrift/protocol/base_protocol.rb +35 -33
  14. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  15. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  16. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  17. data/lib/thrift/protocol/json_protocol.rb +21 -4
  18. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  19. data/lib/thrift/server/base_server.rb +8 -2
  20. data/lib/thrift/server/nonblocking_server.rb +5 -4
  21. data/lib/thrift/server/simple_server.rb +5 -1
  22. data/lib/thrift/server/thread_pool_server.rb +5 -1
  23. data/lib/thrift/server/threaded_server.rb +5 -1
  24. data/lib/thrift/transport/base_server_transport.rb +1 -1
  25. data/lib/thrift/transport/base_transport.rb +8 -0
  26. data/lib/thrift/transport/buffered_transport.rb +9 -1
  27. data/lib/thrift/transport/framed_transport.rb +9 -1
  28. data/lib/thrift/transport/http_client_transport.rb +4 -0
  29. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  30. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  31. data/lib/thrift/transport/server_socket.rb +5 -0
  32. data/lib/thrift/transport/socket.rb +21 -17
  33. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  34. data/lib/thrift/transport/ssl_socket.rb +51 -0
  35. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  36. data/lib/thrift/transport/unix_socket.rb +5 -1
  37. data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
  38. data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
  39. data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
  40. data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
  41. data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
  42. data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
  43. data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
  44. data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
  45. data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
  46. data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
  47. data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
  48. data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
  49. data/lib/thrift/types/core/core_constants.rb +15 -0
  50. data/lib/thrift/types/core/core_types.rb +58 -0
  51. data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
  52. data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
  53. data/lib/thrift/types/known/any/any_constants.rb +1 -1
  54. data/lib/thrift/types/known/any/any_types.rb +2 -2
  55. data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
  56. data/lib/thrift/types/known/duration/duration_types.rb +2 -2
  57. data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
  58. data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
  59. data/lib/thrift/types/plugin/plugin.rb +139 -0
  60. data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
  61. data/lib/thrift/types/plugin/plugin_types.rb +106 -0
  62. data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
  63. data/lib/thrift/types/program_definition/program_definition_types.rb +137 -0
  64. data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
  65. data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
  66. data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
  67. data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
  68. data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
  69. data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
  70. data/lib/thrift/types/value/value_constants.rb +1 -1
  71. data/lib/thrift/types/value/value_types.rb +50 -51
  72. data/lib/thrift/types.rb +11 -3
  73. data/lib/thrift/union.rb +3 -6
  74. data/lib/thrift.rb +6 -0
  75. data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
  76. data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
  77. data/lib/types/annotation/naming/naming_constants.rb +16 -0
  78. data/lib/types/annotation/naming/naming_types.rb +57 -0
  79. data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
  80. data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
  81. data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
  82. data/lib/types/constant_definition/constant_definition_types.rb +290 -0
  83. data/lib/types/core/core_constants.rb +14 -0
  84. data/lib/types/core/core_types.rb +56 -0
  85. data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
  86. data/lib/types/enum_definition/enum_definition_types.rb +104 -0
  87. data/lib/types/known/any/any_constants.rb +16 -0
  88. data/lib/types/known/any/any_types.rb +59 -0
  89. data/lib/types/known/duration/duration_constants.rb +16 -0
  90. data/lib/types/known/duration/duration_types.rb +59 -0
  91. data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
  92. data/lib/types/known/timestamp/timestamp_types.rb +59 -0
  93. data/lib/types/plugin/plugin.rb +137 -0
  94. data/lib/types/plugin/plugin_constants.rb +14 -0
  95. data/lib/types/plugin/plugin_types.rb +104 -0
  96. data/lib/types/program_definition/program_definition_constants.rb +14 -0
  97. data/lib/types/program_definition/program_definition_types.rb +135 -0
  98. data/lib/types/service_definition/service_definition_constants.rb +14 -0
  99. data/lib/types/service_definition/service_definition_types.rb +158 -0
  100. data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
  101. data/lib/types/struct_definition/struct_definition_types.rb +155 -0
  102. data/lib/types/type_definition/type_definition_constants.rb +14 -0
  103. data/lib/types/type_definition/type_definition_types.rb +240 -0
  104. data/lib/types/value/value_constants.rb +14 -0
  105. data/lib/types/value/value_types.rb +330 -0
  106. data/spec/{gen-rb/base → base}/base_service.rb +2 -2
  107. data/spec/{gen-rb/base → base}/base_service_constants.rb +1 -1
  108. data/spec/{gen-rb/base → base}/base_service_types.rb +1 -1
  109. data/spec/base_protocol_spec.rb +79 -71
  110. data/spec/base_transport_spec.rb +155 -117
  111. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  112. data/spec/binary_protocol_spec.rb +16 -8
  113. data/spec/binary_protocol_spec_shared.rb +77 -77
  114. data/spec/bytes_spec.rb +38 -38
  115. data/spec/client_spec.rb +48 -50
  116. data/spec/compact_protocol_spec.rb +59 -46
  117. data/spec/exception_spec.rb +54 -54
  118. data/spec/{gen-rb/extended → extended}/extended_service.rb +2 -2
  119. data/spec/{gen-rb/extended → extended}/extended_service_constants.rb +1 -1
  120. data/spec/{gen-rb/extended → extended}/extended_service_types.rb +1 -1
  121. data/spec/flat_spec.rb +5 -5
  122. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +4 -4
  123. data/spec/gen-rb/flat/referenced_constants.rb +1 -1
  124. data/spec/gen-rb/flat/referenced_types.rb +1 -1
  125. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +1 -1
  126. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +1 -1
  127. data/spec/http_client_spec.rb +96 -43
  128. data/spec/json_protocol_spec.rb +170 -131
  129. data/spec/namespaced_spec.rb +24 -27
  130. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/namespaced_nonblocking_service.rb +4 -4
  131. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_constants.rb +1 -1
  132. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_types.rb +1 -1
  133. data/spec/nonblocking_server_spec.rb +16 -16
  134. data/spec/{gen-rb/nonblocking_service.rb → nonblocking_service.rb} +4 -4
  135. data/spec/{gen-rb/other_namespace → other_namespace}/referenced_constants.rb +1 -1
  136. data/spec/{gen-rb/other_namespace → other_namespace}/referenced_types.rb +1 -1
  137. data/spec/processor_spec.rb +42 -31
  138. data/spec/rack_application_spec.rb +22 -26
  139. data/spec/serializer_spec.rb +20 -20
  140. data/spec/server_socket_spec.rb +27 -22
  141. data/spec/server_spec.rb +91 -51
  142. data/spec/socket_spec.rb +23 -16
  143. data/spec/socket_spec_shared.rb +31 -31
  144. data/spec/spec_helper.rb +1 -1
  145. data/spec/ssl_server_socket_spec.rb +34 -0
  146. data/spec/ssl_socket_spec.rb +78 -0
  147. data/spec/streaming_spec.rb +442 -0
  148. data/spec/struct_nested_containers_spec.rb +24 -24
  149. data/spec/struct_spec.rb +120 -120
  150. data/spec/thin_http_server_spec.rb +71 -28
  151. data/spec/{gen-rb/thrift_spec_constants.rb → thrift_spec_constants.rb} +1 -1
  152. data/spec/{gen-rb/thrift_spec_types.rb → thrift_spec_types.rb} +16 -16
  153. data/spec/types/known/any_spec.rb +2 -2
  154. data/spec/types/known/duration_spec.rb +1 -1
  155. data/spec/types/known/timestamp_spec.rb +1 -1
  156. data/spec/types/value_spec.rb +2 -1
  157. data/spec/types_spec.rb +56 -53
  158. data/spec/union_spec.rb +51 -40
  159. data/spec/unix_socket_spec.rb +43 -34
  160. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +267 -260
  161. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +1481 -1416
  162. data/test/debug_proto/gen-rb/empty_service.rb +31 -27
  163. data/test/debug_proto/gen-rb/inherited.rb +102 -98
  164. data/test/debug_proto/gen-rb/reverse_order_service.rb +112 -108
  165. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +99 -95
  166. data/test/debug_proto/gen-rb/srv.rb +525 -406
  167. metadata +178 -41
@@ -0,0 +1,442 @@
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 'Streaming' do
23
+ # ---------------------------------------------------------------------------
24
+ # Helpers shared across streaming processor and client specs
25
+ # ---------------------------------------------------------------------------
26
+
27
+ # A minimal args class whose instances know their field.
28
+ class StreamArgs
29
+ attr_accessor :value
30
+
31
+ def initialize(value: nil)
32
+ @value = value
33
+ end
34
+
35
+ def read(iprot)
36
+ @value = iprot.read_string
37
+ iprot.read_field_end
38
+ iprot.read_field_stop
39
+ end
40
+
41
+ def write(oprot)
42
+ oprot.write_string(@value.to_s)
43
+ end
44
+ end
45
+
46
+ # A minimal result class that `execute` builds.
47
+ class StreamResult
48
+ attr_accessor :success
49
+
50
+ def write(oprot)
51
+ oprot.write_string(@success.to_s)
52
+ end
53
+ end
54
+
55
+ # Stub middleware that just calls the next handler.
56
+ class NopMiddleware
57
+ def handle_binary(name, args)
58
+ yield args
59
+ end
60
+
61
+ def handle_unary(name, args)
62
+ yield args
63
+ end
64
+
65
+ def handle_outbound_stream(name, args, stream)
66
+ yield args, stream
67
+ end
68
+
69
+ def handle_inbound_stream(name, args, sink)
70
+ yield args, sink
71
+ end
72
+
73
+ def handle_bidi_stream(name, args, sink, stream)
74
+ yield args, sink, stream
75
+ end
76
+ end
77
+
78
+ # A stub handler for outbound (server-push) streaming.
79
+ class OutboundHandler
80
+ attr_reader :received_args, :received_stream
81
+
82
+ def test_stream(args, stream)
83
+ @received_args = args
84
+ @received_stream = stream
85
+ StreamResult.new.tap { |r| r.success = 'ok' }
86
+ end
87
+ end
88
+
89
+ # A stub handler for inbound (client-push) streaming.
90
+ class InboundHandler
91
+ attr_reader :received_args, :received_sink
92
+
93
+ def test_sink(args, sink)
94
+ @received_args = args
95
+ @received_sink = sink
96
+ StreamResult.new.tap { |r| r.success = 'ok' }
97
+ end
98
+ end
99
+
100
+ # A stub handler for bidirectional streaming.
101
+ class BidiHandler
102
+ attr_reader :received_args, :received_sink, :received_stream
103
+
104
+ def test_bidi(args, stream, sink)
105
+ @received_args = args
106
+ @received_stream = stream
107
+ @received_sink = sink
108
+ StreamResult.new.tap { |r| r.success = 'ok' }
109
+ end
110
+ end
111
+
112
+ # Build a minimal info hash for a streaming processor.
113
+ def outbound_info(handler_sym: :test_stream)
114
+ {
115
+ args: [:value],
116
+ args_klass: StreamArgs,
117
+ result_klass: StreamResult,
118
+ void_result: false,
119
+ exceptions: {},
120
+ stream_klass: double('StreamKlass'),
121
+ }
122
+ end
123
+
124
+ def inbound_info
125
+ {
126
+ args: [:value],
127
+ args_klass: StreamArgs,
128
+ result_klass: StreamResult,
129
+ void_result: false,
130
+ exceptions: {},
131
+ sink_klass: double('SinkKlass'),
132
+ }
133
+ end
134
+
135
+ def bidi_info
136
+ {
137
+ args: [:value],
138
+ args_klass: StreamArgs,
139
+ result_klass: StreamResult,
140
+ void_result: false,
141
+ exceptions: {},
142
+ sink_klass: double('SinkKlass'),
143
+ stream_klass: double('StreamKlass'),
144
+ }
145
+ end
146
+
147
+ # ---------------------------------------------------------------------------
148
+ # Thrift::Processor::OutboundStreamProcessor
149
+ # ---------------------------------------------------------------------------
150
+
151
+ describe Thrift::Processor::OutboundStreamProcessor do
152
+ let(:handler) { OutboundHandler.new }
153
+ let(:middleware) { NopMiddleware.new }
154
+ let(:iprot) { double('MockIProt') }
155
+ let(:oprot) { double('MockOProt') }
156
+
157
+ subject do
158
+ described_class.new(
159
+ 'test_stream',
160
+ outbound_info,
161
+ middleware,
162
+ handler
163
+ )
164
+ end
165
+
166
+ it 'initialises with the stream_klass from info' do
167
+ expect(subject.instance_variable_get(:@stream_klass)).not_to be_nil
168
+ end
169
+
170
+ it 'reads args, calls the handler, writes the result, then calls stream.ready' do
171
+ # Set up iprot to return a minimal args read.
172
+ allow(iprot).to receive(:read_string).and_return('hello')
173
+ allow(iprot).to receive(:read_field_end)
174
+ allow(iprot).to receive(:read_field_stop)
175
+ allow(iprot).to receive(:read_message_end)
176
+
177
+ # Set up oprot to accept the REPLY frame.
178
+ allow(oprot).to receive(:write_message_begin)
179
+ allow(oprot).to receive(:write_string)
180
+ allow(oprot).to receive(:write_message_end)
181
+ allow(oprot).to receive(:trans).and_return(double('trans', flush: nil))
182
+
183
+ # Capture the TOutboundStream that the processor creates.
184
+ stream_double = instance_double(
185
+ Thrift::TOutboundStream,
186
+ ready: nil,
187
+ close: nil
188
+ )
189
+
190
+ allow(Thrift::TOutboundStream).to receive(:new).and_return(stream_double)
191
+
192
+ # Simulate immediate closure so the processor doesn't block in #wait.
193
+ allow(subject).to receive(:wait)
194
+
195
+ result = subject.process(1, iprot, oprot)
196
+
197
+ expect(result).to be true
198
+ expect(handler.received_stream).to eq(stream_double)
199
+ expect(stream_double).to have_received(:ready)
200
+ end
201
+ end
202
+
203
+ # ---------------------------------------------------------------------------
204
+ # Thrift::Processor::InboundStreamProcessor
205
+ # ---------------------------------------------------------------------------
206
+
207
+ describe Thrift::Processor::InboundStreamProcessor do
208
+ let(:handler) { InboundHandler.new }
209
+ let(:middleware) { NopMiddleware.new }
210
+ let(:iprot) { double('MockIProt') }
211
+ let(:oprot) { double('MockOProt') }
212
+
213
+ subject do
214
+ described_class.new(
215
+ 'test_sink',
216
+ inbound_info,
217
+ middleware,
218
+ handler
219
+ )
220
+ end
221
+
222
+ it 'initialises with sink_klass from info' do
223
+ expect(subject.instance_variable_get(:@sink_klass)).not_to be_nil
224
+ end
225
+
226
+ it 'reads args, calls the handler, writes the result, then calls sink.ready' do
227
+ allow(iprot).to receive(:read_string).and_return('world')
228
+ allow(iprot).to receive(:read_field_end)
229
+ allow(iprot).to receive(:read_field_stop)
230
+ allow(iprot).to receive(:read_message_end)
231
+
232
+ allow(oprot).to receive(:write_message_begin)
233
+ allow(oprot).to receive(:write_string)
234
+ allow(oprot).to receive(:write_message_end)
235
+ allow(oprot).to receive(:trans).and_return(double('trans', flush: nil))
236
+
237
+ sink_double = instance_double(
238
+ Thrift::TInboundStream,
239
+ ready: nil,
240
+ close: nil
241
+ )
242
+
243
+ allow(Thrift::TInboundStream).to receive(:new).and_return(sink_double)
244
+ allow(subject).to receive(:wait)
245
+
246
+ result = subject.process(1, iprot, oprot)
247
+
248
+ expect(result).to be true
249
+ expect(handler.received_sink).to eq(sink_double)
250
+ expect(sink_double).to have_received(:ready)
251
+ end
252
+ end
253
+
254
+ # ---------------------------------------------------------------------------
255
+ # Thrift::Processor::BidiStreamProcessor
256
+ # ---------------------------------------------------------------------------
257
+
258
+ describe Thrift::Processor::BidiStreamProcessor do
259
+ let(:handler) { BidiHandler.new }
260
+ let(:middleware) { NopMiddleware.new }
261
+ let(:iprot) { double('MockIProt') }
262
+ let(:oprot) { double('MockOProt') }
263
+
264
+ subject do
265
+ described_class.new(
266
+ 'test_bidi',
267
+ bidi_info,
268
+ middleware,
269
+ handler
270
+ )
271
+ end
272
+
273
+ it 'initialises with both sink_klass and stream_klass from info' do
274
+ expect(subject.instance_variable_get(:@sink_klass)).not_to be_nil
275
+ expect(subject.instance_variable_get(:@stream_klass)).not_to be_nil
276
+ end
277
+
278
+ it 'reads args, calls the handler with sink and stream, writes result, calls bidi_stream.ready' do
279
+ allow(iprot).to receive(:read_string).and_return('bidi')
280
+ allow(iprot).to receive(:read_field_end)
281
+ allow(iprot).to receive(:read_field_stop)
282
+ allow(iprot).to receive(:read_message_end)
283
+
284
+ allow(oprot).to receive(:write_message_begin)
285
+ allow(oprot).to receive(:write_string)
286
+ allow(oprot).to receive(:write_message_end)
287
+ allow(oprot).to receive(:trans).and_return(double('trans', flush: nil))
288
+
289
+ bidi_double = instance_double(
290
+ Thrift::TBidiStream,
291
+ ready: nil,
292
+ close: nil
293
+ )
294
+
295
+ allow(Thrift::TBidiStream).to receive(:new).and_return(bidi_double)
296
+ allow(Thrift::TBidiInboundStream).to receive(:new).with(bidi_double).and_call_original
297
+ allow(Thrift::TBidiOutboundStream).to receive(:new).with(bidi_double).and_call_original
298
+ allow(subject).to receive(:wait)
299
+
300
+ result = subject.process(1, iprot, oprot)
301
+
302
+ expect(result).to be true
303
+ expect(handler.received_stream).to be_a(Thrift::TBidiOutboundStream)
304
+ expect(handler.received_sink).to be_a(Thrift::TBidiInboundStream)
305
+ expect(bidi_double).to have_received(:ready)
306
+ end
307
+ end
308
+
309
+ # ---------------------------------------------------------------------------
310
+ # Thrift::BaseClient streaming methods
311
+ # ---------------------------------------------------------------------------
312
+
313
+ describe Thrift::BaseClient do
314
+ class StreamingClientSpec < Thrift::BaseClient; end
315
+
316
+ let(:mock_trans) { double('MockTransport', open?: true, flush: nil) }
317
+ let(:oprot) do
318
+ double('MockOProt').tap do |p|
319
+ allow(p).to receive(:trans).and_return(mock_trans)
320
+ end
321
+ end
322
+ let(:iprot) { double('MockIProt') }
323
+
324
+ let(:client) { StreamingClientSpec.new(iprot, oprot) }
325
+
326
+ # Stub the rpc_call internals so tests only concern themselves with the
327
+ # stream objects, not protocol-level details.
328
+ def stub_rpc_call(client, method_name, resp_klass)
329
+ allow(oprot).to receive(:write_message_begin)
330
+ allow(oprot).to receive(:write_message_end)
331
+
332
+ result_obj = resp_klass.new
333
+
334
+ allow(iprot).to receive(:read_message_begin).and_return(
335
+ [method_name, Thrift::MessageTypes::REPLY, client.instance_variable_get(:@seqid) + 1]
336
+ )
337
+ allow(iprot).to receive(:read_message_end)
338
+ allow(result_obj).to receive(:read)
339
+
340
+ result_obj
341
+ end
342
+
343
+ describe '#stream_client (outbound from client perspective)' do
344
+ it 'returns [resp, TOutboundStream] and marks the client not ready' do
345
+ resp_klass = double('RespKlass')
346
+ resp_obj = double('resp_obj')
347
+ allow(resp_klass).to receive(:new).and_return(resp_obj)
348
+ allow(resp_obj).to receive(:read)
349
+ allow(resp_obj).to receive(:write)
350
+ allow(oprot).to receive(:write_message_begin)
351
+ allow(oprot).to receive(:write_message_end)
352
+ allow(iprot).to receive(:read_message_begin).and_return(
353
+ ['test', Thrift::MessageTypes::REPLY, 1]
354
+ )
355
+ allow(iprot).to receive(:read_message_end)
356
+
357
+ sink_klass = double('SinkKlass')
358
+ stream_double = instance_double(Thrift::TOutboundStream, ready: nil)
359
+
360
+ allow(Thrift::TOutboundStream).to receive(:new).and_return(stream_double)
361
+
362
+ resp, stream = client.stream_client('test', double('req', write: nil), resp_klass, sink_klass)
363
+
364
+ expect(stream).to eq(stream_double)
365
+ expect(stream_double).to have_received(:ready)
366
+ expect(client.instance_variable_get(:@ready)).to be false
367
+ end
368
+ end
369
+
370
+ describe '#stream_server (inbound to client perspective)' do
371
+ it 'returns [resp, TInboundStream] and marks the client not ready' do
372
+ resp_klass = double('RespKlass')
373
+ resp_obj = double('resp_obj')
374
+ allow(resp_klass).to receive(:new).and_return(resp_obj)
375
+ allow(resp_obj).to receive(:read)
376
+ allow(resp_obj).to receive(:write)
377
+ allow(oprot).to receive(:write_message_begin)
378
+ allow(oprot).to receive(:write_message_end)
379
+ allow(iprot).to receive(:read_message_begin).and_return(
380
+ ['test', Thrift::MessageTypes::REPLY, 1]
381
+ )
382
+ allow(iprot).to receive(:read_message_end)
383
+
384
+ sink_klass = double('SinkKlass')
385
+ stream_double = instance_double(Thrift::TInboundStream, ready: nil)
386
+
387
+ allow(Thrift::TInboundStream).to receive(:new).and_return(stream_double)
388
+
389
+ resp, stream = client.stream_server('test', double('req', write: nil), resp_klass, sink_klass)
390
+
391
+ expect(stream).to eq(stream_double)
392
+ expect(stream_double).to have_received(:ready)
393
+ expect(client.instance_variable_get(:@ready)).to be false
394
+ end
395
+ end
396
+
397
+ describe '#stream_bidi' do
398
+ it 'returns [resp, TBidiInboundStream, TBidiOutboundStream] and marks the client not ready' do
399
+ resp_klass = double('RespKlass')
400
+ resp_obj = double('resp_obj')
401
+ allow(resp_klass).to receive(:new).and_return(resp_obj)
402
+ allow(resp_obj).to receive(:read)
403
+ allow(resp_obj).to receive(:write)
404
+ allow(oprot).to receive(:write_message_begin)
405
+ allow(oprot).to receive(:write_message_end)
406
+ allow(iprot).to receive(:read_message_begin).and_return(
407
+ ['test', Thrift::MessageTypes::REPLY, 1]
408
+ )
409
+ allow(iprot).to receive(:read_message_end)
410
+
411
+ stream_klass = double('StreamKlass')
412
+ sink_klass = double('SinkKlass')
413
+ bidi_double = instance_double(Thrift::TBidiStream, ready: nil)
414
+
415
+ allow(Thrift::TBidiStream).to receive(:new).and_return(bidi_double)
416
+
417
+ resp, inbound, outbound = client.stream_bidi(
418
+ 'test',
419
+ double('req', write: nil),
420
+ resp_klass,
421
+ stream_klass,
422
+ sink_klass
423
+ )
424
+
425
+ expect(inbound).to be_a(Thrift::TBidiInboundStream)
426
+ expect(outbound).to be_a(Thrift::TBidiOutboundStream)
427
+ expect(bidi_double).to have_received(:ready)
428
+ expect(client.instance_variable_get(:@ready)).to be false
429
+ end
430
+ end
431
+
432
+ describe 'finish_call' do
433
+ it 'sets @ready back to true and signals the condition variable' do
434
+ # Directly mark the client as not ready (as stream_call would do).
435
+ client.instance_variable_set(:@ready, false)
436
+ client.send(:finish_call)
437
+
438
+ expect(client.instance_variable_get(:@ready)).to be true
439
+ end
440
+ end
441
+ end
442
+ end
@@ -39,9 +39,9 @@ describe 'StructNestedContainers' do
39
39
  thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ]
40
40
  thrift_struct.validate
41
41
  end
42
- a.should == b
42
+ expect(a).to eq(b)
43
43
  b.value.push [3, 4, 5]
44
- a.should_not == b
44
+ expect(a).not_to eq(b)
45
45
  end
46
46
  end
47
47
 
@@ -52,9 +52,9 @@ describe 'StructNestedContainers' do
52
52
  thrift_struct.value = [ [1, 2, 3], [2, 3, 4] ].to_set
53
53
  thrift_struct.validate
54
54
  end
55
- a.should == b
55
+ expect(a).to eq(b)
56
56
  b.value.add [3, 4, 5]
57
- a.should_not == b
57
+ expect(a).not_to eq(b)
58
58
  end
59
59
  end
60
60
 
@@ -65,9 +65,9 @@ describe 'StructNestedContainers' do
65
65
  thrift_struct.value = { [1, 2, 3] => 1, [2, 3, 4] => 2 }
66
66
  thrift_struct.validate
67
67
  end
68
- a.should == b
68
+ expect(a).to eq(b)
69
69
  b.value[[3, 4, 5]] = 3
70
- a.should_not == b
70
+ expect(a).not_to eq(b)
71
71
  end
72
72
  end
73
73
 
@@ -78,9 +78,9 @@ describe 'StructNestedContainers' do
78
78
  thrift_struct.value = { 1 => [1, 2, 3], 2 => [2, 3, 4] }
79
79
  thrift_struct.validate
80
80
  end
81
- a.should == b
81
+ expect(a).to eq(b)
82
82
  b.value[3] = [3, 4, 5]
83
- a.should_not == b
83
+ expect(a).not_to eq(b)
84
84
  end
85
85
  end
86
86
 
@@ -91,9 +91,9 @@ describe 'StructNestedContainers' do
91
91
  thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ]
92
92
  thrift_struct.validate
93
93
  end
94
- a.should == b
94
+ expect(a).to eq(b)
95
95
  b.value.push([3, 4, 5].to_set)
96
- a.should_not == b
96
+ expect(a).not_to eq(b)
97
97
  end
98
98
  end
99
99
 
@@ -104,9 +104,9 @@ describe 'StructNestedContainers' do
104
104
  thrift_struct.value = [ [1, 2, 3].to_set, [2, 3, 4].to_set ].to_set
105
105
  thrift_struct.validate
106
106
  end
107
- a.should == b
107
+ expect(a).to eq(b)
108
108
  b.value.add([3, 4, 5].to_set)
109
- a.should_not == b
109
+ expect(a).not_to eq(b)
110
110
  end
111
111
  end
112
112
 
@@ -117,9 +117,9 @@ describe 'StructNestedContainers' do
117
117
  thrift_struct.value = { [1, 2, 3].to_set => 1, [2, 3, 4].to_set => 2 }
118
118
  thrift_struct.validate
119
119
  end
120
- a.should == b
120
+ expect(a).to eq(b)
121
121
  b.value[[3, 4, 5].to_set] = 3
122
- a.should_not == b
122
+ expect(a).not_to eq(b)
123
123
  end
124
124
  end
125
125
 
@@ -130,9 +130,9 @@ describe 'StructNestedContainers' do
130
130
  thrift_struct.value = { 1 => [1, 2, 3].to_set, 2 => [2, 3, 4].to_set }
131
131
  thrift_struct.validate
132
132
  end
133
- a.should == b
133
+ expect(a).to eq(b)
134
134
  b.value[3] = [3, 4, 5].to_set
135
- a.should_not == b
135
+ expect(a).not_to eq(b)
136
136
  end
137
137
  end
138
138
 
@@ -143,9 +143,9 @@ describe 'StructNestedContainers' do
143
143
  thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ]
144
144
  thrift_struct.validate
145
145
  end
146
- a.should == b
146
+ expect(a).to eq(b)
147
147
  b.value.push({ 3 => 4, 5 => 6 })
148
- a.should_not == b
148
+ expect(a).not_to eq(b)
149
149
  end
150
150
  end
151
151
 
@@ -156,9 +156,9 @@ describe 'StructNestedContainers' do
156
156
  thrift_struct.value = [ {1 => 2, 3 => 4}, {2 => 3, 4 => 5} ].to_set
157
157
  thrift_struct.validate
158
158
  end
159
- a.should == b
159
+ expect(a).to eq(b)
160
160
  b.value.add({ 3 => 4, 5 => 6 })
161
- a.should_not == b
161
+ expect(a).not_to eq(b)
162
162
  end
163
163
  end
164
164
 
@@ -169,9 +169,9 @@ describe 'StructNestedContainers' do
169
169
  thrift_struct.value = { { 1 => 2, 3 => 4} => 1, {2 => 3, 4 => 5} => 2 }
170
170
  thrift_struct.validate
171
171
  end
172
- a.should == b
172
+ expect(a).to eq(b)
173
173
  b.value[{3 => 4, 5 => 6}] = 3
174
- a.should_not == b
174
+ expect(a).not_to eq(b)
175
175
  end
176
176
  end
177
177
 
@@ -182,9 +182,9 @@ describe 'StructNestedContainers' do
182
182
  thrift_struct.value = { 1 => { 1 => 2, 3 => 4}, 2 => {2 => 3, 4 => 5} }
183
183
  thrift_struct.validate
184
184
  end
185
- a.should == b
185
+ expect(a).to eq(b)
186
186
  b.value[3] = { 3 => 4, 5 => 6 }
187
- a.should_not == b
187
+ expect(a).not_to eq(b)
188
188
  end
189
189
  end
190
190
  end