12
12
import org .slf4j .Logger ;
13
13
import org .slf4j .LoggerFactory ;
14
14
15
- import static java . util . concurrent . TimeUnit . MINUTES ;
16
- import static java .util .concurrent .TimeUnit .SECONDS ;
15
+
16
+ import static java .util .concurrent .TimeUnit .* ;
17
17
import static org .awaitility .Awaitility .await ;
18
18
import static org .hamcrest .CoreMatchers .equalTo ;
19
19
import static org .hamcrest .CoreMatchers .is ;
@@ -76,8 +76,8 @@ public void test() {
76
76
tomcatClient .inNamespace (TEST_NS ).create (tomcat );
77
77
webappClient .inNamespace (TEST_NS ).create (webapp1 );
78
78
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 (() -> {
81
81
Tomcat updatedTomcat = tomcatClient .inNamespace (TEST_NS ).withName (tomcat .getMetadata ().getName ()).get ();
82
82
Webapp updatedWebapp = webappClient .inNamespace (TEST_NS ).withName (webapp1 .getMetadata ().getName ()).get ();
83
83
assertThat (updatedTomcat .getStatus (), is (notNullValue ()));
@@ -97,21 +97,32 @@ public void test() {
97
97
}
98
98
99
99
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 (() -> {
109
104
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
+
111
117
String curlOutput = client .pods ().inNamespace (TEST_NS ).withName (curlPod .getMetadata ().getName ()).getLog ();
118
+ log .info ("Output from curl: '{}'" , curlOutput );
112
119
assertThat (curlOutput , equalTo ("200" ));
113
120
} catch (KubernetesClientException ex ) {
114
121
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 );
115
126
}
116
127
});
117
128
}
0 commit comments