Skip to content

Commit

Permalink
Fix flaky test in Md5UtilTest (#1494)
Browse files Browse the repository at this point in the history
* Fix flaky test in Md5UtilTest

* Remove unused imports

---------

Co-authored-by: bbelide2 <[email protected]>
  • Loading branch information
bbelide2 and bbelide2 authored Oct 6, 2023
1 parent 79dc8f5 commit cf854b3
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import org.junit.Test;
import org.mockito.MockedStatic;

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
Expand All @@ -50,12 +54,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<ContentUtil> 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
Expand Down

0 comments on commit cf854b3

Please sign in to comment.