upload_pipeline_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package page_writer
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/util"
  4. "testing"
  5. )
  6. func TestUploadPipeline(t *testing.T) {
  7. uploadPipeline := NewUploadPipeline(nil, 2*1024*1024, nil, 16, "")
  8. writeRange(uploadPipeline, 0, 131072)
  9. writeRange(uploadPipeline, 131072, 262144)
  10. writeRange(uploadPipeline, 262144, 1025536)
  11. confirmRange(t, uploadPipeline, 0, 1025536)
  12. writeRange(uploadPipeline, 1025536, 1296896)
  13. confirmRange(t, uploadPipeline, 1025536, 1296896)
  14. writeRange(uploadPipeline, 1296896, 2162688)
  15. confirmRange(t, uploadPipeline, 1296896, 2162688)
  16. confirmRange(t, uploadPipeline, 1296896, 2162688)
  17. }
  18. // startOff and stopOff must be divided by 4
  19. func writeRange(uploadPipeline *UploadPipeline, startOff, stopOff int64) {
  20. p := make([]byte, 4)
  21. for i := startOff / 4; i < stopOff/4; i += 4 {
  22. util.Uint32toBytes(p, uint32(i))
  23. uploadPipeline.SaveDataAt(p, i, false, 0)
  24. }
  25. }
  26. func confirmRange(t *testing.T, uploadPipeline *UploadPipeline, startOff, stopOff int64) {
  27. p := make([]byte, 4)
  28. for i := startOff; i < stopOff/4; i += 4 {
  29. uploadPipeline.MaybeReadDataAt(p, i, 0)
  30. x := util.BytesToUint32(p)
  31. if x != uint32(i) {
  32. t.Errorf("expecting %d found %d at offset [%d,%d)", i, x, i, i+4)
  33. }
  34. }
  35. }