From 4af414e3c98ca36d63e512caa7abbf3f1c36ed21 Mon Sep 17 00:00:00 2001 From: Michal T Date: Thu, 17 Oct 2024 12:08:07 +0200 Subject: [PATCH] Fix testPersistAddressAfterCOBrokerRestart --- .../src/main/java/io/brokerqe/claire/KubeClient.java | 11 ++++++----- .../java/io/brokerqe/claire/helpers/JMXHelper.java | 11 +++++------ .../java/io/brokerqe/claire/address/AddressTests.java | 6 ++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java b/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java index f5e42158..57142a25 100644 --- a/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java +++ b/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java @@ -333,14 +333,15 @@ public Pod waitForPodReload(String namespace, Pod pod, String podName, long maxT }); for (Pod podTmp : listPodsByPrefixName(namespace, podName)) { + if (podTmp.getMetadata().getUid().equals(originalUid)) { + waitUntilPodIsDeleted(namespace, podTmp); + } if (!podTmp.getMetadata().getUid().equals(originalUid)) { - this.waitUntilPodIsReady(namespace, podTmp); - LOGGER.trace("[{}] Returning reloaded pod {}", namespace, podName); - return getPod(namespace, podTmp.getMetadata().getName()); + waitUntilPodIsReady(namespace, podTmp); } } - LOGGER.error("[{}] Reloaded pod {} has not been found!", namespace, podName); - return null; + LOGGER.debug("[{}] Returning reloaded pod {}", namespace, podName); + return getFirstPodByPrefixName(namespace, podName); } public String executeCommandInPod(Pod pod, String cmd, long timeout) { diff --git a/operator-suite/src/main/java/io/brokerqe/claire/helpers/JMXHelper.java b/operator-suite/src/main/java/io/brokerqe/claire/helpers/JMXHelper.java index 68535060..3ee0bb37 100644 --- a/operator-suite/src/main/java/io/brokerqe/claire/helpers/JMXHelper.java +++ b/operator-suite/src/main/java/io/brokerqe/claire/helpers/JMXHelper.java @@ -8,7 +8,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.brokerqe.claire.ArtemisConstants; +import io.brokerqe.claire.Constants; import io.brokerqe.claire.KubeClient; +import io.brokerqe.claire.TestUtils; import io.fabric8.openshift.api.model.Route; import org.json.JSONArray; import org.json.JSONObject; @@ -19,7 +21,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.net.URL; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -59,9 +60,7 @@ private String getBasicAuth() { } private String performJmxCall(String host, String jmxPath) throws IOException { - URL url = new URL("http://" + host + jmxPath); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("GET"); + HttpURLConnection con = (HttpURLConnection) TestUtils.makeHttpRequest("http://" + host + jmxPath, Constants.GET); con.setRequestProperty("Authorization", getBasicAuth()); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -75,7 +74,7 @@ private String performJmxCall(String host, String jmxPath) throws IOException { return content.toString(); } - private List getAllAdresses(String host) throws IOException { + private List getAllAddresses(String host) throws IOException { String jmxPath = JMX_CALL_BASE + "/AddressNames"; String content = performJmxCall(host, jmxPath); JSONObject json = new JSONObject(content); @@ -125,7 +124,7 @@ public List getAllAddressesQueues(String deployName, String routing try { Route route = getRoute(deployName, pod); String host = route.getSpec().getHost(); - List addresses = getAllAdresses(host); + List addresses = getAllAddresses(host); for (String address: addresses) { for (String queue: getQueueNames(host, address)) { AddressData addressData = new AddressData(); diff --git a/operator-suite/src/test/java/io/brokerqe/claire/address/AddressTests.java b/operator-suite/src/test/java/io/brokerqe/claire/address/AddressTests.java index 36161916..64ff889b 100644 --- a/operator-suite/src/test/java/io/brokerqe/claire/address/AddressTests.java +++ b/operator-suite/src/test/java/io/brokerqe/claire/address/AddressTests.java @@ -67,8 +67,10 @@ void persistAddressAfterCOBrokerRestart() { LOGGER.info("[{}] Getting info from {} with uid {}", testNamespace, brokerPod.getMetadata().getName(), brokerPod.getMetadata().getUid()); List allAddresses = jmx.getAllAddressesQueues(brokerName, ArtemisConstants.ROUTING_TYPE_ANYCAST, 0); verifyAddresses(allAddresses, myAddress); + getClient().reloadPodWithWait(testNamespace, operatorPod, operatorName); - getClient().reloadPodWithWait(testNamespace, brokerPod, brokerName); + getClient().deletePod(testNamespace, brokerPod, false); + ResourceManager.waitForBrokerDeployment(testNamespace, broker, true, brokerPod); brokerPod = getClient().getFirstPodByPrefixName(testNamespace, brokerName); LOGGER.info("[{}] Getting info from {} with uid {}", testNamespace, brokerPod.getMetadata().getName(), brokerPod.getMetadata().getUid()); @@ -83,7 +85,7 @@ void persistAddressAfterCOBrokerRestart() { return commandOutput.contains(myAddress.getSpec().getAddressName()); }); - TestUtils.waitFor("[JMX] Addresses to show up in artemis address call", Constants.DURATION_5_SECONDS, Constants.DURATION_30_SECONDS, () -> { + TestUtils.waitFor("[JMX] Updated addresses to show up in artemis address call", Constants.DURATION_5_SECONDS, Constants.DURATION_30_SECONDS, () -> { List updatedAddressesTmp = new ArrayList<>(); try { updatedAddressesTmp = jmx.getAllAddressesQueues(brokerName, ArtemisConstants.ROUTING_TYPE_ANYCAST, 0);