1212*/
1313package io .kubernetes .client .spring .extended .manifests ;
1414
15- import static junit .framework .Assert .assertNull ;
1615import static junit .framework .TestCase .assertEquals ;
1716import static junit .framework .TestCase .assertNotNull ;
17+ import static org .awaitility .Awaitility .await ;
1818
1919import io .kubernetes .client .openapi .models .V1ConfigMap ;
2020import io .kubernetes .client .spring .extended .manifests .annotation .FromConfigMap ;
2323import java .time .Duration ;
2424import java .util .Map ;
2525import java .util .concurrent .atomic .AtomicReference ;
26- import org .awaitility .Awaitility ;
2726import org .junit .Rule ;
2827import org .junit .Test ;
2928import org .junit .rules .TestRule ;
@@ -98,8 +97,9 @@ public void testValueUpdate() throws InterruptedException {
9897 assertEquals ("bar1" , myBean .dynamicData .get ("foo" ));
9998 mockAtomicConfigMapGetter .configMapAtomicReference .set (
10099 new V1ConfigMap ().putDataItem ("foo" , "bar2" ));
101- Thread .sleep (manifestsProperties .getRefreshInterval ().toMillis ());
102- assertEquals ("bar2" , myBean .dynamicData .get ("foo" ));
100+ await ()
101+ .timeout (manifestsProperties .getRefreshInterval ().multipliedBy (2 ))
102+ .until (() -> "bar2" .equals (myBean .dynamicData .get ("foo" )));
103103 }
104104
105105 @ Test
@@ -109,14 +109,13 @@ public void testKeyUpdate() throws InterruptedException {
109109 assertEquals ("bar1" , myBean .dynamicData .get ("foo" ));
110110 mockAtomicConfigMapGetter .configMapAtomicReference .set (
111111 new V1ConfigMap ().putDataItem ("foo1" , "bar" ));
112- Thread .sleep (manifestsProperties .getRefreshInterval ().toMillis ());
113- assertNull (myBean .dynamicData .get ("foo" )); // old key should be removed
114- assertEquals ("bar" , myBean .dynamicData .get ("foo1" )); // new key should be added
115- }
116-
117- private void reset () {
118- mockAtomicConfigMapGetter .configMapAtomicReference .set (
119- new V1ConfigMap ().putDataItem ("foo" , "bar1" ));
112+ await ()
113+ .timeout (manifestsProperties .getRefreshInterval ().multipliedBy (2 ))
114+ .until (
115+ () -> {
116+ return myBean .dynamicData .get ("foo" ) == null
117+ && "bar" .equals (myBean .dynamicData .get ("foo1" ));
118+ });
120119 }
121120
122121 static class MockConfigMapGetter implements ConfigMapGetter {
@@ -144,7 +143,7 @@ public Statement apply(Statement statement, Description description) {
144143 public void evaluate () throws Throwable {
145144 mockAtomicConfigMapGetter .configMapAtomicReference .set (
146145 new V1ConfigMap ().putDataItem ("foo" , "bar1" ));
147- Awaitility . await ().until (() -> "bar1" .equals (myBean .dynamicData .get ("foo" )));
146+ await ().until (() -> "bar1" .equals (myBean .dynamicData .get ("foo" )));
148147 statement .evaluate ();
149148 }
150149 };
0 commit comments