From 96fae35a6bb278482257e302105f200fa12ba291 Mon Sep 17 00:00:00 2001 From: Alberto Codutti Date: Tue, 21 Jan 2025 09:51:51 +0100 Subject: [PATCH] :recycle: [Test] Improvements on readyness checks of resources Signed-off-by: Alberto Codutti --- .../utils/TestReadinessHttpConnection.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qa/integration-steps/src/main/java/org/eclipse/kapua/qa/integration/steps/utils/TestReadinessHttpConnection.java b/qa/integration-steps/src/main/java/org/eclipse/kapua/qa/integration/steps/utils/TestReadinessHttpConnection.java index 722b6f1cb6f..9cf05473db8 100644 --- a/qa/integration-steps/src/main/java/org/eclipse/kapua/qa/integration/steps/utils/TestReadinessHttpConnection.java +++ b/qa/integration-steps/src/main/java/org/eclipse/kapua/qa/integration/steps/utils/TestReadinessHttpConnection.java @@ -23,7 +23,8 @@ */ public class TestReadinessHttpConnection implements AutoCloseable { - private final HttpURLConnection testReadinessConnection; + private final URL testReadinessURL; + private HttpURLConnection testReadinessConnection; private final int readyResponseCode; /** @@ -47,13 +48,7 @@ public TestReadinessHttpConnection(String testUrl) throws Exception { * @since 2.1.0 */ public TestReadinessHttpConnection(String testUrl, int readyResponseCode) throws IOException { - URL testReadinessURL = new URL(testUrl); - - testReadinessConnection = (HttpURLConnection) testReadinessURL.openConnection(); - testReadinessConnection.setConnectTimeout(5000); - testReadinessConnection.setReadTimeout(5000); - testReadinessConnection.setRequestMethod("GET"); - + this.testReadinessURL = new URL(testUrl); this.readyResponseCode = readyResponseCode; } @@ -65,11 +60,16 @@ public TestReadinessHttpConnection(String testUrl, int readyResponseCode) throws * @since 2.1.0 */ public boolean isReady() throws IOException { + testReadinessConnection = (HttpURLConnection) testReadinessURL.openConnection(); + testReadinessConnection.setConnectTimeout(5000); + testReadinessConnection.setReadTimeout(5000); + testReadinessConnection.setRequestMethod("GET"); + return testReadinessConnection.getResponseCode() == readyResponseCode; } /** - * Invokes {@link HttpURLConnection#disconnect()} + * Invokes {@link HttpURLConnection#disconnect()} to clean up resources. * * @since 2.1.0 */