github.com/jbendotnet/noms@v0.0.0-20190904222105-c43e4293ea92/go/nbs/table_persister_test.go (about) 1 // Copyright 2017 Attic Labs, Inc. All rights reserved. 2 // Licensed under the Apache License, version 2.0: 3 // http://www.apache.org/licenses/LICENSE-2.0 4 5 package nbs 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestPlanCompaction(t *testing.T) { 14 assert := assert.New(t) 15 tableContents := [][][]byte{ 16 {[]byte("hello2"), []byte("goodbye2"), []byte("badbye2")}, 17 {[]byte("red"), []byte("blue")}, 18 {[]byte("solo")}, 19 } 20 21 var sources chunkSources 22 var dataLens []uint64 23 var totalUnc uint64 24 for _, content := range tableContents { 25 for _, chnk := range content { 26 totalUnc += uint64(len(chnk)) 27 } 28 data, name := buildTable(content) 29 src := chunkSourceAdapter{newTableReader(parseTableIndex(data), tableReaderAtFromBytes(data), fileBlockSize), name} 30 dataLens = append(dataLens, uint64(len(data))-indexSize(src.count())-footerSize) 31 sources = append(sources, src) 32 } 33 34 plan := planConjoin(sources, &Stats{}) 35 36 var totalChunks uint32 37 for i, src := range sources { 38 assert.Equal(dataLens[i], plan.sources[i].dataLen) 39 totalChunks += src.count() 40 } 41 42 idx := parseTableIndex(plan.mergedIndex) 43 44 assert.Equal(totalChunks, idx.chunkCount) 45 assert.Equal(totalUnc, idx.totalUncompressedData) 46 47 tr := newTableReader(idx, tableReaderAtFromBytes(nil), fileBlockSize) 48 for _, content := range tableContents { 49 assertChunksInReader(content, tr, assert) 50 } 51 }