Skip to content

Commit 0f7d2a3

Browse files
committed
add UnknownSync action
1 parent 8cf6c6d commit 0f7d2a3

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ private ApolloConfig loadApolloConfig() {
268268
(previousConfig != null) ? previousConfig.getConfigurations() : null;
269269
result.setConfigurations(
270270
mergeConfigurations(previousConfigurations, result.getConfigurationChanges()));
271+
} else if (configSyncType == ConfigSyncType.UNKNOWN) {
272+
String message = String.format(
273+
"Apollo Config Sync type invalid - configSyncType: %s",
274+
result.getConfigSyncType());
275+
throw new ApolloConfigException(message, exception);
271276
}
277+
272278
}
273279

274280
logger.debug("Loaded config for {}: {}", m_namespace, result);

apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,24 @@ public void testMergeConfigurationWithChangesIsNULL() throws Exception {
274274
assertEquals(value2, result.get(key2));
275275
}
276276

277+
@Test(expected = ApolloConfigException.class)
278+
public void testGetRemoteConfigWithUnknownSync() throws Exception {
279+
280+
ApolloConfig someApolloConfigWithUnknownSync = assembleApolloConfigWithUnknownSync(
281+
new ArrayList<>());
282+
283+
when(someResponse.getStatusCode()).thenReturn(200);
284+
when(someResponse.getBody()).thenReturn(someApolloConfigWithUnknownSync);
285+
286+
RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,
287+
someNamespace);
288+
289+
//must stop the long polling before exception occurred
290+
remoteConfigLongPollService.stopLongPollingRefresh();
291+
292+
remoteConfigRepository.getConfig();
293+
}
294+
277295
@Test
278296
public void testLoadConfigWithOrderedProperties() throws Exception {
279297
String someKey = "someKey";
@@ -504,6 +522,19 @@ private ApolloConfig assembleApolloConfigWithIncrementalSync(
504522
return apolloConfig;
505523
}
506524

525+
private ApolloConfig assembleApolloConfigWithUnknownSync(
526+
List<ConfigurationChange> configurationChanges) {
527+
String someAppId = "appId";
528+
String someClusterName = "cluster";
529+
String someReleaseKey = "1";
530+
ApolloConfig apolloConfig =
531+
new ApolloConfig(someAppId, someClusterName, someNamespace, someReleaseKey);
532+
533+
apolloConfig.setConfigSyncType(ConfigSyncType.UNKNOWN.getValue());
534+
apolloConfig.setConfigurationChanges(configurationChanges);
535+
return apolloConfig;
536+
}
537+
507538
public static class MockConfigUtil extends ConfigUtil {
508539

509540
@Override

apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public enum ConfigSyncType {
3737
*
3838
* @param value the string that matches
3939
* @return the matching {@link ConfigSyncType}
40-
* @throws IllegalArgumentException in case the <code>value</code> is empty or there is no
41-
* matching {@link ConfigSyncType}
4240
*/
4341
public static ConfigSyncType fromString(String value) {
4442
if (StringUtils.isEmpty(value)) {

0 commit comments

Comments
 (0)