mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add methods
This commit is contained in:
@@ -13,8 +13,6 @@
|
||||
package org.dromara.hutool.core.data.id;
|
||||
|
||||
import org.dromara.hutool.core.collection.ConcurrentHashSet;
|
||||
import org.dromara.hutool.core.data.id.IdUtil;
|
||||
import org.dromara.hutool.core.data.id.Snowflake;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.lang.tuple.Pair;
|
||||
@@ -83,6 +81,22 @@ public class SnowflakeTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void uniqueTest2(){
|
||||
// 测试并发环境下生成ID是否重复
|
||||
final Snowflake snowflake = IdUtil.getSnowflake();
|
||||
|
||||
final Set<Long> ids = new ConcurrentHashSet<>();
|
||||
ThreadUtil.concurrencyTest(100, () -> {
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
if(!ids.add(snowflake.next())){
|
||||
throw new HutoolException("重复ID!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSnowflakeLengthTest(){
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
Reference in New Issue
Block a user