🎨 #2663 优化重复消息检查器多实例导致多守护线程的问题,修改成单例+定时任务线程池处理

This commit is contained in:
helloworldByChinese
2022-05-27 09:16:56 +08:00
committed by GitHub
parent 41bb3b9901
commit 95be03bf1c
7 changed files with 150 additions and 8 deletions

View File

@ -0,0 +1,45 @@
package me.chanjar.weixin.common.api;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
* @author jiangby
* @version 1.0
* @description: 作用
* @date 2022/5/26 1:46
*/
@Test
public class WxMessageInMemoryDuplicateCheckerSingletonTest {
private static WxMessageInMemoryDuplicateCheckerSingleton checkerSingleton = WxMessageInMemoryDuplicateCheckerSingleton.getInstance();
public void test() throws InterruptedException {
Long[] msgIds = new Long[]{1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L};
// 第一次检查
for (Long msgId : msgIds) {
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
assertFalse(result);
}
// 初始化后1S进行检查 每五秒检查一次过期时间为15秒过15秒再检查
TimeUnit.SECONDS.sleep(15);
for (Long msgId : msgIds) {
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
assertTrue(result);
}
// 过6秒再检查
TimeUnit.SECONDS.sleep(6);
for (Long msgId : msgIds) {
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
assertFalse(result);
}
}
}