8000 Merge branch 'finalize-tomcat-test' into testing-registry · java-operator-sdk/samples@f15ae6a · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit f15ae6a

Browse files
authored
Merge branch 'finalize-tomcat-test' into testing-registry
2 parents f3c8e77 + a699b58 commit f15ae6a

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

.github/workflows/TomcatIntegrationTest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,4 @@ jobs:
156156
sleep 5; \
157157
done
158158
if [[ $(kubectl logs -n tomcatoperator-sample sample1 --tail=500 | grep tomcat.gif | wc -l) -ne 1 ]]; then exit 1; fi
159-
if [[ $(kubectl logs -n tomcatoperator-sample sample2 --tail=500 | grep dog.jpeg | wc -l) -ne 1 ]]; then exit 1; fi
159+
if [[ $(kubectl logs -n tomcatoperator-sample sample2 --tail=500 | grep dog.jpeg | wc -l) -ne 1 ]]; then exit 1; fi

tomcat/src/test/java/io/javaoperatorsdk/operator/sample/IntegrationTest.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
import static java.util.concurrent.TimeUnit.MINUTES;
16-
import static java.util.concurrent.TimeUnit.SECONDS;
15+
16+
import static java.util.concurrent.TimeUnit.*;
1717
import static org.awaitility.Awaitility.await;
1818
import static org.hamcrest.CoreMatchers.equalTo;
1919
import static org.hamcrest.CoreMatchers.is;
@@ -76,8 +76,8 @@ public void test() {
7676
tomcatClient.inNamespace(TEST_NS).create(tomcat);
7777
webappClient.inNamespace(TEST_NS).create(webapp1);
7878

79-
log.info("Waiting 2 minutes for Tomcat and Webapp CR statuses to be updated");
80-
await().atMost(2, MINUTES).untilAsserted(() -> {
79+
log.info("Waiting 5 minutes for Tomcat and Webapp CR statuses to be updated");
80+
await().atMost(5, MINUTES).untilAsserted(() -> {
8181
Tomcat updatedTomcat = tomcatClient.inNamespace(TEST_NS).withName(tomcat.getMetadata().getName()).get();
8282
Webapp updatedWebapp = webappClient.inNamespace(TEST_NS).withName(webapp1.getMetadata().getName()).get();
8383
assertThat(updatedTomcat.getStatus(), is(notNullValue()));
@@ -97,21 +97,32 @@ public void test() {
9797
}
9898

9999
String url = "http://" + tomcat.getMetadata().getName() + "/" + webapp1.getSpec().getContextPath() + "/";
100-
log.info("Starting curl Pod and waiting 2 minutes for GET of {} to return 200", url);
101-
Pod curlPod = client.run().inNamespace(TEST_NS)
102-
.withRunConfig(new RunConfigBuilder()
103-
.withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url)
104-
.withName("curl")
105-
.withImage("curlimages/curl:7.78.0")
106-
.withRestartPolicy("Never")
107-
.build()).done();
108-
await().atMost(2, MINUTES).untilAsserted(() -> {
100+
log.info("Starting curl Pod and waiting 5 minutes for GET of {} to return 200", url);
101+
102+
int timeoutMinutes = 5;
103+
await().atMost(timeoutMinutes, MINUTES).untilAsserted(() -> {
109104
try {
110-
//let's do som tries
105+
106+
log.info("Starting curl Pod to test if webapp was deployed correctly");
107+
Pod curlPod = client.run().inNamespace(TEST_NS)
108+
.withRunConfig(new RunConfigBuilder()
109+
.withArgs("-s", "-o", "/dev/null", "-w", "%{http_code}", url)
110+
.withName("curl")
111+
.withImage("curlimages/curl:7.78.0")
112+
.withRestartPolicy("Never")
113+
.build()).done();
114+
log.info("Waiting for curl Pod to finish running");
115+
await("wait-for-curl-pod-run").atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get().getStatus().getPhase().equals("Succeeded"));
116+
111117
String curlOutput = client.pods().inNamespace(TEST_NS).withName(curlPod.getMetadata().getName()).getLog();
118+
log.info("Output from curl: '{}'", curlOutput);
112119
assertThat(curlOutput, equalTo("200"));
113120
} catch (KubernetesClientException ex) {
114121
throw new AssertionError(ex);
122+
} finally {
123+
client.pods().inNamespace(TEST_NS).withName("curl").delete();
124+
log.info("Waiting for curl Pod to be deleted");
125+
await("wait-for-curl-pod-stop").atMost(timeoutMinutes, MINUTES).until(() -> client.pods().inNamespace(TEST_NS).withName("curl").get() == null);
115126
}
116127
});
117128
}

0 commit comments

Comments
 (0)
0