From 5908e5b6017f0585426f023c36fb28c801e64c36 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 12 Feb 2016 12:24:46 -0800 Subject: [PATCH] clientv3: support serializable --- clientv3/integration/kv_test.go | 27 ++++++++++++++++++++++++--- clientv3/op.go | 14 +++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/clientv3/integration/kv_test.go b/clientv3/integration/kv_test.go index c6dfab8f2..66bec68c1 100644 --- a/clientv3/integration/kv_test.go +++ b/clientv3/integration/kv_test.go @@ -96,9 +96,10 @@ func TestKVRange(t *testing.T) { wheader := resp.Header tests := []struct { - begin, end string - rev int64 - sortOption *clientv3.SortOption + begin, end string + rev int64 + sortOption *clientv3.SortOption + serializable bool wantSet []*storagepb.KeyValue }{ @@ -107,6 +108,19 @@ func TestKVRange(t *testing.T) { "a", "c", 0, nil, + false, + + []*storagepb.KeyValue{ + {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, + {Key: []byte("b"), Value: nil, CreateRevision: 3, ModRevision: 3, Version: 1}, + }, + }, + // range first two with serializable + { + "a", "c", + 0, + nil, + true, []*storagepb.KeyValue{ {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, @@ -118,6 +132,7 @@ func TestKVRange(t *testing.T) { "a", "x", 2, nil, + false, []*storagepb.KeyValue{ {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, @@ -128,6 +143,7 @@ func TestKVRange(t *testing.T) { "a", "x", 0, &clientv3.SortOption{Target: clientv3.SortByKey, Order: clientv3.SortAscend}, + false, []*storagepb.KeyValue{ {Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1}, @@ -143,6 +159,7 @@ func TestKVRange(t *testing.T) { "a", "x", 0, &clientv3.SortOption{Target: clientv3.SortByCreatedRev, Order: clientv3.SortDescend}, + false, []*storagepb.KeyValue{ {Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, @@ -158,6 +175,7 @@ func TestKVRange(t *testing.T) { "a", "x", 0, &clientv3.SortOption{Target: clientv3.SortByModifiedRev, Order: clientv3.SortDescend}, + false, []*storagepb.KeyValue{ {Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, @@ -175,6 +193,9 @@ func TestKVRange(t *testing.T) { if tt.sortOption != nil { opts = append(opts, clientv3.WithSort(tt.sortOption.Target, tt.sortOption.Order)) } + if tt.serializable == true { + opts = append(opts, clientv3.WithSerializable()) + } resp, err := kv.Get(ctx, tt.begin, opts...) if err != nil { t.Fatalf("#%d: couldn't range (%v)", i, err) diff --git a/clientv3/op.go b/clientv3/op.go index e7c499090..f3458e1d9 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -35,9 +35,10 @@ type Op struct { end []byte // for range - limit int64 - rev int64 - sort *SortOption + limit int64 + rev int64 + sort *SortOption + serializable bool // for put val []byte @@ -86,6 +87,8 @@ func OpDelete(key string, opts ...OpOption) Op { panic("unexpected revision in delete") case ret.sort != nil: panic("unexpected sort in delete") + case ret.serializable != false: + panic("unexpected serializable in delete") } return ret } @@ -102,6 +105,8 @@ func OpPut(key, val string, opts ...OpOption) Op { panic("unexpected revision in put") case ret.sort != nil: panic("unexpected sort in put") + case ret.serializable != false: + panic("unexpected serializable in delete") } return ret } @@ -127,3 +132,6 @@ func WithSort(tgt SortTarget, order SortOrder) OpOption { func WithRange(endKey string) OpOption { return func(op *Op) { op.end = []byte(endKey) } } +func WithSerializable() OpOption { + return func(op *Op) { op.serializable = true } +}