aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-03-10 09:49:30 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-03-10 09:52:58 +0100
commit280eedd2e58aa4d1cacf56eb2102a7be5f4b0841 (patch)
treeb47a5de70d9f17c70c32d08ace31b21832f898d6 /src/ruby
parent4d52cca1ef29837c7610e31897240b6f4abd6991 (diff)
parent40ed554bc0b315ff58c571d992dfd0542ec9ed77 (diff)
Merge branch 'master' into pre-0.13.1-downmerge
Conflicts: INSTALL.md examples/cpp/README.md
Diffstat (limited to 'src/ruby')
-rw-r--r--src/ruby/.rubocop.yml2
-rw-r--r--src/ruby/ext/grpc/rb_grpc_imports.generated.c2
-rw-r--r--src/ruby/ext/grpc/rb_grpc_imports.generated.h7
-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
10 files changed, 77 insertions, 87 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/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c
index 1af34d97fb..56db4ec686 100644
--- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c
+++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c
@@ -220,6 +220,7 @@ gpr_event_get_type gpr_event_get_import;
gpr_event_wait_type gpr_event_wait_import;
gpr_ref_init_type gpr_ref_init_import;
gpr_ref_type gpr_ref_import;
+gpr_ref_non_zero_type gpr_ref_non_zero_import;
gpr_refn_type gpr_refn_import;
gpr_unref_type gpr_unref_import;
gpr_stats_init_type gpr_stats_init_import;
@@ -481,6 +482,7 @@ void grpc_rb_load_imports(HMODULE library) {
gpr_event_wait_import = (gpr_event_wait_type) GetProcAddress(library, "gpr_event_wait");
gpr_ref_init_import = (gpr_ref_init_type) GetProcAddress(library, "gpr_ref_init");
gpr_ref_import = (gpr_ref_type) GetProcAddress(library, "gpr_ref");
+ gpr_ref_non_zero_import = (gpr_ref_non_zero_type) GetProcAddress(library, "gpr_ref_non_zero");
gpr_refn_import = (gpr_refn_type) GetProcAddress(library, "gpr_refn");
gpr_unref_import = (gpr_unref_type) GetProcAddress(library, "gpr_unref");
gpr_stats_init_import = (gpr_stats_init_type) GetProcAddress(library, "gpr_stats_init");
diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h
index b61c5282b6..b972f60fc3 100644
--- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h
+++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h
@@ -91,10 +91,10 @@ extern census_context_next_tag_type census_context_next_tag_import;
typedef int(*census_context_get_tag_type)(const census_context *context, const char *key, census_tag *tag);
extern census_context_get_tag_type census_context_get_tag_import;
#define census_context_get_tag census_context_get_tag_import
-typedef char *(*census_context_encode_type)(const census_context *context, char *buffer, size_t buf_size, size_t *print_buf_size, size_t *bin_buf_size);
+typedef size_t(*census_context_encode_type)(const census_context *context, char *buffer, size_t buf_size);
extern census_context_encode_type census_context_encode_import;
#define census_context_encode census_context_encode_import
-typedef census_context *(*census_context_decode_type)(const char *buffer, size_t size, const char *bin_buffer, size_t bin_size);
+typedef census_context *(*census_context_decode_type)(const char *buffer, size_t size);
extern census_context_decode_type census_context_decode_import;
#define census_context_decode census_context_decode_import
typedef int(*census_trace_mask_type)(const census_context *context);
@@ -610,6 +610,9 @@ extern gpr_ref_init_type gpr_ref_init_import;
typedef void(*gpr_ref_type)(gpr_refcount *r);
extern gpr_ref_type gpr_ref_import;
#define gpr_ref gpr_ref_import
+typedef void(*gpr_ref_non_zero_type)(gpr_refcount *r);
+extern gpr_ref_non_zero_type gpr_ref_non_zero_import;
+#define gpr_ref_non_zero gpr_ref_non_zero_import
typedef void(*gpr_refn_type)(gpr_refcount *r, int n);
extern gpr_refn_type gpr_refn_import;
#define gpr_refn gpr_refn_import
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