mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: support serializable
This commit is contained in:
parent
00f89941a9
commit
5908e5b601
@ -96,9 +96,10 @@ func TestKVRange(t *testing.T) {
|
|||||||
wheader := resp.Header
|
wheader := resp.Header
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
begin, end string
|
begin, end string
|
||||||
rev int64
|
rev int64
|
||||||
sortOption *clientv3.SortOption
|
sortOption *clientv3.SortOption
|
||||||
|
serializable bool
|
||||||
|
|
||||||
wantSet []*storagepb.KeyValue
|
wantSet []*storagepb.KeyValue
|
||||||
}{
|
}{
|
||||||
@ -107,6 +108,19 @@ func TestKVRange(t *testing.T) {
|
|||||||
"a", "c",
|
"a", "c",
|
||||||
0,
|
0,
|
||||||
nil,
|
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{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
||||||
@ -118,6 +132,7 @@ func TestKVRange(t *testing.T) {
|
|||||||
"a", "x",
|
"a", "x",
|
||||||
2,
|
2,
|
||||||
nil,
|
nil,
|
||||||
|
false,
|
||||||
|
|
||||||
[]*storagepb.KeyValue{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
||||||
@ -128,6 +143,7 @@ func TestKVRange(t *testing.T) {
|
|||||||
"a", "x",
|
"a", "x",
|
||||||
0,
|
0,
|
||||||
&clientv3.SortOption{Target: clientv3.SortByKey, Order: clientv3.SortAscend},
|
&clientv3.SortOption{Target: clientv3.SortByKey, Order: clientv3.SortAscend},
|
||||||
|
false,
|
||||||
|
|
||||||
[]*storagepb.KeyValue{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
{Key: []byte("a"), Value: nil, CreateRevision: 2, ModRevision: 2, Version: 1},
|
||||||
@ -143,6 +159,7 @@ func TestKVRange(t *testing.T) {
|
|||||||
"a", "x",
|
"a", "x",
|
||||||
0,
|
0,
|
||||||
&clientv3.SortOption{Target: clientv3.SortByCreatedRev, Order: clientv3.SortDescend},
|
&clientv3.SortOption{Target: clientv3.SortByCreatedRev, Order: clientv3.SortDescend},
|
||||||
|
false,
|
||||||
|
|
||||||
[]*storagepb.KeyValue{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
||||||
@ -158,6 +175,7 @@ func TestKVRange(t *testing.T) {
|
|||||||
"a", "x",
|
"a", "x",
|
||||||
0,
|
0,
|
||||||
&clientv3.SortOption{Target: clientv3.SortByModifiedRev, Order: clientv3.SortDescend},
|
&clientv3.SortOption{Target: clientv3.SortByModifiedRev, Order: clientv3.SortDescend},
|
||||||
|
false,
|
||||||
|
|
||||||
[]*storagepb.KeyValue{
|
[]*storagepb.KeyValue{
|
||||||
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1},
|
||||||
@ -175,6 +193,9 @@ func TestKVRange(t *testing.T) {
|
|||||||
if tt.sortOption != nil {
|
if tt.sortOption != nil {
|
||||||
opts = append(opts, clientv3.WithSort(tt.sortOption.Target, tt.sortOption.Order))
|
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...)
|
resp, err := kv.Get(ctx, tt.begin, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("#%d: couldn't range (%v)", i, err)
|
t.Fatalf("#%d: couldn't range (%v)", i, err)
|
||||||
|
@ -35,9 +35,10 @@ type Op struct {
|
|||||||
end []byte
|
end []byte
|
||||||
|
|
||||||
// for range
|
// for range
|
||||||
limit int64
|
limit int64
|
||||||
rev int64
|
rev int64
|
||||||
sort *SortOption
|
sort *SortOption
|
||||||
|
serializable bool
|
||||||
|
|
||||||
// for put
|
// for put
|
||||||
val []byte
|
val []byte
|
||||||
@ -86,6 +87,8 @@ func OpDelete(key string, opts ...OpOption) Op {
|
|||||||
panic("unexpected revision in delete")
|
panic("unexpected revision in delete")
|
||||||
case ret.sort != nil:
|
case ret.sort != nil:
|
||||||
panic("unexpected sort in delete")
|
panic("unexpected sort in delete")
|
||||||
|
case ret.serializable != false:
|
||||||
|
panic("unexpected serializable in delete")
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@ -102,6 +105,8 @@ func OpPut(key, val string, opts ...OpOption) Op {
|
|||||||
panic("unexpected revision in put")
|
panic("unexpected revision in put")
|
||||||
case ret.sort != nil:
|
case ret.sort != nil:
|
||||||
panic("unexpected sort in put")
|
panic("unexpected sort in put")
|
||||||
|
case ret.serializable != false:
|
||||||
|
panic("unexpected serializable in delete")
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@ -127,3 +132,6 @@ func WithSort(tgt SortTarget, order SortOrder) OpOption {
|
|||||||
func WithRange(endKey string) OpOption {
|
func WithRange(endKey string) OpOption {
|
||||||
return func(op *Op) { op.end = []byte(endKey) }
|
return func(op *Op) { op.end = []byte(endKey) }
|
||||||
}
|
}
|
||||||
|
func WithSerializable() OpOption {
|
||||||
|
return func(op *Op) { op.serializable = true }
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user