-
-
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
feat(apollo-client): add method interestedChangedKeys to ConfigChangeEvent #3666
Merged
nobodyiam
merged 20 commits into
apolloconfig:master
from
Anilople:feature/interested/key/20210508
Jun 11, 2021
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
817c9a7
feat(apollo-client): add method interestedChangedKeys to ConfigChange…
Anilople 2b28a27
docs: add Apache LICENSE-2.0
Anilople 1e40d80
fix(apollo-client): null exception
Anilople 2dda71b
Merge branch 'master' into feature/interested/key/20210508
nobodyiam 67d49bc
Merge branch 'master' into feature/interested/key/20210508
Anilople 835823d
delete getChanges in ConfigChangeEvent
Anilople e6c20a0
docs: update LICENSE
Anilople 66d59ee
feat: use InterestedConfigChangeEvent
Anilople cca7e5b
revert a test back
Anilople 0ce9957
test: interested key config change event
Anilople 428f461
Merge branch 'master' into feature/interested/key/20210508
Anilople a3a5cfa
test: add another key
Anilople c475174
Merge branch 'feature/interested/key/20210508' of https://github.com/…
Anilople 2880a4f
Update CHANGES.md
Anilople 3064aaf
Merge branch 'master' into feature/interested/key/20210508
Anilople e78a706
feat: fireConfigChange return how many listener be fired
Anilople 259cda1
test: expose bug in fireConfigChange
Anilople cd30d53
fix: notify multiple time if exists multiple listener
Anilople 5759735
feat: move InterestedConfigChangeEvent, it cannot be use by other pac…
Anilople 479a5d2
rollback fireConfigChange return type to 'void'
Anilople File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions
55
...lo-client/src/main/java/com/ctrip/framework/apollo/model/InterestedConfigChangeEvent.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,55 @@ | ||
/* | ||
* Copyright 2021 Apollo Authors | ||
* | ||
* 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 com.ctrip.framework.apollo.model; | ||
|
||
import com.ctrip.framework.apollo.Config; | ||
import com.ctrip.framework.apollo.ConfigChangeListener; | ||
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* In {@link ApolloConfigChangeListener} you set some interested key's rule, you can get those keys | ||
* by this class's instance. | ||
* | ||
* @author wxq | ||
*/ | ||
public class InterestedConfigChangeEvent extends ConfigChangeEvent { | ||
|
||
/** | ||
* @see Config#addChangeListener(ConfigChangeListener, Set) | ||
* @see Config#addChangeListener(ConfigChangeListener, Set, Set) | ||
* @see ApolloConfigChangeListener#interestedKeys() | ||
* @see ApolloConfigChangeListener#interestedKeyPrefixes() | ||
*/ | ||
private final Set<String> m_interestedChangedKeys; | ||
|
||
public InterestedConfigChangeEvent(String namespace, | ||
Map<String, ConfigChange> changes, Set<String> interestedChangedKeys) { | ||
super(namespace, changes); | ||
this.m_interestedChangedKeys = interestedChangedKeys; | ||
} | ||
|
||
/** | ||
* @return interested and changed keys | ||
*/ | ||
@Override | ||
public Set<String> interestedChangedKeys() { | ||
return Collections.unmodifiableSet(this.m_interestedChangedKeys); | ||
} | ||
} |
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
97 changes: 97 additions & 0 deletions
97
...lient/src/test/java/com/ctrip/framework/apollo/model/InterestedConfigChangeEventTest.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,97 @@ | ||
/* | ||
* Copyright 2021 Apollo Authors | ||
* | ||
* 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 com.ctrip.framework.apollo.model; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import com.ctrip.framework.apollo.ConfigChangeListener; | ||
import com.ctrip.framework.apollo.enums.ConfigSourceType; | ||
import com.ctrip.framework.apollo.enums.PropertyChangeType; | ||
import com.ctrip.framework.apollo.internals.AbstractConfig; | ||
import com.google.common.util.concurrent.SettableFuture; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import org.junit.Test; | ||
import org.mockito.Matchers; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author wxq | ||
*/ | ||
public class InterestedConfigChangeEventTest { | ||
|
||
@Test | ||
public void TestInterestedChangedKeys() | ||
throws ExecutionException, InterruptedException, TimeoutException { | ||
|
||
final String namespace = "app"; | ||
final String keyPrefix = "key-abc."; | ||
final String key = keyPrefix + UUID.randomUUID().toString(); | ||
|
||
final SettableFuture<ConfigChangeEvent> onChangeFuture = SettableFuture.create(); | ||
ConfigChangeListener configChangeListener = spy(new ConfigChangeListener() { | ||
@Override | ||
public void onChange(ConfigChangeEvent changeEvent) { | ||
assertEquals(namespace, changeEvent.getNamespace()); | ||
assertEquals(1, changeEvent.interestedChangedKeys().size()); | ||
assertTrue(changeEvent.interestedChangedKeys().contains(key)); | ||
onChangeFuture.set(changeEvent); | ||
} | ||
}); | ||
|
||
UnsupportedOperationConfig config = new UnsupportedOperationConfig(); | ||
config.addChangeListener(configChangeListener, Collections.singleton("key-nothing"), Collections.singleton(keyPrefix)); | ||
config.fireConfigChange(namespace, Collections.singletonMap(key, | ||
new ConfigChange(namespace, key, "123", "456", PropertyChangeType.MODIFIED))); | ||
|
||
onChangeFuture.get(500, TimeUnit.MILLISECONDS); | ||
|
||
verify(configChangeListener, atLeastOnce()).onChange(Matchers.<ConfigChangeEvent>any()); | ||
} | ||
|
||
/** | ||
* @author wxq | ||
*/ | ||
private static class UnsupportedOperationConfig extends AbstractConfig { | ||
|
||
@Override | ||
public String getProperty(String key, String defaultValue) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Set<String> getPropertyNames() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public ConfigSourceType getSourceType() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void fireConfigChange(String namespace, Map<String, ConfigChange> changes) { | ||
super.fireConfigChange(namespace, changes); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I would suggest we add some irrelavent change here to check whether the interested keys logic works, e.g.
and then verify the
changedKeys
andinterestedChangedKeys
methods both work