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

Function TestBufferCacheMoveToHotCache

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

Source from the content-addressed store, hash-verified

239}
240
241func TestBufferCacheMoveToHotCache(t *testing.T) {
242 // Test the hash map is correctly updated when an adv is moved to hot cache
243 cfg := Config{
244 MaxBufferLength: 128,
245 MaxCapacity: 10240,
246 CellsPerBucket: 64,
247 Buckets: []int{64},
248 OnFlush: func([]byte) {},
249 }
250 c, _ := New(cfg)
251
252 // Adding to cold cache must not change the size
253 c.Put("key1", []byte("ciao"))
254 if c.cacheTotalize() != 64*64 {
255 t.Errorf("got cacheTotalSize=%v want %v", c.cacheTotalize(), 64*64)
256 }
257
258 assertKeyInColdCache(t, c, "key1")
259
260 loc := c.m.m["key1"]
261 c.moveToHotCache("key1", loc)
262 assertKeyInHotCache(t, c, "key1")
263
264 c.Flush()
265 // After a flush, putting the key again should add it to the cold cache
266 c.Put("key1", []byte("hello"))
267 assertKeyInColdCache(t, c, "key1")
268}
269
270func TestBufferCacheFlushAutoHotOnMaxBufferLength(t *testing.T) {
271 // Test the hash map is correctly updated when the hot cache is auto-flushed

Callers

nothing calls this directly

Calls 7

assertKeyInColdCacheFunction · 0.85
assertKeyInHotCacheFunction · 0.85
PutMethod · 0.80
cacheTotalizeMethod · 0.80
moveToHotCacheMethod · 0.80
NewFunction · 0.70
FlushMethod · 0.45

Tested by

no test coverage detected