Skip to content

Commit

Permalink
Merge pull request #4413 from gyuho/TestKVCompact
Browse files Browse the repository at this point in the history
clientv3/integration: add TestKVCompact
  • Loading branch information
gyuho committed Feb 4, 2016
2 parents 60085a0 + 5b4b1c7 commit d21ef68
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions clientv3/integration/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"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"
Expand Down Expand Up @@ -251,3 +252,41 @@ func TestKVDelete(t *testing.T) {
t.Fatalf("gresp.Kvs got %+v, want none", gresp.Kvs)
}
}

func TestKVCompact(t *testing.T) {
defer testutil.AfterTest(t)

clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3})
defer clus.Terminate(t)

kv := clientv3.NewKV(clus.RandClient())

for i := 0; i < 10; i++ {
if _, err := kv.Put("foo", "bar", lease.NoLease); err != nil {
t.Fatalf("couldn't put 'foo' (%v)", err)
}
}

err := kv.Compact(7)
if err != nil {
t.Fatalf("couldn't compact kv space (%v)", err)
}
err = kv.Compact(7)
if err == nil || err != v3rpc.ErrCompacted {
t.Fatalf("error got %v, want %v", err, v3rpc.ErrFutureRev)
}

wc := clientv3.NewWatcher(clus.RandClient())
defer wc.Close()
wchan := wc.Watch(context.TODO(), "foo", 3)

_, ok := <-wchan
if ok {
t.Fatalf("wchan ok got %v, want false", ok)
}

err = kv.Compact(1000)
if err == nil || err != v3rpc.ErrFutureRev {
t.Fatalf("error got %v, want %v", err, v3rpc.ErrFutureRev)
}
}

0 comments on commit d21ef68

Please sign in to comment.