grpc 0.13.0.pre1.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/etc/roots.pem +5114 -0
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
- data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/src/ruby/bin/grpc_ruby_interop_client +33 -0
- data/src/ruby/bin/grpc_ruby_interop_server +33 -0
- data/src/ruby/bin/interop/interop_client.rb +51 -0
- data/src/ruby/bin/interop/interop_server.rb +50 -0
- data/src/ruby/bin/math.rb +32 -0
- data/src/ruby/bin/math_client.rb +147 -0
- data/src/ruby/bin/math_server.rb +206 -0
- data/src/ruby/bin/math_services.rb +27 -0
- data/src/ruby/bin/noproto_client.rb +108 -0
- data/src/ruby/bin/noproto_server.rb +112 -0
- data/src/ruby/ext/grpc/extconf.rb +129 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +70 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +47 -0
- data/src/ruby/ext/grpc/rb_call.c +908 -0
- data/src/ruby/ext/grpc/rb_call.h +66 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +319 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
- data/src/ruby/ext/grpc/rb_channel.c +432 -0
- data/src/ruby/ext/grpc/rb_channel.h +47 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +169 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +183 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +55 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
- data/src/ruby/ext/grpc/rb_grpc.c +336 -0
- data/src/ruby/ext/grpc/rb_grpc.h +85 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +560 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +843 -0
- data/src/ruby/ext/grpc/rb_loader.c +72 -0
- data/src/ruby/ext/grpc/rb_loader.h +40 -0
- data/src/ruby/ext/grpc/rb_server.c +400 -0
- data/src/ruby/ext/grpc/rb_server.h +47 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +284 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
- data/src/ruby/lib/grpc.rb +44 -0
- data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
- data/src/ruby/lib/grpc/errors.rb +62 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +488 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +218 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +471 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +147 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +504 -0
- data/src/ruby/lib/grpc/generic/service.rb +234 -0
- data/src/ruby/lib/grpc/grpc.rb +34 -0
- data/src/ruby/lib/grpc/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/logconfig.rb +59 -0
- data/src/ruby/lib/grpc/notifier.rb +60 -0
- data/src/ruby/lib/grpc/version.rb +33 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1alpha/health.rb +29 -0
- data/src/ruby/pb/grpc/health/v1alpha/health_services.rb +28 -0
- data/src/ruby/pb/test/client.rb +469 -0
- data/src/ruby/pb/test/proto/empty.rb +15 -0
- data/src/ruby/pb/test/proto/messages.rb +80 -0
- data/src/ruby/pb/test/proto/test.rb +14 -0
- data/src/ruby/pb/test/proto/test_services.rb +64 -0
- data/src/ruby/pb/test/server.rb +253 -0
- data/src/ruby/spec/call_credentials_spec.rb +57 -0
- data/src/ruby/spec/call_spec.rb +163 -0
- data/src/ruby/spec/channel_credentials_spec.rb +97 -0
- data/src/ruby/spec/channel_spec.rb +177 -0
- data/src/ruby/spec/client_server_spec.rb +475 -0
- data/src/ruby/spec/completion_queue_spec.rb +42 -0
- data/src/ruby/spec/generic/active_call_spec.rb +373 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +476 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +331 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +138 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +576 -0
- data/src/ruby/spec/generic/service_spec.rb +345 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +232 -0
- data/src/ruby/spec/server_credentials_spec.rb +94 -0
- data/src/ruby/spec/server_spec.rb +209 -0
- data/src/ruby/spec/spec_helper.rb +69 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +15 -0
- data/src/ruby/spec/testdata/server1.key +16 -0
- data/src/ruby/spec/testdata/server1.pem +16 -0
- data/src/ruby/spec/time_consts_spec.rb +89 -0
- metadata +320 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
# Copyright 2015, Google Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are
|
6
|
+
# met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above
|
11
|
+
# copyright notice, this list of conditions and the following disclaimer
|
12
|
+
# in the documentation and/or other materials provided with the
|
13
|
+
# distribution.
|
14
|
+
# * Neither the name of Google Inc. nor the names of its
|
15
|
+
# contributors may be used to endorse or promote products derived from
|
16
|
+
# this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
require 'grpc'
|
31
|
+
require 'grpc/generic/rpc_desc'
|
32
|
+
require 'grpc/generic/service'
|
33
|
+
|
34
|
+
# A test message that encodes/decodes using marshal/marshal.
|
35
|
+
class GoodMsg
|
36
|
+
def self.marshal(_o)
|
37
|
+
''
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.unmarshal(_o)
|
41
|
+
GoodMsg.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# A test message that encodes/decodes using encode/decode.
|
46
|
+
class EncodeDecodeMsg
|
47
|
+
def self.encode(_o)
|
48
|
+
''
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.decode(_o)
|
52
|
+
GoodMsg.new
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
GenericService = GRPC::GenericService
|
57
|
+
Dsl = GenericService::Dsl
|
58
|
+
|
59
|
+
describe Dsl do
|
60
|
+
it 'can be included in new classes' do
|
61
|
+
blk = proc { Class.new { include Dsl } }
|
62
|
+
expect(&blk).to_not raise_error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe GenericService do
|
67
|
+
context '#underscore' do
|
68
|
+
it 'should convert CamelCase to underscore separated' do
|
69
|
+
expect(GenericService.underscore('AnRPC')).to eq('an_rpc')
|
70
|
+
expect(GenericService.underscore('AMethod')).to eq('a_method')
|
71
|
+
expect(GenericService.underscore('PrintHTML')).to eq('print_html')
|
72
|
+
expect(GenericService.underscore('SeeHTMLBooks')).to eq('see_html_books')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'including it' do
|
77
|
+
it 'adds a class method, rpc' do
|
78
|
+
c = Class.new do
|
79
|
+
include GenericService
|
80
|
+
end
|
81
|
+
expect(c.methods).to include(:rpc)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'adds rpc descs using the added class method, #rpc' do
|
85
|
+
c = Class.new do
|
86
|
+
include GenericService
|
87
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
88
|
+
end
|
89
|
+
|
90
|
+
expect(c.rpc_descs).to include(:AnRpc)
|
91
|
+
expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'give subclasses access to #rpc_descs' do
|
95
|
+
base = Class.new do
|
96
|
+
include GenericService
|
97
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
98
|
+
end
|
99
|
+
c = Class.new(base) do
|
100
|
+
end
|
101
|
+
expect(c.rpc_descs).to include(:AnRpc)
|
102
|
+
expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'adds a default service name' do
|
106
|
+
c = Class.new do
|
107
|
+
include GenericService
|
108
|
+
end
|
109
|
+
expect(c.service_name).to eq('GenericService')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'adds a default service name to subclasses' do
|
113
|
+
base = Class.new do
|
114
|
+
include GenericService
|
115
|
+
end
|
116
|
+
c = Class.new(base) do
|
117
|
+
end
|
118
|
+
expect(c.service_name).to eq('GenericService')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'adds the specified service name' do
|
122
|
+
c = Class.new do
|
123
|
+
include GenericService
|
124
|
+
self.service_name = 'test.service.TestService'
|
125
|
+
end
|
126
|
+
expect(c.service_name).to eq('test.service.TestService')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'adds the specified service name to subclasses' do
|
130
|
+
base = Class.new do
|
131
|
+
include GenericService
|
132
|
+
self.service_name = 'test.service.TestService'
|
133
|
+
end
|
134
|
+
c = Class.new(base) do
|
135
|
+
end
|
136
|
+
expect(c.service_name).to eq('test.service.TestService')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#include' do
|
141
|
+
it 'raises if #rpc is missing an arg' do
|
142
|
+
blk = proc do
|
143
|
+
Class.new do
|
144
|
+
include GenericService
|
145
|
+
rpc :AnRpc, GoodMsg
|
146
|
+
end
|
147
|
+
end
|
148
|
+
expect(&blk).to raise_error ArgumentError
|
149
|
+
|
150
|
+
blk = proc do
|
151
|
+
Class.new do
|
152
|
+
include GenericService
|
153
|
+
rpc :AnRpc
|
154
|
+
end
|
155
|
+
end
|
156
|
+
expect(&blk).to raise_error ArgumentError
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'when #rpc args are incorrect' do
|
160
|
+
it 'raises if an arg does not have the marshal or unmarshal methods' do
|
161
|
+
blk = proc do
|
162
|
+
Class.new do
|
163
|
+
include GenericService
|
164
|
+
rpc :AnRpc, GoodMsg, Object
|
165
|
+
end
|
166
|
+
end
|
167
|
+
expect(&blk).to raise_error ArgumentError
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'raises if a type arg only has the marshal method' do
|
171
|
+
# a bad message type with only a marshal method
|
172
|
+
class OnlyMarshal
|
173
|
+
def marshal(o)
|
174
|
+
o
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
blk = proc do
|
179
|
+
Class.new do
|
180
|
+
include GenericService
|
181
|
+
rpc :AnRpc, OnlyMarshal, GoodMsg
|
182
|
+
end
|
183
|
+
end
|
184
|
+
expect(&blk).to raise_error ArgumentError
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'raises if a type arg only has the unmarshal method' do
|
188
|
+
# a bad message type with only an unmarshal method
|
189
|
+
class OnlyUnmarshal
|
190
|
+
def self.ummarshal(o)
|
191
|
+
o
|
192
|
+
end
|
193
|
+
end
|
194
|
+
blk = proc do
|
195
|
+
Class.new do
|
196
|
+
include GenericService
|
197
|
+
rpc :AnRpc, GoodMsg, OnlyUnmarshal
|
198
|
+
end
|
199
|
+
end
|
200
|
+
expect(&blk).to raise_error ArgumentError
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'is ok for services that expect the default {un,}marshal methods' do
|
205
|
+
blk = proc do
|
206
|
+
Class.new do
|
207
|
+
include GenericService
|
208
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
209
|
+
end
|
210
|
+
end
|
211
|
+
expect(&blk).not_to raise_error
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'is ok for services that override the default {un,}marshal methods' do
|
215
|
+
blk = proc do
|
216
|
+
Class.new do
|
217
|
+
include GenericService
|
218
|
+
self.marshal_class_method = :encode
|
219
|
+
self.unmarshal_class_method = :decode
|
220
|
+
rpc :AnRpc, EncodeDecodeMsg, EncodeDecodeMsg
|
221
|
+
end
|
222
|
+
end
|
223
|
+
expect(&blk).not_to raise_error
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#rpc_stub_class' do
|
228
|
+
it 'generates a client class that defines any of the rpc methods' do
|
229
|
+
s = Class.new do
|
230
|
+
include GenericService
|
231
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
232
|
+
rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
|
233
|
+
rpc :AClientStreamer, stream(GoodMsg), GoodMsg
|
234
|
+
rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
|
235
|
+
end
|
236
|
+
client_class = s.rpc_stub_class
|
237
|
+
expect(client_class.instance_methods).to include(:an_rpc)
|
238
|
+
expect(client_class.instance_methods).to include(:a_server_streamer)
|
239
|
+
expect(client_class.instance_methods).to include(:a_client_streamer)
|
240
|
+
expect(client_class.instance_methods).to include(:a_bidi_streamer)
|
241
|
+
end
|
242
|
+
|
243
|
+
describe 'the generated instances' do
|
244
|
+
it 'can be instanciated with just a hostname and credentials' do
|
245
|
+
s = Class.new do
|
246
|
+
include GenericService
|
247
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
248
|
+
rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
|
249
|
+
rpc :AClientStreamer, stream(GoodMsg), GoodMsg
|
250
|
+
rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
|
251
|
+
end
|
252
|
+
client_class = s.rpc_stub_class
|
253
|
+
blk = proc do
|
254
|
+
client_class.new('fakehostname', :this_channel_is_insecure)
|
255
|
+
end
|
256
|
+
expect(&blk).not_to raise_error
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'has the methods defined in the service' do
|
260
|
+
s = Class.new do
|
261
|
+
include GenericService
|
262
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
263
|
+
rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
|
264
|
+
rpc :AClientStreamer, stream(GoodMsg), GoodMsg
|
265
|
+
rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
|
266
|
+
end
|
267
|
+
client_class = s.rpc_stub_class
|
268
|
+
o = client_class.new('fakehostname', :this_channel_is_insecure)
|
269
|
+
expect(o.methods).to include(:an_rpc)
|
270
|
+
expect(o.methods).to include(:a_bidi_streamer)
|
271
|
+
expect(o.methods).to include(:a_client_streamer)
|
272
|
+
expect(o.methods).to include(:a_bidi_streamer)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe '#assert_rpc_descs_have_methods' do
|
278
|
+
it 'fails if there is no instance method for an rpc descriptor' do
|
279
|
+
c1 = Class.new do
|
280
|
+
include GenericService
|
281
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
282
|
+
end
|
283
|
+
expect { c1.assert_rpc_descs_have_methods }.to raise_error
|
284
|
+
|
285
|
+
c2 = Class.new do
|
286
|
+
include GenericService
|
287
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
288
|
+
rpc :AnotherRpc, GoodMsg, GoodMsg
|
289
|
+
|
290
|
+
def an_rpc
|
291
|
+
end
|
292
|
+
end
|
293
|
+
expect { c2.assert_rpc_descs_have_methods }.to raise_error
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'passes if there are corresponding methods for each descriptor' do
|
297
|
+
c = Class.new do
|
298
|
+
include GenericService
|
299
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
300
|
+
rpc :AServerStreamer, GoodMsg, stream(GoodMsg)
|
301
|
+
rpc :AClientStreamer, stream(GoodMsg), GoodMsg
|
302
|
+
rpc :ABidiStreamer, stream(GoodMsg), stream(GoodMsg)
|
303
|
+
|
304
|
+
def an_rpc(_req, _call)
|
305
|
+
end
|
306
|
+
|
307
|
+
def a_server_streamer(_req, _call)
|
308
|
+
end
|
309
|
+
|
310
|
+
def a_client_streamer(_call)
|
311
|
+
end
|
312
|
+
|
313
|
+
def a_bidi_streamer(_call)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
expect { c.assert_rpc_descs_have_methods }.to_not raise_error
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'passes for subclasses of that include GenericService' do
|
320
|
+
base = Class.new do
|
321
|
+
include GenericService
|
322
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
323
|
+
|
324
|
+
def an_rpc(_req, _call)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
c = Class.new(base)
|
328
|
+
expect { c.assert_rpc_descs_have_methods }.to_not raise_error
|
329
|
+
expect(c.include?(GenericService)).to be(true)
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'passes if subclasses define the rpc methods' do
|
333
|
+
base = Class.new do
|
334
|
+
include GenericService
|
335
|
+
rpc :AnRpc, GoodMsg, GoodMsg
|
336
|
+
end
|
337
|
+
c = Class.new(base) do
|
338
|
+
def an_rpc(_req, _call)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
expect { c.assert_rpc_descs_have_methods }.to_not raise_error
|
342
|
+
expect(c.include?(GenericService)).to be(true)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# Copyright 2015-2016, Google Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are
|
6
|
+
# met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above
|
11
|
+
# copyright notice, this list of conditions and the following disclaimer
|
12
|
+
# in the documentation and/or other materials provided with the
|
13
|
+
# distribution.
|
14
|
+
# * Neither the name of Google Inc. nor the names of its
|
15
|
+
# contributors may be used to endorse or promote products derived from
|
16
|
+
# this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
require 'grpc'
|
31
|
+
require 'grpc/health/v1alpha/health'
|
32
|
+
require 'grpc/health/checker'
|
33
|
+
require 'open3'
|
34
|
+
require 'tmpdir'
|
35
|
+
|
36
|
+
def can_run_codegen_check
|
37
|
+
system('which grpc_ruby_plugin') && system('which protoc')
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'Health protobuf code generation' do
|
41
|
+
context 'the health service file used by grpc/health/checker' do
|
42
|
+
if !can_run_codegen_check
|
43
|
+
skip 'protoc || grpc_ruby_plugin missing, cannot verify health code-gen'
|
44
|
+
else
|
45
|
+
it 'should already be loaded indirectly i.e, used by the other specs' do
|
46
|
+
expect(require('grpc/health/v1alpha/health_services')).to be(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should have the same content as created by code generation' do
|
50
|
+
root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
|
51
|
+
pb_dir = File.join(root_dir, 'proto')
|
52
|
+
|
53
|
+
# Get the current content
|
54
|
+
service_path = File.join(root_dir, 'ruby', 'pb', 'grpc',
|
55
|
+
'health', 'v1alpha', 'health_services.rb')
|
56
|
+
want = nil
|
57
|
+
File.open(service_path) { |f| want = f.read }
|
58
|
+
|
59
|
+
# Regenerate it
|
60
|
+
plugin, = Open3.capture2('which', 'grpc_ruby_plugin')
|
61
|
+
plugin = plugin.strip
|
62
|
+
got = nil
|
63
|
+
Dir.mktmpdir do |tmp_dir|
|
64
|
+
gen_out = File.join(tmp_dir, 'grpc', 'health', 'v1alpha',
|
65
|
+
'health_services.rb')
|
66
|
+
pid = spawn(
|
67
|
+
'protoc',
|
68
|
+
'-I.',
|
69
|
+
'grpc/health/v1alpha/health.proto',
|
70
|
+
"--grpc_out=#{tmp_dir}",
|
71
|
+
"--plugin=protoc-gen-grpc=#{plugin}",
|
72
|
+
chdir: pb_dir)
|
73
|
+
Process.wait(pid)
|
74
|
+
File.open(gen_out) { |f| got = f.read }
|
75
|
+
end
|
76
|
+
expect(got).to eq(want)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe Grpc::Health::Checker do
|
83
|
+
StatusCodes = GRPC::Core::StatusCodes
|
84
|
+
ServingStatus = Grpc::Health::V1alpha::HealthCheckResponse::ServingStatus
|
85
|
+
HCResp = Grpc::Health::V1alpha::HealthCheckResponse
|
86
|
+
HCReq = Grpc::Health::V1alpha::HealthCheckRequest
|
87
|
+
success_tests =
|
88
|
+
[
|
89
|
+
{
|
90
|
+
desc: 'neither host or service are specified',
|
91
|
+
host: '',
|
92
|
+
service: ''
|
93
|
+
}, {
|
94
|
+
desc: 'only the host is specified',
|
95
|
+
host: 'test-fake-host',
|
96
|
+
service: ''
|
97
|
+
}, {
|
98
|
+
desc: 'the host and service are specified',
|
99
|
+
host: 'test-fake-host',
|
100
|
+
service: 'fake-service-1'
|
101
|
+
}, {
|
102
|
+
desc: 'only the service is specified',
|
103
|
+
host: '',
|
104
|
+
service: 'fake-service-2'
|
105
|
+
}
|
106
|
+
]
|
107
|
+
|
108
|
+
context 'initialization' do
|
109
|
+
it 'can be constructed with no args' do
|
110
|
+
expect(subject).to_not be(nil)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'method `add_status` and `check`' do
|
115
|
+
success_tests.each do |t|
|
116
|
+
it "should succeed when #{t[:desc]}" do
|
117
|
+
subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
|
118
|
+
got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
|
119
|
+
nil)
|
120
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
121
|
+
expect(got).to eq(want)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'method `check`' do
|
127
|
+
success_tests.each do |t|
|
128
|
+
it "should fail with NOT_FOUND when #{t[:desc]}" do
|
129
|
+
blk = proc do
|
130
|
+
subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
|
131
|
+
end
|
132
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
133
|
+
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'method `clear_status`' do
|
139
|
+
success_tests.each do |t|
|
140
|
+
it "should fail after clearing status when #{t[:desc]}" do
|
141
|
+
subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
|
142
|
+
got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
|
143
|
+
nil)
|
144
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
145
|
+
expect(got).to eq(want)
|
146
|
+
|
147
|
+
subject.clear_status(t[:host], t[:service])
|
148
|
+
blk = proc do
|
149
|
+
subject.check(HCReq.new(host: t[:host], service: t[:service]),
|
150
|
+
nil)
|
151
|
+
end
|
152
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
153
|
+
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'method `clear_all`' do
|
159
|
+
it 'should return NOT_FOUND after being invoked' do
|
160
|
+
success_tests.each do |t|
|
161
|
+
subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
|
162
|
+
got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
|
163
|
+
nil)
|
164
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
165
|
+
expect(got).to eq(want)
|
166
|
+
end
|
167
|
+
|
168
|
+
subject.clear_all
|
169
|
+
|
170
|
+
success_tests.each do |t|
|
171
|
+
blk = proc do
|
172
|
+
subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
|
173
|
+
end
|
174
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
175
|
+
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'running on RpcServer' do
|
181
|
+
RpcServer = GRPC::RpcServer
|
182
|
+
CheckerStub = Grpc::Health::Checker.rpc_stub_class
|
183
|
+
|
184
|
+
before(:each) do
|
185
|
+
@server_queue = GRPC::Core::CompletionQueue.new
|
186
|
+
server_host = '0.0.0.0:0'
|
187
|
+
@server = GRPC::Core::Server.new(@server_queue, nil)
|
188
|
+
server_port = @server.add_http2_port(server_host, :this_port_is_insecure)
|
189
|
+
@host = "localhost:#{server_port}"
|
190
|
+
@ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure)
|
191
|
+
@client_opts = { channel_override: @ch }
|
192
|
+
server_opts = {
|
193
|
+
server_override: @server,
|
194
|
+
completion_queue_override: @server_queue,
|
195
|
+
poll_period: 1
|
196
|
+
}
|
197
|
+
@srv = RpcServer.new(**server_opts)
|
198
|
+
end
|
199
|
+
|
200
|
+
after(:each) do
|
201
|
+
@srv.stop
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should receive the correct status', server: true do
|
205
|
+
@srv.handle(subject)
|
206
|
+
subject.add_status('', '', ServingStatus::NOT_SERVING)
|
207
|
+
t = Thread.new { @srv.run }
|
208
|
+
@srv.wait_till_running
|
209
|
+
|
210
|
+
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
|
211
|
+
got = stub.check(HCReq.new)
|
212
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
213
|
+
expect(got).to eq(want)
|
214
|
+
@srv.stop
|
215
|
+
t.join
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should fail on unknown services', server: true do
|
219
|
+
@srv.handle(subject)
|
220
|
+
t = Thread.new { @srv.run }
|
221
|
+
@srv.wait_till_running
|
222
|
+
blk = proc do
|
223
|
+
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
|
224
|
+
stub.check(HCReq.new(host: 'unknown', service: 'unknown'))
|
225
|
+
end
|
226
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
227
|
+
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
|
228
|
+
@srv.stop
|
229
|
+
t.join
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|