mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
9eb29695bf
commit
9ecc1406b8
@ -1,7 +1,6 @@
|
|||||||
package cn.hutool.core.cache;
|
package cn.hutool.core.cache;
|
||||||
|
|
||||||
import cn.hutool.core.cache.impl.LRUCache;
|
import cn.hutool.core.cache.impl.LRUCache;
|
||||||
import cn.hutool.core.lang.Console;
|
|
||||||
import cn.hutool.core.text.StrUtil;
|
import cn.hutool.core.text.StrUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
@ -10,6 +9,7 @@ import org.junit.Ignore;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 见:<a href="https://github.com/dromara/hutool/issues/1895">https://github.com/dromara/hutool/issues/1895</a><br>
|
* 见:<a href="https://github.com/dromara/hutool/issues/1895">https://github.com/dromara/hutool/issues/1895</a><br>
|
||||||
@ -69,13 +69,20 @@ public class LRUCacheTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void issue2647Test(){
|
public void issue2647Test(){
|
||||||
|
final AtomicInteger removeCount = new AtomicInteger();
|
||||||
|
|
||||||
final LRUCache<String, Integer> cache = CacheUtil.newLRUCache(3,1);
|
final LRUCache<String, Integer> cache = CacheUtil.newLRUCache(3,1);
|
||||||
cache.setListener((key, value) -> Console.log("Start remove k-v, key:{}, value:{}", key, value));
|
cache.setListener((key, value) -> {
|
||||||
|
// 共移除7次
|
||||||
|
removeCount.incrementAndGet();
|
||||||
|
//Console.log("Start remove k-v, key:{}, value:{}", key, value);
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
cache.put(StrUtil.format("key-{}", i), i);
|
cache.put(StrUtil.format("key-{}", i), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(7, removeCount.get());
|
||||||
Assert.assertEquals(3, cache.size());
|
Assert.assertEquals(3, cache.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user