diff --git a/clientv3/integration/client_test.go b/clientv3/integration/kv_test.go similarity index 100% rename from clientv3/integration/client_test.go rename to clientv3/integration/kv_test.go diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go new file mode 100644 index 000000000..c44fafcbd --- /dev/null +++ b/clientv3/integration/lease_test.go @@ -0,0 +1,75 @@ +// Copyright 2016 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 integration + +import ( + "testing" + + "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context" + "github.com/coreos/etcd/clientv3" + "github.com/coreos/etcd/etcdserver/api/v3rpc" + "github.com/coreos/etcd/integration" + "github.com/coreos/etcd/lease" + "github.com/coreos/etcd/pkg/testutil" +) + +func TestLeaseCreate(t *testing.T) { + defer testutil.AfterTest(t) + + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3}) + defer clus.Terminate(t) + + lapi := clientv3.NewLease(clus.RandClient()) + defer lapi.Close() + + kv := clientv3.NewKV(clus.RandClient()) + + resp, err := lapi.Create(context.Background(), 10) + if err != nil { + t.Errorf("failed to create lease %v", err) + } + + _, err = kv.Put("foo", "bar", lease.LeaseID(resp.ID)) + if err != nil { + t.Fatalf("failed to create key with lease %v", err) + } +} + +func TestLeaseRevoke(t *testing.T) { + defer testutil.AfterTest(t) + + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + lapi := clientv3.NewLease(clus.RandClient()) + defer lapi.Close() + + kv := clientv3.NewKV(clus.RandClient()) + + resp, err := lapi.Create(context.Background(), 10) + if err != nil { + t.Errorf("failed to create lease %v", err) + } + + _, err = lapi.Revoke(context.Background(), lease.LeaseID(resp.ID)) + if err != nil { + t.Errorf("failed to revoke lease", err) + } + + _, err = kv.Put("foo", "bar", lease.LeaseID(resp.ID)) + if err != v3rpc.ErrLeaseNotFound { + t.Fatalf("err = %v, want %v", err, v3rpc.ErrLeaseNotFound) + } +} diff --git a/etcdserver/api/v3rpc/key.go b/etcdserver/api/v3rpc/key.go index afe0a446e..52a8bb564 100644 --- a/etcdserver/api/v3rpc/key.go +++ b/etcdserver/api/v3rpc/key.go @@ -22,6 +22,7 @@ import ( "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc/codes" "github.com/coreos/etcd/etcdserver" pb "github.com/coreos/etcd/etcdserver/etcdserverpb" + "github.com/coreos/etcd/lease" "github.com/coreos/etcd/storage" ) @@ -213,6 +214,8 @@ func togRPCError(err error) error { 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())