diff options
Diffstat (limited to 'weed/filer/reader_at_test.go')
| -rw-r--r-- | weed/filer/reader_at_test.go | 142 |
1 files changed, 66 insertions, 76 deletions
diff --git a/weed/filer/reader_at_test.go b/weed/filer/reader_at_test.go index 29bd47ea4..f61d68a6d 100644 --- a/weed/filer/reader_at_test.go +++ b/weed/filer/reader_at_test.go @@ -5,7 +5,6 @@ import ( "io" "math" "strconv" - "sync" "testing" ) @@ -34,42 +33,40 @@ func (m *mockChunkCache) SetChunk(fileId string, data []byte) { func TestReaderAt(t *testing.T) { - visibles := []VisibleInterval{ - { - start: 1, - stop: 2, - fileId: "1", - chunkSize: 9, - }, - { - start: 3, - stop: 4, - fileId: "3", - chunkSize: 1, - }, - { - start: 5, - stop: 6, - fileId: "5", - chunkSize: 2, - }, - { - start: 7, - stop: 9, - fileId: "7", - chunkSize: 2, - }, - { - start: 9, - stop: 10, - fileId: "9", - chunkSize: 2, - }, - } + visibles := NewIntervalList[*VisibleInterval]() + addVisibleInterval(visibles, &VisibleInterval{ + start: 1, + stop: 2, + fileId: "1", + chunkSize: 9, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 3, + stop: 4, + fileId: "3", + chunkSize: 1, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 5, + stop: 6, + fileId: "5", + chunkSize: 2, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 7, + stop: 9, + fileId: "7", + chunkSize: 2, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 9, + stop: 10, + fileId: "9", + chunkSize: 2, + }) readerAt := &ChunkReadAt{ chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64), - readerLock: sync.Mutex{}, fileSize: 10, readerCache: newReaderCache(3, &mockChunkCache{}, nil), readerPattern: NewReaderPattern(), @@ -86,7 +83,7 @@ func testReadAt(t *testing.T, readerAt *ChunkReadAt, offset int64, size int, exp if data == nil { data = make([]byte, size) } - n, err := readerAt.doReadAt(data, offset) + n, _, err := readerAt.doReadAt(data, offset) if expectedN != n { t.Errorf("unexpected read size: %d, expect: %d", n, expectedN) @@ -101,24 +98,22 @@ func testReadAt(t *testing.T, readerAt *ChunkReadAt, offset int64, size int, exp func TestReaderAt0(t *testing.T) { - visibles := []VisibleInterval{ - { - start: 2, - stop: 5, - fileId: "1", - chunkSize: 9, - }, - { - start: 7, - stop: 9, - fileId: "2", - chunkSize: 9, - }, - } + visibles := NewIntervalList[*VisibleInterval]() + addVisibleInterval(visibles, &VisibleInterval{ + start: 2, + stop: 5, + fileId: "1", + chunkSize: 9, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 7, + stop: 9, + fileId: "2", + chunkSize: 9, + }) readerAt := &ChunkReadAt{ chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64), - readerLock: sync.Mutex{}, fileSize: 10, readerCache: newReaderCache(3, &mockChunkCache{}, nil), readerPattern: NewReaderPattern(), @@ -135,18 +130,16 @@ func TestReaderAt0(t *testing.T) { func TestReaderAt1(t *testing.T) { - visibles := []VisibleInterval{ - { - start: 2, - stop: 5, - fileId: "1", - chunkSize: 9, - }, - } + visibles := NewIntervalList[*VisibleInterval]() + addVisibleInterval(visibles, &VisibleInterval{ + start: 2, + stop: 5, + fileId: "1", + chunkSize: 9, + }) readerAt := &ChunkReadAt{ chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64), - readerLock: sync.Mutex{}, fileSize: 20, readerCache: newReaderCache(3, &mockChunkCache{}, nil), readerPattern: NewReaderPattern(), @@ -164,24 +157,22 @@ func TestReaderAt1(t *testing.T) { } func TestReaderAtGappedChunksDoNotLeak(t *testing.T) { - visibles := []VisibleInterval{ - { - start: 2, - stop: 3, - fileId: "1", - chunkSize: 5, - }, - { - start: 7, - stop: 9, - fileId: "1", - chunkSize: 4, - }, - } + visibles := NewIntervalList[*VisibleInterval]() + addVisibleInterval(visibles, &VisibleInterval{ + start: 2, + stop: 3, + fileId: "1", + chunkSize: 5, + }) + addVisibleInterval(visibles, &VisibleInterval{ + start: 7, + stop: 9, + fileId: "1", + chunkSize: 4, + }) readerAt := &ChunkReadAt{ chunkViews: ViewFromVisibleIntervals(visibles, 0, math.MaxInt64), - readerLock: sync.Mutex{}, fileSize: 9, readerCache: newReaderCache(3, &mockChunkCache{}, nil), readerPattern: NewReaderPattern(), @@ -193,8 +184,7 @@ func TestReaderAtGappedChunksDoNotLeak(t *testing.T) { func TestReaderAtSparseFileDoesNotLeak(t *testing.T) { readerAt := &ChunkReadAt{ - chunkViews: ViewFromVisibleIntervals([]VisibleInterval{}, 0, math.MaxInt64), - readerLock: sync.Mutex{}, + chunkViews: ViewFromVisibleIntervals(NewIntervalList[*VisibleInterval](), 0, math.MaxInt64), fileSize: 3, readerCache: newReaderCache(3, &mockChunkCache{}, nil), readerPattern: NewReaderPattern(), |
