Skip to content

Commit

Permalink
[JBWS-4383]:Improve the common utility to check the WFLY readiness in…
Browse files Browse the repository at this point in the history
… cloud test
  • Loading branch information
jimma committed Sep 11, 2023
1 parent e76c3ca commit 9334492
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
public class EndpointTestCase extends JBossWSKubernetesTest {

private static final String APP_NAME = "jbossws-cxf-k8s-basic";
private final String APP_NAME = "jbossws-cxf-k8s-basic";
@Test
public void checkWSEndpoint(@InjectKubeClient KubernetesClient kubeClient) throws Exception {
List<Pod> lst = kubeClient.pods().withLabel("app.kubernetes.io/name", APP_NAME).list().getItems();
Expand All @@ -66,11 +66,4 @@ private Endpoint initPort(URL baseUrl) throws Exception {
Endpoint proxy = service.getPort(Endpoint.class);
return proxy;
}
/**
* Get the WFLY container name, this container name will be used to check the WFLY readiness.
* @return the WFLY container name, ${project.artifactId} will be the default one.
*/
public String getContainerName() {
return APP_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,73 @@
*/
package org.jboss.ws.cloud.test;

import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.ServiceSpec;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.LocalPortForward;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeEach;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class JBossWSKubernetesTest implements JBossWSServerContainer {
public class JBossWSKubernetesTest {

@InjectKubeClient
private KubernetesClient jbossWSKubernetesTestKubeClient;

@BeforeEach
public void checkServerReady() {
waitWFLYReady(this.jbossWSKubernetesTestKubeClient, this.getContainerName(), 60000);
waitWFLYReady(this.jbossWSKubernetesTestKubeClient, 30000);
}
public static boolean waitWFLYReady(KubernetesClient k8sClient, String containerName, long timeout) {
LocalPortForward p = k8sClient.services().withName(containerName).portForward(9990);
assertTrue(p.isAlive());
URL url = null;
try {
url = new URL("http://localhost:" + p.getLocalPort() + "/health/ready");
} catch (MalformedURLException e) {
//
}
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < timeout) {
public static boolean waitWFLYReady(KubernetesClient k8sClient, long timeout) {
AtomicBoolean ready = new AtomicBoolean(false);
k8sClient.services().resources().filter(serviceResource ->
serviceResource.get().getSpec().getPorts().stream().anyMatch(
servicePort -> servicePort.getTargetPort().getIntVal() == 9990)
).forEach(serviceResource -> {
ServicePort servicePort = serviceResource.get().getSpec().getPorts().stream().filter(port -> port.getTargetPort().getIntVal() == 9990).findFirst().get();
LocalPortForward p = serviceResource.portForward(servicePort.getPort());
assertTrue(p.isAlive());
URL url = null;
try {
//This is a workaround for restassured print out some warning message, we try to openstream before check response with restassured
//INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:53380:
//The target server failed to respond
url.openStream();
io.restassured.response.Response response = RestAssured.given().get(url);
if (response.getStatusCode() == 200) {
JsonPath jsonPath = response.jsonPath();
String readyStatus = jsonPath.getString("status");
if (readyStatus.equalsIgnoreCase("UP")) {
return true;
url = new URL("http://localhost:" + p.getLocalPort() + "/health/ready");
} catch (MalformedURLException e) {
//
}
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < timeout) {
try {
//This is a workaround for restassured print out some warning message, we try to openstream before check response with restassured
//INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:53380:
//The target server failed to respond
url.openStream();
io.restassured.response.Response response = RestAssured.given().get(url);
if (response.getStatusCode() == 200) {
JsonPath jsonPath = response.jsonPath();
String readyStatus = jsonPath.getString("status");
if (readyStatus.equalsIgnoreCase("UP")) {
ready.set(true);
return;
}
}
} catch (IOException e) {
//the WFLY is not ready.
}
try {
Thread.sleep(timeout / 5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
} catch (IOException e) {
//the WFLY is not ready.
}
try {
Thread.sleep(timeout/5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
return false;
ready.set(false);
});
//There is no WFLY instance running or the WFLY management port isn't exposed in service
return ready.get();
}
}

This file was deleted.

3 changes: 0 additions & 3 deletions modules/testsuite/cloud-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
<systemPropertyVariables>
<project.artifactId>${project.artifactId}</project.artifactId>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
Expand Down

0 comments on commit 9334492

Please sign in to comment.