Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
fullyRefreshCache(configMapGetter, fromConfigMapAnnotation, configMapDataCache);
configMapKeyRefresher.scheduleAtFixedRate(
() -> {
fullyRefreshCache(configMapGetter, fromConfigMapAnnotation, configMapDataCache);
try {
fullyRefreshCache(configMapGetter, fromConfigMapAnnotation, configMapDataCache);
} catch (RuntimeException e) {
log.warn(
"Failed refreshing ConfigMap {}/{}",
fromConfigMapAnnotation.namespace(),
fromConfigMapAnnotation.name(),
e);
}
},
manifestsProperties.getRefreshInterval().getSeconds(),
manifestsProperties.getRefreshInterval().getSeconds(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -104,6 +105,25 @@ void valueUpdate() {
.until(() -> "bar2".equals(myBean.dynamicData.get("foo")));
}

@Test
void refreshRecoversAfterReadFailure() {
assertThat(myBean.dynamicData).containsEntry("foo", "bar1");
int failedReads = mockAtomicConfigMapGetter.failedReads.get();
mockAtomicConfigMapGetter.readFailure.set(new IllegalStateException("Transient API failure"));
try {
await().until(() -> mockAtomicConfigMapGetter.failedReads.get() > failedReads);
assertThat(myBean.dynamicData).containsExactlyEntriesOf(Map.of("foo", "bar1"));
} finally {
mockAtomicConfigMapGetter.readFailure.set(null);
}

mockAtomicConfigMapGetter.configMapAtomicReference.set(
new V1ConfigMap().putDataItem("foo", "recovered"));
await()
.timeout(manifestsProperties.getRefreshInterval().multipliedBy(2))
.until(() -> "recovered".equals(myBean.dynamicData.get("foo")));
}

@Test
void keyUpdate() {
assertThat(manifestsProperties.getRefreshInterval()).isEqualTo(Duration.ofSeconds(1));
Expand Down Expand Up @@ -285,9 +305,16 @@ public V1ConfigMap get(String namespace, String name) {
static class MockAtomicConfigMapGetter implements ConfigMapGetter {

private final AtomicReference<V1ConfigMap> configMapAtomicReference = new AtomicReference<>();
private final AtomicReference<RuntimeException> readFailure = new AtomicReference<>();
private final AtomicInteger failedReads = new AtomicInteger();

@Override
public V1ConfigMap get(String namespace, String name) {
RuntimeException failure = readFailure.get();
if (failure != null) {
failedReads.incrementAndGet();
throw failure;
}
return configMapAtomicReference.get();
}
}
Expand Down
Loading