-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5ec844
commit 7638ab6
Showing
15 changed files
with
424 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../test-configcenter/src/test/java/org/dromara/dynamictp/test/configcenter/DtpBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dromara.dynamictp.test.configcenter; | ||
|
||
import org.dromara.dynamictp.core.spring.EnableDynamicTp; | ||
import org.dromara.dynamictp.core.spring.YamlPropertySourceFactory; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
|
||
/** | ||
* DtpBaseTest related | ||
* | ||
* @author yanhom | ||
* @since 1.1.7 | ||
*/ | ||
@EnableDynamicTp | ||
@EnableAutoConfiguration | ||
@SpringBootTest(classes = {DtpBaseTest.class}) | ||
@PropertySource(value = "classpath:/dynamic-tp-demo-dtp-dev.yml", factory = YamlPropertySourceFactory.class) | ||
@ComponentScan(basePackages = "org.dromara.dynamictp.test.configcenter") | ||
@AutoConfigureAfter(ConfigurationPropertiesRebinderAutoConfiguration.class) | ||
public class DtpBaseTest { | ||
|
||
@Autowired | ||
protected ApplicationEventPublisher publisher; | ||
|
||
@Autowired | ||
protected Environment environment; | ||
|
||
protected static ConfigurableApplicationContext context; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
context = SpringApplication.run(DtpBaseTest.class); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...nter/src/test/java/org/dromara/dynamictp/test/configcenter/apollo/ApolloInitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dromara.dynamictp.test.configcenter.apollo; | ||
|
||
import com.ctrip.framework.apollo.ConfigService; | ||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; | ||
import com.ctrip.framework.apollo.internals.YmlConfigFile; | ||
import com.ctrip.framework.apollo.spring.config.PropertySourcesConstants; | ||
import com.google.common.collect.Maps; | ||
import org.springframework.boot.ConfigurableBootstrapContext; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.SpringApplicationRunListener; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.MapPropertySource; | ||
import org.springframework.core.env.MutablePropertySources; | ||
|
||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import static com.ctrip.framework.apollo.core.ConfigConsts.CONFIG_FILE_CONTENT_KEY; | ||
|
||
/** | ||
* ApolloInitListener related | ||
* | ||
* @author yanhom | ||
* @since 1.1.0 | ||
*/ | ||
public class ApolloInitListener implements SpringApplicationRunListener { | ||
|
||
public ApolloInitListener(SpringApplication application, String[] args) { | ||
|
||
} | ||
|
||
@Override | ||
public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) { | ||
MutablePropertySources propertySources = environment.getPropertySources(); | ||
Map<String, Object> tmpMap = Maps.newHashMap(); | ||
tmpMap.put(PropertySourcesConstants.APOLLO_BOOTSTRAP_NAMESPACES, "dynamic-tp-demo-dtp-dev.yml"); | ||
propertySources.addFirst(new MapPropertySource("DtpRefreshTestPropertySource", tmpMap)); | ||
|
||
YmlConfigFile configFile = (YmlConfigFile) ConfigService.getConfigFile("dynamic-tp-demo-dtp-dev", ConfigFileFormat.YML); | ||
Properties newProperties = new Properties(); | ||
String content = "spring:\n" + | ||
" dynamic:\n" + | ||
" tp:\n" + | ||
" enabled: true # 是否启用 dynamictp,默认true\n" + | ||
" executors: # 动态线程池配置,都有默认值,采用默认值的可以不配置该项,减少配置量\n" + | ||
" - threadPoolName: dtpExecutor1\n" + | ||
" threadPoolAliasName: 测试线程池 # 线程池别名\n" + | ||
" executorType: common # 线程池类型 common、eager、ordered、scheduled,默认 common\n" + | ||
" corePoolSize: 6 # 核心线程数,默认1\n" + | ||
" maximumPoolSize: 8 # 最大线程数,默认cpu核数\n" + | ||
" queueCapacity: 2000 # 队列容量,默认1024\n"; | ||
newProperties.setProperty(CONFIG_FILE_CONTENT_KEY, content); | ||
configFile.onRepositoryChange("dynamic-tp-demo-dtp-dev.yml", newProperties); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ter/src/test/java/org/dromara/dynamictp/test/configcenter/apollo/ApolloRefresherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dromara.dynamictp.test.configcenter.apollo; | ||
|
||
import com.ctrip.framework.apollo.ConfigService; | ||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; | ||
import com.ctrip.framework.apollo.internals.YamlConfigFile; | ||
import org.dromara.dynamictp.test.configcenter.DtpBaseTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Properties; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import static com.ctrip.framework.apollo.core.ConfigConsts.CONFIG_FILE_CONTENT_KEY; | ||
|
||
/** | ||
* CloudRefreshTest related | ||
* | ||
* @author yanhom | ||
* @since 1.1.7 | ||
*/ | ||
class ApolloRefresherTest extends DtpBaseTest { | ||
|
||
@Test | ||
void testRefresh() throws InterruptedException { | ||
int corePoolSize = context.getBean("dtpExecutor1", ThreadPoolExecutor.class).getCorePoolSize(); | ||
System.out.println(corePoolSize); | ||
Assertions.assertEquals(6, corePoolSize); | ||
mockConfigChange(); | ||
Thread.sleep(6000L); | ||
corePoolSize = context.getBean("dtpExecutor1", ThreadPoolExecutor.class).getCorePoolSize(); | ||
System.out.println(corePoolSize); | ||
Assertions.assertEquals(10, corePoolSize); | ||
} | ||
|
||
private void mockConfigChange() { | ||
YamlConfigFile configFile = (YamlConfigFile) ConfigService.getConfigFile("dynamic-tp-demo-dtp-dev", ConfigFileFormat.YML); | ||
Properties newProperties = new Properties(); | ||
String content = "spring:\n" + | ||
" dynamic:\n" + | ||
" tp:\n" + | ||
" enabled: true # 是否启用 dynamictp,默认true\n" + | ||
" executors: # 动态线程池配置,都有默认值,采用默认值的可以不配置该项,减少配置量\n" + | ||
" - threadPoolName: dtpExecutor1\n" + | ||
" threadPoolAliasName: 测试线程池 # 线程池别名\n" + | ||
" executorType: common # 线程池类型 common、eager、ordered、scheduled,默认 common\n" + | ||
" corePoolSize: 10 # 核心线程数,默认1\n" + | ||
" maximumPoolSize: 20 # 最大线程数,默认cpu核数\n"; | ||
newProperties.setProperty(CONFIG_FILE_CONTENT_KEY, content); | ||
configFile.onRepositoryChange("dynamic-tp-demo-dtp-dev.yml", newProperties); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ter/src/test/java/org/dromara/dynamictp/test/configcenter/cloud/CloudRefresherConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dromara.dynamictp.test.configcenter.cloud; | ||
|
||
import org.dromara.dynamictp.common.properties.DtpProperties; | ||
import org.dromara.dynamictp.starter.cloud.nacos.refresher.CloudNacosRefresher; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* RefresherConfig related | ||
* | ||
* @author yanhom | ||
* @since 1.1.0 | ||
*/ | ||
@Configuration | ||
public class CloudRefresherConfig { | ||
|
||
@Bean | ||
public CloudNacosRefresher cloudNacosRefresher(DtpProperties dtpProperties) { | ||
return new CloudNacosRefresher(dtpProperties); | ||
} | ||
} |
Oops, something went wrong.