|
@@ -17,7 +17,7 @@ import java.util.concurrent.CountDownLatch;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* {@link IdUtil} 单元测试
|
|
* {@link IdUtil} 单元测试
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @author looly
|
|
* @author looly
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
@@ -31,12 +31,12 @@ public class IdUtilTest {
|
|
|
String randomUUID = IdUtil.randomUUID();
|
|
String randomUUID = IdUtil.randomUUID();
|
|
|
Assert.assertEquals(36, randomUUID.length());
|
|
Assert.assertEquals(36, randomUUID.length());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void fastUUIDTest() {
|
|
public void fastUUIDTest() {
|
|
|
String simpleUUID = IdUtil.fastSimpleUUID();
|
|
String simpleUUID = IdUtil.fastSimpleUUID();
|
|
|
Assert.assertEquals(32, simpleUUID.length());
|
|
Assert.assertEquals(32, simpleUUID.length());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
String randomUUID = IdUtil.fastUUID();
|
|
String randomUUID = IdUtil.fastUUID();
|
|
|
Assert.assertEquals(36, randomUUID.length());
|
|
Assert.assertEquals(36, randomUUID.length());
|
|
|
}
|
|
}
|
|
@@ -60,25 +60,26 @@ public class IdUtilTest {
|
|
|
}
|
|
}
|
|
|
Console.log(timer.interval());
|
|
Console.log(timer.interval());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void objectIdTest() {
|
|
public void objectIdTest() {
|
|
|
String id = IdUtil.objectId();
|
|
String id = IdUtil.objectId();
|
|
|
Assert.assertEquals(24, id.length());
|
|
Assert.assertEquals(24, id.length());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void createSnowflakeTest() {
|
|
public void createSnowflakeTest() {
|
|
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
|
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
|
|
long id = snowflake.nextId();
|
|
long id = snowflake.nextId();
|
|
|
Assert.assertTrue(id > 0);
|
|
Assert.assertTrue(id > 0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
|
|
+ @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.createSnowflake(1, 1);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//线程数
|
|
//线程数
|
|
|
int threadCount = 100;
|
|
int threadCount = 100;
|
|
|
//每个线程生成的ID数
|
|
//每个线程生成的ID数
|
|
@@ -94,7 +95,7 @@ public class IdUtilTest {
|
|
|
latch.countDown();
|
|
latch.countDown();
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//等待全部线程结束
|
|
//等待全部线程结束
|
|
|
try {
|
|
try {
|
|
|
latch.await();
|
|
latch.await();
|
|
@@ -103,11 +104,12 @@ public class IdUtilTest {
|
|
|
}
|
|
}
|
|
|
Assert.assertEquals(threadCount * idCountPerThread, set.size());
|
|
Assert.assertEquals(threadCount * idCountPerThread, set.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
|
|
+ @Ignore
|
|
|
public void snowflakeBenchTest2() {
|
|
public void snowflakeBenchTest2() {
|
|
|
final Set<Long> set = new ConcurrentHashSet<>();
|
|
final Set<Long> set = new ConcurrentHashSet<>();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//线程数
|
|
//线程数
|
|
|
int threadCount = 100;
|
|
int threadCount = 100;
|
|
|
//每个线程生成的ID数
|
|
//每个线程生成的ID数
|
|
@@ -123,7 +125,7 @@ public class IdUtilTest {
|
|
|
latch.countDown();
|
|
latch.countDown();
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//等待全部线程结束
|
|
//等待全部线程结束
|
|
|
try {
|
|
try {
|
|
|
latch.await();
|
|
latch.await();
|