-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmax_content_defined_chunker_test.go
50 lines (43 loc) · 1.26 KB
/
max_content_defined_chunker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cdc_test
import (
"io"
"math/rand"
"testing"
"github.com/buildbarn/go-cdc"
"github.com/stretchr/testify/require"
)
func TestMaxContentDefinedChunker(t *testing.T) {
// Test that MaxContentDefinedChunker behaves the same way as
// SimpleMaxContentDefinedChunker.
seed := rand.Int63()
r1 := rand.New(rand.NewSource(seed))
r2 := rand.New(rand.NewSource(seed))
for i := 0; i < 1000; i++ {
chunker1 := cdc.NewSimpleMaxContentDefinedChunker(
io.LimitReader(r1, 1024*1024),
/* peekSizeBytes = */ 64*1024,
/* minSizeBytes = */ 2*1024,
/* maxSizeBytes = */ 16*1024,
)
chunker2 := cdc.NewMaxContentDefinedChunker(
io.LimitReader(r2, 1024*1024),
/* peekSizeBytes = */ 64*1024,
/* minSizeBytes = */ 2*1024,
/* maxSizeBytes = */ 16*1024,
)
for totalRead := 0; totalRead < 1024*1024; {
chunk1, err1 := chunker1.ReadNextChunk()
require.NoError(t, err1)
require.LessOrEqual(t, 2*1024, len(chunk1))
require.GreaterOrEqual(t, 16*1024, len(chunk1))
chunk2, err2 := chunker2.ReadNextChunk()
require.NoError(t, err2)
require.Equal(t, chunk1, chunk2)
totalRead += len(chunk1)
}
_, err1 := chunker1.ReadNextChunk()
require.Equal(t, io.EOF, err1)
_, err2 := chunker2.ReadNextChunk()
require.Equal(t, io.EOF, err2)
}
}