This commit is contained in:
Looly 2021-08-11 09:20:32 +08:00
parent 163ce2a67c
commit b048cc7fd7
2 changed files with 10 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package cn.hutool.core.lang;
import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -56,10 +55,10 @@ public class SnowflakeTest {
@Ignore @Ignore
public void uniqueTest(){ public void uniqueTest(){
// 测试并发环境下生成ID是否重复 // 测试并发环境下生成ID是否重复
Snowflake snowflake = IdUtil.createSnowflake(0, 0); Snowflake snowflake = IdUtil.getSnowflake(0, 0);
Set<Long> ids = new ConcurrentHashSet<>(); Set<Long> ids = new ConcurrentHashSet<>();
ConcurrencyTester tester = ThreadUtil.concurrencyTest(100, () -> { ThreadUtil.concurrencyTest(100, () -> {
for (int i = 0; i < 5000; i++) { for (int i = 0; i < 5000; i++) {
if(false == ids.add(snowflake.nextId())){ if(false == ids.add(snowflake.nextId())){
throw new UtilException("重复ID"); throw new UtilException("重复ID");

View File

@ -68,8 +68,8 @@ public class IdUtilTest {
} }
@Test @Test
public void createSnowflakeTest() { public void getSnowflakeTest() {
Snowflake snowflake = IdUtil.createSnowflake(1, 1); Snowflake snowflake = IdUtil.getSnowflake(1, 1);
long id = snowflake.nextId(); long id = snowflake.nextId();
Assert.assertTrue(id > 0); Assert.assertTrue(id > 0);
} }
@ -78,7 +78,7 @@ public class IdUtilTest {
@Ignore @Ignore
public void snowflakeBenchTest() { public void snowflakeBenchTest() {
final Set<Long> set = new ConcurrentHashSet<>(); final Set<Long> set = new ConcurrentHashSet<>();
final Snowflake snowflake = IdUtil.createSnowflake(1, 1); final Snowflake snowflake = IdUtil.getSnowflake(1, 1);
//线程数 //线程数
int threadCount = 100; int threadCount = 100;