提交 fb022bde 编写于 作者: W wgy8283335

Modify test cases for "digest" in LeafSnowflakeKeyGeneratorTest.

上级 66ab9dad
......@@ -70,6 +70,24 @@ public final class LeafSnowflakeKeyGeneratorTest {
assertThat(actual, is(expected));
}
@Test
public void assertGenerateKeyWithDigest() {
Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181");
properties.setProperty("serviceId", "testService1");
properties.setProperty("digest", "name:123456");
properties.setProperty("maxTimeDifference", "5000");
properties.setProperty("registryCenterType", "ForthTestRegistryCenter");
leafSnowflakeKeyGenerator.setProperties(properties);
FieldUtil.setStaticFinalField(leafSnowflakeKeyGenerator, "timeService", new FixedTimeService(1));
List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(4198401L, 4198402L, 8392704L, 8392705L, 12587009L, 12587010L, 16781312L, 16781313L, 20975617L, 20975618L);
List<Comparable<?>> actual = new ArrayList<>();
for (int i = 0; i < 10; i++) {
actual.add(leafSnowflakeKeyGenerator.generateKey());
}
assertThat(actual, is(expected));
}
@Test
public void assertGenerateKeyWithFixedWorkId() {
Properties properties = new Properties();
......@@ -133,30 +151,6 @@ public final class LeafSnowflakeKeyGeneratorTest {
assertThat(actual.size(), is(taskNumber));
}
@Test
public void assertGenerateKeyWithDigest() throws Exception {
int threadNumber = Runtime.getRuntime().availableProcessors() << 1;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181");
properties.setProperty("serviceId", "testService1");
properties.setProperty("maxTimeDifference", "5000");
properties.setProperty("registryCenterType", "ForthTestRegistryCenter");
leafSnowflakeKeyGenerator.setProperties(properties);
Set<Comparable<?>> actual = new HashSet<>();
int taskNumber = threadNumber << 2;
for (int i = 0; i < taskNumber; i++) {
actual.add(executor.submit(new Callable<Comparable<?>>() {
@Override
public Comparable<?> call() {
return leafSnowflakeKeyGenerator.generateKey();
}
}).get());
}
assertThat(actual.size(), is(taskNumber));
}
@Test
public void assertGenerateKeyWithDefaultMaxTimeDifference() throws Exception {
int threadNumber = Runtime.getRuntime().availableProcessors() << 1;
......@@ -266,7 +260,7 @@ public final class LeafSnowflakeKeyGeneratorTest {
}
@Test(expected = Exception.class)
public void assertSetRegistryCenterTypeFailureWhenArgumentEmpty() {
public void assertSetRegistryCenterTypeFailureWhenArgumentWrong() {
Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181");
properties.setProperty("serviceId", "testService1");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册