Skip to content

Commit

Permalink
♻️ [Test] Improvements on readyness checks of resources
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jan 21, 2025
1 parent bb131df commit 96fae35
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
public class TestReadinessHttpConnection implements AutoCloseable {

private final HttpURLConnection testReadinessConnection;
private final URL testReadinessURL;
private HttpURLConnection testReadinessConnection;
private final int readyResponseCode;

/**
Expand All @@ -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;
}

Expand All @@ -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
*/
Expand Down

0 comments on commit 96fae35

Please sign in to comment.