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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +3 -3
  3. data/README.md +41 -39
  4. data/bin/apis/pubsub_demo.rb +2 -2
  5. data/bin/interop/interop_client.rb +6 -4
  6. data/bin/interop/interop_server.rb +7 -4
  7. data/bin/math.proto +7 -7
  8. data/bin/math_client.rb +22 -22
  9. data/bin/math_server.rb +6 -6
  10. data/bin/noproto_client.rb +4 -4
  11. data/bin/noproto_server.rb +3 -3
  12. data/ext/grpc/extconf.rb +20 -5
  13. data/ext/grpc/rb_byte_buffer.c +5 -4
  14. data/ext/grpc/rb_byte_buffer.h +2 -1
  15. data/ext/grpc/rb_call.c +5 -6
  16. data/ext/grpc/rb_call.h +2 -1
  17. data/ext/grpc/rb_channel.c +1 -1
  18. data/ext/grpc/rb_channel.h +2 -1
  19. data/ext/grpc/rb_channel_args.c +2 -1
  20. data/ext/grpc/rb_channel_args.h +2 -1
  21. data/ext/grpc/rb_completion_queue.c +7 -49
  22. data/ext/grpc/rb_completion_queue.h +4 -3
  23. data/ext/grpc/rb_credentials.c +1 -1
  24. data/ext/grpc/rb_credentials.h +2 -1
  25. data/ext/grpc/rb_grpc.h +2 -1
  26. data/ext/grpc/rb_server.c +10 -11
  27. data/ext/grpc/rb_server.h +2 -1
  28. data/ext/grpc/rb_server_credentials.c +1 -1
  29. data/ext/grpc/rb_server_credentials.h +2 -1
  30. data/grpc.gemspec +1 -1
  31. data/lib/grpc/core/time_consts.rb +1 -1
  32. data/lib/grpc/generic/active_call.rb +13 -9
  33. data/lib/grpc/generic/bidi_call.rb +37 -41
  34. data/lib/grpc/generic/rpc_desc.rb +8 -7
  35. data/lib/grpc/generic/rpc_server.rb +55 -42
  36. data/lib/grpc/generic/service.rb +22 -24
  37. data/lib/grpc/logconfig.rb +4 -1
  38. data/lib/grpc/version.rb +1 -1
  39. data/spec/completion_queue_spec.rb +0 -32
  40. data/spec/generic/rpc_server_pool_spec.rb +2 -2
  41. data/spec/generic/rpc_server_spec.rb +34 -12
  42. data/spec/generic/service_spec.rb +9 -9
  43. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fc4ef4584055918c9fb5118a4ae2be97fefd82b
4
- data.tar.gz: b09b8e12d13fb1d46687a3738621ec863afa5abd
3
+ metadata.gz: 38b1655a47e1edbbd0d48d73e566c37b1c7241dc
4
+ data.tar.gz: f6a98f39e718c84decc81af8cc6638e8cdac43d9
5
5
  SHA512:
6
- metadata.gz: b63ec97352b08405828884a32b6115c025b1507d0294b9553e5aa9bea6c9d6ff2d6f5651f13d85f50080a4888ee6976011a5b2e4c81147c93d1e08eead30d4a7
7
- data.tar.gz: 9057402bc495a85cfd1970e1622a18031d089173cfbbfd82e691d56479cbbfddc34c3be6fe47c885c0383a1fa0e550129d7bad35415e8384789cd24aeb060ed2
6
+ metadata.gz: 241414922a1e18924af518dba9bb5aa39bf7f526392f911da83c2d94aee5c1d1ae60c6435fef0a45e8dc8098128fc2bc6d8f609434db9944d0164f57ac48dd0b
7
+ data.tar.gz: 9e85cb271539ab885332570b9b38339a354c087a92b5ebc7a397439a29dc514197f5ef88aa74fa3bb9b04aab5a15a6d5f59314b0c847fa58665dcb664a7d4750
data/.rubocop_todo.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-04-17 14:43:27 -0700 using RuboCop version 0.30.0.
2
+ # on 2015-05-22 13:23:34 -0700 using RuboCop version 0.30.1.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
@@ -7,12 +7,12 @@
7
7
 
8
8
  # Offense count: 30
9
9
  Metrics/AbcSize:
10
- Max: 40
10
+ Max: 38
11
11
 
12
12
  # Offense count: 3
13
13
  # Configuration parameters: CountComments.
14
14
  Metrics/ClassLength:
15
- Max: 184
15
+ Max: 192
16
16
 
17
17
  # Offense count: 35
18
18
  # Configuration parameters: CountComments.
data/README.md CHANGED
@@ -4,48 +4,44 @@ gRPC Ruby
4
4
  A Ruby implementation of gRPC.
5
5
 
6
6
  Status
7
- -------
7
+ ------
8
8
 
9
9
  Alpha : Ready for early adopters
10
10
 
11
- INSTALLATION PREREQUISITES
12
- --------------------------
11
+ PREREQUISITES
12
+ -------------
13
13
 
14
- This requires Ruby 2.1, as the RPC API surface uses keyword args.
14
+ - Ruby 2.x. The gRPC API uses keyword args.
15
+ - [homebrew][] on Mac OS X, [linuxbrew][] on Linux. These simplify the installation of the gRPC C core.
15
16
 
16
-
17
- QUICK - INSTALL
17
+ INSTALLATION
18
18
  ---------------
19
-
20
- - Clone this repository.
21
- - Follow the instructions in [INSTALL](../../INSTALL) to install the gRPC C core.
22
- - If you don't have Ruby 2.1 installed, switch to the more detailed instructions below
23
- - Use bundler to install
19
+ On Mac OS X, install [homebrew][]. On Linux, install [linuxbrew][].
20
+ Run the following command to install gRPC Ruby.
24
21
  ```sh
25
- $ # from this directory
26
- $ gem install bundler && bundle install
22
+ $ curl -fsSL https://goo.gl/getgrpc | bash -s ruby
27
23
  ```
24
+ This will download and run the [gRPC install script][], then install the latest version of gRPC Ruby gem. It also installs Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin for ruby.
28
25
 
29
- Installing from source
30
- ----------------------
31
-
26
+ BUILD FROM SOURCE
27
+ ---------------------
28
+ - Clone this repository
32
29
  - Build the gRPC C core
