MCPcopy Create free account
hub / github.com/AdRoll/baker / TestBufferCacheAutoFlushCold

Function TestBufferCacheAutoFlushCold

pkg/buffercache/cache_test.go:163–195  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

161}
162
163func TestBufferCacheAutoFlushCold(t *testing.T) {
164 // Fill the cold cache and check flush is called and that the locationMap
165 // reflects the state of the cache.
166 flushed := false
167 cfg := Config{
168 MaxBufferLength: 128,
169 MaxCapacity: 512,
170 CellsPerBucket: 64,
171 Buckets: []int{64},
172 OnFlush: func([]byte) { flushed = true },
173 }
174
175 c, _ := New(cfg)
176
177 for i := 0; i < cfg.CellsPerBucket; i++ {
178 c.Put(fmt.Sprintf("key%d", i), genBuffer("ciao", 32))
179 }
180 if flushed {
181 t.Errorf("got flushed = true, want false")
182 }
183 c.Put("extrakey", genBuffer("ciao", 32))
184 if !flushed {
185 t.Errorf("got flushed = false, want true")
186 }
187
188 // check all keys are absent from the cache
189 for i := 0; i < cfg.CellsPerBucket; i++ {
190 key := fmt.Sprintf("key%d", i)
191 assertKeyNotInCache(t, c, key)
192 }
193
194 assertKeyInColdCache(t, c, "extrakey")
195}
196
197func (c *BufferCache) cacheTotalize() int {
198 coldCacheSize := 0

Callers

nothing calls this directly

Calls 5

genBufferFunction · 0.85
assertKeyNotInCacheFunction · 0.85
assertKeyInColdCacheFunction · 0.85
PutMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected