mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-18 04:37:52 +08:00
fix all tests
This commit is contained in:
parent
d4d7ced922
commit
5b1fd374be
@ -30,9 +30,10 @@ func loadNewNeedleMap(file *os.File) {
|
||||
}
|
||||
for count > 0 && e == nil {
|
||||
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 {
|
||||
m.Set(NeedleId(key), offset, size)
|
||||
} else {
|
||||
|
@ -22,7 +22,7 @@ func TestIssue52(t *testing.T) {
|
||||
func TestXYZ(t *testing.T) {
|
||||
m := NewCompactMap()
|
||||
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 {
|
||||
@ -30,7 +30,7 @@ func TestXYZ(t *testing.T) {
|
||||
}
|
||||
|
||||
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++ {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
func TestFastLoadingNeedleMapMetrics(t *testing.T) {
|
||||
@ -13,9 +14,9 @@ func TestFastLoadingNeedleMapMetrics(t *testing.T) {
|
||||
nm := NewBtreeNeedleMap(idxFile)
|
||||
|
||||
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 {
|
||||
nm.Delete(uint64(rand.Int63n(int64(i))+1), uint32(0))
|
||||
nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
package storage
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
func TestParseKeyHash(t *testing.T) {
|
||||
testcases := []struct {
|
||||
KeyHash string
|
||||
ID uint64
|
||||
Cookie uint32
|
||||
ID types.NeedleId
|
||||
Cookie types.Cookie
|
||||
Err bool
|
||||
}{
|
||||
// normal
|
||||
|
@ -54,6 +54,10 @@ func OffsetToBytes(bytes []byte, offset Offset) {
|
||||
util.Uint32toBytes(bytes, uint32(offset))
|
||||
}
|
||||
|
||||
func Uint32ToOffset(offset uint32) (Offset) {
|
||||
return Offset(offset)
|
||||
}
|
||||
|
||||
func BytesToOffset(bytes []byte) (Offset) {
|
||||
return Offset(util.BytesToUint32(bytes[0:4]))
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -153,12 +154,12 @@ func newRandomNeedle(id uint64) *Needle {
|
||||
rand.Read(n.Data)
|
||||
|
||||
n.Checksum = NewCRC(n.Data)
|
||||
n.Id = id
|
||||
n.Id = types.Uint64ToNeedleId(id)
|
||||
return n
|
||||
}
|
||||
|
||||
func newEmptyNeedle(id uint64) *Needle {
|
||||
n := new(Needle)
|
||||
n.Id = id
|
||||
n.Id = types.Uint64ToNeedleId(id)
|
||||
return n
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -21,8 +22,8 @@ func main() {
|
||||
}
|
||||
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
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user