add SingletonTest test case(#642) (#702)

Co-authored-by: liulinfei <qq@qq.com>
pull/704/head
liulinfei121 2 years ago committed by GitHub
parent 6283ad6936
commit 8ddc528af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,5 +17,30 @@
package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import org.junit.Assert;
import org.junit.Test;
public class SingletonTest {
@Test
public void assertSingletonGet() {
Assert.assertNull(Singleton.get("userName"));
Singleton.put("userName", "hippo4j");
Assert.assertEquals("hippo4j", Singleton.get("userName"));
ThreadPoolParameterInfo threadPoolParameterInfo = ThreadPoolParameterInfo.builder().tenantId("prescription")
.itemId("dynamic-threadpool-example").tpId("message-consume").content("描述信息").corePoolSize(1)
.maximumPoolSize(2).queueType(1).capacity(4).keepAliveTime(513).executeTimeOut(null).rejectedType(4)
.isAlarm(1).capacityAlarm(80).livenessAlarm(80).allowCoreThreadTimeOut(1).build();
Singleton.put(threadPoolParameterInfo);
Assert.assertEquals(threadPoolParameterInfo, Singleton.get(ThreadPoolParameterInfo.class.getName()));
}
@Test
public void assertSingletonGet2() {
Assert.assertNull(Singleton.get("userName1", () -> null));
Assert.assertEquals("hippo4j", Singleton.get("userName1", () -> "hippo4j"));
Assert.assertEquals("123456", Singleton.get("pw", () -> "123456") + "");
Assert.assertNotEquals("135790", Singleton.get("pw", () -> "135790") + "");
}
}

Loading…
Cancel
Save