This commit is contained in:
Daniel Qian
2015-01-20 09:49:39 +08:00
parent 85168a14aa
commit 9fe73319d1
7 changed files with 199 additions and 92 deletions

View File

@ -0,0 +1,38 @@
package me.chanjar.weixin.common.util;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Created by qianjia on 15/1/20.
*/
@Test
public class WxMsgIdInMemoryDuplicateCheckerTest {
public void test() throws InterruptedException {
Long[] msgIds = new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l };
WxMsgIdInMemoryDuplicateChecker checker = new WxMsgIdInMemoryDuplicateChecker(2000l, 1000l);
// 第一次检查
for (Long msgId : msgIds) {
boolean result = checker.isDuplicate(msgId);
Assert.assertFalse(result);
}
// 过1秒再检查
Thread.sleep(1000l);
for (Long msgId : msgIds) {
boolean result = checker.isDuplicate(msgId);
Assert.assertTrue(result);
}
// 过1.5秒再检查
Thread.sleep(1500l);
for (Long msgId : msgIds) {
boolean result = checker.isDuplicate(msgId);
Assert.assertFalse(result);
}
}
}

View File

@ -7,6 +7,7 @@
<class name="me.chanjar.weixin.common.bean.WxErrorTest" />
<class name="me.chanjar.weixin.common.bean.WxMenuTest" />
<class name="me.chanjar.weixin.common.util.crypto.WxCryptUtilTest" />
<class name="me.chanjar.weixin.common.util.WxMsgIdInMemoryDuplicateCheckerTest" />
</classes>
</test>
</suite>