fix listener bug

This commit is contained in:
Looly
2022-10-12 00:05:31 +08:00
parent 7b7240aa4b
commit 9eb29695bf
3 changed files with 49 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package cn.hutool.core.cache;
import cn.hutool.core.cache.impl.LRUCache;
import cn.hutool.core.lang.Console;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
@@ -64,4 +66,16 @@ public class LRUCacheTest {
}
Assert.assertEquals("null123456789", sb2.toString());
}
@Test
public void issue2647Test(){
final LRUCache<String, Integer> cache = CacheUtil.newLRUCache(3,1);
cache.setListener((key, value) -> Console.log("Start remove k-v, key:{}, value:{}", key, value));
for (int i = 0; i < 10; i++) {
cache.put(StrUtil.format("key-{}", i), i);
}
Assert.assertEquals(3, cache.size());
}
}