2022-01-18 05:40:41 +08:00
|
|
|
package page_writer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUploadPipeline(t *testing.T) {
|
|
|
|
|
2022-01-18 14:24:44 +08:00
|
|
|
uploadPipeline := NewUploadPipeline("", nil, 2*1024*1024, nil)
|
2022-01-18 05:40:41 +08:00
|
|
|
|
|
|
|
writeRange(uploadPipeline, 0, 131072)
|
|
|
|
writeRange(uploadPipeline, 131072, 262144)
|
|
|
|
writeRange(uploadPipeline, 262144, 1025536)
|
|
|
|
|
|
|
|
confirmRange(t, uploadPipeline, 0, 1025536)
|
|
|
|
|
|
|
|
writeRange(uploadPipeline, 1025536, 1296896)
|
|
|
|
|
|
|
|
confirmRange(t, uploadPipeline, 1025536, 1296896)
|
|
|
|
|
|
|
|
writeRange(uploadPipeline, 1296896, 2162688)
|
|
|
|
|
|
|
|
confirmRange(t, uploadPipeline, 1296896, 2162688)
|
|
|
|
|
|
|
|
confirmRange(t, uploadPipeline, 1296896, 2162688)
|
|
|
|
}
|
|
|
|
|
|
|
|
// startOff and stopOff must be divided by 4
|
|
|
|
func writeRange(uploadPipeline *UploadPipeline, startOff, stopOff int64) {
|
|
|
|
p := make([]byte, 4)
|
|
|
|
for i := startOff / 4; i < stopOff/4; i += 4 {
|
|
|
|
util.Uint32toBytes(p, uint32(i))
|
|
|
|
uploadPipeline.SaveDataAt(p, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func confirmRange(t *testing.T, uploadPipeline *UploadPipeline, startOff, stopOff int64) {
|
|
|
|
p := make([]byte, 4)
|
|
|
|
for i := startOff; i < stopOff/4; i += 4 {
|
|
|
|
uploadPipeline.MaybeReadDataAt(p, i)
|
|
|
|
x := util.BytesToUint32(p)
|
|
|
|
if x != uint32(i) {
|
|
|
|
t.Errorf("expecting %d found %d at offset [%d,%d)", i, x, i, i+4)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|