Software /
code /
prosody
Comparison
tests/test_util_cache.lua @ 7291:688a7f5d3624
tests: util.cache: Tests for different return values of on_evict
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 17 Mar 2016 19:14:58 +0000 |
parent | 7290:70ab13e81cf5 |
child | 7484:d962ccf90735 |
comparison
equal
deleted
inserted
replaced
7290:70ab13e81cf5 | 7291:688a7f5d3624 |
---|---|
269 assert_equal(c4:set("d", 4), false); | 269 assert_equal(c4:set("d", 4), false); |
270 | 270 |
271 expect_kv("c", 3, c4:head()); | 271 expect_kv("c", 3, c4:head()); |
272 expect_kv("a", 1, c4:tail()); | 272 expect_kv("a", 1, c4:tail()); |
273 | 273 |
274 local c5 = new(3, function (k, v) | |
275 if k == "a" then | |
276 return nil; | |
277 elseif k == "b" then | |
278 return true; | |
279 end | |
280 return false; | |
281 end); | |
282 | |
283 assert_equal(c5:set("a", 1), true); | |
284 assert_equal(c5:set("a", 1), true); | |
285 assert_equal(c5:set("a", 1), true); | |
286 assert_equal(c5:set("a", 1), true); | |
287 assert_equal(c5:set("b", 2), true); | |
288 assert_equal(c5:set("c", 3), true); | |
289 assert_equal(c5:set("d", 4), true); -- "a" evicted (cb returned nil) | |
290 assert_equal(c5:set("d", 4), true); -- nop | |
291 assert_equal(c5:set("d", 4), true); -- nop | |
292 assert_equal(c5:set("e", 5), true); -- "b" evicted (cb returned true) | |
293 assert_equal(c5:set("f", 6), false); -- "c" won't evict (cb returned false) | |
294 | |
295 expect_kv("e", 5, c5:head()); | |
296 expect_kv("c", 3, c5:tail()); | |
297 | |
274 end | 298 end |