forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: optimize Apollo configuration (apache#4018)
- Loading branch information
Showing
9 changed files
with
158 additions
and
26 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
50 changes: 50 additions & 0 deletions
50
...igure-core/src/test/java/io/seata/spring/boot/autoconfigure/BaseConfigPropertiesTest.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,50 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.spring.boot.autoconfigure; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
/** | ||
* @author slievrly | ||
*/ | ||
public class BaseConfigPropertiesTest { | ||
protected static AnnotationConfigApplicationContext applicationContex; | ||
protected static final String STR_TEST_AAA = "aaa"; | ||
protected static final String STR_TEST_BBB = "bbb"; | ||
protected static final String STR_TEST_CCC = "ccc"; | ||
protected static final String STR_TEST_DDD = "ddd"; | ||
protected static final String STR_TEST_EEE = "eee"; | ||
protected static final String STR_TEST_FFF = "fff"; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
applicationContex = new AnnotationConfigApplicationContext( | ||
new String[] {"io.seata.spring.boot.autoconfigure.properties.test"}); | ||
SeataCoreEnvironmentPostProcessor processor = new SeataCoreEnvironmentPostProcessor(); | ||
processor.postProcessEnvironment(null, null); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
if (null != applicationContex) { | ||
applicationContex.close(); | ||
} | ||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
...t/java/io/seata/spring/boot/autoconfigure/properties/test/ConfigApolloPropertiesTest.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,60 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.spring.boot.autoconfigure.properties.test; | ||
|
||
import io.seata.common.loader.EnhancedServiceLoader; | ||
import io.seata.config.Configuration; | ||
import io.seata.config.ExtConfigurationProvider; | ||
import io.seata.config.FileConfiguration; | ||
import io.seata.config.apollo.ApolloConfiguration; | ||
import io.seata.spring.boot.autoconfigure.BaseConfigPropertiesTest; | ||
import io.seata.spring.boot.autoconfigure.properties.config.ConfigApolloProperties; | ||
import io.seata.spring.boot.autoconfigure.provider.SpringApplicationContextProvider; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
* @author slievrly | ||
*/ | ||
@org.springframework.context.annotation.Configuration | ||
@Import(SpringApplicationContextProvider.class) | ||
class ConfigApolloPropertiesTest extends BaseConfigPropertiesTest { | ||
|
||
@Bean | ||
public ConfigApolloProperties configApolloProperties() { | ||
return new ConfigApolloProperties().setApolloMeta(STR_TEST_AAA).setApolloAccessKeySecret(STR_TEST_BBB).setAppId( | ||
STR_TEST_CCC).setNamespace(STR_TEST_DDD).setCluster(STR_TEST_EEE).setApolloConfigService(STR_TEST_FFF); | ||
} | ||
|
||
@Test | ||
public void testConfigApolloProperties() { | ||
FileConfiguration configuration = mock(FileConfiguration.class); | ||
Configuration currentConfiguration = EnhancedServiceLoader.load(ExtConfigurationProvider.class).provide( | ||
configuration); | ||
|
||
assertEquals(STR_TEST_AAA, currentConfiguration.getConfig(ApolloConfiguration.getApolloMetaFileKey())); | ||
assertEquals(STR_TEST_BBB, currentConfiguration.getConfig(ApolloConfiguration.getApolloSecretFileKey())); | ||
assertEquals(STR_TEST_CCC, currentConfiguration.getConfig(ApolloConfiguration.getApolloAppIdFileKey())); | ||
assertEquals(STR_TEST_DDD, currentConfiguration.getConfig(ApolloConfiguration.getApolloNamespaceKey())); | ||
assertEquals(STR_TEST_EEE, currentConfiguration.getConfig(ApolloConfiguration.getApolloCluster())); | ||
assertEquals(STR_TEST_FFF, currentConfiguration.getConfig(ApolloConfiguration.getApolloConfigService())); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...utoconfigure/seata-spring-autoconfigure-core/src/test/resources/META-INF/spring.factories
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,3 @@ | ||
# Environment Post Processors | ||
org.springframework.boot.env.EnvironmentPostProcessor=\ | ||
io.seata.spring.boot.autoconfigure.SeataCoreEnvironmentPostProcessor |