-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
resolved embedded value in annotation @ApolloConfigChangeListener #3349
resolved embedded value in annotation @ApolloConfigChangeListener #3349
Conversation
Looks good! Will take a detailed look soon |
@Anilople I'm thinking is it necessary to support embedded value for |
Implement But I'm not sure it will work. |
Meet |
...-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ApolloConfigRegistrarHelper.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #3349 +/- ##
============================================
+ Coverage 51.43% 51.51% +0.07%
- Complexity 2301 2307 +6
============================================
Files 442 441 -1
Lines 13741 13762 +21
Branches 1399 1400 +1
============================================
+ Hits 7068 7089 +21
Misses 6185 6185
Partials 488 488
Continue to review full report at Codecov.
|
.../src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java
Outdated
Show resolved
Hide resolved
…loConfig' instead of ConfigurableBeanFactory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see some comments below.
BTW is it possible to make it work for xml configuration? i.e. to resolve the namespace placeholder in com.ctrip.framework.apollo.spring.config.NamespaceHandler.BeanParser#doParse
...t/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigChangeListener.java
Outdated
Show resolved
Hide resolved
...va/com/ctrip/framework/apollo/spring/JavaConfigAnnotationApolloConfigChangeListenerTest.java
Outdated
Show resolved
Hide resolved
...va/com/ctrip/framework/apollo/spring/JavaConfigAnnotationApolloConfigChangeListenerTest.java
Outdated
Show resolved
Hide resolved
...va/com/ctrip/framework/apollo/spring/JavaConfigAnnotationApolloConfigChangeListenerTest.java
Outdated
Show resolved
Hide resolved
...va/com/ctrip/framework/apollo/spring/JavaConfigAnnotationApolloConfigChangeListenerTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigTest.java
Outdated
Show resolved
Hide resolved
...lient/src/test/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfigTest.java
Outdated
Show resolved
Hide resolved
...lient/src/test/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfigTest.java
Outdated
Show resolved
Hide resolved
...lient/src/test/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfigTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Jason Song <[email protected]>
Sometime test failure in DefaultConfigTest#testGetIntPropertyMultipleTimesWithShortExpireTime, because system property is global
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version looks much better, but I still have some comments as below, please take a look.
BTW, I noticed you created many inner classes and xmls for the tests, however I think many of them are quite similar, so maybe we could try to reuse them instead of creating new ones.
assertEquals(someValue, configuration.getSomeKey()); | ||
verify(yyyConfig, times(1)).getProperty(eq(someKey), anyString()); | ||
|
||
System.clearProperty(propertyKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clear the state in tearDown method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
@After
public void javaConfigAnnotationTestTearDown() {
// clear the system property
clearSystemPropertiesDefineWithStaticStringField(SystemPropertyKeyConstants.class);
}
to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little complex, I think we could simply assign some variables and just use System.clearProperty(xxx) in tear down method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to code like follow:
/**
* forbidden to override the method {@link super#tearDown()}.
*/
@After
public void javaConfigAnnotationTestTearDown() {
// clear the system properties
System.clearProperty(SystemPropertyKeyConstants.SIMPLE_NAMESPACE);
System.clearProperty(SystemPropertyKeyConstants.REDIS_NAMESPACE);
System.clearProperty(SystemPropertyKeyConstants.FROM_SYSTEM_NAMESPACE);
System.clearProperty(SystemPropertyKeyConstants.FROM_SYSTEM_YAML_NAMESPACE);
System.clearProperty(SystemPropertyKeyConstants.FROM_NAMESPACE_APPLICATION_KEY);
System.clearProperty(SystemPropertyKeyConstants.FROM_NAMESPACE_APPLICATION_KEY_YAML);
}
Clear system properties manually instead of using reflection.
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
// no using | ||
verify(ignoreConfig, never()).addChangeListener(any(ConfigChangeListener.class)); | ||
|
||
// strange, it invoke 2 times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because there is an auto update feature enabled: com.ctrip.framework.apollo.spring.config.PropertySourcesProcessor#initializeAutoUpdatePropertiesFeature
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
Outdated
Show resolved
Hide resolved
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/XmlConfigPlaceholderTest.java
Outdated
Show resolved
Hide resolved
private void check(String xmlLocation, int expectedTimeout, int expectedBatch) { | ||
|
||
@Test | ||
public void testResolveNamespacesWithDefaultValue() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this case failed in my machine, as there is no value for xxx.from.system.property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, this case looks like the same as testUnresolvedNamespaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it in commit b5eb6f0
…figChangeListenerResolveExpressionFromApplicationNamespace.
…rty'. Merge similar xml file.
In my machine(Win10), there is a test Failure in Results :
Failed tests:
DefaultConfigTest.testGetIntPropertyMultipleTimesWithShortExpireTime:280
properties.getProperty("someKey");
Wanted 2 times:
-> at com.ctrip.framework.apollo.internals.DefaultConfigTest.testGetIntPropertyMultipleTimesWithShortExpireTime(DefaultConfigTest.java:280)
But was 1 time:
-> at com.ctrip.framework.apollo.internals.DefaultConfig.getProperty(DefaultConfig.java:77)
Tests in error:
RemoteConfigRepositoryTest.testLongPollingRefresh:298 ? Timeout Waited 5000 mi...
Tests run: 293, Failures: 1, Errors: 1, Skipped: 0 I don't know why. Maybe a bug in mockito? Or exists some concurrent problem between tests? It seems ok on Linux platform. |
This test was not well written, I'll fix it later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What's the purpose of this PR
Make ApolloConfigChangeListener's value more dynamic.
Which issue(s) this PR fixes:
#3091
Brief changelog
The value in
ApolloConfigChangeListener
can be resolved now.One can write like follow:
"${redis.namespace}"
will be resolved.If there is property
redis.namespace=xxx
then
"${redis.namespace}"
will getxxx
If there is property
redis.namespace=yyy
then
"${redis.namespace}"
will getyyy
Also one can write code like follow:
"${simple.application:abc}"
will be resolved toabc
if there is no property for keysimple.application
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.