diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/FileUtilTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/FileUtilTest.java index aa1c9ca8..75b5edf4 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/FileUtilTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/FileUtilTest.java @@ -27,4 +27,15 @@ public class FileUtilTest { String contentByFileUtil = FileUtil.readUtf8String(testFilePath); Assert.notEmpty(contentByFileUtil); } + + @Test + public void assertReadUtf8String2() { + String linebreaks = System.getProperty("line.separator"); + String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *" + linebreaks + + "second line" + linebreaks + + "empty line next" + linebreaks; + String testFilePath = "test/test_utf8.txt"; + String contentByFileUtil = FileUtil.readUtf8String(testFilePath); + Assert.isTrue(testText.equals(contentByFileUtil)); + } } diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java index a6944f49..0c9191b1 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/Md5UtilTest.java @@ -17,5 +17,55 @@ package cn.hippo4j.common.toolkit; +import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import org.junit.Test; + +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; + public class Md5UtilTest { + + @Test + public void assertMd5Hex() throws NoSuchAlgorithmException { + String md5 = "3cdefff74dcf7a5d60893865b84b62c8"; + String message = "message-consume"; + Assert.isTrue(md5.equals(Md5Util.md5Hex(message.getBytes()))); + } + + @Test + public void assertMd5Hex2() { + String md5 = "503840dc3af3cdb39749cd099e4dfeff"; + String message = "dynamic-threadpool-example"; + Assert.isTrue(md5.equals(Md5Util.md5Hex(message, "UTF-8"))); + } + + @Test + public void assetEncodeHexString() { + String encodeHexString = "00010f107f80203040506070"; + byte[] bytes = {0, 1, 15, 16, 127, -128, 32, 48, 64, 80, 96, 112}; + Assert.isTrue(encodeHexString.equals(Md5Util.encodeHexString(bytes))); + } + + @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(513).executeTimeOut(null).rejectedType(4) + .isAlarm(1).capacityAlarm(80).livenessAlarm(80).allowCoreThreadTimeOut(1).build(); + Assert.isTrue(md5Result.equals(Md5Util.getTpContentMd5(threadPoolParameterInfo))); + } + + @Test + public void assetCompareMd5ResultString() throws IOException { + Assert.isTrue("".equals(Md5Util.compareMd5ResultString(null))); + String result = "prescription%02dynamic-threadpool-example%02message-consume%01" + + "prescription%02dynamic-threadpool-example%02message-produce%01"; + List changedGroupKeys = new ArrayList<>(2); + changedGroupKeys.add("prescription+dynamic-threadpool-example+message-consume+12"); + changedGroupKeys.add("prescription+dynamic-threadpool-example+message-produce+11"); + Assert.isTrue(result.equals(Md5Util.compareMd5ResultString(changedGroupKeys))); + } } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/config/MybatisPlusConfig.java b/hippo4j-config/src/main/java/cn/hippo4j/config/config/MybatisPlusConfig.java index f339efde..6af649b8 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/config/MybatisPlusConfig.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/config/MybatisPlusConfig.java @@ -30,8 +30,8 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class MybatisPlusConfig { - - @Value("${spring.profiles.active}") + + @Value("${spring.profiles.active:mysql}") private String profilesActive; @Bean diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java similarity index 99% rename from hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java rename to hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index aa24eaeb..18cb3163 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolCoreAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -64,7 +64,7 @@ import org.springframework.core.annotation.Order; ConfigHandlerConfiguration.EmbeddedApollo.class, ConfigHandlerConfiguration.EmbeddedZookeeper.class, ConfigHandlerConfiguration.EmbeddedEtcd.class }) -public class DynamicThreadPoolCoreAutoConfiguration { +public class DynamicThreadPoolAutoConfiguration { private final BootstrapConfigProperties bootstrapConfigProperties; diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/resources/META-INF/spring.factories b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/resources/META-INF/spring.factories index 5f39cf76..89ccf301 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolCoreAutoConfiguration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolAutoConfiguration diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java index fe80b71b..bbabf6bc 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -153,20 +153,19 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { .allowCoreThreadTimeOut(EnableEnum.getBool(threadPoolParameterInfo.getAllowCoreThreadTimeOut())) .build(); // Set dynamic thread pool enhancement parameters. - ThreadPoolExecutor customDynamicThreadPool; - if ((customDynamicThreadPool = executor) instanceof AbstractDynamicExecutorSupport) { + if (executor instanceof AbstractDynamicExecutorSupport) { ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( BooleanUtil.toBoolean(threadPoolParameterInfo.getIsAlarm().toString()), threadPoolParameterInfo.getCapacityAlarm(), threadPoolParameterInfo.getLivenessAlarm()); GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm); - TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) customDynamicThreadPool).getTaskDecorator(); + TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) executor).getTaskDecorator(); ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setTaskDecorator(taskDecorator); - long awaitTerminationMillis = ((DynamicThreadPoolExecutor) customDynamicThreadPool).awaitTerminationMillis; - boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) customDynamicThreadPool).waitForTasksToCompleteOnShutdown; + long awaitTerminationMillis = ((DynamicThreadPoolExecutor) executor).awaitTerminationMillis; + boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) executor).waitForTasksToCompleteOnShutdown; ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown); long executeTimeOut = Optional.ofNullable(threadPoolParameterInfo.getExecuteTimeOut()) - .orElse(((DynamicThreadPoolExecutor) customDynamicThreadPool).getExecuteTimeOut()); + .orElse(((DynamicThreadPoolExecutor) executor).getExecuteTimeOut()); ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setExecuteTimeOut(executeTimeOut); } dynamicThreadPoolWrapper.setExecutor(newDynamicThreadPoolExecutor);