diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadConfigMapTest.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadConfigMapTest.java index cfdbfb9f2..1c72fd36a 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadConfigMapTest.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadConfigMapTest.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; @@ -81,7 +82,7 @@ class EventReloadConfigMapTest { private static final String NAMESPACE = "spring-k8s"; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); private static CoreV1Api coreV1Api; @@ -158,7 +159,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -168,7 +169,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(10)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static V1ConfigMap configMap(String name, Map data) { @@ -237,7 +238,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadSecretTest.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadSecretTest.java index 86e3b09ed..afe24991c 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadSecretTest.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/EventReloadSecretTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import com.github.tomakehurst.wiremock.WireMockServer; @@ -83,7 +84,7 @@ class EventReloadSecretTest { private static final String NAMESPACE = "spring-k8s"; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); private static CoreV1Api coreV1Api; @@ -160,7 +161,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -170,7 +171,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(10)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static V1Secret secret(String name, Map data) { @@ -242,7 +243,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadConfigMapTest.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadConfigMapTest.java index 7c395cf88..a33beb98b 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadConfigMapTest.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadConfigMapTest.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; @@ -79,7 +80,7 @@ class PollingReloadConfigMapTest { private static final String NAMESPACE = "spring-k8s"; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); private static CoreV1Api coreV1Api; @@ -140,15 +141,18 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); + System.out.println("one: " + one + " two: " + two + " three: " + three + " updateStrategyNotCalled: " + updateStrategyNotCalled); return one && two && three && updateStrategyNotCalled; }); + System.out.println("first assertion passed"); + // it passes while reading 'configMapTwo' Awaitility.await() .atMost(Duration.ofSeconds(20)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static V1ConfigMap configMap(String name, Map data) { @@ -216,7 +220,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadSecretTest.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadSecretTest.java index e30c4f821..4421ca32e 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadSecretTest.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload_it/PollingReloadSecretTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import com.github.tomakehurst.wiremock.WireMockServer; @@ -81,7 +82,7 @@ class PollingReloadSecretTest { private static final String NAMESPACE = "spring-k8s"; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); private static CoreV1Api coreV1Api; @@ -141,7 +142,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -149,7 +150,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(20)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static V1Secret secret(String name, Map data) { @@ -222,7 +223,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java index 3986f6c82..c8df28210 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java @@ -71,7 +71,7 @@ public static boolean reload(PropertySourceLocator locator, ConfigurableEnvironm boolean changed = changed(sourceFromK8s, existingSources); if (changed) { - LOG.info("Detected change in config maps/secrets, reload will ne triggered"); + LOG.info("Detected change in config maps/secrets, reload will be triggered"); return true; } else { diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadConfigMapTest.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadConfigMapTest.java index 0f4c7c3db..9702dd657 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadConfigMapTest.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadConfigMapTest.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; @@ -72,7 +73,7 @@ public class EventReloadConfigMapTest { private static KubernetesClient kubernetesClient; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); @BeforeAll static void beforeAll() { @@ -118,7 +119,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -132,7 +133,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(10)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static ConfigMap configMap(String name, Map data) { @@ -197,7 +198,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadSecretTest.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadSecretTest.java index 57a699bc5..7515bba3f 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadSecretTest.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadSecretTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.Secret; @@ -75,7 +76,7 @@ class EventReloadSecretTest { private static KubernetesClient kubernetesClient; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); @BeforeAll static void beforeAll() { @@ -120,7 +121,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -134,7 +135,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(10)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static Secret secret(String name, Map data) { @@ -204,7 +205,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadConfigMapTest.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadConfigMapTest.java index 3326c9274..1a355cf7c 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadConfigMapTest.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadConfigMapTest.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; @@ -73,7 +74,7 @@ class PollingReloadConfigMapTest { private static KubernetesClient kubernetesClient; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); @BeforeAll static void beforeAll() { @@ -113,7 +114,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -121,7 +122,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(20)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static ConfigMap configMap(String name, Map data) { @@ -187,7 +188,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); } diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadSecretTest.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadSecretTest.java index 9be63575e..02a4ab566 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadSecretTest.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/PollingReloadSecretTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.Secret; @@ -76,7 +77,7 @@ public class PollingReloadSecretTest { private static KubernetesClient kubernetesClient; - private static final boolean[] strategyCalled = new boolean[] { false }; + private static final AtomicBoolean STRATEGY_CALLED = new AtomicBoolean(false); @BeforeAll static void beforeAll() { @@ -116,7 +117,7 @@ void test(CapturedOutput output) { boolean two = output.getOut().contains("Failed to load source"); boolean three = output.getOut() .contains("Reloadable condition was not satisfied, reload will not be triggered"); - boolean updateStrategyNotCalled = !strategyCalled[0]; + boolean updateStrategyNotCalled = !STRATEGY_CALLED.get(); return one && two && three && updateStrategyNotCalled; }); @@ -124,7 +125,7 @@ void test(CapturedOutput output) { Awaitility.await() .atMost(Duration.ofSeconds(20)) .pollInterval(Duration.ofSeconds(1)) - .until(() -> strategyCalled[0]); + .until(STRATEGY_CALLED::get); } private static Secret secret(String name, Map data) { @@ -194,7 +195,7 @@ KubernetesNamespaceProvider namespaceProvider(AbstractEnvironment environment) { @Primary ConfigurationUpdateStrategy configurationUpdateStrategy() { return new ConfigurationUpdateStrategy("to-console", () -> { - strategyCalled[0] = true; + STRATEGY_CALLED.set(true); }); }