1717package org .springframework .cloud .kubernetes .fabric8 .client .reload ;
1818
1919import java .io .InputStream ;
20+ import java .time .Duration ;
2021import java .util .HashMap ;
2122import java .util .Map ;
2223import java .util .Optional ;
2627import org .junit .jupiter .api .AfterAll ;
2728import org .junit .jupiter .api .BeforeAll ;
2829import org .junit .jupiter .api .Test ;
29- import org .testcontainers .containers .Container ;
3030import org .testcontainers .k3s .K3sContainer ;
3131
3232import org .springframework .cloud .kubernetes .integration .tests .commons .Commons ;
3636import org .springframework .web .reactive .function .client .WebClient ;
3737
3838import static org .assertj .core .api .Assertions .assertThat ;
39+ import static org .awaitility .Awaitility .await ;
3940import static org .springframework .cloud .kubernetes .fabric8 .client .reload .TestAssertions .builder ;
4041import static org .springframework .cloud .kubernetes .fabric8 .client .reload .TestAssertions .manifests ;
4142import static org .springframework .cloud .kubernetes .fabric8 .client .reload .TestAssertions .retrySpec ;
@@ -90,7 +91,7 @@ static void afterAll() {
9091 * </pre>
9192 */
9293 @ Test
93- void test () throws Exception {
94+ void test () {
9495 WebClient webClient = builder ().baseUrl ("http://localhost/key" ).build ();
9596 String result = webClient .method (HttpMethod .GET )
9697 .retrieve ()
@@ -108,41 +109,20 @@ void test() throws Exception {
108109 configMapConfigTree .setData (Map .of ("from.properties.key" , "as-mount-changed" ));
109110 // add label so that configuration-watcher picks this up
110111 Map <String , String > existingLabels = new HashMap <>(
111- Optional .ofNullable (configMapConfigTree .getMetadata ().getLabels ()).orElse (Map . of ()));
112+ Optional .ofNullable (configMapConfigTree .getMetadata ().getLabels ()).orElse (new HashMap <> ()));
112113 existingLabels .put ("spring.cloud.kubernetes.config" , "true" );
113114 configMapConfigTree .getMetadata ().setLabels (existingLabels );
114115
115116 util .client ().configMaps ().resource (configMapConfigTree ).createOrReplace ();
116117
117- // await().atMost(Duration.ofSeconds(180))
118- // .pollInterval(Duration.ofSeconds(1))
119- // .until(() -> webClient.method(HttpMethod.GET)
120- // .retrieve()
121- // .bodyToMono(String.class)
122- // .retryWhen(retrySpec())
123- // .block()
124- // .equals("as-mount-changed"));
125-
126- Thread .sleep (180_000 );
127-
128- System .out .println (logs ());
129- }
130-
131- private String logs () {
132- try {
133- String appPodName = K3S
134- .execInContainer ("sh" , "-c" ,
135- "kubectl get pods -l app=" + CONFIGURATION_WATCHER_IMAGE_NAME
136- + " -o=name --no-headers | tr -d '\n '" )
137- .getStdout ();
138-
139- Container .ExecResult execResult = K3S .execInContainer ("sh" , "-c" , "kubectl logs " + appPodName .trim ());
140- return execResult .getStdout ();
141- }
142- catch (Exception e ) {
143- e .printStackTrace ();
144- throw new RuntimeException (e );
145- }
118+ await ().atMost (Duration .ofSeconds (180 ))
119+ .pollInterval (Duration .ofSeconds (1 ))
120+ .until (() -> webClient .method (HttpMethod .GET )
121+ .retrieve ()
122+ .bodyToMono (String .class )
123+ .retryWhen (retrySpec ())
124+ .block ()
125+ .equals ("as-mount-changed" ));
146126 }
147127
148128}
0 commit comments