Commit 77029324 by jian.tan

Multimap并未严格保持@EnableApolloConfig注解中namespace定义的顺序。

parent 3573f3ef
...@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.spring.config; ...@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.spring.config;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.Config;
...@@ -31,7 +32,7 @@ import java.util.Iterator; ...@@ -31,7 +32,7 @@ import java.util.Iterator;
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
public class PropertySourcesProcessor implements BeanFactoryPostProcessor, EnvironmentAware, PriorityOrdered { public class PropertySourcesProcessor implements BeanFactoryPostProcessor, EnvironmentAware, PriorityOrdered {
private static final Multimap<Integer, String> NAMESPACE_NAMES = HashMultimap.create(); private static final Multimap<Integer, String> NAMESPACE_NAMES = LinkedHashMultimap.create();
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
......
...@@ -96,6 +96,26 @@ public class JavaConfigPlaceholderTest extends AbstractSpringIntegrationTest { ...@@ -96,6 +96,26 @@ public class JavaConfigPlaceholderTest extends AbstractSpringIntegrationTest {
check(someTimeout, someBatch, AppConfig3.class); check(someTimeout, someBatch, AppConfig3.class);
} }
@Test
public void testMultiplePropertySourcesCoverWithSameProperties() throws Exception {
//Multimap does not maintain the strict input order of namespace.
int someTimeout = 1000;
int anotherTimeout = someTimeout + 1;
int someBatch = 2000;
Config fxApollo = mock(Config.class);
when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
when(fxApollo.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
mockConfig(FX_APOLLO_NAMESPACE, fxApollo);
Config application = mock(Config.class);
when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);
check(someTimeout, someBatch, AppConfig6.class);
}
@Test @Test
public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception { public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception {
int someTimeout = 1000; int someTimeout = 1000;
...@@ -188,6 +208,15 @@ public class JavaConfigPlaceholderTest extends AbstractSpringIntegrationTest { ...@@ -188,6 +208,15 @@ public class JavaConfigPlaceholderTest extends AbstractSpringIntegrationTest {
} }
} }
@Configuration
@EnableApolloConfig({"FX.apollo", "application"})
static class AppConfig6 {
@Bean
TestJavaConfigBean testJavaConfigBean() {
return new TestJavaConfigBean();
}
}
@Component @Component
static class TestJavaConfigBean { static class TestJavaConfigBean {
@Value("${timeout:100}") @Value("${timeout:100}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment