12
12
*/
13
13
package io .kubernetes .client .spring .extended .manifests ;
14
14
15
- import static junit .framework .Assert .assertNull ;
16
15
import static junit .framework .TestCase .assertEquals ;
17
16
import static junit .framework .TestCase .assertNotNull ;
17
+ import static org .awaitility .Awaitility .await ;
18
18
19
19
import io .kubernetes .client .openapi .models .V1ConfigMap ;
20
20
import io .kubernetes .client .spring .extended .manifests .annotation .FromConfigMap ;
23
23
import java .time .Duration ;
24
24
import java .util .Map ;
25
25
import java .util .concurrent .atomic .AtomicReference ;
26
- import org .awaitility .Awaitility ;
27
26
import org .junit .Rule ;
28
27
import org .junit .Test ;
29
28
import org .junit .rules .TestRule ;
@@ -98,8 +97,9 @@ public void testValueUpdate() throws InterruptedException {
98
97
assertEquals ("bar1" , myBean .dynamicData .get ("foo" ));
99
98
mockAtomicConfigMapGetter .configMapAtomicReference .set (
100
99
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" )));
103
103
}
104
104
105
105
@ Test
@@ -109,14 +109,13 @@ public void testKeyUpdate() throws InterruptedException {
109
109
assertEquals ("bar1" , myBean .dynamicData .get ("foo" ));
110
110
mockAtomicConfigMapGetter .configMapAtomicReference .set (
111
111
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
+ });
120
119
}
121
120
122
121
static class MockConfigMapGetter implements ConfigMapGetter {
@@ -144,7 +143,7 @@ public Statement apply(Statement statement, Description description) {
144
143
public void evaluate () throws Throwable {
145
144
mockAtomicConfigMapGetter .configMapAtomicReference .set (
146
145
new V1ConfigMap ().putDataItem ("foo" , "bar1" ));
147
- Awaitility . await ().until (() -> "bar1" .equals (myBean .dynamicData .get ("foo" )));
146
+ await ().until (() -> "bar1" .equals (myBean .dynamicData .get ("foo" )));
148
147
statement .evaluate ();
149
148
}
150
149
};
0 commit comments