-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [Test] Improved Job Engine container readiness check
Signed-off-by: Alberto Codutti <[email protected]>
- Loading branch information
Showing
2 changed files
with
138 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...s/src/main/java/org/eclipse/kapua/qa/integration/steps/utils/TestReadinessConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025, 2025 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.qa.integration.steps.utils; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
/** | ||
* Wrapper for {@link HttpURLConnection} that implements {@link AutoCloseable} | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public class TestReadinessConnection implements AutoCloseable { | ||
|
||
private final HttpURLConnection testReadinessConnection; | ||
private final int readyResponseCode; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param testUrl The HTTP URL to check for readiness | ||
* @throws Exception | ||
* @since 2.1.0 | ||
*/ | ||
public TestReadinessConnection(String testUrl) throws Exception { | ||
this(testUrl, 200); | ||
} | ||
|
||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param testUrl The HTTP URL to check for readiness | ||
* @param readyResponseCode Which HTTP response code consider valid for readiness | ||
* @throws Exception | ||
* @since 2.1.0 | ||
*/ | ||
public TestReadinessConnection(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.readyResponseCode = readyResponseCode; | ||
} | ||
|
||
/** | ||
* Checks that the HTTP returns the expected HTTP response code. | ||
* | ||
* @return {@code true} if expected code is returned, {@code false} otherwise | ||
* @throws IOException | ||
* @since 2.1.0 | ||
*/ | ||
public boolean isReady() throws IOException { | ||
return testReadinessConnection.getResponseCode() == readyResponseCode; | ||
} | ||
|
||
/** | ||
* Invokes {@link HttpURLConnection#disconnect()} | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
@Override | ||
public void close() { | ||
if (testReadinessConnection != null) { | ||
testReadinessConnection.disconnect(); | ||
} | ||
} | ||
} |