-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat(biz): Added the value length limit function for AppId-level configuration items #5264
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
Merged
nobodyiam
merged 9 commits into
apolloconfig:master
from
youngzil:feature/item-value-length-limit-for-appid
Nov 3, 2024
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
12a5a67
feat(biz): Added the value length limit function for AppId-level conf…
youngzil 6ab0caa
fix:add CHANGES.md
youngzil c380c91
refactor(biz): Refactor configuration parsing logic and optimize test…
youngzil 2bb1e5f
test(biz): Optimize appIdValueLengthLimitOverride test case
youngzil cd70ba7
refactor: Triggering a build
youngzil 2a0aa08
refactor: Triggering a build2
youngzil ae8b256
Merge branch 'master' into feature/item-value-length-limit-for-appid
youngzil e1522bd
Merge branch 'master' into feature/item-value-length-limit-for-appid
youngzil f4b4e9b
fix(apollo-biz): Fix the parsing logic of configuration override valu…
youngzil 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -18,13 +18,13 @@ | |
|
|
||
| import com.ctrip.framework.apollo.biz.repository.ServerConfigRepository; | ||
| import com.ctrip.framework.apollo.biz.service.BizDBPropertySource; | ||
| import java.util.Map; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
| import org.springframework.core.env.ConfigurableEnvironment; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import javax.sql.DataSource; | ||
|
|
@@ -93,7 +93,7 @@ public void testReleaseHistoryRetentionSizeOverride() { | |
| int someOverrideLimit = 10; | ||
| String overrideValueString = "{'a+b+c+b':10}"; | ||
| when(environment.getProperty("apollo.release-history.retention.size.override")).thenReturn(overrideValueString); | ||
| int overrideValue = bizConfig.releaseHistoryRetentionSizeOverride().get("a+b+c+b"); | ||
| int overrideValue = bizConfig.releaseHistoryRetentionSizeOverride().get("a+b+c+b"); | ||
| assertEquals(someOverrideLimit, overrideValue); | ||
|
|
||
| overrideValueString = "{'a+b+c+b':0,'a+b+d+b':2}"; | ||
|
|
@@ -107,6 +107,42 @@ public void testReleaseHistoryRetentionSizeOverride() { | |
| assertEquals(0, bizConfig.releaseHistoryRetentionSizeOverride().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAppIdValueLengthLimitOverride() { | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(null); | ||
| Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride(); | ||
| assertTrue(result.isEmpty()); | ||
|
|
||
| String input = "{}"; | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input); | ||
| result = bizConfig.appIdValueLengthLimitOverride(); | ||
| assertTrue(result.isEmpty()); | ||
|
|
||
| input = "invalid json"; | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input); | ||
| result = bizConfig.appIdValueLengthLimitOverride(); | ||
| assertTrue(result.isEmpty()); | ||
|
|
||
| input = "{'appid1':555}"; | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input); | ||
| int overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid1"); | ||
| assertEquals(1, bizConfig.appIdValueLengthLimitOverride().size()); | ||
| assertEquals(555, overrideValue); | ||
|
|
||
| input = "{'appid1':555,'appid2':666}"; | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input); | ||
| overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid2"); | ||
| assertEquals(2, bizConfig.appIdValueLengthLimitOverride().size()); | ||
| assertEquals(666, overrideValue); | ||
|
|
||
| input = "{'appid1':555,'appid2':666,'appid3':0,'appid4':-1}"; | ||
| when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input); | ||
| overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid2"); | ||
| assertEquals(2, bizConfig.appIdValueLengthLimitOverride().size()); | ||
| assertEquals(666, overrideValue); | ||
youngzil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
youngzil marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+110
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve test organization and documentation. The test method is handling multiple scenarios which makes it harder to understand and maintain. Consider:
Example refactor: @DisplayName("AppId value length limit override tests")
class AppIdValueLengthLimitTests {
private static final String GATEWAY_APP_ID = "api-gateway";
private static final int GATEWAY_LENGTH_LIMIT = 102400;
@Test
@DisplayName("Should return empty map for null config")
void nullConfigReturnsEmptyMap() {
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(null);
assertTrue(bizConfig.appIdValueLengthLimitOverride().isEmpty());
}
@Test
@DisplayName("Should handle valid single entry")
void validSingleEntry() {
String input = String.format("{'%s':%d}", GATEWAY_APP_ID, GATEWAY_LENGTH_LIMIT);
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
assertEquals(1, result.size());
assertEquals(GATEWAY_LENGTH_LIMIT, result.get(GATEWAY_APP_ID).intValue());
}
// Add more focused test methods...
} |
||
|
|
||
| @Test | ||
| public void testReleaseMessageNotificationBatchWithNAN() throws Exception { | ||
| String someNAN = "someNAN"; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.