|
|
@@ -205,7 +205,7 @@ func TestKeyIndexTombstone(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestKeyIndexCompact(t *testing.T) {
|
|
|
+func TestKeyIndexCompactAndKeep(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
compact int64
|
|
|
|
|
|
@@ -441,10 +441,19 @@ func TestKeyIndexCompact(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- // Continuous Compaction
|
|
|
+ // Continuous Compaction and finding Keep
|
|
|
ki := newTestKeyIndex()
|
|
|
for i, tt := range tests {
|
|
|
am := make(map[revision]struct{})
|
|
|
+ kiclone := cloneKeyIndex(ki)
|
|
|
+ ki.keep(tt.compact, am)
|
|
|
+ if !reflect.DeepEqual(ki, kiclone) {
|
|
|
+ t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiclone)
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(am, tt.wam) {
|
|
|
+ t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
|
|
|
+ }
|
|
|
+ am = make(map[revision]struct{})
|
|
|
ki.compact(tt.compact, am)
|
|
|
if !reflect.DeepEqual(ki, tt.wki) {
|
|
|
t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
|
|
|
@@ -454,11 +463,20 @@ func TestKeyIndexCompact(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Jump Compaction
|
|
|
+ // Jump Compaction and finding Keep
|
|
|
ki = newTestKeyIndex()
|
|
|
for i, tt := range tests {
|
|
|
if (i%2 == 0 && i < 6) || (i%2 == 1 && i > 6) {
|
|
|
am := make(map[revision]struct{})
|
|
|
+ kiclone := cloneKeyIndex(ki)
|
|
|
+ ki.keep(tt.compact, am)
|
|
|
+ if !reflect.DeepEqual(ki, kiclone) {
|
|
|
+ t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiclone)
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(am, tt.wam) {
|
|
|
+ t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
|
|
|
+ }
|
|
|
+ am = make(map[revision]struct{})
|
|
|
ki.compact(tt.compact, am)
|
|
|
if !reflect.DeepEqual(ki, tt.wki) {
|
|
|
t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
|
|
|
@@ -469,10 +487,19 @@ func TestKeyIndexCompact(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Once Compaction
|
|
|
+ kiClone := newTestKeyIndex()
|
|
|
+ // Once Compaction and finding Keep
|
|
|
for i, tt := range tests {
|
|
|
ki := newTestKeyIndex()
|
|
|
am := make(map[revision]struct{})
|
|
|
+ ki.keep(tt.compact, am)
|
|
|
+ if !reflect.DeepEqual(ki, kiClone) {
|
|
|
+ t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiClone)
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(am, tt.wam) {
|
|
|
+ t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)
|
|
|
+ }
|
|
|
+ am = make(map[revision]struct{})
|
|
|
ki.compact(tt.compact, am)
|
|
|
if !reflect.DeepEqual(ki, tt.wki) {
|
|
|
t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)
|
|
|
@@ -483,6 +510,23 @@ func TestKeyIndexCompact(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func cloneKeyIndex(ki *keyIndex) *keyIndex {
|
|
|
+ generations := make([]generation, len(ki.generations))
|
|
|
+ for i, gen := range ki.generations {
|
|
|
+ generations[i] = *cloneGeneration(&gen)
|
|
|
+ }
|
|
|
+ return &keyIndex{ki.key, ki.modified, generations}
|
|
|
+}
|
|
|
+
|
|
|
+func cloneGeneration(g *generation) *generation {
|
|
|
+ if g.revs == nil {
|
|
|
+ return &generation{g.ver, g.created, nil}
|
|
|
+ }
|
|
|
+ tmp := make([]revision, len(g.revs))
|
|
|
+ copy(tmp, g.revs)
|
|
|
+ return &generation{g.ver, g.created, tmp}
|
|
|
+}
|
|
|
+
|
|
|
// test that compact on version that higher than last modified version works well
|
|
|
func TestKeyIndexCompactOnFurtherRev(t *testing.T) {
|
|
|
ki := &keyIndex{key: []byte("foo")}
|