forked from attic-labs/noms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
persisting_chunk_source_test.go
55 lines (42 loc) · 1.52 KB
/
persisting_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
// Copyright 2016 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 TestPersistingChunkStoreEmpty(t *testing.T) {
mt := newMemTable(testMemTableSize)
ccs := newPersistingChunkSource(mt, nil, newFakeTablePersister(), make(chan struct{}, 1), &Stats{})
assert.Equal(t, addr{}, ccs.hash())
assert.Zero(t, ccs.count())
}
type pausingFakeTablePersister struct {
tablePersister
trigger <-chan struct{}
}
func (ftp pausingFakeTablePersister) Persist(mt *memTable, haver chunkReader, stats *Stats) chunkSource {
<-ftp.trigger
return ftp.tablePersister.Persist(mt, haver, stats)
}
func TestPersistingChunkStore(t *testing.T) {
assert := assert.New(t)
mt := newMemTable(testMemTableSize)
for _, c := range testChunks {
assert.True(mt.addChunk(computeAddr(c), c))
}
trigger := make(chan struct{})
ccs := newPersistingChunkSource(mt, nil, pausingFakeTablePersister{newFakeTablePersister(), trigger}, make(chan struct{}, 1), &Stats{})
assertChunksInReader(testChunks, ccs, assert)
assert.EqualValues(mt.count(), ccs.getReader().count())
close(trigger)
assert.NotEqual(addr{}, ccs.hash())
assert.EqualValues(len(testChunks), ccs.count())
assertChunksInReader(testChunks, ccs, assert)
assert.Nil(ccs.mt)
newChunk := []byte("additional")
mt.addChunk(computeAddr(newChunk), newChunk)
assert.NotEqual(mt.count(), ccs.count())
assert.False(ccs.has(computeAddr(newChunk)))
}