-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加EnvironmentPostProcessor处理,将Apollo配置加载提到初始化日志系统之前
- Loading branch information
Showing
4 changed files
with
125 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package com.ctrip.framework.apollo.spring; | ||
|
||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.ctrip.framework.apollo.Config; | ||
import com.ctrip.framework.apollo.core.ConfigConsts; | ||
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; | ||
import com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer; | ||
import com.ctrip.framework.apollo.spring.config.PropertySourcesConstants; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Collections2; | ||
import com.google.common.collect.Sets; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
|
@@ -20,12 +18,21 @@ | |
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.env.EnvironmentPostProcessor; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.SpringFactoriesLoader; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
|
@@ -265,6 +272,48 @@ public void test() throws Exception { | |
} | ||
} | ||
|
||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest(classes = ConfigurationWithoutConditionalOnProperty.class) | ||
@DirtiesContext | ||
public static class TestWithBootstrapEnabledAndEagerLoadEnabled extends | ||
AbstractSpringIntegrationTest { | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
doSetUp(); | ||
|
||
System.setProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_ENABLED, "true"); | ||
System.setProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_EAGER_LOAD_ENABLED, "true"); | ||
|
||
Config config = mock(Config.class); | ||
|
||
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() { | ||
System.clearProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_ENABLED); | ||
System.clearProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_EAGER_LOAD_ENABLED); | ||
|
||
doTearDown(); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
List<EnvironmentPostProcessor> processorList = SpringFactoriesLoader.loadFactories(EnvironmentPostProcessor.class, getClass().getClassLoader()); | ||
|
||
Boolean containsApollo = !Collections2.filter(processorList, new Predicate<EnvironmentPostProcessor>() { | ||
@Override | ||
public boolean apply(EnvironmentPostProcessor input) { | ||
return input instanceof ApolloApplicationContextInitializer; | ||
} | ||
}).isEmpty(); | ||
Assert.assertTrue(containsApollo); | ||
} | ||
} | ||
|
||
|
||
@EnableAutoConfiguration | ||
@Configuration | ||
static class ConfigurationWithoutConditionalOnProperty { | ||
|