(t *testing.T)
| 239 | } |
| 240 | |
| 241 | func 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 | |
| 270 | func TestBufferCacheFlushAutoHotOnMaxBufferLength(t *testing.T) { |
| 271 | // Test the hash map is correctly updated when the hot cache is auto-flushed |
nothing calls this directly
no test coverage detected