|
11 | 11 | import org.slf4j.Logger;
|
12 | 12 | import org.slf4j.LoggerFactory;
|
13 | 13 |
|
14 |
| -import static java.util.concurrent.TimeUnit.MINUTES; |
| 14 | +import static java.util.concurrent.TimeUnit.*; |
15 | 15 | import static org.awaitility.Awaitility.await;
|
16 | 16 | import static org.hamcrest.CoreMatchers.equalTo;
|
17 | 17 | import static org.hamcrest.CoreMatchers.is;
|
@@ -86,19 +86,30 @@ public void test() {
|
86 | 86 |
|
87 | 87 | String url = "http://" + tomcat.getMetadata().getName() + "/" + webapp1.getSpec().getContextPath() + "/";
|
88 | 88 | log.info("Starting curl Pod and waiting 5 minutes for GET of {} to return 200", url);
|
89 |
| - Pod curlPod = client.run().inNamespace(TEST_NS) |
90 |
| - .withRunConfig(new RunConfigBuilder() |
91 |
| - .withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url) |
92 |
| - .withName("curl") |
93 |
| - .withImage("curlimages/curl:7.78.0") |
94 |
| - .withRestartPolicy("Never") |
95 |
| - .build()).done(); |
96 |
| - await().atMost(5, MINUTES).untilAsserted(() -> { |
| 89 | + |
| 90 | + int timeoutMinutes = 5; |
| 91 | + await().atMost(timeoutMinutes, MINUTES).untilAsserted(() -> { |
97 | 92 | try {
|
| 93 | + log.info("Starting curl Pod to test if webapp was deployed correctly"); |
| 94 | + Pod curlPod = client.run().inNamespace(TEST_NS) |
| 95 | + .withRunConfig(new RunConfigBuilder() |
| 96 | + .withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url) |
| 97 | + .withName("curl") |
| 98 | + .withImage("curlimages/curl:7.78.0") |
| 99 | + .withRestartPolicy("Never") |
| 100 | + .build()).done(); |
| 101 | + log.info("Waiting for curl Pod to finish running"); |
| 102 | + await().atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get().getStatus().getPhase().equals("Succeeded")); |
| 103 | + |
98 | 104 | String curlOutput = client.pods().inNamespace(TEST_NS).withName(curlPod.getMetadata().getName()).getLog();
|
| 105 | + log.info("Output from curl: '{}'", curlOutput); |
99 | 106 | assertThat(curlOutput, equalTo("200"));
|
100 | 107 | } catch (KubernetesClientException ex) {
|
101 | 108 | throw new AssertionError(ex);
|
| 109 | + } finally { |
| 110 | + client.pods().inNamespace(TEST_NS).withName("curl").delete(); |
| 111 | + log.info("Waiting for curl Pod to be deleted"); |
| 112 | + await().atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get() == null); |
102 | 113 | }
|
103 | 114 | });
|
104 | 115 |
|
|
0 commit comments