diff --git a/doc/health-checking.md b/doc/health-checking.md index 0b3f9c6a034c43e45859086b5a39d3acb12ab370..92512e942bd90f7d03bd1f3e6db4f48795f0a959 100644 --- a/doc/health-checking.md +++ b/doc/health-checking.md @@ -26,7 +26,7 @@ The server should export a service defined in the following proto: ``` syntax = "proto3"; -package grpc.health.v1alpha; +package grpc.health.v1; message HealthCheckRequest { string service = 1; @@ -49,7 +49,7 @@ service Health { A client can query the server’s health status by calling the `Check` method, and a deadline should be set on the rpc. The client can optionally set the service name it wants to query for health status. The suggested format of service name -is `package_names.ServiceName`, such as `grpc.health.v1alpha.Health`. +is `package_names.ServiceName`, such as `grpc.health.v1.Health`. The server should register all the services manually and set the individual status, including an empty service name and its status. For each diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs index a8a76c749229468a56bd246d39ca2c7cdc19e087..c3fac05324c8245694c425eb88cab306dcc7f641 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs +++ b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs @@ -36,7 +36,7 @@ using System.Text; using System.Threading.Tasks; using Grpc.Core; -using Grpc.Health.V1Alpha; +using Grpc.Health.V1; using NUnit.Framework; namespace Grpc.HealthCheck.Tests @@ -49,7 +49,7 @@ namespace Grpc.HealthCheck.Tests const string Host = "localhost"; Server server; Channel channel; - Grpc.Health.V1Alpha.Health.IHealthClient client; + Grpc.Health.V1.Health.IHealthClient client; Grpc.HealthCheck.HealthServiceImpl serviceImpl; [TestFixtureSetUp] @@ -59,13 +59,13 @@ namespace Grpc.HealthCheck.Tests server = new Server { - Services = { Grpc.Health.V1Alpha.Health.BindService(serviceImpl) }, + Services = { Grpc.Health.V1.Health.BindService(serviceImpl) }, Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } } }; server.Start(); channel = new Channel(Host, server.Ports.Single().BoundPort, ChannelCredentials.Insecure); - client = Grpc.Health.V1Alpha.Health.NewClient(channel); + client = Grpc.Health.V1.Health.NewClient(channel); } [TestFixtureTearDown] @@ -79,16 +79,16 @@ namespace Grpc.HealthCheck.Tests [Test] public void ServiceIsRunning() { - serviceImpl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING); + serviceImpl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING); - var response = client.Check(new HealthCheckRequest { Host = "", Service = "" }); + var response = client.Check(new HealthCheckRequest { Service = "" }); Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, response.Status); } [Test] public void ServiceDoesntExist() { - Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Host = "", Service = "nonexistent.service" })); + Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Service = "nonexistent.service" })); } // TODO(jtattermusch): add test with timeout once timeouts are supported diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs index 2097c0dc8cf7daa2c79f72a4706299af0ee76d0d..47e4b7c2a70194bb84232f42db9588756c6dffca 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs +++ b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs @@ -1,5 +1,5 @@ #region Copyright notice and license -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ using System.Text; using System.Threading.Tasks; using Grpc.Core; -using Grpc.Health.V1Alpha; +using Grpc.Health.V1; using NUnit.Framework; namespace Grpc.HealthCheck.Tests @@ -50,58 +50,56 @@ namespace Grpc.HealthCheck.Tests public void SetStatus() { var impl = new HealthServiceImpl(); - impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING); - Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "", "")); + impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING); + Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "")); - impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.NOT_SERVING); - Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, "", "")); + impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.NOT_SERVING); + Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, "")); - impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN); - Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", "")); + impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.UNKNOWN); + Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "")); - impl.SetStatus("virtual-host", "grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING); - Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "virtual-host", "grpc.test.TestService")); + impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING); + Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "grpc.test.TestService")); } [Test] public void ClearStatus() { var impl = new HealthServiceImpl(); - impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING); - impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN); + impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING); + impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN); - impl.ClearStatus("", ""); + impl.ClearStatus(""); - Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, "", "")); - Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", "")); + Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, "")); + Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "grpc.test.TestService")); } [Test] public void ClearAll() { var impl = new HealthServiceImpl(); - impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING); - impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN); + impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING); + impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN); impl.ClearAll(); - Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "", "")); - Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "virtual-host", "")); + Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "")); + Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "grpc.test.TestService")); } [Test] public void NullsRejected() { var impl = new HealthServiceImpl(); - Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, "", HealthCheckResponse.Types.ServingStatus.SERVING)); - Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus("", null, HealthCheckResponse.Types.ServingStatus.SERVING)); + Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, HealthCheckResponse.Types.ServingStatus.SERVING)); - Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null, "")); - Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus("", null)); + Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null)); } - private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string host, string service) + private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string service) { - return impl.Check(new HealthCheckRequest { Host = host, Service = service }, null).Result.Status; + return impl.Check(new HealthCheckRequest { Service = service }, null).Result.Status; } } } diff --git a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec index 66386288df132f448b0dee70305b15ae41e0c824..7b3b391009eb05ca1ba9a85aceec8b829d22939b 100644 --- a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec +++ b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec @@ -4,7 +4,7 @@ <id>Grpc.HealthCheck</id> <title>gRPC C# Healthchecking</title> <summary>Implementation of gRPC health service</summary> - <description>Example implementation of grpc.health.v1alpha service that can be used for health-checking.</description> + <description>Example implementation of grpc.health.v1 service that can be used for health-checking.</description> <version>$version$</version> <authors>Google Inc.</authors> <owners>grpc-packages</owners> diff --git a/src/csharp/Grpc.HealthCheck/Health.cs b/src/csharp/Grpc.HealthCheck/Health.cs index 56673f1adf699bef3998cae252799bcbe7d3bfe5..d0d0c0b519665376069e283e7ae90f347c4b127a 100644 --- a/src/csharp/Grpc.HealthCheck/Health.cs +++ b/src/csharp/Grpc.HealthCheck/Health.cs @@ -7,7 +7,7 @@ using pb = global::Google.Protobuf; using pbc = global::Google.Protobuf.Collections; using pbr = global::Google.Protobuf.Reflection; using scg = global::System.Collections.Generic; -namespace Grpc.Health.V1Alpha { +namespace Grpc.Health.V1 { /// <summary>Holder for reflection information generated from health.proto</summary> [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -23,20 +23,19 @@ namespace Grpc.Health.V1Alpha { static HealthReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "CgxoZWFsdGgucHJvdG8SE2dycGMuaGVhbHRoLnYxYWxwaGEiMwoSSGVhbHRo", - "Q2hlY2tSZXF1ZXN0EgwKBGhvc3QYASABKAkSDwoHc2VydmljZRgCIAEoCSKZ", - "AQoTSGVhbHRoQ2hlY2tSZXNwb25zZRJGCgZzdGF0dXMYASABKA4yNi5ncnBj", - "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVzcG9uc2UuU2VydmluZ1N0", - "YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsKB1VOS05PV04QABILCgdTRVJWSU5H", - "EAESDwoLTk9UX1NFUlZJTkcQAjJkCgZIZWFsdGgSWgoFQ2hlY2sSJy5ncnBj", - "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVxdWVzdBooLmdycGMuaGVh", - "bHRoLnYxYWxwaGEuSGVhbHRoQ2hlY2tSZXNwb25zZUIWqgITR3JwYy5IZWFs", - "dGguVjFBbHBoYWIGcHJvdG8z")); + "CgxoZWFsdGgucHJvdG8SDmdycGMuaGVhbHRoLnYxIiUKEkhlYWx0aENoZWNr", + "UmVxdWVzdBIPCgdzZXJ2aWNlGAEgASgJIpQBChNIZWFsdGhDaGVja1Jlc3Bv", + "bnNlEkEKBnN0YXR1cxgBIAEoDjIxLmdycGMuaGVhbHRoLnYxLkhlYWx0aENo", + "ZWNrUmVzcG9uc2UuU2VydmluZ1N0YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsK", + "B1VOS05PV04QABILCgdTRVJWSU5HEAESDwoLTk9UX1NFUlZJTkcQAjJaCgZI", + "ZWFsdGgSUAoFQ2hlY2sSIi5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jl", + "cXVlc3QaIy5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jlc3BvbnNlQhGq", + "Ag5HcnBjLkhlYWx0aC5WMWIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] { - new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckRequest), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser, new[]{ "Host", "Service" }, null, null, null), - new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) }, null) + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckRequest), global::Grpc.Health.V1.HealthCheckRequest.Parser, new[]{ "Service" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckResponse), global::Grpc.Health.V1.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) }, null) })); } #endregion @@ -49,7 +48,7 @@ namespace Grpc.Health.V1Alpha { public static pb::MessageParser<HealthCheckRequest> Parser { get { return _parser; } } public static pbr::MessageDescriptor Descriptor { - get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[0]; } + get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[0]; } } pbr::MessageDescriptor pb::IMessage.Descriptor { @@ -63,7 +62,6 @@ namespace Grpc.Health.V1Alpha { partial void OnConstruction(); public HealthCheckRequest(HealthCheckRequest other) : this() { - host_ = other.host_; service_ = other.service_; } @@ -71,18 +69,8 @@ namespace Grpc.Health.V1Alpha { return new HealthCheckRequest(this); } - /// <summary>Field number for the "host" field.</summary> - public const int HostFieldNumber = 1; - private string host_ = ""; - public string Host { - get { return host_; } - set { - host_ = pb::Preconditions.CheckNotNull(value, "value"); - } - } - /// <summary>Field number for the "service" field.</summary> - public const int ServiceFieldNumber = 2; + public const int ServiceFieldNumber = 1; private string service_ = ""; public string Service { get { return service_; } @@ -102,14 +90,12 @@ namespace Grpc.Health.V1Alpha { if (ReferenceEquals(other, this)) { return true; } - if (Host != other.Host) return false; if (Service != other.Service) return false; return true; } public override int GetHashCode() { int hash = 1; - if (Host.Length != 0) hash ^= Host.GetHashCode(); if (Service.Length != 0) hash ^= Service.GetHashCode(); return hash; } @@ -119,21 +105,14 @@ namespace Grpc.Health.V1Alpha { } public void WriteTo(pb::CodedOutputStream output) { - if (Host.Length != 0) { - output.WriteRawTag(10); - output.WriteString(Host); - } if (Service.Length != 0) { - output.WriteRawTag(18); + output.WriteRawTag(10); output.WriteString(Service); } } public int CalculateSize() { int size = 0; - if (Host.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Host); - } if (Service.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Service); } @@ -144,9 +123,6 @@ namespace Grpc.Health.V1Alpha { if (other == null) { return; } - if (other.Host.Length != 0) { - Host = other.Host; - } if (other.Service.Length != 0) { Service = other.Service; } @@ -160,10 +136,6 @@ namespace Grpc.Health.V1Alpha { input.SkipLastField(); break; case 10: { - Host = input.ReadString(); - break; - } - case 18: { Service = input.ReadString(); break; } @@ -179,7 +151,7 @@ namespace Grpc.Health.V1Alpha { public static pb::MessageParser<HealthCheckResponse> Parser { get { return _parser; } } public static pbr::MessageDescriptor Descriptor { - get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[1]; } + get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[1]; } } pbr::MessageDescriptor pb::IMessage.Descriptor { @@ -202,8 +174,8 @@ namespace Grpc.Health.V1Alpha { /// <summary>Field number for the "status" field.</summary> public const int StatusFieldNumber = 1; - private global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN; - public global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus Status { + private global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN; + public global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus Status { get { return status_; } set { status_ = value; @@ -227,7 +199,7 @@ namespace Grpc.Health.V1Alpha { public override int GetHashCode() { int hash = 1; - if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode(); + if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode(); return hash; } @@ -236,7 +208,7 @@ namespace Grpc.Health.V1Alpha { } public void WriteTo(pb::CodedOutputStream output) { - if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { + if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { output.WriteRawTag(8); output.WriteEnum((int) Status); } @@ -244,7 +216,7 @@ namespace Grpc.Health.V1Alpha { public int CalculateSize() { int size = 0; - if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { + if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status); } return size; @@ -254,7 +226,7 @@ namespace Grpc.Health.V1Alpha { if (other == null) { return; } - if (other.Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { + if (other.Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) { Status = other.Status; } } @@ -267,7 +239,7 @@ namespace Grpc.Health.V1Alpha { input.SkipLastField(); break; case 8: { - status_ = (global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) input.ReadEnum(); + status_ = (global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) input.ReadEnum(); break; } } diff --git a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs index 882edd56270b6fbb2173c5b6cfcf058a3dd7e8df..68320eb5c2effa410693eec82851005105a854b7 100644 --- a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs +++ b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs @@ -7,15 +7,15 @@ using System.Threading; using System.Threading.Tasks; using Grpc.Core; -namespace Grpc.Health.V1Alpha { +namespace Grpc.Health.V1 { public static class Health { - static readonly string __ServiceName = "grpc.health.v1alpha.Health"; + static readonly string __ServiceName = "grpc.health.v1.Health"; - static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser.ParseFrom); - static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser.ParseFrom); + static readonly Marshaller<global::Grpc.Health.V1.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckRequest.Parser.ParseFrom); + static readonly Marshaller<global::Grpc.Health.V1.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckResponse.Parser.ParseFrom); - static readonly Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse>( + static readonly Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse>( MethodType.Unary, __ServiceName, "Check", @@ -25,22 +25,22 @@ namespace Grpc.Health.V1Alpha { // service descriptor public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor { - get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.Services[0]; } + get { return global::Grpc.Health.V1.HealthReflection.Descriptor.Services[0]; } } // client interface public interface IHealthClient { - global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); - global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options); - AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); - AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options); + global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options); + AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options); } // server-side interface public interface IHealth { - Task<global::Grpc.Health.V1Alpha.HealthCheckResponse> Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, ServerCallContext context); + Task<global::Grpc.Health.V1.HealthCheckResponse> Check(global::Grpc.Health.V1.HealthCheckRequest request, ServerCallContext context); } // client stub @@ -49,22 +49,22 @@ namespace Grpc.Health.V1Alpha { public HealthClient(Channel channel) : base(channel) { } - public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + public global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) { var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken)); return Calls.BlockingUnaryCall(call, request); } - public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options) + public global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options) { var call = CreateCall(__Method_Check, options); return Calls.BlockingUnaryCall(call, request); } - public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + public AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) { var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken)); return Calls.AsyncUnaryCall(call, request); } - public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options) + public AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options) { var call = CreateCall(__Method_Check, options); return Calls.AsyncUnaryCall(call, request); diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs index e2ad1a834bfd57c9943c369e8c7dd91e476f5802..21482b302b4dcc1659e5ea33cb2d08e52f0e1412 100644 --- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs +++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs @@ -37,7 +37,7 @@ using System.Threading.Tasks; using Grpc.Core; using Grpc.Core.Utils; -using Grpc.Health.V1Alpha; +using Grpc.Health.V1; namespace Grpc.HealthCheck { @@ -48,44 +48,42 @@ namespace Grpc.HealthCheck /// <code> /// var serviceImpl = new HealthServiceImpl(); /// server = new Server(); - /// server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl)); + /// server.AddServiceDefinition(Grpc.Health.V1.Health.BindService(serviceImpl)); /// </code> /// </summary> - public class HealthServiceImpl : Grpc.Health.V1Alpha.Health.IHealth + public class HealthServiceImpl : Grpc.Health.V1.Health.IHealth { private readonly object myLock = new object(); - private readonly Dictionary<Key, HealthCheckResponse.Types.ServingStatus> statusMap = - new Dictionary<Key, HealthCheckResponse.Types.ServingStatus>(); + private readonly Dictionary<string, HealthCheckResponse.Types.ServingStatus> statusMap = + new Dictionary<string, HealthCheckResponse.Types.ServingStatus>(); /// <summary> - /// Sets the health status for given host and service. + /// Sets the health status for given service. /// </summary> - /// <param name="host">The host. Cannot be null.</param> /// <param name="service">The service. Cannot be null.</param> /// <param name="status">the health status</param> - public void SetStatus(string host, string service, HealthCheckResponse.Types.ServingStatus status) + public void SetStatus(string service, HealthCheckResponse.Types.ServingStatus status) { lock (myLock) { - statusMap[CreateKey(host, service)] = status; + statusMap[service] = status; } } /// <summary> - /// Clears health status for given host and service. + /// Clears health status for given service. /// </summary> - /// <param name="host">The host. Cannot be null.</param> /// <param name="service">The service. Cannot be null.</param> - public void ClearStatus(string host, string service) + public void ClearStatus(string service) { lock (myLock) { - statusMap.Remove(CreateKey(host, service)); + statusMap.Remove(service); } } /// <summary> - /// Clears statuses for all hosts and services. + /// Clears statuses for all services. /// </summary> public void ClearAll() { @@ -105,11 +103,10 @@ namespace Grpc.HealthCheck { lock (myLock) { - var host = request.Host; var service = request.Service; HealthCheckResponse.Types.ServingStatus status; - if (!statusMap.TryGetValue(CreateKey(host, service), out status)) + if (!statusMap.TryGetValue(service, out status)) { // TODO(jtattermusch): returning specific status from server handler is not supported yet. throw new RpcException(new Status(StatusCode.NotFound, "")); @@ -117,22 +114,5 @@ namespace Grpc.HealthCheck return Task.FromResult(new HealthCheckResponse { Status = status }); } } - - private static Key CreateKey(string host, string service) - { - return new Key(host, service); - } - - private struct Key - { - public Key(string host, string service) - { - this.Host = GrpcPreconditions.CheckNotNull(host); - this.Service = GrpcPreconditions.CheckNotNull(service); - } - - readonly string Host; - readonly string Service; - } } } diff --git a/src/csharp/generate_proto_csharp.sh b/src/csharp/generate_proto_csharp.sh index 0261a458af730dd3996a21e9f10d3e346fa68791..23e0540253a3ec226619959dbc8000a3bba741a1 100755 --- a/src/csharp/generate_proto_csharp.sh +++ b/src/csharp/generate_proto_csharp.sh @@ -42,7 +42,7 @@ $PROTOC --plugin=$PLUGIN --csharp_out=$EXAMPLES_DIR --grpc_out=$EXAMPLES_DIR \ -I src/proto/math src/proto/math/math.proto $PROTOC --plugin=$PLUGIN --csharp_out=$HEALTHCHECK_DIR --grpc_out=$HEALTHCHECK_DIR \ - -I src/proto/grpc/health/v1alpha src/proto/grpc/health/v1alpha/health.proto + -I src/proto/grpc/health/v1 src/proto/grpc/health/v1/health.proto $PROTOC --plugin=$PLUGIN --csharp_out=$TESTING_DIR --grpc_out=$TESTING_DIR \ -I . src/proto/grpc/testing/{control,empty,messages,payloads,services,stats,test}.proto diff --git a/src/node/health_check/health.js b/src/node/health_check/health.js index 1a2c0366875701b6b57cf52e0bbfabaf9137f2a2..6ab41571831b803f372fd7f32fd78a972d1ec2a3 100644 --- a/src/node/health_check/health.js +++ b/src/node/health_check/health.js @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,9 +38,9 @@ var grpc = require('../'); var _ = require('lodash'); var health_proto = grpc.load(__dirname + - '/../../proto/grpc/health/v1alpha/health.proto'); + '/../../proto/grpc/health/v1/health.proto'); -var HealthClient = health_proto.grpc.health.v1alpha.Health; +var HealthClient = health_proto.grpc.health.v1.Health; function HealthImplementation(statusMap) { this.statusMap = _.clone(statusMap); diff --git a/src/proto/grpc/health/v1alpha/health.proto b/src/proto/grpc/health/v1/health.proto similarity index 93% rename from src/proto/grpc/health/v1alpha/health.proto rename to src/proto/grpc/health/v1/health.proto index 05f837dd9904ad7f9ea043abe59e1866dec7a99d..6e27606d1b6fdb4f3e658e0ff4b07d21f1bbc017 100644 --- a/src/proto/grpc/health/v1alpha/health.proto +++ b/src/proto/grpc/health/v1/health.proto @@ -29,12 +29,11 @@ syntax = "proto3"; -package grpc.health.v1alpha; -option csharp_namespace = "Grpc.Health.V1Alpha"; +package grpc.health.v1; +option csharp_namespace = "Grpc.Health.V1"; message HealthCheckRequest { - string host = 1; - string service = 2; + string service = 1; } message HealthCheckResponse { diff --git a/src/python/grpcio_health_checking/grpc/health/v1alpha/__init__.py b/src/python/grpcio_health_checking/grpc/health/v1/__init__.py similarity index 97% rename from src/python/grpcio_health_checking/grpc/health/v1alpha/__init__.py rename to src/python/grpcio_health_checking/grpc/health/v1/__init__.py index 708651910607ffb686d781713f6893567821b9fd..13aac79160b8db0fd6863590a4d044464b72dbcc 100644 --- a/src/python/grpcio_health_checking/grpc/health/v1alpha/__init__.py +++ b/src/python/grpcio_health_checking/grpc/health/v1/__init__.py @@ -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 diff --git a/src/python/grpcio_health_checking/grpc/health/v1alpha/health.proto b/src/python/grpcio_health_checking/grpc/health/v1/health.proto similarity index 96% rename from src/python/grpcio_health_checking/grpc/health/v1alpha/health.proto rename to src/python/grpcio_health_checking/grpc/health/v1/health.proto index 57f4aaa9c08d9bbc81aa755cf6b0b3efb76d8adb..de10719b6ced765117e2a4c5672af8a010fa2bd3 100644 --- a/src/python/grpcio_health_checking/grpc/health/v1alpha/health.proto +++ b/src/python/grpcio_health_checking/grpc/health/v1/health.proto @@ -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 @@ -29,7 +29,7 @@ syntax = "proto3"; -package grpc.health.v1alpha; +package grpc.health.v1; message HealthCheckRequest { string service = 1; diff --git a/src/python/grpcio_health_checking/grpc/health/v1alpha/health.py b/src/python/grpcio_health_checking/grpc/health/v1/health.py similarity index 96% rename from src/python/grpcio_health_checking/grpc/health/v1alpha/health.py rename to src/python/grpcio_health_checking/grpc/health/v1/health.py index 9dfcd962f06142a6f6f85dee8dde2338635d4c58..60cbd644330b2ac48126fed40c58768de087c007 100644 --- a/src/python/grpcio_health_checking/grpc/health/v1alpha/health.py +++ b/src/python/grpcio_health_checking/grpc/health/v1/health.py @@ -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 @@ -33,7 +33,7 @@ import abc import enum import threading -from grpc.health.v1alpha import health_pb2 +from grpc.health.v1 import health_pb2 @enum.unique @@ -64,7 +64,7 @@ class _HealthServicer(health_pb2.EarlyAdopterHealthServicer): def set(service, status): if not isinstance(status, HealthStatus): - raise TypeError('expected grpc.health.v1alpha.health.HealthStatus ' + raise TypeError('expected grpc.health.v1.health.HealthStatus ' 'for argument `status` but got {}'.format(status)) with self._server_status_lock: self._server_status[service] = status diff --git a/src/ruby/.rubocop.yml b/src/ruby/.rubocop.yml index dd57ab60828bc0bf6902ae6ef571992feb4f957d..ff5cf8db83190a6fab07d6c37cbf4f626a2fb29e 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 e04aef185caaa51720922dbd73e02c82da147450..d9e30bbc854434947bb9560d4115d448170ef64a 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 576b1c08d300f0a1bf97388a38ae71e18b91524f..86c082099d98304859e4ab55f5a6512b0116f8ab 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 8c692e74f900bbc78b15685e4df41274f358a8ba..9f1ee65c41935164c322cde79e7412265010df0e 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 0000000000000000000000000000000000000000..aa87a93918b123f6af2f91f58fc7f004b91481b0 --- /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 similarity index 71% rename from src/ruby/pb/grpc/health/v1alpha/health_services.rb rename to src/ruby/pb/grpc/health/v1/health_services.rb index d5cba2e9ec71c22555c3ebb7c4f739e6bb3c6ed8..cb79b20437f573b40f9c3f6265eec722db4e87c7 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 9c04298ea54394cda76b9953b15bfae08755f8ce..0000000000000000000000000000000000000000 --- 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 c1decd822a76062a58ea9dda0e83a18ec7776590..9bb79bb4cae057c8a5ebab92467570d570076e2d 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