From f654cb37c454c42033591ed16a61b89da9e62057 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Tue, 26 Nov 2024 15:57:23 +0800 Subject: [PATCH 01/23] feat: support incremental configuration synchronization client --- .../internals/RemoteConfigRepository.java | 55 +++++++- .../internals/RemoteConfigRepositoryTest.java | 129 +++++++++++++++++- .../apollo/core/dto/ApolloConfig.java | 24 ++++ .../apollo/core/dto/ConfigurationChange.java | 64 +++++++++ .../apollo/core/enums/ConfigSyncType.java | 66 +++++++++ .../core/enums/ConfigurationChangeType.java | 25 ++++ pom.xml | 2 +- 7 files changed, 356 insertions(+), 9 deletions(-) create mode 100644 apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java create mode 100644 apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java create mode 100644 apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 6008f63e..5b638ed0 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -21,7 +21,9 @@ import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.dto.ApolloConfig; import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages; +import com.ctrip.framework.apollo.core.dto.ConfigurationChange; import com.ctrip.framework.apollo.core.dto.ServiceDTO; +import com.ctrip.framework.apollo.core.enums.ConfigSyncType; import com.ctrip.framework.apollo.core.schedule.ExponentialSchedulePolicy; import com.ctrip.framework.apollo.core.schedule.SchedulePolicy; import com.ctrip.framework.apollo.core.signature.Signature; @@ -46,10 +48,8 @@ import com.google.common.net.UrlEscapers; import com.google.common.util.concurrent.RateLimiter; import com.google.gson.Gson; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; + +import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -247,6 +247,24 @@ private ApolloConfig loadApolloConfig() { } ApolloConfig result = response.getBody(); + if(result!=null){ + ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType()); + + if(configSyncType!=null&&configSyncType.equals(ConfigSyncType.INCREMENTALSYNC)){ + + Map previousConfigurations=null; + + ApolloConfig previousConfig = m_configCache.get(); + + if(previousConfig!=null){ + previousConfigurations=previousConfig.getConfigurations(); + } + + result.setConfigurations(mergeConfigurations(previousConfigurations,result.getConfigurationChanges())); + + } + + } logger.debug("Loaded config for {}: {}", m_namespace, result); @@ -354,4 +372,33 @@ private List getConfigServices() { return services; } + + public Map mergeConfigurations(Map previousConfigurations,List configurationChanges) { + Map newConfigurations = new HashMap<>(); + + if(previousConfigurations!=null){ + newConfigurations=Maps.newHashMap(previousConfigurations); + } + + if (configurationChanges == null) { + return newConfigurations; + } + + for (ConfigurationChange change : configurationChanges) { + switch (change.getConfigurationChangeType()) { + case ADDED: + case MODIFIED: + newConfigurations.put(change.getKey(), change.getNewValue()); + break; + case DELETED: + newConfigurations.remove(change.getKey()); + break; + default: + //do nothing + break; + } + } + + return newConfigurations; + } } diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index 812ec962..f16f55e4 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -31,10 +31,9 @@ import static org.mockito.Mockito.when; import com.ctrip.framework.apollo.build.MockInjector; -import com.ctrip.framework.apollo.core.dto.ApolloConfig; -import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification; -import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages; -import com.ctrip.framework.apollo.core.dto.ServiceDTO; +import com.ctrip.framework.apollo.core.dto.*; +import com.ctrip.framework.apollo.core.enums.ConfigSyncType; +import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType; import com.ctrip.framework.apollo.core.signature.Signature; import com.ctrip.framework.apollo.enums.ConfigSourceType; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; @@ -53,6 +52,7 @@ import com.google.common.util.concurrent.SettableFuture; import com.google.gson.Gson; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -153,6 +153,116 @@ public void testLoadConfig() throws Exception { remoteConfigLongPollService.stopLongPollingRefresh(); } + @Test + public void testLoadConfigWithIncrementalSync() throws Exception { + + String someKey = "someKey"; + String someValue = "someValue"; + String someKey1 = "someKey1"; + String someValue1 = "someKey1"; + Map configurations = Maps.newHashMap(); + configurations.put(someKey, someValue); + configurations.put(someKey1, someValue1); + ApolloConfig someApolloConfig = assembleApolloConfig(configurations); + + when(someResponse.getStatusCode()).thenReturn(200); + when(someResponse.getBody()).thenReturn(someApolloConfig); + + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + + remoteConfigRepository.sync(); + + + List configurationChanges=new ArrayList<>(); + String someNewValue = "someNewValue"; + configurationChanges.add(new ConfigurationChange(someKey, someNewValue, ConfigurationChangeType.MODIFIED)); + configurationChanges.add(new ConfigurationChange(someKey1, null, ConfigurationChangeType.DELETED)); + String someKey2 = "someKey2"; + String someValue2 = "someValue2"; + configurationChanges.add(new ConfigurationChange(someKey2, someValue2, ConfigurationChangeType.ADDED)); + ApolloConfig someApolloConfigWithIncrementalSync = assembleApolloConfigWithIncrementalSync(configurationChanges); + + when(someResponse.getStatusCode()).thenReturn(200); + when(someResponse.getBody()).thenReturn(someApolloConfigWithIncrementalSync); + + remoteConfigRepository.sync(); + + Properties config = remoteConfigRepository.getConfig(); + + assertEquals(2, config.size()); + assertEquals("someNewValue", config.getProperty("someKey")); + assertEquals("someValue2", config.getProperty("someKey2")); + assertEquals(ConfigSourceType.REMOTE, remoteConfigRepository.getSourceType()); + remoteConfigLongPollService.stopLongPollingRefresh(); + } + + @Test + public void testMergeConfigurations() throws Exception { + String key1 = "key1"; + String value1 = "value1"; + String anotherValue1 = "anotherValue1"; + + String key3 = "key3"; + String value3 = "value3"; + Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); + + List configurationChanges=new ArrayList<>(); + configurationChanges.add(new ConfigurationChange(key1, anotherValue1, ConfigurationChangeType.MODIFIED)); + String key2 = "key2"; + String value2 = "value2"; + configurationChanges.add(new ConfigurationChange(key2, value2, ConfigurationChangeType.ADDED)); + configurationChanges.add(new ConfigurationChange(key3, null, ConfigurationChangeType.DELETED)); + + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, configurationChanges); + + assertEquals(2, result.size()); + assertEquals(anotherValue1, result.get(key1)); + assertEquals(value2, result.get(key2)); + } + @Test + public void testMergeConfigurationWithPreviousConfigurationsIsNULL() throws Exception { + String key1 = "key1"; + String value1 = "value1"; + + String key3 = "key3"; + String value3 = "value3"; + + Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); + + + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, null); + + assertEquals(2, result.size()); + assertEquals(value1, result.get(key1)); + assertEquals(value3, result.get(key3)); + } + + @Test + public void testMergeConfigurationWithChangesIsNULL() throws Exception { + String key1 = "key1"; + String value1 = "value1"; + String anotherValue1 = "anotherValue1"; + + String key3 = "key3"; + String value3 = "value3"; + + List configurationChanges=new ArrayList<>(); + configurationChanges.add(new ConfigurationChange(key1, anotherValue1, ConfigurationChangeType.MODIFIED)); + String key2 = "key2"; + String value2 = "value2"; + configurationChanges.add(new ConfigurationChange(key2, value2, ConfigurationChangeType.ADDED)); + configurationChanges.add(new ConfigurationChange(key3, null, ConfigurationChangeType.DELETED)); + + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + Map result=remoteConfigRepository.mergeConfigurations(null, configurationChanges); + + assertEquals(2, result.size()); + assertEquals(anotherValue1, result.get(key1)); + assertEquals(value2, result.get(key2)); + } + @Test public void testLoadConfigWithOrderedProperties() throws Exception { String someKey = "someKey"; @@ -374,6 +484,17 @@ private ApolloConfig assembleApolloConfig(Map configurations) { return apolloConfig; } + private ApolloConfig assembleApolloConfigWithIncrementalSync(List configurationChanges) { + String someAppId = "appId"; + String someClusterName = "cluster"; + String someReleaseKey = "1"; + ApolloConfig apolloConfig = + new ApolloConfig(someAppId, someClusterName, someNamespace, someReleaseKey); + + apolloConfig.setConfigSyncType(ConfigSyncType.INCREMENTALSYNC.getValue()); + apolloConfig.setConfigurationChanges(configurationChanges); + return apolloConfig; + } public static class MockConfigUtil extends ConfigUtil { diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index 6ae5584f..b1d296be 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -16,6 +16,8 @@ */ package com.ctrip.framework.apollo.core.dto; + +import java.util.List; import java.util.Map; /** @@ -33,6 +35,10 @@ public class ApolloConfig { private String releaseKey; + private String configSyncType; + + private List configurationChanges; + public ApolloConfig() { } @@ -62,6 +68,14 @@ public String getReleaseKey() { return releaseKey; } + public String getConfigSyncType() { + return configSyncType; + } + + public List getConfigurationChanges() { + return configurationChanges; + } + public Map getConfigurations() { return configurations; } @@ -82,10 +96,20 @@ public void setReleaseKey(String releaseKey) { this.releaseKey = releaseKey; } + public void setConfigSyncType(String configSyncType) { + this.configSyncType = configSyncType; + } + + public void setConfigurations(Map configurations) { this.configurations = configurations; } + public void setConfigurationChanges(List configurationChanges) { + this.configurationChanges = configurationChanges; + } + + @Override public String toString() { final StringBuilder sb = new StringBuilder("ApolloConfig{"); diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java new file mode 100644 index 00000000..506ea5a1 --- /dev/null +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java @@ -0,0 +1,64 @@ +/* + * Copyright 2022 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.core.dto; + + +import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType; + +/** + * Holds the information for a Configuration change. + * @author jason + */ +public class ConfigurationChange { + private final String key; + private final String newValue; + private final ConfigurationChangeType configurationChangeType; + + /** + * Constructor. + * @param key the key whose value is changed + * @param newValue the value after change + * @param configurationChangeType the change type + */ + public ConfigurationChange(String key, String newValue, ConfigurationChangeType configurationChangeType) { + this.key = key; + this.newValue = newValue; + this.configurationChangeType = configurationChangeType; + } + + public String getKey() { + return key; + } + public String getNewValue() { + return newValue; + } + + public ConfigurationChangeType getConfigurationChangeType() { + return configurationChangeType; + } + + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("ConfigChange{"); + sb.append(" key='").append(key).append('\''); + sb.append(", newValue='").append(newValue).append('\''); + sb.append(", configurationChangeType=").append(configurationChangeType); + sb.append('}'); + return sb.toString(); + } +} diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java new file mode 100644 index 00000000..48881558 --- /dev/null +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -0,0 +1,66 @@ +/* + * Copyright 2022 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.core.enums; + +import com.ctrip.framework.apollo.core.utils.StringUtils; + +import java.util.stream.Stream; + +/** + * This enum represents all the possible Configuration sync from apollo-config + * + * @author jason + */ +public enum ConfigSyncType { + FULLSYNC("FullSync"), INCREMENTALSYNC("IncrementalSync"); + + private final String value; + + ConfigSyncType(String value) { + this.value = value; + } + + + + /** + * Transforms a given string to its matching {@link ConfigSyncType}. + * + * @param value the string that matches + * @return the matching {@link ConfigSyncType} + * @throws IllegalArgumentException in case the value is empty or there is no + * matching {@link ConfigSyncType} + */ + public static ConfigSyncType fromString(String value) { + if (StringUtils.isEmpty(value)) { + return FULLSYNC; + } + for (ConfigSyncType type : values()) { + if (type.value.equals(value)) { + return type; + } + } + throw new IllegalArgumentException("Invalid ConfigSyncType: " + value); + + } + + /** + * @return The string representation of the given {@link ConfigSyncType} + */ + public String getValue() { + return value; + } +} diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java new file mode 100644 index 00000000..7edb47af --- /dev/null +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java @@ -0,0 +1,25 @@ +/* + * Copyright 2022 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.core.enums; + + +/** + * @author jason + */ +public enum ConfigurationChangeType { + ADDED, MODIFIED, DELETED +} diff --git a/pom.xml b/pom.xml index 15949fc7..64e15f9e 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ - 2.2.0-SNAPSHOT + 2.5.0-SNAPSHOT 1.8 UTF-8 2.6.8 From 6859fe13e255a7fc868a5be99445512e7a295f16 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sun, 8 Dec 2024 19:30:09 +0800 Subject: [PATCH 02/23] code format --- .../internals/RemoteConfigRepository.java | 18 +++---- .../internals/RemoteConfigRepositoryTest.java | 26 +++++----- .../apollo/core/dto/ConfigurationChange.java | 6 +-- .../core/enums/ConfigurationChangeType.java | 12 ++++- .../enums/ConfigurationChangeTypeUtils.java | 50 +++++++++++++++++++ 5 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 3ab7091f..58984015 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -26,6 +26,7 @@ import com.ctrip.framework.apollo.core.dto.ConfigurationChange; import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.core.enums.ConfigSyncType; +import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType; import com.ctrip.framework.apollo.core.schedule.ExponentialSchedulePolicy; import com.ctrip.framework.apollo.core.schedule.SchedulePolicy; import com.ctrip.framework.apollo.core.signature.Signature; @@ -254,23 +255,21 @@ private ApolloConfig loadApolloConfig() { } ApolloConfig result = response.getBody(); + if(result!=null){ - ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType()); - if(configSyncType!=null&&configSyncType.equals(ConfigSyncType.INCREMENTALSYNC)){ + ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType()); - Map previousConfigurations=null; + if (configSyncType == ConfigSyncType.INCREMENTALSYNC) { ApolloConfig previousConfig = m_configCache.get(); - if(previousConfig!=null){ - previousConfigurations=previousConfig.getConfigurations(); - } + Map previousConfigurations = + (previousConfig != null) ? previousConfig.getConfigurations() : null; result.setConfigurations(mergeConfigurations(previousConfigurations,result.getConfigurationChanges())); } - } logger.debug("Loaded config for {}: {}", m_namespace, result); @@ -382,7 +381,8 @@ private List getConfigServices() { return services; } - public Map mergeConfigurations(Map previousConfigurations,List configurationChanges) { + Map mergeConfigurations(Map previousConfigurations, + List configurationChanges) { Map newConfigurations = new HashMap<>(); if(previousConfigurations!=null){ @@ -394,7 +394,7 @@ public Map mergeConfigurations(Map previousConfi } for (ConfigurationChange change : configurationChanges) { - switch (change.getConfigurationChangeType()) { + switch (ConfigurationChangeType.fromString(change.getConfigurationChangeType())) { case ADDED: case MODIFIED: newConfigurations.put(change.getKey(), change.getNewValue()); diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index 77079b27..e0334ccb 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -169,18 +169,18 @@ public void testLoadConfigWithIncrementalSync() throws Exception { when(someResponse.getStatusCode()).thenReturn(200); when(someResponse.getBody()).thenReturn(someApolloConfig); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); remoteConfigRepository.sync(); List configurationChanges=new ArrayList<>(); String someNewValue = "someNewValue"; - configurationChanges.add(new ConfigurationChange(someKey, someNewValue, ConfigurationChangeType.MODIFIED)); - configurationChanges.add(new ConfigurationChange(someKey1, null, ConfigurationChangeType.DELETED)); + configurationChanges.add(new ConfigurationChange(someKey, someNewValue, "MODIFIED")); + configurationChanges.add(new ConfigurationChange(someKey1, null, "DELETED")); String someKey2 = "someKey2"; String someValue2 = "someValue2"; - configurationChanges.add(new ConfigurationChange(someKey2, someValue2, ConfigurationChangeType.ADDED)); + configurationChanges.add(new ConfigurationChange(someKey2, someValue2,"ADDED")); ApolloConfig someApolloConfigWithIncrementalSync = assembleApolloConfigWithIncrementalSync(configurationChanges); when(someResponse.getStatusCode()).thenReturn(200); @@ -208,13 +208,13 @@ public void testMergeConfigurations() throws Exception { Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); List configurationChanges=new ArrayList<>(); - configurationChanges.add(new ConfigurationChange(key1, anotherValue1, ConfigurationChangeType.MODIFIED)); + configurationChanges.add(new ConfigurationChange(key1, anotherValue1, "MODIFIED")); String key2 = "key2"; String value2 = "value2"; - configurationChanges.add(new ConfigurationChange(key2, value2, ConfigurationChangeType.ADDED)); - configurationChanges.add(new ConfigurationChange(key3, null, ConfigurationChangeType.DELETED)); + configurationChanges.add(new ConfigurationChange(key2, value2, "ADDED")); + configurationChanges.add(new ConfigurationChange(key3, null, "DELETED")); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, configurationChanges); assertEquals(2, result.size()); @@ -232,7 +232,7 @@ public void testMergeConfigurationWithPreviousConfigurationsIsNULL() throws Exce Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, null); assertEquals(2, result.size()); @@ -250,13 +250,13 @@ public void testMergeConfigurationWithChangesIsNULL() throws Exception { String value3 = "value3"; List configurationChanges=new ArrayList<>(); - configurationChanges.add(new ConfigurationChange(key1, anotherValue1, ConfigurationChangeType.MODIFIED)); + configurationChanges.add(new ConfigurationChange(key1, anotherValue1, "MODIFIED")); String key2 = "key2"; String value2 = "value2"; - configurationChanges.add(new ConfigurationChange(key2, value2, ConfigurationChangeType.ADDED)); - configurationChanges.add(new ConfigurationChange(key3, null, ConfigurationChangeType.DELETED)); + configurationChanges.add(new ConfigurationChange(key2, value2, "ADDED")); + configurationChanges.add(new ConfigurationChange(key3, null, "DELETED")); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); Map result=remoteConfigRepository.mergeConfigurations(null, configurationChanges); assertEquals(2, result.size()); diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java index 506ea5a1..e4595a59 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java @@ -26,7 +26,7 @@ public class ConfigurationChange { private final String key; private final String newValue; - private final ConfigurationChangeType configurationChangeType; + private final String configurationChangeType; /** * Constructor. @@ -34,7 +34,7 @@ public class ConfigurationChange { * @param newValue the value after change * @param configurationChangeType the change type */ - public ConfigurationChange(String key, String newValue, ConfigurationChangeType configurationChangeType) { + public ConfigurationChange(String key, String newValue, String configurationChangeType) { this.key = key; this.newValue = newValue; this.configurationChangeType = configurationChangeType; @@ -47,7 +47,7 @@ public String getNewValue() { return newValue; } - public ConfigurationChangeType getConfigurationChangeType() { + public String getConfigurationChangeType() { return configurationChangeType; } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java index 7edb47af..d3ac703d 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java @@ -17,9 +17,19 @@ package com.ctrip.framework.apollo.core.enums; +import com.google.common.base.Preconditions; + /** * @author jason */ public enum ConfigurationChangeType { - ADDED, MODIFIED, DELETED + ADDED, MODIFIED, DELETED, UNKNOWN; + + public static ConfigurationChangeType fromString(String changeType) { + ConfigurationChangeType configurationChangeType = ConfigurationChangeTypeUtils.transformChangeType( + changeType); + Preconditions.checkArgument(configurationChangeType != UNKNOWN, + String.format("ConfigurationChangeType %s is invalid", changeType)); + return configurationChangeType; + } } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java new file mode 100644 index 00000000..4a5ef93c --- /dev/null +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.core.enums; + +import com.ctrip.framework.apollo.core.utils.StringUtils; + +/** + * A utility class for the {@link ConfigurationChangeType} enum. + *

+ * The class provides simple functionalities that extend the capabilities of {@link ConfigurationChangeType} + * + * @author json + */ +public final class ConfigurationChangeTypeUtils { + + /** + * Transforms a given String to its matching {@link ConfigurationChangeType} + * + * @param changeType the String to convert + * @return the matching {@link ConfigurationChangeType} for the given String + */ + public static ConfigurationChangeType transformChangeType(String changeType) { + if (StringUtils.isBlank(changeType)) { + return ConfigurationChangeType.UNKNOWN; + } + + String cleanedChangeType = changeType.trim().toUpperCase(); + + try { + return ConfigurationChangeType.valueOf(cleanedChangeType); + } catch (IllegalArgumentException e) { + + return ConfigurationChangeType.UNKNOWN; + } + } +} From 984228962c7063e0795f804707e6368a20239e0c Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sat, 14 Dec 2024 22:37:36 +0800 Subject: [PATCH 03/23] add Unknown sync mode --- .../apollo/internals/RemoteConfigRepository.java | 2 +- .../apollo/internals/RemoteConfigRepositoryTest.java | 3 +-- .../framework/apollo/core/dto/ConfigurationChange.java | 1 - .../ctrip/framework/apollo/core/enums/ConfigSyncType.java | 8 +++----- pom.xml | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 58984015..155f4c58 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -260,7 +260,7 @@ private ApolloConfig loadApolloConfig() { ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType()); - if (configSyncType == ConfigSyncType.INCREMENTALSYNC) { + if (configSyncType == ConfigSyncType.INCREMENTAL_SYNC) { ApolloConfig previousConfig = m_configCache.get(); diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index e0334ccb..e5e44920 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -33,7 +33,6 @@ import com.ctrip.framework.apollo.build.MockInjector; import com.ctrip.framework.apollo.core.dto.*; import com.ctrip.framework.apollo.core.enums.ConfigSyncType; -import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType; import com.ctrip.framework.apollo.core.signature.Signature; import com.ctrip.framework.apollo.enums.ConfigSourceType; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; @@ -487,7 +486,7 @@ private ApolloConfig assembleApolloConfigWithIncrementalSync(List - 2.5.0-SNAPSHOT + 2.4.0-SNAPSHOT 1.8 UTF-8 2.7.18 From b454698f856ba2cd49fa59267aac3891b30d3259 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Fri, 20 Dec 2024 19:24:37 +0800 Subject: [PATCH 04/23] code format --- .../apollo/internals/RemoteConfigRepository.java | 11 ++++++----- .../framework/apollo/core/enums/ConfigSyncType.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 155f4c58..58519e72 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -256,9 +256,9 @@ private ApolloConfig loadApolloConfig() { ApolloConfig result = response.getBody(); - if(result!=null){ + if (result != null) { - ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType()); + ConfigSyncType configSyncType = ConfigSyncType.fromString(result.getConfigSyncType()); if (configSyncType == ConfigSyncType.INCREMENTAL_SYNC) { @@ -267,7 +267,8 @@ private ApolloConfig loadApolloConfig() { Map previousConfigurations = (previousConfig != null) ? previousConfig.getConfigurations() : null; - result.setConfigurations(mergeConfigurations(previousConfigurations,result.getConfigurationChanges())); + result.setConfigurations( + mergeConfigurations(previousConfigurations, result.getConfigurationChanges())); } } @@ -385,8 +386,8 @@ Map mergeConfigurations(Map previousConfiguratio List configurationChanges) { Map newConfigurations = new HashMap<>(); - if(previousConfigurations!=null){ - newConfigurations=Maps.newHashMap(previousConfigurations); + if (previousConfigurations != null) { + newConfigurations = Maps.newHashMap(previousConfigurations); } if (configurationChanges == null) { diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index 540c2d9a..481a59e8 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -47,7 +47,7 @@ public static ConfigSyncType fromString(String value) { return FULL_SYNC; } for (ConfigSyncType type : values()) { - if (type.value.equals(value)) { + if (type.value.equals(value)) { return type; } } From 89321acfc14f1407a259588ba36a542560595f4a Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sat, 21 Dec 2024 13:29:12 +0800 Subject: [PATCH 05/23] code format --- .../internals/RemoteConfigRepository.java | 42 +++++--- .../internals/RemoteConfigRepositoryTest.java | 97 ++++++++++++------- .../apollo/core/dto/ApolloConfig.java | 6 +- .../apollo/core/dto/ConfigurationChange.java | 9 +- .../apollo/core/enums/ConfigSyncType.java | 9 +- .../enums/ConfigurationChangeTypeUtils.java | 4 +- 6 files changed, 102 insertions(+), 65 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 58519e72..7a028909 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -51,8 +51,11 @@ import com.google.common.net.UrlEscapers; import com.google.common.util.concurrent.RateLimiter; import com.google.gson.Gson; - -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -64,7 +67,9 @@ * @author Jason Song(song_s@ctrip.com) */ public class RemoteConfigRepository extends AbstractConfigRepository { - private static final Logger logger = DeferredLoggerFactory.getLogger(RemoteConfigRepository.class); + + private static final Logger logger = DeferredLoggerFactory.getLogger( + RemoteConfigRepository.class); private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR); private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("="); private static final Escaper pathEscaper = UrlEscapers.urlPathSegmentEscaper(); @@ -93,7 +98,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { /** * Constructor. * - * @param appId the appId + * @param appId the appId * @param namespace the namespace */ public RemoteConfigRepository(String appId, String namespace) { @@ -108,7 +113,8 @@ public RemoteConfigRepository(String appId, String namespace) { m_remoteMessages = new AtomicReference<>(); m_loadConfigRateLimiter = RateLimiter.create(m_configUtil.getLoadConfigQPS()); m_configNeedForceRefresh = new AtomicBoolean(true); - m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy(m_configUtil.getOnErrorRetryInterval(), + m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy( + m_configUtil.getOnErrorRetryInterval(), m_configUtil.getOnErrorRetryInterval() * 8); this.schedulePeriodicRefresh(); this.scheduleLongPollingRefresh(); @@ -119,7 +125,7 @@ public Properties getConfig() { if (m_configCache.get() == null) { long start = System.currentTimeMillis(); this.sync(); - Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND+":"+m_namespace, + Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND + ":" + m_namespace, String.valueOf(System.currentTimeMillis() - start)); } return transformApolloConfigToProperties(m_configCache.get()); @@ -142,7 +148,8 @@ private void schedulePeriodicRefresh() { new Runnable() { @Override public void run() { - Tracer.logEvent(APOLLO_CONFIGSERVICE, String.format("periodicRefresh: %s", m_namespace)); + Tracer.logEvent(APOLLO_CONFIGSERVICE, + String.format("periodicRefresh: %s", m_namespace)); logger.debug("refresh config for namespace: {}", m_namespace); trySync(); Tracer.logEvent(APOLLO_CLIENT_VERSION, Apollo.VERSION); @@ -167,7 +174,7 @@ protected synchronized void sync() { } if (current != null) { - Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS+"%s", current.getNamespaceName()), + Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS + "%s", current.getNamespaceName()), current.getReleaseKey()); } @@ -218,7 +225,8 @@ private ApolloConfig loadApolloConfig() { if (onErrorSleepTime > 0) { logger.warn( "Load config failed, will retry in {} {}. appId: {}, cluster: {}, namespaces: {}", - onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, m_namespace); + onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, + m_namespace); try { m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(onErrorSleepTime); @@ -228,7 +236,7 @@ private ApolloConfig loadApolloConfig() { } url = assembleQueryConfigUrl(configService.getHomepageUrl(), appId, cluster, m_namespace, - dataCenter, m_remoteMessages.get(), m_configCache.get()); + dataCenter, m_remoteMessages.get(), m_configCache.get()); logger.debug("Loading config from {}", url); @@ -286,13 +294,14 @@ private ApolloConfig loadApolloConfig() { appId, cluster, m_namespace); statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(), message); - Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND,m_namespace); - + Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND, m_namespace); + } - Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(statusCodeException)); + Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, + ExceptionUtil.getDetailMessage(statusCodeException)); transaction.setStatus(statusCodeException); exception = statusCodeException; - if(ex.getStatusCode() == 404) { + if (ex.getStatusCode() == 404) { break retryLoopLabel; } } catch (Throwable ex) { @@ -316,7 +325,7 @@ private ApolloConfig loadApolloConfig() { } String assembleQueryConfigUrl(String uri, String appId, String cluster, String namespace, - String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { + String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { String path = "configs/%s/%s/%s"; List pathParams = @@ -361,7 +370,8 @@ private void scheduleLongPollingRefresh() { remoteConfigLongPollService.submit(m_appId, m_namespace, this); } - public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages) { + public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, + ApolloNotificationMessages remoteMessages) { m_longPollServiceDto.set(longPollNotifiedServiceDto); m_remoteMessages.set(remoteMessages); m_executorService.submit(new Runnable() { diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index e5e44920..07a99f48 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -31,7 +31,11 @@ import static org.mockito.Mockito.when; import com.ctrip.framework.apollo.build.MockInjector; -import com.ctrip.framework.apollo.core.dto.*; +import com.ctrip.framework.apollo.core.dto.ApolloConfig; +import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification; +import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages; +import com.ctrip.framework.apollo.core.dto.ConfigurationChange; +import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.core.enums.ConfigSyncType; import com.ctrip.framework.apollo.core.signature.Signature; import com.ctrip.framework.apollo.enums.ConfigSourceType; @@ -145,7 +149,8 @@ public void testLoadConfig() throws Exception { when(someResponse.getStatusCode()).thenReturn(200); when(someResponse.getBody()).thenReturn(someApolloConfig); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); Properties config = remoteConfigRepository.getConfig(); @@ -168,19 +173,20 @@ public void testLoadConfigWithIncrementalSync() throws Exception { when(someResponse.getStatusCode()).thenReturn(200); when(someResponse.getBody()).thenReturn(someApolloConfig); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); - - remoteConfigRepository.sync(); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); + remoteConfigRepository.sync(); - List configurationChanges=new ArrayList<>(); + List configurationChanges = new ArrayList<>(); String someNewValue = "someNewValue"; configurationChanges.add(new ConfigurationChange(someKey, someNewValue, "MODIFIED")); configurationChanges.add(new ConfigurationChange(someKey1, null, "DELETED")); String someKey2 = "someKey2"; String someValue2 = "someValue2"; - configurationChanges.add(new ConfigurationChange(someKey2, someValue2,"ADDED")); - ApolloConfig someApolloConfigWithIncrementalSync = assembleApolloConfigWithIncrementalSync(configurationChanges); + configurationChanges.add(new ConfigurationChange(someKey2, someValue2, "ADDED")); + ApolloConfig someApolloConfigWithIncrementalSync = assembleApolloConfigWithIncrementalSync( + configurationChanges); when(someResponse.getStatusCode()).thenReturn(200); when(someResponse.getBody()).thenReturn(someApolloConfigWithIncrementalSync); @@ -204,22 +210,25 @@ public void testMergeConfigurations() throws Exception { String key3 = "key3"; String value3 = "value3"; - Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); + Map previousConfigurations = ImmutableMap.of(key1, value1, key3, value3); - List configurationChanges=new ArrayList<>(); + List configurationChanges = new ArrayList<>(); configurationChanges.add(new ConfigurationChange(key1, anotherValue1, "MODIFIED")); String key2 = "key2"; String value2 = "value2"; configurationChanges.add(new ConfigurationChange(key2, value2, "ADDED")); configurationChanges.add(new ConfigurationChange(key3, null, "DELETED")); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); - Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, configurationChanges); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); + Map result = remoteConfigRepository.mergeConfigurations(previousConfigurations, + configurationChanges); assertEquals(2, result.size()); assertEquals(anotherValue1, result.get(key1)); assertEquals(value2, result.get(key2)); } + @Test public void testMergeConfigurationWithPreviousConfigurationsIsNULL() throws Exception { String key1 = "key1"; @@ -228,11 +237,12 @@ public void testMergeConfigurationWithPreviousConfigurationsIsNULL() throws Exce String key3 = "key3"; String value3 = "value3"; - Map previousConfigurations = ImmutableMap.of(key1, value1,key3,value3); + Map previousConfigurations = ImmutableMap.of(key1, value1, key3, value3); - - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); - Map result=remoteConfigRepository.mergeConfigurations(previousConfigurations, null); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); + Map result = remoteConfigRepository.mergeConfigurations(previousConfigurations, + null); assertEquals(2, result.size()); assertEquals(value1, result.get(key1)); @@ -248,15 +258,17 @@ public void testMergeConfigurationWithChangesIsNULL() throws Exception { String key3 = "key3"; String value3 = "value3"; - List configurationChanges=new ArrayList<>(); + List configurationChanges = new ArrayList<>(); configurationChanges.add(new ConfigurationChange(key1, anotherValue1, "MODIFIED")); String key2 = "key2"; String value2 = "value2"; configurationChanges.add(new ConfigurationChange(key2, value2, "ADDED")); configurationChanges.add(new ConfigurationChange(key3, null, "DELETED")); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId,someNamespace); - Map result=remoteConfigRepository.mergeConfigurations(null, configurationChanges); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); + Map result = remoteConfigRepository.mergeConfigurations(null, + configurationChanges); assertEquals(2, result.size()); assertEquals(anotherValue1, result.get(key1)); @@ -281,7 +293,8 @@ public Properties answer(InvocationOnMock invocation) { } }); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); Properties config = remoteConfigRepository.getConfig(); @@ -318,7 +331,8 @@ public HttpResponse answer(InvocationOnMock invocation) throws Thr } }).when(httpClient).doGet(any(HttpRequest.class), any(Class.class)); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); Properties config = remoteConfigRepository.getConfig(); @@ -331,7 +345,8 @@ public void testGetRemoteConfigWithServerError() throws Exception { when(someResponse.getStatusCode()).thenReturn(500); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); //must stop the long polling before exception occurred remoteConfigLongPollService.stopLongPollingRefresh(); @@ -344,7 +359,8 @@ public void testGetRemoteConfigWithNotFount() throws Exception { when(someResponse.getStatusCode()).thenReturn(404); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); //must stop the long polling before exception occurred remoteConfigLongPollService.stopLongPollingRefresh(); @@ -361,7 +377,8 @@ public void testRepositoryChangeListener() throws Exception { when(someResponse.getBody()).thenReturn(someApolloConfig); RepositoryChangeListener someListener = mock(RepositoryChangeListener.class); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); remoteConfigRepository.addChangeListener(someListener); final ArgumentCaptor captor = ArgumentCaptor.forClass(Properties.class); @@ -372,7 +389,8 @@ public void testRepositoryChangeListener() throws Exception { remoteConfigRepository.sync(); - verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), captor.capture()); + verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), + captor.capture()); assertEquals(newConfigurations, captor.getValue()); } @@ -395,9 +413,11 @@ public Void answer(InvocationOnMock invocation) throws Throwable { return null; } - }).when(someListener).onRepositoryChange(any(String.class), any(String.class), any(Properties.class)); + }).when(someListener) + .onRepositoryChange(any(String.class), any(String.class), any(Properties.class)); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); remoteConfigRepository.addChangeListener(someListener); final ArgumentCaptor captor = ArgumentCaptor.forClass(Properties.class); @@ -421,12 +441,14 @@ public Void answer(InvocationOnMock invocation) throws Throwable { remoteConfigLongPollService.stopLongPollingRefresh(); - verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), captor.capture()); + verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), + captor.capture()); assertEquals(newConfigurations, captor.getValue()); final ArgumentCaptor httpRequestArgumentCaptor = ArgumentCaptor .forClass(HttpRequest.class); - verify(httpClient, atLeast(1)).doGet(httpRequestArgumentCaptor.capture(), eq(ApolloConfig.class)); + verify(httpClient, atLeast(1)).doGet(httpRequestArgumentCaptor.capture(), + eq(ApolloConfig.class)); HttpRequest request = httpRequestArgumentCaptor.getValue(); @@ -449,7 +471,8 @@ public void testAssembleQueryConfigUrl() throws Exception { notificationMessages.put(someKey, someNotificationId); notificationMessages.put(anotherKey, anotherNotificationId); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, + someNamespace); ApolloConfig someApolloConfig = mock(ApolloConfig.class); when(someApolloConfig.getReleaseKey()).thenReturn(someReleaseKey); @@ -479,12 +502,14 @@ private ApolloConfig assembleApolloConfig(Map configurations) { return apolloConfig; } - private ApolloConfig assembleApolloConfigWithIncrementalSync(List configurationChanges) { + + private ApolloConfig assembleApolloConfigWithIncrementalSync( + List configurationChanges) { String someAppId = "appId"; String someClusterName = "cluster"; String someReleaseKey = "1"; ApolloConfig apolloConfig = - new ApolloConfig(someAppId, someClusterName, someNamespace, someReleaseKey); + new ApolloConfig(someAppId, someClusterName, someNamespace, someReleaseKey); apolloConfig.setConfigSyncType(ConfigSyncType.INCREMENTAL_SYNC.getValue()); apolloConfig.setConfigurationChanges(configurationChanges); @@ -539,8 +564,8 @@ public long getLongPollingInitialDelayInMills() { } @Override - public String getAccessKeySecret(String appId){ - if(appId.equals(someAppId)){ + public String getAccessKeySecret(String appId) { + if (appId.equals(someAppId)) { return someSecret; } return null; @@ -555,8 +580,8 @@ public HttpResponse doGet(HttpRequest httpRequest, Class responseType) return (HttpResponse) someResponse; } throw new ApolloConfigStatusCodeException(someResponse.getStatusCode(), - String.format("Http request failed due to status code: %d", - someResponse.getStatusCode())); + String.format("Http request failed due to status code: %d", + someResponse.getStatusCode())); } @Override diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index b1d296be..ca68a513 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -43,9 +43,9 @@ public ApolloConfig() { } public ApolloConfig(String appId, - String cluster, - String namespaceName, - String releaseKey) { + String cluster, + String namespaceName, + String releaseKey) { this.appId = appId; this.cluster = cluster; this.namespaceName = namespaceName; diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java index 7296dc4b..d8a1d5a7 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java @@ -17,20 +17,22 @@ package com.ctrip.framework.apollo.core.dto; - /** * Holds the information for a Configuration change. + * * @author jason */ public class ConfigurationChange { + private final String key; private final String newValue; private final String configurationChangeType; /** * Constructor. - * @param key the key whose value is changed - * @param newValue the value after change + * + * @param key the key whose value is changed + * @param newValue the value after change * @param configurationChangeType the change type */ public ConfigurationChange(String key, String newValue, String configurationChangeType) { @@ -42,6 +44,7 @@ public ConfigurationChange(String key, String newValue, String configurationChan public String getKey() { return key; } + public String getNewValue() { return newValue; } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index 481a59e8..19b31e42 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -24,7 +24,7 @@ * @author jason */ public enum ConfigSyncType { - FULL_SYNC("FullSync"), INCREMENTAL_SYNC("IncrementalSync"), UNKNOWN("UnKnown"); + FULL_SYNC("FullSync"), INCREMENTAL_SYNC("IncrementalSync"), UNKNOWN("Unknown"); private final String value; @@ -33,7 +33,6 @@ public enum ConfigSyncType { } - /** * Transforms a given string to its matching {@link ConfigSyncType}. * @@ -48,9 +47,9 @@ public static ConfigSyncType fromString(String value) { } for (ConfigSyncType type : values()) { if (type.value.equals(value)) { - return type; - } - } + return type; + } + } return UNKNOWN; } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java index 4a5ef93c..57218707 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java @@ -21,7 +21,8 @@ /** * A utility class for the {@link ConfigurationChangeType} enum. *

- * The class provides simple functionalities that extend the capabilities of {@link ConfigurationChangeType} + * The class provides simple functionalities that extend the capabilities of + * {@link ConfigurationChangeType} * * @author json */ @@ -43,7 +44,6 @@ public static ConfigurationChangeType transformChangeType(String changeType) { try { return ConfigurationChangeType.valueOf(cleanedChangeType); } catch (IllegalArgumentException e) { - return ConfigurationChangeType.UNKNOWN; } } From 08e2705e381304ab5f5ddf49a5f85200fca010cc Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sat, 21 Dec 2024 13:33:29 +0800 Subject: [PATCH 06/23] code format --- .../framework/apollo/internals/RemoteConfigRepository.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 7a028909..6fe20a57 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -265,20 +265,16 @@ private ApolloConfig loadApolloConfig() { ApolloConfig result = response.getBody(); if (result != null) { - ConfigSyncType configSyncType = ConfigSyncType.fromString(result.getConfigSyncType()); if (configSyncType == ConfigSyncType.INCREMENTAL_SYNC) { - ApolloConfig previousConfig = m_configCache.get(); - Map previousConfigurations = (previousConfig != null) ? previousConfig.getConfigurations() : null; - result.setConfigurations( mergeConfigurations(previousConfigurations, result.getConfigurationChanges())); - } + } logger.debug("Loaded config for {}: {}", m_namespace, result); From 69f4677ec71e3e37deb6ce2ef5000edf3f024ea2 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sat, 21 Dec 2024 13:55:16 +0800 Subject: [PATCH 07/23] code format --- .../internals/RemoteConfigRepository.java | 35 +++++++--------- .../internals/RemoteConfigRepositoryTest.java | 41 +++++++------------ .../apollo/core/dto/ApolloConfig.java | 6 +-- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 6fe20a57..07c7a791 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -67,9 +67,7 @@ * @author Jason Song(song_s@ctrip.com) */ public class RemoteConfigRepository extends AbstractConfigRepository { - - private static final Logger logger = DeferredLoggerFactory.getLogger( - RemoteConfigRepository.class); + private static final Logger logger = DeferredLoggerFactory.getLogger(RemoteConfigRepository.class); private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR); private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("="); private static final Escaper pathEscaper = UrlEscapers.urlPathSegmentEscaper(); @@ -98,7 +96,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { /** * Constructor. * - * @param appId the appId + * @param appId the appId * @param namespace the namespace */ public RemoteConfigRepository(String appId, String namespace) { @@ -113,8 +111,7 @@ public RemoteConfigRepository(String appId, String namespace) { m_remoteMessages = new AtomicReference<>(); m_loadConfigRateLimiter = RateLimiter.create(m_configUtil.getLoadConfigQPS()); m_configNeedForceRefresh = new AtomicBoolean(true); - m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy( - m_configUtil.getOnErrorRetryInterval(), + m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy(m_configUtil.getOnErrorRetryInterval(), m_configUtil.getOnErrorRetryInterval() * 8); this.schedulePeriodicRefresh(); this.scheduleLongPollingRefresh(); @@ -125,7 +122,7 @@ public Properties getConfig() { if (m_configCache.get() == null) { long start = System.currentTimeMillis(); this.sync(); - Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND + ":" + m_namespace, + Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND+":"+m_namespace, String.valueOf(System.currentTimeMillis() - start)); } return transformApolloConfigToProperties(m_configCache.get()); @@ -148,8 +145,7 @@ private void schedulePeriodicRefresh() { new Runnable() { @Override public void run() { - Tracer.logEvent(APOLLO_CONFIGSERVICE, - String.format("periodicRefresh: %s", m_namespace)); + Tracer.logEvent(APOLLO_CONFIGSERVICE, String.format("periodicRefresh: %s", m_namespace)); logger.debug("refresh config for namespace: {}", m_namespace); trySync(); Tracer.logEvent(APOLLO_CLIENT_VERSION, Apollo.VERSION); @@ -174,7 +170,7 @@ protected synchronized void sync() { } if (current != null) { - Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS + "%s", current.getNamespaceName()), + Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS+"%s", current.getNamespaceName()), current.getReleaseKey()); } @@ -225,8 +221,7 @@ private ApolloConfig loadApolloConfig() { if (onErrorSleepTime > 0) { logger.warn( "Load config failed, will retry in {} {}. appId: {}, cluster: {}, namespaces: {}", - onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, - m_namespace); + onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, m_namespace); try { m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(onErrorSleepTime); @@ -236,7 +231,7 @@ private ApolloConfig loadApolloConfig() { } url = assembleQueryConfigUrl(configService.getHomepageUrl(), appId, cluster, m_namespace, - dataCenter, m_remoteMessages.get(), m_configCache.get()); + dataCenter, m_remoteMessages.get(), m_configCache.get()); logger.debug("Loading config from {}", url); @@ -274,7 +269,7 @@ private ApolloConfig loadApolloConfig() { result.setConfigurations( mergeConfigurations(previousConfigurations, result.getConfigurationChanges())); } - + } logger.debug("Loaded config for {}: {}", m_namespace, result); @@ -290,14 +285,13 @@ private ApolloConfig loadApolloConfig() { appId, cluster, m_namespace); statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(), message); - Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND, m_namespace); + Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND,m_namespace); } - Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, - ExceptionUtil.getDetailMessage(statusCodeException)); + Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(statusCodeException)); transaction.setStatus(statusCodeException); exception = statusCodeException; - if (ex.getStatusCode() == 404) { + if(ex.getStatusCode() == 404) { break retryLoopLabel; } } catch (Throwable ex) { @@ -321,7 +315,7 @@ private ApolloConfig loadApolloConfig() { } String assembleQueryConfigUrl(String uri, String appId, String cluster, String namespace, - String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { + String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { String path = "configs/%s/%s/%s"; List pathParams = @@ -366,8 +360,7 @@ private void scheduleLongPollingRefresh() { remoteConfigLongPollService.submit(m_appId, m_namespace, this); } - public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, - ApolloNotificationMessages remoteMessages) { + public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages) { m_longPollServiceDto.set(longPollNotifiedServiceDto); m_remoteMessages.set(remoteMessages); m_executorService.submit(new Runnable() { diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index 07a99f48..fda6e47e 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -293,8 +293,7 @@ public Properties answer(InvocationOnMock invocation) { } }); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); Properties config = remoteConfigRepository.getConfig(); @@ -331,8 +330,7 @@ public HttpResponse answer(InvocationOnMock invocation) throws Thr } }).when(httpClient).doGet(any(HttpRequest.class), any(Class.class)); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); Properties config = remoteConfigRepository.getConfig(); @@ -345,8 +343,7 @@ public void testGetRemoteConfigWithServerError() throws Exception { when(someResponse.getStatusCode()).thenReturn(500); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); //must stop the long polling before exception occurred remoteConfigLongPollService.stopLongPollingRefresh(); @@ -359,8 +356,7 @@ public void testGetRemoteConfigWithNotFount() throws Exception { when(someResponse.getStatusCode()).thenReturn(404); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); //must stop the long polling before exception occurred remoteConfigLongPollService.stopLongPollingRefresh(); @@ -377,8 +373,7 @@ public void testRepositoryChangeListener() throws Exception { when(someResponse.getBody()).thenReturn(someApolloConfig); RepositoryChangeListener someListener = mock(RepositoryChangeListener.class); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); remoteConfigRepository.addChangeListener(someListener); final ArgumentCaptor captor = ArgumentCaptor.forClass(Properties.class); @@ -389,8 +384,7 @@ public void testRepositoryChangeListener() throws Exception { remoteConfigRepository.sync(); - verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), - captor.capture()); + verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), captor.capture()); assertEquals(newConfigurations, captor.getValue()); } @@ -413,11 +407,9 @@ public Void answer(InvocationOnMock invocation) throws Throwable { return null; } - }).when(someListener) - .onRepositoryChange(any(String.class), any(String.class), any(Properties.class)); + }).when(someListener).onRepositoryChange(any(String.class), any(String.class), any(Properties.class)); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); remoteConfigRepository.addChangeListener(someListener); final ArgumentCaptor captor = ArgumentCaptor.forClass(Properties.class); @@ -441,14 +433,12 @@ public Void answer(InvocationOnMock invocation) throws Throwable { remoteConfigLongPollService.stopLongPollingRefresh(); - verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), - captor.capture()); + verify(someListener, times(1)).onRepositoryChange(eq(someAppId), eq(someNamespace), captor.capture()); assertEquals(newConfigurations, captor.getValue()); final ArgumentCaptor httpRequestArgumentCaptor = ArgumentCaptor .forClass(HttpRequest.class); - verify(httpClient, atLeast(1)).doGet(httpRequestArgumentCaptor.capture(), - eq(ApolloConfig.class)); + verify(httpClient, atLeast(1)).doGet(httpRequestArgumentCaptor.capture(), eq(ApolloConfig.class)); HttpRequest request = httpRequestArgumentCaptor.getValue(); @@ -471,8 +461,7 @@ public void testAssembleQueryConfigUrl() throws Exception { notificationMessages.put(someKey, someNotificationId); notificationMessages.put(anotherKey, anotherNotificationId); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); ApolloConfig someApolloConfig = mock(ApolloConfig.class); when(someApolloConfig.getReleaseKey()).thenReturn(someReleaseKey); @@ -564,8 +553,8 @@ public long getLongPollingInitialDelayInMills() { } @Override - public String getAccessKeySecret(String appId) { - if (appId.equals(someAppId)) { + public String getAccessKeySecret(String appId){ + if(appId.equals(someAppId)){ return someSecret; } return null; @@ -580,8 +569,8 @@ public HttpResponse doGet(HttpRequest httpRequest, Class responseType) return (HttpResponse) someResponse; } throw new ApolloConfigStatusCodeException(someResponse.getStatusCode(), - String.format("Http request failed due to status code: %d", - someResponse.getStatusCode())); + String.format("Http request failed due to status code: %d", + someResponse.getStatusCode())); } @Override diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index ca68a513..b1d296be 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -43,9 +43,9 @@ public ApolloConfig() { } public ApolloConfig(String appId, - String cluster, - String namespaceName, - String releaseKey) { + String cluster, + String namespaceName, + String releaseKey) { this.appId = appId; this.cluster = cluster; this.namespaceName = namespaceName; From 121317b52f02f73892d3bd6ebfb628f39af8e7b8 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sat, 21 Dec 2024 14:00:16 +0800 Subject: [PATCH 08/23] code format --- .../framework/apollo/internals/RemoteConfigRepositoryTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index fda6e47e..fc49ebfe 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -149,8 +149,7 @@ public void testLoadConfig() throws Exception { when(someResponse.getStatusCode()).thenReturn(200); when(someResponse.getBody()).thenReturn(someApolloConfig); - RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, - someNamespace); + RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someAppId, someNamespace); Properties config = remoteConfigRepository.getConfig(); From d489886413a526a94a68ab72d4619abe77332166 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:43:24 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20RemoteConfigReposito?= =?UTF-8?q?ry.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../ctrip/framework/apollo/internals/RemoteConfigRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 07c7a791..41cf9cd0 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -269,7 +269,6 @@ private ApolloConfig loadApolloConfig() { result.setConfigurations( mergeConfigurations(previousConfigurations, result.getConfigurationChanges())); } - } logger.debug("Loaded config for {}: {}", m_namespace, result); From 4e9e146476aef4fbc5a0cc4108f7de5082e41f5e Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:43:31 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ApolloConfig.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index b1d296be..24ed4024 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -100,7 +100,6 @@ public void setConfigSyncType(String configSyncType) { this.configSyncType = configSyncType; } - public void setConfigurations(Map configurations) { this.configurations = configurations; } From 545c074130e5c969da55905e2175e9d505cbc5cc Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:43:37 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ApolloConfig.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index 24ed4024..903b9c31 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -108,7 +108,6 @@ public void setConfigurationChanges(List configurationChang this.configurationChanges = configurationChanges; } - @Override public String toString() { final StringBuilder sb = new StringBuilder("ApolloConfig{"); From 07b3b13bc0a3bd1b58454dbdabd07cc8aed0493a Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:43:44 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigurationChange.?= =?UTF-8?q?java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../com/ctrip/framework/apollo/core/dto/ConfigurationChange.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java index d8a1d5a7..1893263e 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java @@ -53,7 +53,6 @@ public String getConfigurationChangeType() { return configurationChangeType; } - @Override public String toString() { final StringBuilder sb = new StringBuilder("ConfigChange{"); From be92b58fc47b853462ae61c04b1b9e0d03cbbb06 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:43:50 +0800 Subject: [PATCH 13/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigSyncType.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../com/ctrip/framework/apollo/core/enums/ConfigSyncType.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index 19b31e42..182a5741 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -32,7 +32,6 @@ public enum ConfigSyncType { this.value = value; } - /** * Transforms a given string to its matching {@link ConfigSyncType}. * From 201b782c8b8dac1008130dc1900f37f9169632c0 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:44:04 +0800 Subject: [PATCH 14/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigSyncType.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../com/ctrip/framework/apollo/core/enums/ConfigSyncType.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index 182a5741..fae3ded3 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -50,7 +50,6 @@ public static ConfigSyncType fromString(String value) { } } return UNKNOWN; - } /** From eb737cf7bf7b1f1b83bc2ed090401514e26575e7 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:44:14 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigSyncType.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../com/ctrip/framework/apollo/core/enums/ConfigSyncType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index fae3ded3..c34545d1 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -19,7 +19,7 @@ import com.ctrip.framework.apollo.core.utils.StringUtils; /** - * This enum represents all the possible Configuration sync from apollo-config + * This enum represents all the possible Configuration sync types * * @author jason */ From 18e2139fe779902769f75f7cfea9223f3acc2f9c Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:45:33 +0800 Subject: [PATCH 16/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigurationChange.?= =?UTF-8?q?java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../ctrip/framework/apollo/core/dto/ConfigurationChange.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java index 1893263e..3403df8f 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.java @@ -20,7 +20,7 @@ /** * Holds the information for a Configuration change. * - * @author jason + * @since 2.0.0 */ public class ConfigurationChange { From 81661cfef8c23097fe7a64871045f2241e237c7d Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:45:40 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigurationChangeT?= =?UTF-8?q?ype.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../framework/apollo/core/enums/ConfigurationChangeType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java index d3ac703d..a00c0b46 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java @@ -20,7 +20,7 @@ import com.google.common.base.Preconditions; /** - * @author jason + * @since 2.0.0 */ public enum ConfigurationChangeType { ADDED, MODIFIED, DELETED, UNKNOWN; From 7d1ffd72b2925048f8b3c7ce2c49eba6457b49f7 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:45:46 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigurationChangeT?= =?UTF-8?q?ypeUtils.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../apollo/core/enums/ConfigurationChangeTypeUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java index 57218707..c996ef0c 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeTypeUtils.java @@ -24,7 +24,7 @@ * The class provides simple functionalities that extend the capabilities of * {@link ConfigurationChangeType} * - * @author json + * @since 2.0.0 */ public final class ConfigurationChangeTypeUtils { From a5a47e4081536c958d1649297a9badeef83cdfe9 Mon Sep 17 00:00:00 2001 From: kai <64013698+jackie-coming@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:46:02 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ConfigSyncType.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Song --- .../com/ctrip/framework/apollo/core/enums/ConfigSyncType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index c34545d1..4b151441 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -21,7 +21,7 @@ /** * This enum represents all the possible Configuration sync types * - * @author jason + * @since 2.0.0 */ public enum ConfigSyncType { FULL_SYNC("FullSync"), INCREMENTAL_SYNC("IncrementalSync"), UNKNOWN("Unknown"); From 66aae85140476376ce9e89445b6db8cb2e6eaebb Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sun, 22 Dec 2024 13:04:26 +0800 Subject: [PATCH 20/23] code format --- CHANGES.md | 1 + .../framework/apollo/core/enums/ConfigurationChangeType.java | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 56acae01..e127cc36 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Apollo Java 2.4.0 * [Add more observability in apollo config client](https://github.com/apolloconfig/apollo-java/pull/74) * [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79) * [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70) +* [Feature support incremental configuration synchronization client](https://github.com/apolloconfig/apollo-java/pull/90) ------------------ diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java index a00c0b46..48b071cc 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java @@ -20,6 +20,7 @@ import com.google.common.base.Preconditions; /** + * This enum represents all the possible Configuration Change types * @since 2.0.0 */ public enum ConfigurationChangeType { From 8cf6c6d8dba2410511883dace98d68373fdf99e5 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sun, 22 Dec 2024 13:06:36 +0800 Subject: [PATCH 21/23] code format --- .../framework/apollo/core/enums/ConfigurationChangeType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java index 48b071cc..6a483102 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.java @@ -21,6 +21,7 @@ /** * This enum represents all the possible Configuration Change types + * * @since 2.0.0 */ public enum ConfigurationChangeType { From 0f7d2a33dffbbedf526efc82bed65dd7b17cd413 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Sun, 22 Dec 2024 13:33:32 +0800 Subject: [PATCH 22/23] add UnknownSync action --- .../internals/RemoteConfigRepository.java | 6 ++++ .../internals/RemoteConfigRepositoryTest.java | 31 +++++++++++++++++++ .../apollo/core/enums/ConfigSyncType.java | 2 -- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 41cf9cd0..199ed21d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -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); diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java index fc49ebfe..dac8050a 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java @@ -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"; @@ -504,6 +522,19 @@ private ApolloConfig assembleApolloConfigWithIncrementalSync( return apolloConfig; } + private ApolloConfig assembleApolloConfigWithUnknownSync( + List 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 diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java index 4b151441..07e72aac 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.java @@ -37,8 +37,6 @@ public enum ConfigSyncType { * * @param value the string that matches * @return the matching {@link ConfigSyncType} - * @throws IllegalArgumentException in case the value is empty or there is no - * matching {@link ConfigSyncType} */ public static ConfigSyncType fromString(String value) { if (StringUtils.isEmpty(value)) { From ee7e05aea762a1bf8c2b7b2d0dcc0ff2161e8ffc Mon Sep 17 00:00:00 2001 From: Jason Song Date: Mon, 23 Dec 2024 09:22:31 +0800 Subject: [PATCH 23/23] Apply suggestions from code review --- .../framework/apollo/internals/RemoteConfigRepository.java | 2 +- .../java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 199ed21d..3f6f794c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -270,7 +270,7 @@ private ApolloConfig loadApolloConfig() { mergeConfigurations(previousConfigurations, result.getConfigurationChanges())); } else if (configSyncType == ConfigSyncType.UNKNOWN) { String message = String.format( - "Apollo Config Sync type invalid - configSyncType: %s", + "Invalid config sync type - %s", result.getConfigSyncType()); throw new ApolloConfigException(message, exception); } diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java index 903b9c31..39d589b9 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ApolloConfig.java @@ -16,7 +16,6 @@ */ package com.ctrip.framework.apollo.core.dto; - import java.util.List; import java.util.Map;