add randomSequence support

This commit is contained in:
Looly
2022-04-06 23:50:56 +08:00
parent 552357cc4e
commit d415696e01
3 changed files with 77 additions and 23 deletions

View File

@@ -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");
}
}
});
}
}