mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00: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 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])
|
key := BytesToNeedleId(bytes[i:i+NeedleIdSize])
|
||||||
offset := util.BytesToUint32(bytes[i+8: i+12])
|
offset := BytesToOffset(bytes[i+NeedleIdSize:i+NeedleIdSize+OffsetSize])
|
||||||
size := util.BytesToUint32(bytes[i+12: i+16])
|
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 {
|
||||||
|
|
|
@ -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,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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
ID types.NeedleId
|
||||||
Cookie uint32
|
Cookie types.Cookie
|
||||||
Err bool
|
Err bool
|
||||||
}{
|
}{
|
||||||
// normal
|
// normal
|
||||||
|
|
|
@ -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,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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
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, offset*8+size)
|
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…
Reference in a new issue