chunked_stream_writer_test.go 671 B

123456789101112131415161718192021222324252627282930313233
  1. package page_writer
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "os"
  5. "testing"
  6. )
  7. func TestWriteChunkedStream(t *testing.T) {
  8. x := NewChunkedStreamWriter(20)
  9. defer x.Destroy()
  10. y := NewChunkedFileWriter(os.TempDir(), 12)
  11. defer y.Destroy()
  12. batchSize := 4
  13. buf := make([]byte, batchSize)
  14. for i := 0; i < 256; i++ {
  15. for x := 0; x < batchSize; x++ {
  16. buf[x] = byte(i)
  17. }
  18. x.WriteAt(buf, int64(i*batchSize))
  19. y.WriteAt(buf, int64((255-i)*batchSize))
  20. }
  21. a := make([]byte, 1)
  22. b := make([]byte, 1)
  23. for i := 0; i < 256*batchSize; i++ {
  24. x.ReadDataAt(a, int64(i))
  25. y.ReadDataAt(b, int64(256*batchSize-1-i))
  26. assert.Equal(t, a[0], b[0], "same read")
  27. }
  28. }