-
-
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
Changes from 4 commits
12a5a67
6ab0caa
c380c91
2bb1e5f
cd70ba7
2a0aa08
ae8b256
e1522bd
f4b4e9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,48 @@ 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); | ||
| result = bizConfig.appIdValueLengthLimitOverride(); | ||
|
|
||
| assertTrue(result.containsKey("appid1")); | ||
| assertTrue(result.containsKey("appid2")); | ||
| assertFalse(result.containsKey("appid3")); | ||
| assertFalse(result.containsKey("appid4")); | ||
| assertEquals(2, result.size()); | ||
|
Comment on lines
+138
to
+146
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 Add tests for boundary values. While the test verifies filtering of invalid values (0, -1), it should also test boundary conditions: @Test
@DisplayName("Should handle boundary values")
public void testAppIdValueLengthLimitOverride_Boundaries() {
String input = String.format(
"{'%s':1,'%s':%d,'%s':%d}",
"min-app", "max-app", Integer.MAX_VALUE,
"invalid-app", Integer.MIN_VALUE
);
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
assertTrue(result.containsKey("min-app"));
assertTrue(result.containsKey("max-app"));
assertFalse(result.containsKey("invalid-app"));
assertEquals(Integer.MAX_VALUE, result.get("max-app").intValue());
assertEquals(1, result.get("min-app").intValue());
} |
||
|
|
||
| overrideValue = result.get("appid2"); | ||
| assertEquals(666, overrideValue); | ||
| } | ||
|
youngzil marked this conversation as 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"; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.