(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func 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 | |
| 197 | func (c *BufferCache) cacheTotalize() int { |
| 198 | coldCacheSize := 0 |
nothing calls this directly
no test coverage detected