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.
- checksums.yaml +4 -4
- data/benchmark/{gen-rb/benchmark_constants.rb → benchmark_constants.rb} +1 -1
- data/benchmark/{gen-rb/benchmark_service.rb → benchmark_service.rb} +2 -2
- data/benchmark/{gen-rb/benchmark_types.rb → benchmark_types.rb} +1 -1
- data/ext/struct.c +5 -1
- data/lib/thrift/base_stream.rb +85 -0
- data/lib/thrift/bidi_stream.rb +183 -0
- data/lib/thrift/client.rb +84 -17
- data/lib/thrift/inbound_stream.rb +72 -0
- data/lib/thrift/middleware.rb +42 -0
- data/lib/thrift/outbound_stream.rb +52 -0
- data/lib/thrift/processor.rb +287 -47
- data/lib/thrift/protocol/base_protocol.rb +35 -33
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +8 -0
- data/lib/thrift/protocol/json_protocol.rb +21 -4
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/nonblocking_server.rb +5 -4
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +4 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +5 -0
- data/lib/thrift/transport/socket.rb +21 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
- data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
- data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
- data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
- data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
- data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
- data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
- data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
- data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
- data/lib/thrift/types/core/core_constants.rb +15 -0
- data/lib/thrift/types/core/core_types.rb +58 -0
- data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
- data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
- data/lib/thrift/types/known/any/any_constants.rb +1 -1
- data/lib/thrift/types/known/any/any_types.rb +2 -2
- data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
- data/lib/thrift/types/known/duration/duration_types.rb +2 -2
- data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
- data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
- data/lib/thrift/types/plugin/plugin.rb +139 -0
- data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
- data/lib/thrift/types/plugin/plugin_types.rb +106 -0
- data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
- data/lib/thrift/types/program_definition/program_definition_types.rb +137 -0
- data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
- data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
- data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
- data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
- data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
- data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
- data/lib/thrift/types/value/value_constants.rb +1 -1
- data/lib/thrift/types/value/value_types.rb +50 -51
- data/lib/thrift/types.rb +11 -3
- data/lib/thrift/union.rb +3 -6
- data/lib/thrift.rb +6 -0
- data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
- data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
- data/lib/types/annotation/naming/naming_constants.rb +16 -0
- data/lib/types/annotation/naming/naming_types.rb +57 -0
- data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
- data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
- data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
- data/lib/types/constant_definition/constant_definition_types.rb +290 -0
- data/lib/types/core/core_constants.rb +14 -0
- data/lib/types/core/core_types.rb +56 -0
- data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
- data/lib/types/enum_definition/enum_definition_types.rb +104 -0
- data/lib/types/known/any/any_constants.rb +16 -0
- data/lib/types/known/any/any_types.rb +59 -0
- data/lib/types/known/duration/duration_constants.rb +16 -0
- data/lib/types/known/duration/duration_types.rb +59 -0
- data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
- data/lib/types/known/timestamp/timestamp_types.rb +59 -0
- data/lib/types/plugin/plugin.rb +137 -0
- data/lib/types/plugin/plugin_constants.rb +14 -0
- data/lib/types/plugin/plugin_types.rb +104 -0
- data/lib/types/program_definition/program_definition_constants.rb +14 -0
- data/lib/types/program_definition/program_definition_types.rb +135 -0
- data/lib/types/service_definition/service_definition_constants.rb +14 -0
- data/lib/types/service_definition/service_definition_types.rb +158 -0
- data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
- data/lib/types/struct_definition/struct_definition_types.rb +155 -0
- data/lib/types/type_definition/type_definition_constants.rb +14 -0
- data/lib/types/type_definition/type_definition_types.rb +240 -0
- data/lib/types/value/value_constants.rb +14 -0
- data/lib/types/value/value_types.rb +330 -0
- data/spec/{gen-rb/base → base}/base_service.rb +2 -2
- data/spec/{gen-rb/base → base}/base_service_constants.rb +1 -1
- data/spec/{gen-rb/base → base}/base_service_types.rb +1 -1
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +77 -77
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +48 -50
- data/spec/compact_protocol_spec.rb +59 -46
- data/spec/exception_spec.rb +54 -54
- data/spec/{gen-rb/extended → extended}/extended_service.rb +2 -2
- data/spec/{gen-rb/extended → extended}/extended_service_constants.rb +1 -1
- data/spec/{gen-rb/extended → extended}/extended_service_types.rb +1 -1
- data/spec/flat_spec.rb +5 -5
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +4 -4
- data/spec/gen-rb/flat/referenced_constants.rb +1 -1
- data/spec/gen-rb/flat/referenced_types.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +1 -1
- data/spec/http_client_spec.rb +96 -43
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +24 -27
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/namespaced_nonblocking_service.rb +4 -4
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_types.rb +1 -1
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/{gen-rb/nonblocking_service.rb → nonblocking_service.rb} +4 -4
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_constants.rb +1 -1
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_types.rb +1 -1
- data/spec/processor_spec.rb +42 -31
- data/spec/rack_application_spec.rb +22 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/spec_helper.rb +1 -1
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/streaming_spec.rb +442 -0
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +71 -28
- data/spec/{gen-rb/thrift_spec_constants.rb → thrift_spec_constants.rb} +1 -1
- data/spec/{gen-rb/thrift_spec_types.rb → thrift_spec_types.rb} +16 -16
- data/spec/types/known/any_spec.rb +2 -2
- data/spec/types/known/duration_spec.rb +1 -1
- data/spec/types/known/timestamp_spec.rb +1 -1
- data/spec/types/value_spec.rb +2 -1
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +51 -40
- data/spec/unix_socket_spec.rb +43 -34
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +267 -260
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +1481 -1416
- data/test/debug_proto/gen-rb/empty_service.rb +31 -27
- data/test/debug_proto/gen-rb/inherited.rb +102 -98
- data/test/debug_proto/gen-rb/reverse_order_service.rb +112 -108
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +99 -95
- data/test/debug_proto/gen-rb/srv.rb +525 -406
- 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.
|
|
42
|
+
expect(a).to eq(b)
|
|
43
43
|
b.value.push [3, 4, 5]
|
|
44
|
-
a.
|
|
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.
|
|
55
|
+
expect(a).to eq(b)
|
|
56
56
|
b.value.add [3, 4, 5]
|
|
57
|
-
a.
|
|
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.
|
|
68
|
+
expect(a).to eq(b)
|
|
69
69
|
b.value[[3, 4, 5]] = 3
|
|
70
|
-
a.
|
|
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.
|
|
81
|
+
expect(a).to eq(b)
|
|
82
82
|
b.value[3] = [3, 4, 5]
|
|
83
|
-
a.
|
|
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.
|
|
94
|
+
expect(a).to eq(b)
|
|
95
95
|
b.value.push([3, 4, 5].to_set)
|
|
96
|
-
a.
|
|
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.
|
|
107
|
+
expect(a).to eq(b)
|
|
108
108
|
b.value.add([3, 4, 5].to_set)
|
|
109
|
-
a.
|
|
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.
|
|
120
|
+
expect(a).to eq(b)
|
|
121
121
|
b.value[[3, 4, 5].to_set] = 3
|
|
122
|
-
a.
|
|
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.
|
|
133
|
+
expect(a).to eq(b)
|
|
134
134
|
b.value[3] = [3, 4, 5].to_set
|
|
135
|
-
a.
|
|
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.
|
|
146
|
+
expect(a).to eq(b)
|
|
147
147
|
b.value.push({ 3 => 4, 5 => 6 })
|
|
148
|
-
a.
|
|
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.
|
|
159
|
+
expect(a).to eq(b)
|
|
160
160
|
b.value.add({ 3 => 4, 5 => 6 })
|
|
161
|
-
a.
|
|
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.
|
|
172
|
+
expect(a).to eq(b)
|
|
173
173
|
b.value[{3 => 4, 5 => 6}] = 3
|
|
174
|
-
a.
|
|
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.
|
|
185
|
+
expect(a).to eq(b)
|
|
186
186
|
b.value[3] = { 3 => 4, 5 => 6 }
|
|
187
|
-
a.
|
|
187
|
+
expect(a).not_to eq(b)
|
|
188
188
|
end
|
|
189
189
|
end
|
|
190
190
|
end
|