func testFailedEmptyUnary(t *testing.T, e env) { s, cc := setUp(math.MaxUint32, e) tc := testpb.NewTestServiceClient(cc) defer tearDown(s, cc) ctx := metadata.NewContext(context.Background(), testMetadata) if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != grpc.Errorf(codes.DataLoss, "got extra metadata") { t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", err, grpc.Errorf(codes.DataLoss, "got extra metadata")) } }
func testHealthCheckServingStatus(t *testing.T, e env) { hs := health.NewHealthServer() s, addr := serverSetUp(t, hs, math.MaxUint32, nil, nil, e) cc := clientSetUp(t, addr, nil, nil, "", e) defer tearDown(s, cc) out, err := healthCheck(1*time.Second, cc, "") if err != nil { t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err) } if out.Status != healthpb.HealthCheckResponse_SERVING { t.Fatalf("Got the serving status %v, want SERVING", out.Status) } if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.NotFound, "unknown service") { t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound) } hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_SERVING) out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health") if err != nil { t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err) } if out.Status != healthpb.HealthCheckResponse_SERVING { t.Fatalf("Got the serving status %v, want SERVING", out.Status) } hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_NOT_SERVING) out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health") if err != nil { t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err) } if out.Status != healthpb.HealthCheckResponse_NOT_SERVING { t.Fatalf("Got the serving status %v, want NOT_SERVING", out.Status) } }
func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error { if md, ok := metadata.FromContext(stream.Context()); ok { // For testing purpose, returns an error if there is attached metadata. if len(md) > 0 { return grpc.Errorf(codes.DataLoss, "got extra metadata") } } cs := args.GetResponseParameters() for _, c := range cs { if us := c.GetIntervalUs(); us > 0 { time.Sleep(time.Duration(us) * time.Microsecond) } payload, err := newPayload(args.GetResponseType(), c.GetSize()) if err != nil { return err } if err := stream.Send(&testpb.StreamingOutputCallResponse{ Payload: payload, }); err != nil { return err } } return nil }
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) { if _, ok := metadata.FromContext(ctx); ok { // For testing purpose, returns an error if there is attached metadata. return nil, grpc.Errorf(codes.DataLoss, "got extra metadata") } return new(testpb.Empty), nil }
func testHealthCheckOff(t *testing.T, e env) { s, addr := serverSetUp(t, nil, math.MaxUint32, nil, nil, e) cc := clientSetUp(t, addr, nil, nil, "", e) defer tearDown(s, cc) if _, err := healthCheck(1*time.Second, cc, ""); err != grpc.Errorf(codes.Unimplemented, "unknown service grpc.health.v1alpha.Health") { t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.Unimplemented) } }
func testHealthCheckOnFailure(t *testing.T, e env) { hs := health.NewHealthServer() hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", 1) s, addr := serverSetUp(t, hs, math.MaxUint32, nil, nil, e) cc := clientSetUp(t, addr, nil, nil, "", e) defer tearDown(s, cc) if _, err := healthCheck(0*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.DeadlineExceeded, "context deadline exceeded") { t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.DeadlineExceeded) } }
func togRPCError(err error) error { switch err { case storage.ErrCompacted: return ErrCompacted case storage.ErrFutureRev: return ErrFutureRev // TODO: handle error from raft and timeout default: return grpc.Errorf(codes.Unknown, err.Error()) } }
func (cs *ClusterServer) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { err := cs.server.RemoveMember(ctx, r.ID) switch { case err == etcdserver.ErrIDRemoved: fallthrough case err == etcdserver.ErrIDNotFound: return nil, ErrMemberNotFound case err != nil: return nil, grpc.Errorf(codes.Internal, err.Error()) } return &pb.MemberRemoveResponse{Header: cs.header()}, nil }
func togRPCError(err error) error { switch err { case storage.ErrCompacted: return ErrCompacted case storage.ErrFutureRev: return ErrFutureRev case lease.ErrLeaseNotFound: return ErrLeaseNotFound // TODO: handle error from raft and timeout default: return grpc.Errorf(codes.Internal, err.Error()) } }
func testFailedServerStreaming(t *testing.T, e env) { s, cc := setUp(math.MaxUint32, e) tc := testpb.NewTestServiceClient(cc) defer tearDown(s, cc) respParam := make([]*testpb.ResponseParameters, len(respSizes)) for i, s := range respSizes { respParam[i] = &testpb.ResponseParameters{ Size: proto.Int32(int32(s)), } } req := &testpb.StreamingOutputCallRequest{ ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(), ResponseParameters: respParam, } ctx := metadata.NewContext(context.Background(), testMetadata) stream, err := tc.StreamingOutputCall(ctx, req) if err != nil { t.Fatalf("%v.StreamingOutputCall(_) = _, %v, want <nil>", tc, err) } if _, err := stream.Recv(); err != grpc.Errorf(codes.DataLoss, "got extra metadata") { t.Fatalf("%v.Recv() = _, %v, want _, %v", stream, err, grpc.Errorf(codes.DataLoss, "got extra metadata")) } }
func togRPCError(err error) error { switch err { case storage.ErrCompacted: return rpctypes.ErrCompacted case storage.ErrFutureRev: return rpctypes.ErrFutureRev case lease.ErrLeaseNotFound: return rpctypes.ErrLeaseNotFound // TODO: handle error from raft and timeout case etcdserver.ErrRequestTooLarge: return rpctypes.ErrRequestTooLarge default: return grpc.Errorf(codes.Internal, err.Error()) } }
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) { if md, ok := metadata.FromContext(ctx); ok { // For testing purpose, returns an error if there is attached metadata other than // the user agent set by the client application. if _, ok := md["user-agent"]; !ok { return nil, grpc.Errorf(codes.DataLoss, "got extra metadata") } var str []string for _, entry := range md["user-agent"] { str = append(str, "ua", entry) } grpc.SendHeader(ctx, metadata.Pairs(str...)) } return new(testpb.Empty), nil }
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { s.mu.Lock() defer s.mu.Unlock() if in.Service == "" { // check the server overall health status. return &healthpb.HealthCheckResponse{ Status: healthpb.HealthCheckResponse_SERVING, }, nil } if status, ok := s.statusMap[in.Service]; ok { return &healthpb.HealthCheckResponse{ Status: status, }, nil } return nil, grpc.Errorf(codes.NotFound, "unknown service") }
func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { m := etcdserver.Member{ ID: types.ID(r.ID), RaftAttributes: etcdserver.RaftAttributes{PeerURLs: r.PeerURLs}, } err := cs.server.UpdateMember(ctx, m) switch { case err == etcdserver.ErrPeerURLexists: return nil, ErrPeerURLExist case err == etcdserver.ErrIDNotFound: return nil, ErrMemberNotFound case err != nil: return nil, grpc.Errorf(codes.Internal, err.Error()) } return &pb.MemberUpdateResponse{Header: cs.header()}, nil }
func (cs *ClusterServer) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { urls, err := types.NewURLs(r.PeerURLs) if err != nil { return nil, ErrMemberBadURLs } now := time.Now() m := etcdserver.NewMember("", urls, "", &now) err = cs.server.AddMember(ctx, *m) switch { case err == etcdserver.ErrIDExists: return nil, ErrMemberExist case err == etcdserver.ErrPeerURLexists: return nil, ErrPeerURLExist case err != nil: return nil, grpc.Errorf(codes.Internal, err.Error()) } return &pb.MemberAddResponse{ Header: cs.header(), Member: &pb.Member{ID: uint64(m.ID), IsLeader: m.ID == cs.server.Leader(), PeerURLs: m.PeerURLs}, }, nil }
// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package v3rpc import ( "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc" "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/codes" "github.com/coreos/etcd/storage" ) var ( ErrEmptyKey = grpc.Errorf(codes.InvalidArgument, "key is not provided") ErrTooManyOps = grpc.Errorf(codes.InvalidArgument, "too many operations in txn request") ErrDuplicateKey = grpc.Errorf(codes.InvalidArgument, "duplicate key given in txn request") ErrCompacted = grpc.Errorf(codes.OutOfRange, storage.ErrCompacted.Error()) ErrFutureRev = grpc.Errorf(codes.OutOfRange, storage.ErrFutureRev.Error()) ErrLeaseNotFound = grpc.Errorf(codes.NotFound, "requested lease not found") ErrLeaseExist = grpc.Errorf(codes.FailedPrecondition, "lease already exists") ErrMemberExist = grpc.Errorf(codes.FailedPrecondition, "member ID already exist") ErrPeerURLExist = grpc.Errorf(codes.FailedPrecondition, "Peer URLs already exists") ErrMemberBadURLs = grpc.Errorf(codes.InvalidArgument, "given member URLs are invalid") ErrMemberNotFound = grpc.Errorf(codes.NotFound, "member not found") )
// Copyright 2015 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package v3rpc import ( "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc" "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/codes" "github.com/coreos/etcd/storage" ) var ( ErrEmptyKey = grpc.Errorf(codes.InvalidArgument, "key is not provided") ErrTooManyOps = grpc.Errorf(codes.InvalidArgument, "too many operations in txn request") ErrCompacted = grpc.Errorf(codes.OutOfRange, storage.ErrCompacted.Error()) ErrFutureRev = grpc.Errorf(codes.OutOfRange, storage.ErrFutureRev.Error()) ErrLeaseNotFound = grpc.Errorf(codes.NotFound, "requested lease not found") )
// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package rpctypes import ( "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc" "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/codes" ) var ( ErrEmptyKey = grpc.Errorf(codes.InvalidArgument, "etcdserver: key is not provided") ErrTooManyOps = grpc.Errorf(codes.InvalidArgument, "etcdserver: too many operations in txn request") ErrDuplicateKey = grpc.Errorf(codes.InvalidArgument, "etcdserver: duplicate key given in txn request") ErrCompacted = grpc.Errorf(codes.OutOfRange, "etcdserver: storage: required revision has been compacted") ErrFutureRev = grpc.Errorf(codes.OutOfRange, "etcdserver: storage: required revision is a future revision") ErrLeaseNotFound = grpc.Errorf(codes.NotFound, "etcdserver: requested lease not found") ErrLeaseExist = grpc.Errorf(codes.FailedPrecondition, "etcdserver: lease already exists") ErrMemberExist = grpc.Errorf(codes.FailedPrecondition, "etcdserver: member ID already exist") ErrPeerURLExist = grpc.Errorf(codes.FailedPrecondition, "etcdserver: Peer URLs already exists") ErrMemberBadURLs = grpc.Errorf(codes.InvalidArgument, "etcdserver: given member URLs are invalid") ErrMemberNotFound = grpc.Errorf(codes.NotFound, "etcdserver: member not found") ErrRequestTooLarge = grpc.Errorf(codes.InvalidArgument, "etcdserver: request is too large") )
// Copyright 2015 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package v3rpc import ( "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc" "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/codes" "github.com/coreos/etcd/storage" ) var ( ErrEmptyKey = grpc.Errorf(codes.InvalidArgument, "key is not provided") ErrCompacted = grpc.Errorf(codes.OutOfRange, storage.ErrCompacted.Error()) ErrFutureRev = grpc.Errorf(codes.OutOfRange, storage.ErrFutureRev.Error()) )