This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 266
/
aws_chunk_source_test.go
84 lines (67 loc) · 1.96 KB
/
aws_chunk_source_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2017 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package nbs
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAWSChunkSource(t *testing.T) {
chunks := [][]byte{
[]byte("hello2"),
[]byte("goodbye2"),
[]byte("badbye2"),
}
tableData, h := buildTable(chunks)
s3 := makeFakeS3(t)
ddb := makeFakeDDB(t)
s3or := &s3ObjectReader{s3, "bucket", nil, nil}
dts := &ddbTableStore{ddb, "table", nil, nil}
makeSrc := func(chunkMax int, ic *indexCache) chunkSource {
return newAWSChunkSource(
dts,
s3or,
awsLimits{itemMax: maxDynamoItemSize, chunkMax: uint32(chunkMax)},
h,
uint32(len(chunks)),
ic,
&Stats{},
)
}
t.Run("Dynamo", func(t *testing.T) {
ddb.putData(fmtTableName(h), tableData)
t.Run("NoIndexCache", func(t *testing.T) {
src := makeSrc(len(chunks)+1, nil)
assertChunksInReader(chunks, src, assert.New(t))
})
t.Run("WithIndexCache", func(t *testing.T) {
assert := assert.New(t)
index := parseTableIndex(tableData)
cache := newIndexCache(1024)
cache.put(h, index)
baseline := ddb.numGets
src := makeSrc(len(chunks)+1, cache)
// constructing the table reader shouldn't have resulted in any reads
assert.Zero(ddb.numGets - baseline)
assertChunksInReader(chunks, src, assert)
})
})
t.Run("S3", func(t *testing.T) {
s3.data[h.String()] = tableData
t.Run("NoIndexCache", func(t *testing.T) {
src := makeSrc(len(chunks)-1, nil)
assertChunksInReader(chunks, src, assert.New(t))
})
t.Run("WithIndexCache", func(t *testing.T) {
assert := assert.New(t)
index := parseTableIndex(tableData)
cache := newIndexCache(1024)
cache.put(h, index)
baseline := s3.getCount
src := makeSrc(len(chunks)-1, cache)
// constructing the table reader shouldn't have resulted in any reads
assert.Zero(s3.getCount - baseline)
assertChunksInReader(chunks, src, assert)
})
})
}