(t *testing.T)
| 295 | } |
| 296 | |
| 297 | func TestBufferCacheFlushAutoHotOnMaxCapacity(t *testing.T) { |
| 298 | // Test the hash map is correctly updated when the hot cache is auto-flushed |
| 299 | // after an insertion (because maxcap would have been reached). |
| 300 | |
| 301 | t.Run("after flush, new entry goes in cold cache", func(t *testing.T) { |
| 302 | cfg := Config{ |
| 303 | MaxBufferLength: 136, |
| 304 | MaxCapacity: 137, |
| 305 | CellsPerBucket: 64, |
| 306 | Buckets: []int{64}, |
| 307 | OnFlush: func([]byte) {}, |
| 308 | } |
| 309 | c, err := New(cfg) |
| 310 | if err != nil { |
| 311 | t.Fatal(err) |
| 312 | } |
| 313 | |
| 314 | // Can't stay in a 64b cell, goes directly in hot cache. |
| 315 | c.Put("key1", incompressible[:64]) |
| 316 | assertKeyInHotCache(t, c, "key1") |
| 317 | |
| 318 | // Can't stay in a 64b cell, goes directly in hot cache. |
| 319 | c.Put("key2", incompressible[64:128]) |
| 320 | assertKeyInHotCache(t, c, "key2") |
| 321 | |
| 322 | // Already seen key1, so this should go in the hot cache, but adding this |
| 323 | // would exceed the hot cache capacity, so the whole hot cache is flushed |
| 324 | // and this will finally go into the cold cache (since it can fit there). |
| 325 | cccc30 := incompressible[:30] |
| 326 | c.Put("key1", cccc30) |
| 327 | assertKeyInColdCache(t, c, "key1") |
| 328 | assertKeyValue(t, c, "key1", cccc30) |
| 329 | |
| 330 | // Finally, check key2 is nowhere to be found |
| 331 | assertKeyNotInCache(t, c, "key2") |
| 332 | }) |
| 333 | |
| 334 | t.Run("after flush, new entry goes in hot cache", func(t *testing.T) { |
| 335 | // Test the hash map is correctly updated when the hot cache is auto-flushed |
| 336 | // after an insertion (because maxcap would have been reached), but the new |
| 337 | // entry is too big and goes directly in hot cache. |
| 338 | cfg := Config{ |
| 339 | MaxBufferLength: 136, |
| 340 | MaxCapacity: 137, |
| 341 | CellsPerBucket: 64, |
| 342 | Buckets: []int{64}, |
| 343 | OnFlush: func([]byte) {}, |
| 344 | } |
| 345 | c, _ := New(cfg) |
| 346 | |
| 347 | // Can't stay in a 64b cell, goes directly in hot cache. |
| 348 | c.Put("key1", incompressible[:64]) |
| 349 | assertKeyInHotCache(t, c, "key1") |
| 350 | |
| 351 | // Can't stay in a 64b cell, goes directly in hot cache. |
| 352 | c.Put("key2", incompressible[64:128]) |
| 353 | assertKeyInHotCache(t, c, "key2") |
| 354 |
nothing calls this directly
no test coverage detected