From a2e7dff078af80fb7e0bb296330cae5b7169eeed Mon Sep 17 00:00:00 2001 From: bbelide2 Date: Thu, 21 Sep 2023 16:58:37 -0500 Subject: [PATCH 1/2] Fix flaky test in Md5UtilTest --- .../hippo4j/common/toolkit/Md5UtilTest.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java b/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java index adf128edab..1ae4d920b3 100644 --- a/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java @@ -19,12 +19,18 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockedStatic; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.mockStatic; + public class Md5UtilTest { @Test @@ -50,12 +56,15 @@ public void assetEncodeHexString() { @Test public void assetGetTpContentMd5() { - String md5Result = "ef5ea7cb47377fb9fb85a7125e76715d"; - ThreadPoolParameterInfo threadPoolParameterInfo = ThreadPoolParameterInfo.builder().tenantId("prescription") - .itemId("dynamic-threadpool-example").tpId("message-consume").content("描述信息").corePoolSize(1) - .maximumPoolSize(2).queueType(1).capacity(4).keepAliveTime(513L).executeTimeOut(null).rejectedType(4) - .isAlarm(1).capacityAlarm(80).livenessAlarm(80).allowCoreThreadTimeOut(1).build(); - Assert.isTrue(md5Result.equals(Md5Util.getTpContentMd5(threadPoolParameterInfo))); + final ThreadPoolParameterInfo threadPoolParameterInfo = new ThreadPoolParameterInfo(); + final String mockContent = "mockContent"; + final String mockContentMd5 = "34cf17bc632ece6e4c81a4ce8aa97d5e"; + try (final MockedStatic mockedContentUtil = mockStatic(ContentUtil.class)) { + mockedContentUtil.when(() -> ContentUtil.getPoolContent(threadPoolParameterInfo)).thenReturn(mockContent); + final String result = Md5Util.getTpContentMd5(threadPoolParameterInfo); + Assert.isTrue(result.equals(mockContentMd5)); + mockedContentUtil.verify(() -> ContentUtil.getPoolContent(threadPoolParameterInfo), times(1)); + } } @Test From 776dce66cd279baae40e9945c809b71b2f84c5c9 Mon Sep 17 00:00:00 2001 From: balasukesh Date: Tue, 26 Sep 2023 01:59:10 -0500 Subject: [PATCH 2/2] Remove unused imports --- .../src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java b/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java index 1ae4d920b3..1004e9d352 100644 --- a/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java @@ -19,9 +19,7 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.security.NoSuchAlgorithmException;