Browse Source

fix all tests

pull/680/head
Chris Lu 7 years ago
parent
commit
5b1fd374be
  1. 7
      weed/storage/needle/compact_map_perf_test.go
  2. 4
      weed/storage/needle/compact_map_test.go
  3. 5
      weed/storage/needle_map_metric_test.go
  4. 9
      weed/storage/needle_test.go
  5. 4
      weed/storage/types/needle_types.go
  6. 5
      weed/storage/volume_vacuum_test.go
  7. 5
      weed/tools/read_index.go

7
weed/storage/needle/compact_map_perf_test.go

@ -30,9 +30,10 @@ func loadNewNeedleMap(file *os.File) {
} }
for count > 0 && e == nil { for count > 0 && e == nil {
for i := 0; i < count; i += 16 { for i := 0; i < count; i += 16 {
key := util.BytesToUint64(bytes[i: i+8])
offset := util.BytesToUint32(bytes[i+8: i+12])
size := util.BytesToUint32(bytes[i+12: i+16])
key := BytesToNeedleId(bytes[i:i+NeedleIdSize])
offset := BytesToOffset(bytes[i+NeedleIdSize:i+NeedleIdSize+OffsetSize])
size := util.BytesToUint32(bytes[i+NeedleIdSize+OffsetSize:i+NeedleIdSize+OffsetSize+SizeSize])
if offset > 0 { if offset > 0 {
m.Set(NeedleId(key), offset, size) m.Set(NeedleId(key), offset, size)
} else { } else {

4
weed/storage/needle/compact_map_test.go

@ -22,7 +22,7 @@ func TestIssue52(t *testing.T) {
func TestXYZ(t *testing.T) { func TestXYZ(t *testing.T) {
m := NewCompactMap() m := NewCompactMap()
for i := uint32(0); i < 100*batch; i += 2 { for i := uint32(0); i < 100*batch; i += 2 {
m.Set(NeedleId(i), i, i)
m.Set(NeedleId(i), Offset(i), i)
} }
for i := uint32(0); i < 100*batch; i += 37 { for i := uint32(0); i < 100*batch; i += 37 {
@ -30,7 +30,7 @@ func TestXYZ(t *testing.T) {
} }
for i := uint32(0); i < 10*batch; i += 3 { for i := uint32(0); i < 10*batch; i += 3 {
m.Set(NeedleId(i), i+11, i+5)
m.Set(NeedleId(i), Offset(i+11), i+5)
} }
// for i := uint32(0); i < 100; i++ { // for i := uint32(0); i < 100; i++ {

5
weed/storage/needle_map_metric_test.go

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
. "github.com/chrislusf/seaweedfs/weed/storage/types"
) )
func TestFastLoadingNeedleMapMetrics(t *testing.T) { func TestFastLoadingNeedleMapMetrics(t *testing.T) {
@ -13,9 +14,9 @@ func TestFastLoadingNeedleMapMetrics(t *testing.T) {
nm := NewBtreeNeedleMap(idxFile) nm := NewBtreeNeedleMap(idxFile)
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
nm.Put(uint64(i+1), uint32(0), uint32(1))
nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), uint32(1))
if rand.Float32() < 0.2 { if rand.Float32() < 0.2 {
nm.Delete(uint64(rand.Int63n(int64(i))+1), uint32(0))
nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
} }
} }

9
weed/storage/needle_test.go

@ -1,12 +1,15 @@
package storage package storage
import "testing"
import (
"testing"
"github.com/chrislusf/seaweedfs/weed/storage/types"
)
func TestParseKeyHash(t *testing.T) { func TestParseKeyHash(t *testing.T) {
testcases := []struct { testcases := []struct {
KeyHash string KeyHash string
ID uint64
Cookie uint32
ID types.NeedleId
Cookie types.Cookie
Err bool Err bool
}{ }{
// normal // normal

4
weed/storage/types/needle_types.go

@ -54,6 +54,10 @@ func OffsetToBytes(bytes []byte, offset Offset) {
util.Uint32toBytes(bytes, uint32(offset)) util.Uint32toBytes(bytes, uint32(offset))
} }
func Uint32ToOffset(offset uint32) (Offset) {
return Offset(offset)
}
func BytesToOffset(bytes []byte) (Offset) { func BytesToOffset(bytes []byte) (Offset) {
return Offset(util.BytesToUint32(bytes[0:4])) return Offset(util.BytesToUint32(bytes[0:4]))
} }

5
weed/storage/volume_vacuum_test.go

@ -5,6 +5,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"testing" "testing"
"github.com/chrislusf/seaweedfs/weed/storage/types"
) )
/* /*
@ -153,12 +154,12 @@ func newRandomNeedle(id uint64) *Needle {
rand.Read(n.Data) rand.Read(n.Data)
n.Checksum = NewCRC(n.Data) n.Checksum = NewCRC(n.Data)
n.Id = id
n.Id = types.Uint64ToNeedleId(id)
return n return n
} }
func newEmptyNeedle(id uint64) *Needle { func newEmptyNeedle(id uint64) *Needle {
n := new(Needle) n := new(Needle)
n.Id = id
n.Id = types.Uint64ToNeedleId(id)
return n return n
} }

5
weed/tools/read_index.go

@ -7,6 +7,7 @@ import (
"os" "os"
"github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/storage"
"github.com/chrislusf/seaweedfs/weed/storage/types"
) )
var ( var (
@ -21,8 +22,8 @@ func main() {
} }
defer indexFile.Close() defer indexFile.Close()
storage.WalkIndexFile(indexFile, func(key uint64, offset, size uint32) error {
fmt.Printf("key %d, offset %d, size %d, nextOffset %d\n", key, offset*8, size, offset*8+size)
storage.WalkIndexFile(indexFile, func(key types.NeedleId, offset types.Offset, size uint32) error {
fmt.Printf("key %d, offset %d, size %d, nextOffset %d\n", key, offset*8, size, int64(offset)*types.NeedlePaddingSize+int64(size))
return nil return nil
}) })
} }
Loading…
Cancel
Save