grpc 0.6.1 → 0.9.2
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 +4 -4
- data/.rubocop_todo.yml +3 -3
- data/README.md +41 -39
- data/bin/apis/pubsub_demo.rb +2 -2
- data/bin/interop/interop_client.rb +6 -4
- data/bin/interop/interop_server.rb +7 -4
- data/bin/math.proto +7 -7
- data/bin/math_client.rb +22 -22
- data/bin/math_server.rb +6 -6
- data/bin/noproto_client.rb +4 -4
- data/bin/noproto_server.rb +3 -3
- data/ext/grpc/extconf.rb +20 -5
- data/ext/grpc/rb_byte_buffer.c +5 -4
- data/ext/grpc/rb_byte_buffer.h +2 -1
- data/ext/grpc/rb_call.c +5 -6
- data/ext/grpc/rb_call.h +2 -1
- data/ext/grpc/rb_channel.c +1 -1
- data/ext/grpc/rb_channel.h +2 -1
- data/ext/grpc/rb_channel_args.c +2 -1
- data/ext/grpc/rb_channel_args.h +2 -1
- data/ext/grpc/rb_completion_queue.c +7 -49
- data/ext/grpc/rb_completion_queue.h +4 -3
- data/ext/grpc/rb_credentials.c +1 -1
- data/ext/grpc/rb_credentials.h +2 -1
- data/ext/grpc/rb_grpc.h +2 -1
- data/ext/grpc/rb_server.c +10 -11
- data/ext/grpc/rb_server.h +2 -1
- data/ext/grpc/rb_server_credentials.c +1 -1
- data/ext/grpc/rb_server_credentials.h +2 -1
- data/grpc.gemspec +1 -1
- data/lib/grpc/core/time_consts.rb +1 -1
- data/lib/grpc/generic/active_call.rb +13 -9
- data/lib/grpc/generic/bidi_call.rb +37 -41
- data/lib/grpc/generic/rpc_desc.rb +8 -7
- data/lib/grpc/generic/rpc_server.rb +55 -42
- data/lib/grpc/generic/service.rb +22 -24
- data/lib/grpc/logconfig.rb +4 -1
- data/lib/grpc/version.rb +1 -1
- data/spec/completion_queue_spec.rb +0 -32
- data/spec/generic/rpc_server_pool_spec.rb +2 -2
- data/spec/generic/rpc_server_spec.rb +34 -12
- data/spec/generic/service_spec.rb +9 -9
- metadata +4 -4
data/lib/grpc/generic/service.rb
CHANGED
@@ -30,24 +30,6 @@
|
|
30
30
|
require 'grpc/generic/client_stub'
|
31
31
|
require 'grpc/generic/rpc_desc'
|
32
32
|
|
33
|
-
# Extend String to add a method underscore
|
34
|
-
class String
|
35
|
-
# creates a new string that is the underscore separate version of this one.
|
36
|
-
#
|
37
|
-
# E.g,
|
38
|
-
# PrintHTML -> print_html
|
39
|
-
# AMethod -> a_method
|
40
|
-
# AnRpc -> an_rpc
|
41
|
-
def underscore
|
42
|
-
word = dup
|
43
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
44
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
45
|
-
word.tr!('-', '_')
|
46
|
-
word.downcase!
|
47
|
-
word
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
33
|
# GRPC contains the General RPC module.
|
52
34
|
module GRPC
|
53
35
|
# Provides behaviour used to implement schema-derived service classes.
|
@@ -55,6 +37,22 @@ module GRPC
|
|
55
37
|
# Is intended to be used to support both client and server
|
56
38
|
# IDL-schema-derived servers.
|
57
39
|
module GenericService
|
40
|
+
# creates a new string that is the underscore separate version of s.
|
41
|
+
#
|
42
|
+
# E.g,
|
43
|
+
# PrintHTML -> print_html
|
44
|
+
# AMethod -> a_method
|
45
|
+
# AnRpc -> an_rpc
|
46
|
+
#
|
47
|
+
# @param s [String] the string to be converted.
|
48
|
+
def self.underscore(s)
|
49
|
+
s.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
50
|
+
s.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
51
|
+
s.tr!('-', '_')
|
52
|
+
s.downcase!
|
53
|
+
s
|
54
|
+
end
|
55
|
+
|
58
56
|
# Used to indicate that a name has already been specified
|
59
57
|
class DuplicateRpcName < StandardError
|
60
58
|
def initialize(name)
|
@@ -171,29 +169,29 @@ module GRPC
|
|
171
169
|
# Used define_method to add a method for each rpc_desc. Each method
|
172
170
|
# calls the base class method for the given descriptor.
|
173
171
|
descs.each_pair do |name, desc|
|
174
|
-
mth_name = name.to_s.
|
172
|
+
mth_name = GenericService.underscore(name.to_s).to_sym
|
175
173
|
marshal = desc.marshal_proc
|
176
174
|
unmarshal = desc.unmarshal_proc(:output)
|
177
175
|
route = "/#{route_prefix}/#{name}"
|
178
176
|
if desc.request_response?
|
179
177
|
define_method(mth_name) do |req, deadline = nil, **kw|
|
180
|
-
logger.debug("calling #{@host}:#{route}")
|
178
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
181
179
|
request_response(route, req, marshal, unmarshal, deadline, **kw)
|
182
180
|
end
|
183
181
|
elsif desc.client_streamer?
|
184
182
|
define_method(mth_name) do |reqs, deadline = nil, **kw|
|
185
|
-
logger.debug("calling #{@host}:#{route}")
|
183
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
186
184
|
client_streamer(route, reqs, marshal, unmarshal, deadline, **kw)
|
187
185
|
end
|
188
186
|
elsif desc.server_streamer?
|
189
187
|
define_method(mth_name) do |req, deadline = nil, **kw, &blk|
|
190
|
-
logger.debug("calling #{@host}:#{route}")
|
188
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
191
189
|
server_streamer(route, req, marshal, unmarshal, deadline, **kw,
|
192
190
|
&blk)
|
193
191
|
end
|
194
192
|
else # is a bidi_stream
|
195
193
|
define_method(mth_name) do |reqs, deadline = nil, **kw, &blk|
|
196
|
-
logger.debug("calling #{@host}:#{route}")
|
194
|
+
GRPC.logger.debug("calling #{@host}:#{route}")
|
197
195
|
bidi_streamer(route, reqs, marshal, unmarshal, deadline, **kw,
|
198
196
|
&blk)
|
199
197
|
end
|
@@ -207,7 +205,7 @@ module GRPC
|
|
207
205
|
# implemented.
|
208
206
|
def assert_rpc_descs_have_methods
|
209
207
|
rpc_descs.each_pair do |m, spec|
|
210
|
-
mth_name = m.to_s.
|
208
|
+
mth_name = GenericService.underscore(m.to_s).to_sym
|
211
209
|
unless instance_methods.include?(mth_name)
|
212
210
|
fail "#{self} does not provide instance method '#{mth_name}'"
|
213
211
|
end
|
data/lib/grpc/logconfig.rb
CHANGED
@@ -29,7 +29,10 @@
|
|
29
29
|
|
30
30
|
require 'logging'
|
31
31
|
|
32
|
-
|
32
|
+
# GRPC contains the General RPC module.
|
33
|
+
module GRPC
|
34
|
+
extend Logging.globally
|
35
|
+
end
|
33
36
|
|
34
37
|
Logging.logger.root.appenders = Logging.appenders.stdout
|
35
38
|
Logging.logger.root.level = :info
|
data/lib/grpc/version.rb
CHANGED
@@ -39,36 +39,4 @@ describe GRPC::Core::CompletionQueue do
|
|
39
39
|
expect { GRPC::Core::CompletionQueue.new }.not_to raise_error
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
describe '#next' do
|
44
|
-
it 'can be called without failing' do
|
45
|
-
expect { @cq.next(3) }.not_to raise_error
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'can be called with a time constant' do
|
49
|
-
# don't use INFINITE_FUTURE, as are no events and this blocks.
|
50
|
-
#
|
51
|
-
# don't use INFINITE_PAST, as this fails on docker, and does not need to
|
52
|
-
# be tested, as its not used anywhere in the ruby implementation
|
53
|
-
a_time = GRPC::Core::TimeConsts::ZERO
|
54
|
-
expect { @cq.next(a_time) }.not_to raise_error
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#pluck' do
|
59
|
-
it 'can be called without failing' do
|
60
|
-
tag = Object.new
|
61
|
-
expect { @cq.pluck(tag, 3) }.not_to raise_error
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'can be called with a time constant' do
|
65
|
-
# don't use INFINITE_FUTURE, as there no events and this blocks.
|
66
|
-
#
|
67
|
-
# don't use INFINITE_PAST, as this fails on docker, and does not need to
|
68
|
-
# be tested, as its not used anywhere in the ruby implementation
|
69
|
-
tag = Object.new
|
70
|
-
a_time = GRPC::Core::TimeConsts::ZERO
|
71
|
-
expect { @cq.pluck(tag, a_time) }.not_to raise_error
|
72
|
-
end
|
73
|
-
end
|
74
42
|
end
|
@@ -74,11 +74,11 @@ describe GRPC::Pool do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
describe '#schedule' do
|
77
|
-
it '
|
77
|
+
it 'return if the pool is already stopped' do
|
78
78
|
p = Pool.new(1)
|
79
79
|
p.stop
|
80
80
|
job = proc {}
|
81
|
-
expect { p.schedule(&job) }.
|
81
|
+
expect { p.schedule(&job) }.to_not raise_error
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'adds jobs that get run by the pool' do
|
@@ -69,7 +69,7 @@ class EchoService
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def an_rpc(req, call)
|
72
|
-
logger.info('echo service received a request')
|
72
|
+
GRPC.logger.info('echo service received a request')
|
73
73
|
call.output_metadata.update(@trailing_metadata)
|
74
74
|
@received_md << call.metadata unless call.metadata.nil?
|
75
75
|
req
|
@@ -109,7 +109,7 @@ class SlowService
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def an_rpc(req, call)
|
112
|
-
logger.info("starting a slow #{@delay} rpc")
|
112
|
+
GRPC.logger.info("starting a slow #{@delay} rpc")
|
113
113
|
sleep @delay
|
114
114
|
@received_md << call.metadata unless call.metadata.nil?
|
115
115
|
req # send back the req as the response
|
@@ -212,10 +212,14 @@ describe GRPC::RpcServer do
|
|
212
212
|
|
213
213
|
describe '#stopped?' do
|
214
214
|
before(:each) do
|
215
|
-
opts = { a_channel_arg: 'an_arg', poll_period: 1 }
|
215
|
+
opts = { a_channel_arg: 'an_arg', poll_period: 1.5 }
|
216
216
|
@srv = RpcServer.new(**opts)
|
217
217
|
end
|
218
218
|
|
219
|
+
after(:each) do
|
220
|
+
@srv.stop
|
221
|
+
end
|
222
|
+
|
219
223
|
it 'starts out false' do
|
220
224
|
expect(@srv.stopped?).to be(false)
|
221
225
|
end
|
@@ -225,7 +229,7 @@ describe GRPC::RpcServer do
|
|
225
229
|
expect(@srv.stopped?).to be(false)
|
226
230
|
end
|
227
231
|
|
228
|
-
it 'stays false after the server starts running' do
|
232
|
+
it 'stays false after the server starts running', server: true do
|
229
233
|
@srv.handle(EchoService)
|
230
234
|
t = Thread.new { @srv.run }
|
231
235
|
@srv.wait_till_running
|
@@ -234,7 +238,7 @@ describe GRPC::RpcServer do
|
|
234
238
|
t.join
|
235
239
|
end
|
236
240
|
|
237
|
-
it 'is true after a running server is stopped' do
|
241
|
+
it 'is true after a running server is stopped', server: true do
|
238
242
|
@srv.handle(EchoService)
|
239
243
|
t = Thread.new { @srv.run }
|
240
244
|
@srv.wait_till_running
|
@@ -251,21 +255,22 @@ describe GRPC::RpcServer do
|
|
251
255
|
expect(r.running?).to be(false)
|
252
256
|
end
|
253
257
|
|
254
|
-
it 'is false
|
258
|
+
it 'is false if run is called with no services registered', server: true do
|
255
259
|
opts = {
|
256
260
|
a_channel_arg: 'an_arg',
|
257
|
-
poll_period:
|
261
|
+
poll_period: 2,
|
258
262
|
server_override: @server
|
259
263
|
}
|
260
264
|
r = RpcServer.new(**opts)
|
261
265
|
r.run
|
262
266
|
expect(r.running?).to be(false)
|
267
|
+
r.stop
|
263
268
|
end
|
264
269
|
|
265
270
|
it 'is true after run is called with a registered service' do
|
266
271
|
opts = {
|
267
272
|
a_channel_arg: 'an_arg',
|
268
|
-
poll_period:
|
273
|
+
poll_period: 2.5,
|
269
274
|
server_override: @server
|
270
275
|
}
|
271
276
|
r = RpcServer.new(**opts)
|
@@ -284,6 +289,10 @@ describe GRPC::RpcServer do
|
|
284
289
|
@srv = RpcServer.new(**@opts)
|
285
290
|
end
|
286
291
|
|
292
|
+
after(:each) do
|
293
|
+
@srv.stop
|
294
|
+
end
|
295
|
+
|
287
296
|
it 'raises if #run has already been called' do
|
288
297
|
@srv.handle(EchoService)
|
289
298
|
t = Thread.new { @srv.run }
|
@@ -335,6 +344,10 @@ describe GRPC::RpcServer do
|
|
335
344
|
@srv = RpcServer.new(**server_opts)
|
336
345
|
end
|
337
346
|
|
347
|
+
after(:each) do
|
348
|
+
@srv.stop
|
349
|
+
end
|
350
|
+
|
338
351
|
it 'should return NOT_FOUND status on unknown methods', server: true do
|
339
352
|
@srv.handle(EchoService)
|
340
353
|
t = Thread.new { @srv.run }
|
@@ -376,7 +389,7 @@ describe GRPC::RpcServer do
|
|
376
389
|
t.join
|
377
390
|
end
|
378
391
|
|
379
|
-
it 'should receive metadata
|
392
|
+
it 'should receive metadata if a deadline is specified', server: true do
|
380
393
|
service = SlowService.new
|
381
394
|
@srv.handle(service)
|
382
395
|
t = Thread.new { @srv.run }
|
@@ -445,11 +458,11 @@ describe GRPC::RpcServer do
|
|
445
458
|
|
446
459
|
it 'should handle multiple parallel requests', server: true do
|
447
460
|
@srv.handle(EchoService)
|
448
|
-
Thread.new { @srv.run }
|
461
|
+
t = Thread.new { @srv.run }
|
449
462
|
@srv.wait_till_running
|
450
463
|
req, q = EchoMsg.new, Queue.new
|
451
464
|
n = 5 # arbitrary
|
452
|
-
threads = []
|
465
|
+
threads = [t]
|
453
466
|
n.times do
|
454
467
|
threads << Thread.new do
|
455
468
|
stub = EchoStub.new(@host, **client_opts)
|
@@ -472,7 +485,7 @@ describe GRPC::RpcServer do
|
|
472
485
|
}
|
473
486
|
alt_srv = RpcServer.new(**opts)
|
474
487
|
alt_srv.handle(SlowService)
|
475
|
-
Thread.new { alt_srv.run }
|
488
|
+
t = Thread.new { alt_srv.run }
|
476
489
|
alt_srv.wait_till_running
|
477
490
|
req = EchoMsg.new
|
478
491
|
n = 5 # arbitrary, use as many to ensure the server pool is exceeded
|
@@ -490,6 +503,7 @@ describe GRPC::RpcServer do
|
|
490
503
|
end
|
491
504
|
threads.each(&:join)
|
492
505
|
alt_srv.stop
|
506
|
+
t.join
|
493
507
|
expect(one_failed_as_unavailable).to be(true)
|
494
508
|
end
|
495
509
|
end
|
@@ -513,6 +527,10 @@ describe GRPC::RpcServer do
|
|
513
527
|
@srv = RpcServer.new(**server_opts)
|
514
528
|
end
|
515
529
|
|
530
|
+
after(:each) do
|
531
|
+
@srv.stop
|
532
|
+
end
|
533
|
+
|
516
534
|
it 'should send connect metadata to the client', server: true do
|
517
535
|
service = EchoService.new
|
518
536
|
@srv.handle(service)
|
@@ -545,6 +563,10 @@ describe GRPC::RpcServer do
|
|
545
563
|
@srv = RpcServer.new(**server_opts)
|
546
564
|
end
|
547
565
|
|
566
|
+
after(:each) do
|
567
|
+
@srv.stop
|
568
|
+
end
|
569
|
+
|
548
570
|
it 'should be added to BadStatus when requests fail', server: true do
|
549
571
|
service = FailingService.new
|
550
572
|
@srv.handle(service)
|
@@ -56,15 +56,6 @@ end
|
|
56
56
|
GenericService = GRPC::GenericService
|
57
57
|
Dsl = GenericService::Dsl
|
58
58
|
|
59
|
-
describe 'String#underscore' do
|
60
|
-
it 'should convert CamelCase to underscore separated' do
|
61
|
-
expect('AnRPC'.underscore).to eq('an_rpc')
|
62
|
-
expect('AMethod'.underscore).to eq('a_method')
|
63
|
-
expect('PrintHTML'.underscore).to eq('print_html')
|
64
|
-
expect('PrintHTMLBooks'.underscore).to eq('print_html_books')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
59
|
describe Dsl do
|
69
60
|
it 'can be included in new classes' do
|
70
61
|
blk = proc { Class.new { include Dsl } }
|
@@ -73,6 +64,15 @@ describe Dsl do
|
|
73
64
|
end
|
74
65
|
|
75
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
76
|
describe 'including it' do
|
77
77
|
it 'adds a class method, rpc' do
|
78
78
|
c = Class.new do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gRPC Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 0.30.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.30.0
|
153
153
|
description: Send RPCs from Ruby using GRPC
|
154
154
|
email: temiola@google.com
|
155
155
|
executables:
|