Merge remote-tracking branch 'origin/develop' into develop

pull/678/head
jing 3 years ago
commit 5b45bba46e

@ -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));
}
}

@ -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<String> 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)));
}
}

@ -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

@ -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;

@ -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

@ -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);

Loading…
Cancel
Save