Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ctrip.framework.apollo.spring.config;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

import com.ctrip.framework.apollo.Config;
Expand Down Expand Up @@ -31,7 +31,7 @@
* @author Jason Song([email protected])
*/
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ public void testMultiplePropertySourcesWithSameProperties() throws Exception {
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
public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception {
int someTimeout = 1000;
Expand Down Expand Up @@ -188,6 +208,15 @@ TestJavaConfigBean2 testJavaConfigBean2(@Value("${timeout:100}") int timeout, @V
}
}

@Configuration
@EnableApolloConfig({"FX.apollo", "application"})
static class AppConfig6 {
@Bean
TestJavaConfigBean testJavaConfigBean() {
return new TestJavaConfigBean();
}
}

@Component
static class TestJavaConfigBean {
@Value("${timeout:100}")
Expand Down