aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'src/ruby')
-rw-r--r--src/ruby/.rubocop.yml2
-rw-r--r--src/ruby/pb/README.md4
-rwxr-xr-xsrc/ruby/pb/generate_proto_ruby.sh4
-rw-r--r--src/ruby/pb/grpc/health/checker.rb22
-rw-r--r--src/ruby/pb/grpc/health/v1/health.rb28
-rw-r--r--src/ruby/pb/grpc/health/v1/health_services.rb (renamed from src/ruby/pb/grpc/health/v1alpha/health_services.rb)8
-rw-r--r--src/ruby/pb/grpc/health/v1alpha/health.rb29
-rw-r--r--src/ruby/spec/pb/health/checker_spec.rb58
8 files changed, 70 insertions, 85 deletions
diff --git a/src/ruby/.rubocop.yml b/src/ruby/.rubocop.yml
index dd57ab6082..ff5cf8db83 100644
--- a/src/ruby/.rubocop.yml
+++ b/src/ruby/.rubocop.yml
@@ -7,7 +7,7 @@ AllCops:
- 'bin/apis/**/*'
- 'bin/math.rb'
- 'bin/math_services.rb'
- - 'pb/grpc/health/v1alpha/*'
+ - 'pb/grpc/health/v1/*'
- 'pb/test/**/*'
Metrics/CyclomaticComplexity:
diff --git a/src/ruby/pb/README.md b/src/ruby/pb/README.md
index e04aef185c..d9e30bbc85 100644
--- a/src/ruby/pb/README.md
+++ b/src/ruby/pb/README.md
@@ -11,7 +11,7 @@ The code is is generated using the protoc (> 3.0.0.alpha.1) and the
grpc_ruby_plugin. These must be installed to regenerate the IDL defined
classes, but that's not necessary just to use them.
-health_check/v1alpha
+health_check/v1
--------------------
This package defines the surface of a simple health check service that gRPC
@@ -20,7 +20,7 @@ re-generate the surface.
```bash
$ # (from this directory)
-$ protoc -I ../../proto ../../proto/grpc/health/v1alpha/health.proto \
+$ protoc -I ../../proto ../../proto/grpc/health/v1/health.proto \
--grpc_out=. \
--ruby_out=. \
--plugin=protoc-gen-grpc=`which grpc_ruby_plugin`
diff --git a/src/ruby/pb/generate_proto_ruby.sh b/src/ruby/pb/generate_proto_ruby.sh
index 576b1c08d3..86c082099d 100755
--- a/src/ruby/pb/generate_proto_ruby.sh
+++ b/src/ruby/pb/generate_proto_ruby.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -35,7 +35,7 @@ cd $(dirname $0)/../../..
PROTOC=bins/opt/protobuf/protoc
PLUGIN=protoc-gen-grpc=bins/opt/grpc_ruby_plugin
-$PROTOC -I src/proto src/proto/grpc/health/v1alpha/health.proto \
+$PROTOC -I src/proto src/proto/grpc/health/v1/health.proto \
--grpc_out=src/ruby/pb \
--ruby_out=src/ruby/pb \
--plugin=$PLUGIN
diff --git a/src/ruby/pb/grpc/health/checker.rb b/src/ruby/pb/grpc/health/checker.rb
index 8c692e74f9..9f1ee65c41 100644
--- a/src/ruby/pb/grpc/health/checker.rb
+++ b/src/ruby/pb/grpc/health/checker.rb
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'grpc'
-require 'grpc/health/v1alpha/health_services'
+require 'grpc/health/v1/health_services'
require 'thread'
module Grpc
@@ -36,9 +36,9 @@ module Grpc
# service.
module Health
# Checker is implementation of the schema-specified health checking service.
- class Checker < V1alpha::Health::Service
+ class Checker < V1::Health::Service
StatusCodes = GRPC::Core::StatusCodes
- HealthCheckResponse = V1alpha::HealthCheckResponse
+ HealthCheckResponse = V1::HealthCheckResponse
# Initializes the statuses of participating services
def initialize
@@ -50,20 +50,20 @@ module Grpc
def check(req, _call)
status = nil
@status_mutex.synchronize do
- status = @statuses["#{req.host}/#{req.service}"]
+ status = @statuses["#{req.service}"]
end
fail GRPC::BadStatus, StatusCodes::NOT_FOUND if status.nil?
HealthCheckResponse.new(status: status)
end
- # Adds the health status for a given host and service.
- def add_status(host, service, status)
- @status_mutex.synchronize { @statuses["#{host}/#{service}"] = status }
+ # Adds the health status for a given service.
+ def add_status(service, status)
+ @status_mutex.synchronize { @statuses["#{service}"] = status }
end
- # Clears the status for the given host or service.
- def clear_status(host, service)
- @status_mutex.synchronize { @statuses.delete("#{host}/#{service}") }
+ # Clears the status for the given service.
+ def clear_status(service)
+ @status_mutex.synchronize { @statuses.delete("#{service}") }
end
# Clears alls the statuses.
diff --git a/src/ruby/pb/grpc/health/v1/health.rb b/src/ruby/pb/grpc/health/v1/health.rb
new file mode 100644
index 0000000000..aa87a93918
--- /dev/null
+++ b/src/ruby/pb/grpc/health/v1/health.rb
@@ -0,0 +1,28 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: grpc/health/v1/health.proto
+
+require 'google/protobuf'
+
+Google::Protobuf::DescriptorPool.generated_pool.build do
+ add_message "grpc.health.v1.HealthCheckRequest" do
+ optional :service, :string, 1
+ end
+ add_message "grpc.health.v1.HealthCheckResponse" do
+ optional :status, :enum, 1, "grpc.health.v1.HealthCheckResponse.ServingStatus"
+ end
+ add_enum "grpc.health.v1.HealthCheckResponse.ServingStatus" do
+ value :UNKNOWN, 0
+ value :SERVING, 1
+ value :NOT_SERVING, 2
+ end
+end
+
+module Grpc
+ module Health
+ module V1
+ HealthCheckRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckRequest").msgclass
+ HealthCheckResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse").msgclass
+ HealthCheckResponse::ServingStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse.ServingStatus").enummodule
+ end
+ end
+end
diff --git a/src/ruby/pb/grpc/health/v1alpha/health_services.rb b/src/ruby/pb/grpc/health/v1/health_services.rb
index d5cba2e9ec..cb79b20437 100644
--- a/src/ruby/pb/grpc/health/v1alpha/health_services.rb
+++ b/src/ruby/pb/grpc/health/v1/health_services.rb
@@ -1,12 +1,12 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
-# Source: grpc/health/v1alpha/health.proto for package 'grpc.health.v1alpha'
+# Source: grpc/health/v1/health.proto for package 'grpc.health.v1'
require 'grpc'
-require 'grpc/health/v1alpha/health'
+require 'grpc/health/v1/health'
module Grpc
module Health
- module V1alpha
+ module V1
module Health
# TODO: add proto service documentation here
@@ -16,7 +16,7 @@ module Grpc
self.marshal_class_method = :encode
self.unmarshal_class_method = :decode
- self.service_name = 'grpc.health.v1alpha.Health'
+ self.service_name = 'grpc.health.v1.Health'
rpc :Check, HealthCheckRequest, HealthCheckResponse
end
diff --git a/src/ruby/pb/grpc/health/v1alpha/health.rb b/src/ruby/pb/grpc/health/v1alpha/health.rb
deleted file mode 100644
index 9c04298ea5..0000000000
--- a/src/ruby/pb/grpc/health/v1alpha/health.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# Generated by the protocol buffer compiler. DO NOT EDIT!
-# source: grpc/health/v1alpha/health.proto
-
-require 'google/protobuf'
-
-Google::Protobuf::DescriptorPool.generated_pool.build do
- add_message "grpc.health.v1alpha.HealthCheckRequest" do
- optional :host, :string, 1
- optional :service, :string, 2
- end
- add_message "grpc.health.v1alpha.HealthCheckResponse" do
- optional :status, :enum, 1, "grpc.health.v1alpha.HealthCheckResponse.ServingStatus"
- end
- add_enum "grpc.health.v1alpha.HealthCheckResponse.ServingStatus" do
- value :UNKNOWN, 0
- value :SERVING, 1
- value :NOT_SERVING, 2
- end
-end
-
-module Grpc
- module Health
- module V1alpha
- HealthCheckRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1alpha.HealthCheckRequest").msgclass
- HealthCheckResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1alpha.HealthCheckResponse").msgclass
- HealthCheckResponse::ServingStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1alpha.HealthCheckResponse.ServingStatus").enummodule
- end
- end
-end
diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb
index c1decd822a..9bb79bb4ca 100644
--- a/src/ruby/spec/pb/health/checker_spec.rb
+++ b/src/ruby/spec/pb/health/checker_spec.rb
@@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'grpc'
-require 'grpc/health/v1alpha/health'
+require 'grpc/health/v1/health'
require 'grpc/health/checker'
require 'open3'
require 'tmpdir'
@@ -43,7 +43,7 @@ describe 'Health protobuf code generation' do
skip 'protoc || grpc_ruby_plugin missing, cannot verify health code-gen'
else
it 'should already be loaded indirectly i.e, used by the other specs' do
- expect(require('grpc/health/v1alpha/health_services')).to be(false)
+ expect(require('grpc/health/v1/health_services')).to be(false)
end
it 'should have the same content as created by code generation' do
@@ -52,7 +52,7 @@ describe 'Health protobuf code generation' do
# Get the current content
service_path = File.join(root_dir, 'ruby', 'pb', 'grpc',
- 'health', 'v1alpha', 'health_services.rb')
+ 'health', 'v1', 'health_services.rb')
want = nil
File.open(service_path) { |f| want = f.read }
@@ -61,12 +61,12 @@ describe 'Health protobuf code generation' do
plugin = plugin.strip
got = nil
Dir.mktmpdir do |tmp_dir|
- gen_out = File.join(tmp_dir, 'grpc', 'health', 'v1alpha',
+ gen_out = File.join(tmp_dir, 'grpc', 'health', 'v1',
'health_services.rb')
pid = spawn(
'protoc',
'-I.',
- 'grpc/health/v1alpha/health.proto',
+ 'grpc/health/v1/health.proto',
"--grpc_out=#{tmp_dir}",
"--plugin=protoc-gen-grpc=#{plugin}",
chdir: pb_dir)
@@ -81,27 +81,17 @@ end
describe Grpc::Health::Checker do
StatusCodes = GRPC::Core::StatusCodes
- ServingStatus = Grpc::Health::V1alpha::HealthCheckResponse::ServingStatus
- HCResp = Grpc::Health::V1alpha::HealthCheckResponse
- HCReq = Grpc::Health::V1alpha::HealthCheckRequest
+ ServingStatus = Grpc::Health::V1::HealthCheckResponse::ServingStatus
+ HCResp = Grpc::Health::V1::HealthCheckResponse
+ HCReq = Grpc::Health::V1::HealthCheckRequest
success_tests =
[
{
- desc: 'neither host or service are specified',
- host: '',
+ desc: 'the service is not specified',
service: ''
}, {
- desc: 'only the host is specified',
- host: 'test-fake-host',
- service: ''
- }, {
- desc: 'the host and service are specified',
- host: 'test-fake-host',
+ desc: 'the service is specified',
service: 'fake-service-1'
- }, {
- desc: 'only the service is specified',
- host: '',
- service: 'fake-service-2'
}
]
@@ -114,9 +104,8 @@ describe Grpc::Health::Checker do
context 'method `add_status` and `check`' do
success_tests.each do |t|
it "should succeed when #{t[:desc]}" do
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
end
@@ -127,7 +116,7 @@ describe Grpc::Health::Checker do
success_tests.each do |t|
it "should fail with NOT_FOUND when #{t[:desc]}" do
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -138,16 +127,14 @@ describe Grpc::Health::Checker do
context 'method `clear_status`' do
success_tests.each do |t|
it "should fail after clearing status when #{t[:desc]}" do
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
- subject.clear_status(t[:host], t[:service])
+ subject.clear_status(t[:service])
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -158,9 +145,8 @@ describe Grpc::Health::Checker do
context 'method `clear_all`' do
it 'should return NOT_FOUND after being invoked' do
success_tests.each do |t|
- subject.add_status(t[:host], t[:service], ServingStatus::NOT_SERVING)
- got = subject.check(HCReq.new(host: t[:host], service: t[:service]),
- nil)
+ subject.add_status(t[:service], ServingStatus::NOT_SERVING)
+ got = subject.check(HCReq.new(service: t[:service]), nil)
want = HCResp.new(status: ServingStatus::NOT_SERVING)
expect(got).to eq(want)
end
@@ -169,7 +155,7 @@ describe Grpc::Health::Checker do
success_tests.each do |t|
blk = proc do
- subject.check(HCReq.new(host: t[:host], service: t[:service]), nil)
+ subject.check(HCReq.new(service: t[:service]), nil)
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg
@@ -203,7 +189,7 @@ describe Grpc::Health::Checker do
it 'should receive the correct status', server: true do
@srv.handle(subject)
- subject.add_status('', '', ServingStatus::NOT_SERVING)
+ subject.add_status('', ServingStatus::NOT_SERVING)
t = Thread.new { @srv.run }
@srv.wait_till_running
@@ -221,7 +207,7 @@ describe Grpc::Health::Checker do
@srv.wait_till_running
blk = proc do
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
- stub.check(HCReq.new(host: 'unknown', service: 'unknown'))
+ stub.check(HCReq.new(service: 'unknown'))
end
expected_msg = /#{StatusCodes::NOT_FOUND}/
expect(&blk).to raise_error GRPC::BadStatus, expected_msg