2022-02-14 14:50:44 +08:00
|
|
|
package page_writer
|
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2022-02-14 14:50:44 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUploadPipeline(t *testing.T) {
|
|
|
|
|
2022-03-10 14:26:51 +08:00
|
|
|
uploadPipeline := NewUploadPipeline(nil, 2*1024*1024, nil, 16, "")
|
2022-02-14 14:50:44 +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))
|
2022-03-14 09:17:35 +08:00
|
|
|
uploadPipeline.SaveDataAt(p, i, false)
|
2022-02-14 14:50:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|