Browse Source

storage: enhance TestRestore and kill TODO

Yicheng Qin 10 years ago
parent
commit
26a09d8479
1 changed files with 21 additions and 1 deletions
  1. 21 1
      storage/kvstore_test.go

+ 21 - 1
storage/kvstore_test.go

@@ -3,6 +3,7 @@ package storage
 import (
 import (
 	"bytes"
 	"bytes"
 	"crypto/rand"
 	"crypto/rand"
+	"math"
 	"os"
 	"os"
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
@@ -390,7 +391,6 @@ func TestCompaction(t *testing.T) {
 
 
 // TODO: test more complicated cases:
 // TODO: test more complicated cases:
 // with unfinished compaction
 // with unfinished compaction
-// with removed keys
 func TestRestore(t *testing.T) {
 func TestRestore(t *testing.T) {
 	s0 := newStore("test")
 	s0 := newStore("test")
 	defer os.Remove("test")
 	defer os.Remove("test")
@@ -402,6 +402,19 @@ func TestRestore(t *testing.T) {
 	s0.Put([]byte("foo1"), []byte("bar12"))
 	s0.Put([]byte("foo1"), []byte("bar12"))
 	s0.Put([]byte("foo2"), []byte("bar13"))
 	s0.Put([]byte("foo2"), []byte("bar13"))
 	s0.Put([]byte("foo1"), []byte("bar14"))
 	s0.Put([]byte("foo1"), []byte("bar14"))
+	s0.Put([]byte("foo3"), []byte("bar3"))
+	s0.DeleteRange([]byte("foo3"), nil)
+	s0.Put([]byte("foo3"), []byte("bar31"))
+	s0.DeleteRange([]byte("foo3"), nil)
+
+	mink := newRevBytes()
+	revToBytes(reversion{main: 0, sub: 0}, mink)
+	maxk := newRevBytes()
+	revToBytes(reversion{main: math.MaxInt64, sub: math.MaxInt64}, maxk)
+	s0kvs, _, err := s0.rangeKeys(mink, maxk, 0, 0)
+	if err != nil {
+		t.Fatalf("rangeKeys on s0 error (%v)", err)
+	}
 
 
 	s0.Close()
 	s0.Close()
 
 
@@ -411,6 +424,13 @@ func TestRestore(t *testing.T) {
 	if !s0.Equal(s1) {
 	if !s0.Equal(s1) {
 		t.Errorf("not equal!")
 		t.Errorf("not equal!")
 	}
 	}
+	s1kvs, _, err := s1.rangeKeys(mink, maxk, 0, 0)
+	if err != nil {
+		t.Fatalf("rangeKeys on s1 error (%v)", err)
+	}
+	if !reflect.DeepEqual(s1kvs, s0kvs) {
+		t.Errorf("s1kvs = %+v, want %+v", s1kvs, s0kvs)
+	}
 }
 }
 
 
 func BenchmarkStorePut(b *testing.B) {
 func BenchmarkStorePut(b *testing.B) {