Skip to content

Commit

Permalink
add UnknownSync action
Browse files Browse the repository at this point in the history
  • Loading branch information
jackie-coming committed Dec 22, 2024
1 parent 8cf6c6d commit 0f7d2a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ private ApolloConfig loadApolloConfig() {
(previousConfig != null) ? previousConfig.getConfigurations() : null;
result.setConfigurations(
mergeConfigurations(previousConfigurations, result.getConfigurationChanges()));
} else if (configSyncType == ConfigSyncType.UNKNOWN) {
String message = String.format(
"Apollo Config Sync type invalid - configSyncType: %s",
result.getConfigSyncType());
throw new ApolloConfigException(message, exception);
}

}

logger.debug("Loaded config for {}: {}", m_namespace, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,24 @@ public void testMergeConfigurationWithChangesIsNULL() throws Exception {
assertEquals(value2, result.get(key2));
}

@Test(expected = ApolloConfigException.class)
public void testGetRemoteConfigWithUnknownSync() throws Exception {

ApolloConfig someApolloConfigWithUnknownSync = assembleApolloConfigWithUnknownSync(
new ArrayList<>());

when(someResponse.getStatusCode()).thenReturn(200);
when(someResponse.getBody()).thenReturn(someApolloConfigWithUnknownSync);

RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,
someNamespace);

//must stop the long polling before exception occurred
remoteConfigLongPollService.stopLongPollingRefresh();

remoteConfigRepository.getConfig();
}

@Test
public void testLoadConfigWithOrderedProperties() throws Exception {
String someKey = "someKey";
Expand Down Expand Up @@ -504,6 +522,19 @@ private ApolloConfig assembleApolloConfigWithIncrementalSync(
return apolloConfig;
}

private ApolloConfig assembleApolloConfigWithUnknownSync(
List<ConfigurationChange> configurationChanges) {
String someAppId = "appId";
String someClusterName = "cluster";
String someReleaseKey = "1";
ApolloConfig apolloConfig =
new ApolloConfig(someAppId, someClusterName, someNamespace, someReleaseKey);

apolloConfig.setConfigSyncType(ConfigSyncType.UNKNOWN.getValue());
apolloConfig.setConfigurationChanges(configurationChanges);
return apolloConfig;
}

public static class MockConfigUtil extends ConfigUtil {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public enum ConfigSyncType {
*
* @param value the string that matches
* @return the matching {@link ConfigSyncType}
* @throws IllegalArgumentException in case the <code>value</code> is empty or there is no
* matching {@link ConfigSyncType}
*/
public static ConfigSyncType fromString(String value) {
if (StringUtils.isEmpty(value)) {
Expand Down

0 comments on commit 0f7d2a3

Please sign in to comment.