mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add randomSequence support
This commit is contained in:
@@ -59,7 +59,7 @@ public class SnowflakeTest {
|
||||
|
||||
Set<Long> ids = new ConcurrentHashSet<>();
|
||||
ThreadUtil.concurrencyTest(100, () -> {
|
||||
for (int i = 0; i < 5000; i++) {
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
if(false == ids.add(snowflake.nextId())){
|
||||
throw new UtilException("重复ID!");
|
||||
}
|
||||
@@ -74,4 +74,33 @@ public class SnowflakeTest {
|
||||
Assert.assertEquals(19, StrUtil.toString(l).length());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void snowflakeRandomSequenceTest(){
|
||||
final Snowflake snowflake = new Snowflake(null, 0, 0,
|
||||
false, Snowflake.DEFAULT_TIME_OFFSET, 2);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
final long id = snowflake.nextId();
|
||||
Console.log(id);
|
||||
ThreadUtil.sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uniqueOfRandomSequenceTest(){
|
||||
// 测试并发环境下生成ID是否重复
|
||||
final Snowflake snowflake = new Snowflake(null, 0, 0,
|
||||
false, Snowflake.DEFAULT_TIME_OFFSET, 100);
|
||||
|
||||
Set<Long> ids = new ConcurrentHashSet<>();
|
||||
ThreadUtil.concurrencyTest(100, () -> {
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
if(false == ids.add(snowflake.nextId())){
|
||||
throw new UtilException("重复ID!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user