You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

3 years ago
3 years ago
  1. package page_writer
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/util"
  4. "testing"
  5. )
  6. func TestUploadPipeline(t *testing.T) {
  7. uploadPipeline := NewUploadPipeline("", nil, 2*1024*1024, nil)
  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)
  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)
  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. }