Skip to content

Commit 56df3a8

Browse files
committed
code refactor
1 parent 26e8db5 commit 56df3a8

5 files changed

Lines changed: 19 additions & 18 deletions

File tree

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,10 @@ public boolean isConfigServiceCacheKeyIgnoreCase() {
240240
return getBooleanProperty("config-service.cache.key.ignore-case", false);
241241
}
242242

243-
public boolean isConfigServiceChangeCacheEnabled() {
243+
public boolean isConfigServiceIncrementalChangeEnabled() {
244244
return getBooleanProperty("config-service.incremental.change.enabled", false);
245245
}
246246

247-
248247
int checkInt(int value, int min, int max, int defaultValue) {
249248
if (value >= min && value <= max) {
250249
return value;

apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public GrayReleaseRulesHolder grayReleaseRulesHolder() {
7070

7171
@Bean
7272
public ConfigService configService() {
73+
if (bizConfig.isConfigServiceIncrementalChangeEnabled()) {
74+
return new ConfigServiceWithChangeCache(releaseService, releaseMessageService,
75+
grayReleaseRulesHolder(), bizConfig, meterRegistry);
76+
}
7377
if (bizConfig.isConfigServiceCacheEnabled()) {
7478
return new ConfigServiceWithCache(releaseService, releaseMessageService,
7579
grayReleaseRulesHolder(), bizConfig, meterRegistry);
7680
}
77-
if(bizConfig.isConfigServiceChangeCacheEnabled()){
78-
return new ConfigServiceWithChangeCache(releaseService, releaseMessageService,
79-
grayReleaseRulesHolder(), bizConfig, meterRegistry);
80-
}
8181
return new DefaultConfigService(releaseService, grayReleaseRulesHolder());
8282
}
8383
@Bean

apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.common.collect.Sets;
3737
import com.google.gson.Gson;
3838
import com.google.gson.reflect.TypeToken;
39+
import java.util.regex.Pattern;
3940
import org.springframework.web.bind.annotation.GetMapping;
4041
import org.springframework.web.bind.annotation.PathVariable;
4142
import org.springframework.web.bind.annotation.RequestMapping;
@@ -159,9 +160,11 @@ public ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String
159160

160161
Map<String, String> latestConfigurations = mergeReleaseConfigurations(releases);
161162

162-
if (bizConfig.isConfigServiceChangeCacheEnabled()) {
163+
if (bizConfig.isConfigServiceIncrementalChangeEnabled()) {
163164
LinkedHashSet<String> clientSideReleaseKeys = Sets.newLinkedHashSet(
164-
Arrays.stream(clientSideReleaseKey.split("\\+")).collect(Collectors.toList()));
165+
Arrays.stream(
166+
clientSideReleaseKey.split(Pattern.quote(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)))
167+
.collect(Collectors.toList()));
165168

166169
Map<String, Release> historyReleases = configService.findReleasesByReleaseKeys(
167170
clientSideReleaseKeys);
@@ -184,7 +187,7 @@ public ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String
184187

185188
apolloConfig.setConfigurationChanges(configurationChanges);
186189

187-
apolloConfig.setConfigSyncType(ConfigSyncType.INCREMENTALSYNC.getValue());
190+
apolloConfig.setConfigSyncType(ConfigSyncType.INCREMENTAL_SYNC.getValue());
188191
return apolloConfig;
189192
}
190193

apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
2929
import com.ctrip.framework.apollo.core.dto.ConfigurationChange;
3030
import com.ctrip.framework.apollo.core.enums.ConfigSyncType;
31-
import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType;
3231
import com.google.common.base.Joiner;
3332
import com.google.common.collect.ImmutableMap;
3433
import com.google.common.collect.Lists;
@@ -538,7 +537,7 @@ private AppNamespace assembleAppNamespace(String appId, String namespace, boolea
538537

539538
@Test
540539
public void testQueryConfigWithIncrementalSync() throws Exception {
541-
when(bizConfig.isConfigServiceChangeCacheEnabled())
540+
when(bizConfig.isConfigServiceIncrementalChangeEnabled())
542541
.thenReturn(true);
543542
String clientSideReleaseKey = "1";
544543
String someConfigurations = "{\"apollo.public.foo\": \"foo\"}";
@@ -567,14 +566,14 @@ public void testQueryConfigWithIncrementalSync() throws Exception {
567566
ApolloConfig anotherResult = configController.queryConfig(someAppId, someClusterName,
568567
defaultNamespaceName, someDataCenter, clientSideReleaseKey,
569568
someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
570-
assertEquals(ConfigSyncType.INCREMENTALSYNC.getValue(), anotherResult.getConfigSyncType());
569+
assertEquals(ConfigSyncType.INCREMENTAL_SYNC.getValue(), anotherResult.getConfigSyncType());
571570
assertEquals(configurationChanges, anotherResult.getConfigurationChanges());
572571

573572
}
574573

575574
@Test
576575
public void testQueryConfigWithIncrementalSyncNotFound() throws Exception {
577-
when(bizConfig.isConfigServiceChangeCacheEnabled())
576+
when(bizConfig.isConfigServiceIncrementalChangeEnabled())
578577
.thenReturn(true);
579578

580579
String someClientSideReleaseKey = "1";
@@ -601,7 +600,7 @@ public void testQueryConfigWithIncrementalSyncNotFound() throws Exception {
601600

602601
@Test
603602
public void testQueryConfigWithIncrementalSyncPublicNamespaceAndAppOverride() throws Exception {
604-
when(bizConfig.isConfigServiceChangeCacheEnabled())
603+
when(bizConfig.isConfigServiceIncrementalChangeEnabled())
605604
.thenReturn(true);
606605
String someAppClientSideReleaseKey = "1";
607606
String somePublicAppClientSideReleaseKey = "2";
@@ -666,7 +665,7 @@ public void testQueryConfigWithIncrementalSyncPublicNamespaceAndAppOverride() th
666665
assertEquals(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
667666
.join(someAppServerSideReleaseKey, somePublicAppSideReleaseKey),
668667
result.getReleaseKey());
669-
assertEquals(ConfigSyncType.INCREMENTALSYNC.getValue(), result.getConfigSyncType());
668+
assertEquals(ConfigSyncType.INCREMENTAL_SYNC.getValue(), result.getConfigSyncType());
670669
assertEquals(configurationChanges, result.getConfigurationChanges());
671670
}
672671

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@
200200
<artifactId>commons-lang3</artifactId>
201201
<version>${common-lang3.version}</version>
202202
</dependency>
203-
<!-- to fix CVE-2022-41966 -->
203+
<!-- to fix CVE-2024-47072 -->
204204
<dependency>
205205
<groupId>com.thoughtworks.xstream</groupId>
206206
<artifactId>xstream</artifactId>
207-
<version>1.4.20</version>
207+
<version>1.4.21</version>
208208
</dependency>
209209
<!--for test -->
210210
<dependency>
@@ -649,4 +649,4 @@
649649
</snapshots>
650650
</repository>
651651
</repositories>
652-
</project>
652+
</project>

0 commit comments

Comments
 (0)