Merge pull request #348 from iamqizhao/master

update health check to the latest version
This commit is contained in:
Qi Zhao
2015-09-17 14:42:36 -07:00
3 changed files with 40 additions and 36 deletions

View File

@ -15,6 +15,8 @@ It has these top-level messages:
package grpc_health_v1alpha package grpc_health_v1alpha
import proto "github.com/golang/protobuf/proto" import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import ( import (
context "golang.org/x/net/context" context "golang.org/x/net/context"
@ -23,6 +25,8 @@ import (
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type HealthCheckResponse_ServingStatus int32 type HealthCheckResponse_ServingStatus int32
@ -71,58 +75,58 @@ func init() {
var _ context.Context var _ context.Context
var _ grpc.ClientConn var _ grpc.ClientConn
// Client API for HealthCheck service // Client API for Health service
type HealthCheckClient interface { type HealthClient interface {
Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error)
} }
type healthCheckClient struct { type healthClient struct {
cc *grpc.ClientConn cc *grpc.ClientConn
} }
func NewHealthCheckClient(cc *grpc.ClientConn) HealthCheckClient { func NewHealthClient(cc *grpc.ClientConn) HealthClient {
return &healthCheckClient{cc} return &healthClient{cc}
} }
func (c *healthCheckClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) { func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) {
out := new(HealthCheckResponse) out := new(HealthCheckResponse)
err := grpc.Invoke(ctx, "/grpc.health.v1alpha.HealthCheck/Check", in, out, c.cc, opts...) err := grpc.Invoke(ctx, "/grpc.health.v1alpha.Health/Check", in, out, c.cc, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
// Server API for HealthCheck service // Server API for Health service
type HealthCheckServer interface { type HealthServer interface {
Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error)
} }
func RegisterHealthCheckServer(s *grpc.Server, srv HealthCheckServer) { func RegisterHealthServer(s *grpc.Server, srv HealthServer) {
s.RegisterService(&_HealthCheck_serviceDesc, srv) s.RegisterService(&_Health_serviceDesc, srv)
} }
func _HealthCheck_Check_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { func _Health_Check_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) {
in := new(HealthCheckRequest) in := new(HealthCheckRequest)
if err := codec.Unmarshal(buf, in); err != nil { if err := codec.Unmarshal(buf, in); err != nil {
return nil, err return nil, err
} }
out, err := srv.(HealthCheckServer).Check(ctx, in) out, err := srv.(HealthServer).Check(ctx, in)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
var _HealthCheck_serviceDesc = grpc.ServiceDesc{ var _Health_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpc.health.v1alpha.HealthCheck", ServiceName: "grpc.health.v1alpha.Health",
HandlerType: (*HealthCheckServer)(nil), HandlerType: (*HealthServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "Check", MethodName: "Check",
Handler: _HealthCheck_Check_Handler, Handler: _Health_Check_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},

View File

@ -15,6 +15,6 @@ message HealthCheckResponse {
ServingStatus status = 1; ServingStatus status = 1;
} }
service HealthCheck{ service Health{
rpc Check(HealthCheckRequest) returns (HealthCheckResponse); rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
} }

View File

@ -384,7 +384,7 @@ func setUp(t *testing.T, hs *health.HealthServer, maxStream uint32, ua string, e
} }
s = grpc.NewServer(sopts...) s = grpc.NewServer(sopts...)
if hs != nil { if hs != nil {
healthpb.RegisterHealthCheckServer(s, hs) healthpb.RegisterHealthServer(s, hs)
} }
testpb.RegisterTestServiceServer(s, &testServer{security: e.security}) testpb.RegisterTestServiceServer(s, &testServer{security: e.security})
go s.Serve(lis) go s.Serve(lis)
@ -459,7 +459,7 @@ func testTimeoutOnDeadServer(t *testing.T, e env) {
func healthCheck(t time.Duration, cc *grpc.ClientConn, serviceName string) (*healthpb.HealthCheckResponse, error) { func healthCheck(t time.Duration, cc *grpc.ClientConn, serviceName string) (*healthpb.HealthCheckResponse, error) {
ctx, _ := context.WithTimeout(context.Background(), t) ctx, _ := context.WithTimeout(context.Background(), t)
hc := healthpb.NewHealthCheckClient(cc) hc := healthpb.NewHealthClient(cc)
req := &healthpb.HealthCheckRequest{ req := &healthpb.HealthCheckRequest{
Service: serviceName, Service: serviceName,
} }
@ -474,11 +474,11 @@ func TestHealthCheckOnSuccess(t *testing.T) {
func testHealthCheckOnSuccess(t *testing.T, e env) { func testHealthCheckOnSuccess(t *testing.T, e env) {
hs := health.NewHealthServer() hs := health.NewHealthServer()
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", 1) hs.SetServingStatus("grpc.health.v1alpha.Health", 1)
s, cc := setUp(t, hs, math.MaxUint32, "", e) s, cc := setUp(t, hs, math.MaxUint32, "", e)
defer tearDown(s, cc) defer tearDown(s, cc)
if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != nil { if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health"); err != nil {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err) t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
} }
} }
@ -493,8 +493,8 @@ func testHealthCheckOnFailure(t *testing.T, e env) {
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", 1) hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", 1)
s, cc := setUp(t, hs, math.MaxUint32, "", e) s, cc := setUp(t, hs, math.MaxUint32, "", e)
defer tearDown(s, cc) defer tearDown(s, cc)
if _, err := healthCheck(0*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != grpc.Errorf(codes.DeadlineExceeded, "context deadline exceeded") { if _, err := healthCheck(0*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.DeadlineExceeded, "context deadline exceeded") {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.DeadlineExceeded) t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.DeadlineExceeded)
} }
} }
@ -507,8 +507,8 @@ func TestHealthCheckOff(t *testing.T) {
func testHealthCheckOff(t *testing.T, e env) { func testHealthCheckOff(t *testing.T, e env) {
s, cc := setUp(t, nil, math.MaxUint32, "", e) s, cc := setUp(t, nil, math.MaxUint32, "", e)
defer tearDown(s, cc) defer tearDown(s, cc)
if _, err := healthCheck(1*time.Second, cc, ""); err != grpc.Errorf(codes.Unimplemented, "unknown service grpc.health.v1alpha.HealthCheck") { if _, err := healthCheck(1*time.Second, cc, ""); err != grpc.Errorf(codes.Unimplemented, "unknown service grpc.health.v1alpha.Health") {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.Unimplemented) t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.Unimplemented)
} }
} }
@ -524,26 +524,26 @@ func testHealthCheckServingStatus(t *testing.T, e env) {
defer tearDown(s, cc) defer tearDown(s, cc)
out, err := healthCheck(1*time.Second, cc, "") out, err := healthCheck(1*time.Second, cc, "")
if err != nil { if err != nil {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err) t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
} }
if out.Status != healthpb.HealthCheckResponse_SERVING { if out.Status != healthpb.HealthCheckResponse_SERVING {
t.Fatalf("Got the serving status %v, want SERVING", out.Status) t.Fatalf("Got the serving status %v, want SERVING", out.Status)
} }
if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != grpc.Errorf(codes.NotFound, "unknown service") { if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.NotFound, "unknown service") {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound) t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound)
} }
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", healthpb.HealthCheckResponse_SERVING) hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_SERVING)
out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck") out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health")
if err != nil { if err != nil {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err) t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
} }
if out.Status != healthpb.HealthCheckResponse_SERVING { if out.Status != healthpb.HealthCheckResponse_SERVING {
t.Fatalf("Got the serving status %v, want SERVING", out.Status) t.Fatalf("Got the serving status %v, want SERVING", out.Status)
} }
hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", healthpb.HealthCheckResponse_NOT_SERVING) hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_NOT_SERVING)
out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck") out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health")
if err != nil { if err != nil {
t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, <nil>", err) t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
} }
if out.Status != healthpb.HealthCheckResponse_NOT_SERVING { if out.Status != healthpb.HealthCheckResponse_NOT_SERVING {
t.Fatalf("Got the serving status %v, want NOT_SERVING", out.Status) t.Fatalf("Got the serving status %v, want NOT_SERVING", out.Status)