|
|
@@ -45,9 +45,22 @@ func TestStoreRev(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestStorePut(t *testing.T) {
|
|
|
+ kv := storagepb.KeyValue{
|
|
|
+ Key: []byte("foo"),
|
|
|
+ Value: []byte("bar"),
|
|
|
+ CreateRevision: 1,
|
|
|
+ ModRevision: 2,
|
|
|
+ Version: 1,
|
|
|
+ }
|
|
|
+ kvb, err := kv.Marshal()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
tests := []struct {
|
|
|
rev revision
|
|
|
r indexGetResp
|
|
|
+ rr *rangeResp
|
|
|
|
|
|
wrev revision
|
|
|
wkey []byte
|
|
|
@@ -57,6 +70,8 @@ func TestStorePut(t *testing.T) {
|
|
|
{
|
|
|
revision{1, 0},
|
|
|
indexGetResp{revision{}, revision{}, 0, ErrRevisionNotFound},
|
|
|
+ nil,
|
|
|
+
|
|
|
revision{1, 1},
|
|
|
newTestKeyBytes(revision{2, 0}, false),
|
|
|
storagepb.KeyValue{
|
|
|
@@ -72,6 +87,8 @@ func TestStorePut(t *testing.T) {
|
|
|
{
|
|
|
revision{1, 1},
|
|
|
indexGetResp{revision{2, 0}, revision{2, 0}, 1, nil},
|
|
|
+ &rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
|
+
|
|
|
revision{1, 2},
|
|
|
newTestKeyBytes(revision{2, 1}, false),
|
|
|
storagepb.KeyValue{
|
|
|
@@ -87,6 +104,8 @@ func TestStorePut(t *testing.T) {
|
|
|
{
|
|
|
revision{2, 0},
|
|
|
indexGetResp{revision{2, 1}, revision{2, 0}, 2, nil},
|
|
|
+ &rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
|
+
|
|
|
revision{2, 1},
|
|
|
newTestKeyBytes(revision{3, 0}, false),
|
|
|
storagepb.KeyValue{
|
|
|
@@ -108,6 +127,9 @@ func TestStorePut(t *testing.T) {
|
|
|
s.currentRev = tt.rev
|
|
|
s.tx = b.BatchTx()
|
|
|
fi.indexGetRespc <- tt.r
|
|
|
+ if tt.rr != nil {
|
|
|
+ b.tx.rangeRespc <- *tt.rr
|
|
|
+ }
|
|
|
|
|
|
s.put([]byte("foo"), []byte("bar"), lease.LeaseID(i+1))
|
|
|
|
|
|
@@ -115,9 +137,18 @@ func TestStorePut(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Errorf("#%d: marshal err = %v, want nil", i, err)
|
|
|
}
|
|
|
+
|
|
|
wact := []testutil.Action{
|
|
|
{"put", []interface{}{keyBucketName, tt.wkey, data}},
|
|
|
}
|
|
|
+
|
|
|
+ if tt.rr != nil {
|
|
|
+ wact = []testutil.Action{
|
|
|
+ {"range", []interface{}{keyBucketName, newTestKeyBytes(tt.r.rev, false), []byte(nil), int64(0)}},
|
|
|
+ {"put", []interface{}{keyBucketName, tt.wkey, data}},
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
|
|
|
t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
|
|
|
}
|
|
|
@@ -208,9 +239,23 @@ func TestStoreRange(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestStoreDeleteRange(t *testing.T) {
|
|
|
+ key := newTestKeyBytes(revision{2, 0}, false)
|
|
|
+ kv := storagepb.KeyValue{
|
|
|
+ Key: []byte("foo"),
|
|
|
+ Value: []byte("bar"),
|
|
|
+ CreateRevision: 1,
|
|
|
+ ModRevision: 2,
|
|
|
+ Version: 1,
|
|
|
+ }
|
|
|
+ kvb, err := kv.Marshal()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
tests := []struct {
|
|
|
rev revision
|
|
|
r indexRangeResp
|
|
|
+ rr rangeResp
|
|
|
|
|
|
wkey []byte
|
|
|
wrev revision
|
|
|
@@ -220,6 +265,8 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
{
|
|
|
revision{2, 0},
|
|
|
indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
|
|
|
+ rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
|
+
|
|
|
newTestKeyBytes(revision{3, 0}, true),
|
|
|
revision{2, 1},
|
|
|
2,
|
|
|
@@ -228,6 +275,8 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
{
|
|
|
revision{2, 1},
|
|
|
indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
|
|
|
+ rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
|
+
|
|
|
newTestKeyBytes(revision{3, 1}, true),
|
|
|
revision{2, 2},
|
|
|
3,
|
|
|
@@ -242,6 +291,7 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
s.currentRev = tt.rev
|
|
|
s.tx = b.BatchTx()
|
|
|
fi.indexRangeRespc <- tt.r
|
|
|
+ b.tx.rangeRespc <- tt.rr
|
|
|
|
|
|
n := s.deleteRange([]byte("foo"), []byte("goo"))
|
|
|
if n != 1 {
|
|
|
@@ -256,6 +306,7 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
}
|
|
|
wact := []testutil.Action{
|
|
|
{"put", []interface{}{keyBucketName, tt.wkey, data}},
|
|
|
+ {"range", []interface{}{keyBucketName, newTestKeyBytes(revision{2, 0}, false), []byte(nil), int64(0)}},
|
|
|
}
|
|
|
if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
|
|
|
t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
|