Skip to content

Commit 6545c8e

Browse files
Reload property sources when new property gets added. (#807)
Fixes #803
1 parent 620c0fe commit 6545c8e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/reload/ConfigurationChangeDetector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.awspring.cloud.autoconfigure.config.reload;
1717

1818
import io.awspring.cloud.core.config.AwsPropertySource;
19+
import java.util.Arrays;
1920
import java.util.List;
2021
import java.util.Objects;
2122
import java.util.stream.Collectors;
@@ -68,6 +69,13 @@ protected boolean changed(EnumerablePropertySource<?> left, EnumerablePropertySo
6869
if (left == right) {
6970
return false;
7071
}
72+
73+
// check if a new property is added
74+
if (!Arrays.equals(left.getPropertyNames(), right.getPropertyNames())) {
75+
return true;
76+
}
77+
78+
// check if a value of existing property changed
7179
for (String property : left.getPropertyNames()) {
7280
if (!Objects.equals(left.getProperty(property), right.getProperty(property))) {
7381
return true;

spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoaderIntegrationTests.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void resetParameterValue() {
227227
}
228228

229229
@Test
230-
void reloadsProperties() {
230+
void reloadsPropertiesWhenPropertyValueChanges() {
231231
SpringApplication application = new SpringApplication(App.class);
232232
application.setWebApplicationType(WebApplicationType.NONE);
233233

@@ -252,6 +252,32 @@ void reloadsProperties() {
252252
}
253253
}
254254

255+
@Test
256+
void reloadsPropertiesWhenNewPropertyIsAdded() {
257+
SpringApplication application = new SpringApplication(App.class);
258+
application.setWebApplicationType(WebApplicationType.NONE);
259+
260+
try (ConfigurableApplicationContext context = application.run(
261+
"--spring.config.import=aws-parameterstore:/config/spring/",
262+
"--spring.cloud.aws.parameterstore.reload.strategy=refresh",
263+
"--spring.cloud.aws.parameterstore.reload.period=PT1S",
264+
"--spring.cloud.aws.parameterstore.region=" + REGION,
265+
"--spring.cloud.aws.endpoint=" + localstack.getEndpointOverride(SSM).toString(),
266+
"--spring.cloud.aws.credentials.access-key=noop", "--spring.cloud.aws.credentials.secret-key=noop",
267+
"--spring.cloud.aws.region.static=eu-west-1")) {
268+
assertThat(context.getEnvironment().getProperty("message")).isEqualTo("value from tests");
269+
270+
// update parameter value
271+
SsmClient ssmClient = context.getBean(SsmClient.class);
272+
ssmClient.putParameter(r -> r.name("/config/spring/new-property").value("new value")
273+
.type(ParameterType.STRING).overwrite(true).build());
274+
275+
await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> {
276+
assertThat(context.getEnvironment().getProperty("new-property")).isEqualTo("new value");
277+
});
278+
}
279+
}
280+
255281
@Test
256282
void doesNotReloadPropertiesWhenReloadStrategyIsNotSet() {
257283
SpringApplication application = new SpringApplication(App.class);

0 commit comments

Comments
 (0)