33
- E.g, from the root of the gRPC [git repo](https://github.com/google/grpc)
30
+ E.g, from the root of the gRPC [Git repository](https://github.com/google/grpc)
34
31
  ```sh
35
32
  $ cd ../..
36
33
  $ make && sudo make install
37
34
  ```
38
35
 
39
- - Install Ruby 2.1. Consider doing this with [RVM](http://rvm.io), it's a nice way of controlling
36
+ - Install Ruby 2.x. Consider doing this with [RVM](http://rvm.io), it's a nice way of controlling
40
37
  the exact ruby version that's used.
41
38
  ```sh
42
39
  $ command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
43
- $ \curl -sSL https://get.rvm.io | bash -s stable --ruby=ruby-2.1
40
+ $ \curl -sSL https://get.rvm.io | bash -s stable --ruby=ruby-2
44
41
  $
45
42
  $ # follow the instructions to ensure that your're using the latest stable version of Ruby
46
43
  $ # and that the rvm command is installed
47
44
  ```
48
-
49
45
  - Make sure your run `source $HOME/.rvm/scripts/rvm` as instructed to complete the set up of RVM
50
46
 
51
47
  - Install [bundler](http://bundler.io/)
@@ -53,30 +49,36 @@ $ # and that the rvm command is installed
53
49
  $ gem install bundler
54
50
  ```
55
51
 
56
- - Finally, install the gRPC gem locally.
52
+ - Finally, build and install the gRPC gem locally.
57
53
  ```sh
58
54
  $ # from this directory
59
55
  $ bundle install # creates the ruby bundle, including building the grpc extension
60
56
  $ rake # runs the unit tests, see rake -T for other options
61
57
  ```
62
58
 
59
+ DOCUMENTATION
60
+ -------------
61
+ - rubydoc for the gRPC gem is available online at [rubydoc][].
62
+ - the gRPC Ruby reference documentation is available online at [grpc.io][]
63
+
63
64
  CONTENTS
64
65
  --------
65
-
66
- Directory structure is the layout for [ruby extensions](http://guides.rubygems.org/gems-with-extensions/)
67
-
68
- - ext:
69
- the gRPC ruby extension
70
- - lib:
71
- the entrypoint gRPC ruby library to be used in a 'require' statement
72
- - spec:
73
- Rspec unittest
74
- - bin:
75
- example gRPC clients and servers, e.g,
76
- ```ruby
77
- stub = Math::Math::Stub.new('my.test.math.server.com:8080')
78
- req = Math::DivArgs.new(dividend: 7, divisor: 3)
79
- logger.info("div(7/3): req=#{req.inspect}")
80
- resp = stub.div(req)
81
- logger.info("Answer: #{resp.inspect}")
82
- ```
66
+ Directory structure is the layout for [ruby extensions][]
67
+ - ext: the gRPC ruby extension
68
+ - lib: the entrypoint gRPC ruby library to be used in a 'require' statement
69
+ - spec: Rspec unittests
70
+ - bin: example gRPC clients and servers, e.g,
71
+
72
+ ```ruby
73
+ stub = Math::Math::Stub.new('my.test.math.server.com:8080')
74
+ req = Math::DivArgs.new(dividend: 7, divisor: 3)
75
+ GRPC.logger.info("div(7/3): req=#{req.inspect}")
76
+ resp = stub.div(req)
77
+ GRPC.logger.info("Answer: #{resp.inspect}")
78
+ ```
79
+ [homebrew]:http://brew.sh
80
+ [linuxbrew]:https://github.com/Homebrew/linuxbrew#installation
81
+ [gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
82
+ [ruby extensions]:http://guides.rubygems.org/gems-with-extensions/
83
+ [rubydoc]: http://www.rubydoc.info/gems/grpc
84
+ [grpc.io]: http://www.grpc.io/docs/installation/ruby.html
@@ -79,7 +79,7 @@ end
79
79
  def publisher_stub(opts)
80
80
  address = "#{opts.host}:#{opts.port}"
81
81
  stub_clz = Tech::Pubsub::PublisherService::Stub # shorter
82
- logger.info("... access PublisherService at #{address}")
82
+ GRPC.logger.info("... access PublisherService at #{address}")
83
83
  stub_clz.new(address,
84
84
  creds: ssl_creds, update_metadata: auth_proc(opts),
85
85
  GRPC::Core::Channel::SSL_TARGET => opts.host)
@@ -89,7 +89,7 @@ end
89
89
  def subscriber_stub(opts)
90
90
  address = "#{opts.host}:#{opts.port}"
91
91
  stub_clz = Tech::Pubsub::SubscriberService::Stub # shorter
92
- logger.info("... access SubscriberService at #{address}")
92
+ GRPC.logger.info("... access SubscriberService at #{address}")
93
93
  stub_clz.new(address,
94
94
  creds: ssl_creds, update_metadata: auth_proc(opts),
95
95
  GRPC::Core::Channel::SSL_TARGET => opts.host)
@@ -70,7 +70,7 @@ end
70
70
  # loads the certificates used to access the test server securely.
71
71
  def load_prod_cert
72
72
  fail 'could not find a production cert' if ENV['SSL_CERT_FILE'].nil?
73
- logger.info("loading prod certs from #{ENV['SSL_CERT_FILE']}")
73
+ GRPC.logger.info("loading prod certs from #{ENV['SSL_CERT_FILE']}")
74
74
  File.open(ENV['SSL_CERT_FILE']).read
75
75
  end
76
76
 
@@ -115,10 +115,10 @@ def create_stub(opts)
115
115
  stub_opts[:update_metadata] = auth_creds.updater_proc
116
116
  end
117
117
 
118
- logger.info("... connecting securely to #{address}")
118
+ GRPC.logger.info("... connecting securely to #{address}")
119
119
  Grpc::Testing::TestService::Stub.new(address, **stub_opts)
120
120
  else
121
- logger.info("... connecting insecurely to #{address}")
121
+ GRPC.logger.info("... connecting insecurely to #{address}")
122
122
  Grpc::Testing::TestService::Stub.new(address)
123
123
  end
124
124
  end
@@ -274,6 +274,7 @@ class NamedTests
274
274
  op = @stub.streaming_input_call(reqs, return_op: true)
275
275
  op.cancel
276
276
  assert_raises(GRPC::Cancelled) { op.execute }
277
+ assert(op.cancelled, 'call operation should be CANCELLED')
277
278
  p 'OK: cancel_after_begin'
278
279
  end
279
280
 
@@ -282,7 +283,8 @@ class NamedTests
282
283
  ppp = PingPongPlayer.new(msg_sizes)
283
284
  op = @stub.full_duplex_call(ppp.each_item, return_op: true)
284
285
  ppp.canceller_op = op # causes ppp to cancel after the 1st message
285
- assert_raises(GRPC::Cancelled) { op.execute.each { |r| ppp.queue.push(r) } }
286
+ op.execute.each { |r| ppp.queue.push(r) }
287
+ assert(op.cancelled, 'call operation should be CANCELLED')
286
288
  p 'OK: cancel_after_first_response'
287
289
  end
288
290
 
@@ -128,16 +128,19 @@ class TestTarget < Grpc::Testing::TestService::Service
128
128
  cls = StreamingOutputCallResponse
129
129
  Thread.new do
130
130
  begin
131
+ GRPC.logger.info('interop-server: started receiving')
131
132
  reqs.each do |req|
132
- logger.info("read #{req.inspect}")
133
133
  resp_size = req.response_parameters[0].size
134
+ GRPC.logger.info("read a req, response size is #{resp_size}")
134
135
  resp = cls.new(payload: Payload.new(type: req.response_type,
135
136
  body: nulls(resp_size)))
136
137
  q.push(resp)
137
138
  end
138
- logger.info('finished reads')
139
+ GRPC.logger.info('interop-server: finished receiving')
139
140
  q.push(self)
140
141
  rescue StandardError => e
142
+ GRPC.logger.info('interop-server: failed')
143
+ GRPC.logger.warn(e)
141
144
  q.push(e) # share the exception with the enumerator
142
145
  end
143
146
  end
@@ -179,10 +182,10 @@ def main
179
182
  s = GRPC::RpcServer.new
180
183
  if opts['secure']
181
184
  s.add_http2_port(host, test_server_creds)
182
- logger.info("... running securely on #{host}")
185
+ GRPC.logger.info("... running securely on #{host}")
183
186
  else
184
187
  s.add_http2_port(host)
185
- logger.info("... running insecurely on #{host}")
188
+ GRPC.logger.info("... running insecurely on #{host}")
186
189
  end
187
190
  s.handle(TestTarget)
188
191
  s.run_till_terminated
data/bin/math.proto CHANGED
@@ -33,25 +33,25 @@ syntax = "proto3";
33
33
  package math;
34
34
 
35
35
  message DivArgs {
36
- optional int64 dividend = 1;
37
- optional int64 divisor = 2;
36
+ int64 dividend = 1;
37
+ int64 divisor = 2;
38
38
  }
39
39
 
40
40
  message DivReply {
41
- optional int64 quotient = 1;
42
- optional int64 remainder = 2;
41
+ int64 quotient = 1;
42
+ int64 remainder = 2;
43
43
  }
44
44
 
45
45
  message FibArgs {
46
- optional int64 limit = 1;
46
+ int64 limit = 1;
47
47
  }
48
48
 
49
49
  message Num {
50
- optional int64 num = 1;
50
+ int64 num = 1;
51
51
  }
52
52
 
53
53
  message FibReply {
54
- optional int64 count = 1;
54
+ int64 count = 1;
55
55
  }
56
56
 
57
57
  service Math {
data/bin/math_client.rb CHANGED
@@ -46,51 +46,51 @@ require 'optparse'
46
46
  include GRPC::Core::TimeConsts
47
47
 
48
48
  def do_div(stub)
49
- logger.info('request_response')
50
- logger.info('----------------')
49
+ GRPC.logger.info('request_response')
50
+ GRPC.logger.info('----------------')
51
51
  req = Math::DivArgs.new(dividend: 7, divisor: 3)
52
- logger.info("div(7/3): req=#{req.inspect}")
52
+ GRPC.logger.info("div(7/3): req=#{req.inspect}")
53
53
  resp = stub.div(req, INFINITE_FUTURE)
54
- logger.info("Answer: #{resp.inspect}")
55
- logger.info('----------------')
54
+ GRPC.logger.info("Answer: #{resp.inspect}")
55
+ GRPC.logger.info('----------------')
56
56
  end
57
57
 
58
58
  def do_sum(stub)
59
59
  # to make client streaming requests, pass an enumerable of the inputs
60
- logger.info('client_streamer')
61
- logger.info('---------------')
60
+ GRPC.logger.info('client_streamer')
61
+ GRPC.logger.info('---------------')
62
62
  reqs = [1, 2, 3, 4, 5].map { |x| Math::Num.new(num: x) }
63
- logger.info("sum(1, 2, 3, 4, 5): reqs=#{reqs.inspect}")
63
+ GRPC.logger.info("sum(1, 2, 3, 4, 5): reqs=#{reqs.inspect}")
64
64
  resp = stub.sum(reqs) # reqs.is_a?(Enumerable)
65
- logger.info("Answer: #{resp.inspect}")
66
- logger.info('---------------')
65
+ GRPC.logger.info("Answer: #{resp.inspect}")
66
+ GRPC.logger.info('---------------')
67
67
  end
68
68
 
69
69
  def do_fib(stub)
70
- logger.info('server_streamer')
71
- logger.info('----------------')
70
+ GRPC.logger.info('server_streamer')
71
+ GRPC.logger.info('----------------')
72
72
  req = Math::FibArgs.new(limit: 11)
73
- logger.info("fib(11): req=#{req.inspect}")
73
+ GRPC.logger.info("fib(11): req=#{req.inspect}")
74
74
  resp = stub.fib(req, INFINITE_FUTURE)
75
75
  resp.each do |r|
76
- logger.info("Answer: #{r.inspect}")
76
+ GRPC.logger.info("Answer: #{r.inspect}")
77
77
  end
78
- logger.info('----------------')
78
+ GRPC.logger.info('----------------')
79
79
  end
80
80
 
81
81
  def do_div_many(stub)
82
- logger.info('bidi_streamer')
83
- logger.info('-------------')
82
+ GRPC.logger.info('bidi_streamer')
83
+ GRPC.logger.info('-------------')
84
84
  reqs = []
85
85
  reqs << Math::DivArgs.new(dividend: 7, divisor: 3)
86
86
  reqs << Math::DivArgs.new(dividend: 5, divisor: 2)
87
87
  reqs << Math::DivArgs.new(dividend: 7, divisor: 2)
88
- logger.info("div(7/3), div(5/2), div(7/2): reqs=#{reqs.inspect}")
88
+ GRPC.logger.info("div(7/3), div(5/2), div(7/2): reqs=#{reqs.inspect}")
89
89
  resp = stub.div_many(reqs, 10)
90
90
  resp.each do |r|
91
- logger.info("Answer: #{r.inspect}")
91
+ GRPC.logger.info("Answer: #{r.inspect}")
92
92
  end
93
- logger.info('----------------')
93
+ GRPC.logger.info('----------------')
94
94
  end
95
95
 
96
96
  def load_test_certs
@@ -132,10 +132,10 @@ def main
132
132
  p stub_opts
133
133
  p options['host']
134
134
  stub = Math::Math::Stub.new(options['host'], **stub_opts)
135
- logger.info("... connecting securely on #{options['host']}")
135
+ GRPC.logger.info("... connecting securely on #{options['host']}")
136
136
  else
137
137
  stub = Math::Math::Stub.new(options['host'])
138
- logger.info("... connecting insecurely on #{options['host']}")
138
+ GRPC.logger.info("... connecting insecurely on #{options['host']}")
139
139
  end
140
140
 
141
141
  do_div(stub)
data/bin/math_server.rb CHANGED
@@ -55,7 +55,7 @@ class Fibber
55
55
  return enum_for(:generator) unless block_given?
56
56
  idx, current, previous = 0, 1, 1
57
57
  until idx == @limit
58
- if idx == 0 || idx == 1
58
+ if idx.zero? || idx == 1
59
59
  yield Math::Num.new(num: 1)
60
60
  idx += 1
61
61
  next
@@ -94,7 +94,7 @@ end
94
94
  # package. That practice should be avoided by defining real services.
95
95
  class Calculator < Math::Math::Service
96
96
  def div(div_args, _call)
97
- if div_args.divisor == 0
97
+ if div_args.divisor.zero?
98
98
  # To send non-OK status handlers raise a StatusError with the code and
99
99
  # and detail they want sent as a Status.
100
100
  fail GRPC::StatusError.new(GRPC::Status::INVALID_ARGUMENT,
@@ -128,13 +128,13 @@ class Calculator < Math::Math::Service
128
128
  t = Thread.new do
129
129
  begin
130
130
  requests.each do |req|
131
- logger.info("read #{req.inspect}")
131
+ GRPC.logger.info("read #{req.inspect}")
132
132
  resp = Math::DivReply.new(quotient: req.dividend / req.divisor,
133
133
  remainder: req.dividend % req.divisor)
134
134
  q.push(resp)
135
135
  Thread.pass # let the internal Bidi threads run
136
136
  end
137
- logger.info('finished reads')
137
+ GRPC.logger.info('finished reads')
138
138
  q.push(self)
139
139
  rescue StandardError => e
140
140
  q.push(e) # share the exception with the enumerator
@@ -176,10 +176,10 @@ def main
176
176
  s = GRPC::RpcServer.new
177
177
  if options['secure']
178
178
  s.add_http2_port(options['host'], test_server_creds)
179
- logger.info("... running securely on #{options['host']}")
179
+ GRPC.logger.info("... running securely on #{options['host']}")
180
180
  else
181
181
  s.add_http2_port(options['host'])
182
- logger.info("... running insecurely on #{options['host']}")
182
+ GRPC.logger.info("... running insecurely on #{options['host']}")
183
183
  end
184
184
 
185
185
  s.handle(Calculator)
@@ -94,15 +94,15 @@ def main
94
94
  p stub_opts
95
95
  p options['host']
96
96
  stub = NoProtoStub.new(options['host'], **stub_opts)
97
- logger.info("... connecting securely on #{options['host']}")
97
+ GRPC.logger.info("... connecting securely on #{options['host']}")
98
98
  else
99
99
  stub = NoProtoStub.new(options['host'])
100
- logger.info("... connecting insecurely on #{options['host']}")
100
+ GRPC.logger.info("... connecting insecurely on #{options['host']}")
101
101
  end
102
102
 
103
- logger.info('sending a NoProto rpc')
103
+ GRPC.logger.info('sending a NoProto rpc')
104
104
  resp = stub.an_rpc(NoProtoMsg.new)
105
- logger.info("got a response: #{resp}")
105
+ GRPC.logger.info("got a response: #{resp}")
106
106
  end
107
107
 
108
108
  main
@@ -63,7 +63,7 @@ class NoProto < NoProtoService
63
63
  end
64
64
 
65
65
  def an_rpc(req, _call)
66
- logger.info('echo service received a request')
66
+ GRPC.logger.info('echo service received a request')
67
67
  req
68
68
  end
69
69
  end
@@ -98,10 +98,10 @@ def main
98
98
  s = GRPC::RpcServer.new
99
99
  if options['secure']
100
100
  s.add_http2_port(options['host'], test_server_creds)
101
- logger.info("... running securely on #{options['host']}")
101
+ GRPC.logger.info("... running securely on #{options['host']}")
102
102
  else
103
103
  s.add_http2_port(options['host'])
104
- logger.info("... running insecurely on #{options['host']}")
104
+ GRPC.logger.info("... running insecurely on #{options['host']}")
105
105
  end
106
106
 
107
107
  s.handle(NoProto)