forked from attic-labs/noms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_persister_test.go
51 lines (41 loc) · 1.35 KB
/
table_persister_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
// 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 TestPlanCompaction(t *testing.T) {
assert := assert.New(t)
tableContents := [][][]byte{
{[]byte("hello2"), []byte("goodbye2"), []byte("badbye2")},
{[]byte("red"), []byte("blue")},
{[]byte("solo")},
}
var sources chunkSources
var dataLens []uint64
var totalUnc uint64
for _, content := range tableContents {
for _, chnk := range content {
totalUnc += uint64(len(chnk))
}
data, name := buildTable(content)
src := chunkSourceAdapter{newTableReader(parseTableIndex(data), tableReaderAtFromBytes(data), fileBlockSize), name}
dataLens = append(dataLens, uint64(len(data))-indexSize(src.count())-footerSize)
sources = append(sources, src)
}
plan := planConjoin(sources, &Stats{})
var totalChunks uint32
for i, src := range sources {
assert.Equal(dataLens[i], plan.sources[i].dataLen)
totalChunks += src.count()
}
idx := parseTableIndex(plan.mergedIndex)
assert.Equal(totalChunks, idx.chunkCount)
assert.Equal(totalUnc, idx.totalUncompressedData)
tr := newTableReader(idx, tableReaderAtFromBytes(nil), fileBlockSize)
for _, content := range tableContents {
assertChunksInReader(content, tr, assert)
}
}