Skip to content

Commit 038edc4

Browse files
authored
chore(deps): Bump com.marcnuri.helm-java:helm-java from 0.0.15 to 0.0.16 (3749)
chore(deps): Bump com.marcnuri.helm-java:helm-java from 0.0.15 to 0.0.16 --- fix(tests): start remote OCI server in setup and improve readiness check
1 parent 7547464 commit 038edc4

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

jkube-kit/build/service/jib/src/test/java/org/eclipse/jkube/kit/service/jib/JibServiceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class JibServiceTest {
6363
@BeforeEach
6464
void setUp() {
6565
remoteOciServer = new TestOciServer();
66+
remoteOciServer.start();
6667
jibLogger = new JibLogger(new KitLogger.SilentLogger());
6768
testAuthConfigFactory = new TestAuthConfigFactory();
6869
configuration = JKubeConfiguration.builder()

jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/TestOciServer.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
import java.net.URL;
2626
import java.time.Duration;
2727

28-
import static org.eclipse.jkube.kit.common.util.AsyncUtil.await;
29-
import static org.eclipse.jkube.kit.common.util.AsyncUtil.get;
30-
3128
@Getter
3229
public class TestOciServer implements Closeable {
3330

34-
private static final Duration TIMEOUT = Duration.ofSeconds(5);
31+
private static final Duration TIMEOUT = Duration.ofSeconds(10);
32+
private static final Duration RETRY_INTERVAL = Duration.ofMillis(100);
3533
private static final String DEFAULT_USER = "oci-user";
3634
private static final String DEFAULT_PASSWORD = "oci-password";
3735

@@ -46,7 +44,7 @@ private static HelmLib getHelmLib() {
4644

4745
private final String user;
4846
private final String password;
49-
private final String url;
47+
private String url;
5048

5149
public TestOciServer() {
5250
this(DEFAULT_USER, DEFAULT_PASSWORD);
@@ -55,28 +53,69 @@ public TestOciServer() {
5553
public TestOciServer(String user, String password) {
5654
this.user = user;
5755
this.password = password;
58-
url = get(await(this::startServer).apply(this::waitForServer), TIMEOUT);
56+
}
57+
58+
/**
59+
* Starts the OCI server and waits until it is ready to accept connections.
60+
* This method blocks until the server is ready or the timeout is reached.
61+
*
62+
* @throws IllegalStateException if the server fails to start within the timeout period
63+
*/
64+
public void start() {
65+
if (url != null) {
66+
throw new IllegalStateException("Server is already started");
67+
}
68+
69+
url = getHelmLib().RepoOciServerStart(
70+
new RepoServerOptions(null, user, password)
71+
).out;
72+
73+
waitForServerReady();
5974
}
6075

6176
@Override
6277
public void close() throws IOException {
63-
// No effect yet https://github.com/manusa/helm-java/blob/f44a88ed1ad351b2b5a00b5e735deb5cb35b32f7/native/internal/helm/repotest.go#L138
64-
getHelmLib().RepoServerStop(url);
78+
if (url != null) {
79+
// No effect yet https://github.com/manusa/helm-java/blob/f44a88ed1ad351b2b5a00b5e735deb5cb35b32f7/native/internal/helm/repotest.go#L138
80+
getHelmLib().RepoServerStop(url);
81+
url = null;
82+
}
6583
}
6684

67-
private String startServer() {
68-
return getHelmLib().RepoOciServerStart(
69-
new RepoServerOptions(null, user, password)
70-
).out;
85+
private void waitForServerReady() {
86+
final long startTime = System.currentTimeMillis();
87+
final long timeoutMillis = TIMEOUT.toMillis();
88+
final long retryIntervalMillis = RETRY_INTERVAL.toMillis();
89+
90+
while (System.currentTimeMillis() - startTime < timeoutMillis) {
91+
if (isServerReady()) {
92+
return;
93+
}
94+
95+
try {
96+
Thread.sleep(retryIntervalMillis);
97+
} catch (InterruptedException e) {
98+
Thread.currentThread().interrupt();
99+
throw new IllegalStateException("Interrupted while waiting for OCI server to start", e);
100+
}
101+
}
102+
103+
throw new IllegalStateException(
104+
String.format("OCI server at %s failed to become ready within %d milliseconds", url, timeoutMillis)
105+
);
71106
}
72107

73-
private boolean waitForServer(String serverUrl) {
108+
private boolean isServerReady() {
74109
try {
75-
final HttpURLConnection connection = (HttpURLConnection) new URL("http://" + serverUrl + "/v2/")
110+
final HttpURLConnection connection = (HttpURLConnection) new URL("http://" + url + "/v2/")
76111
.openConnection();
77112
connection.setRequestProperty("Authorization", "Basic " + Base64Util.encodeToString(String.join(":", user, password)));
113+
connection.setConnectTimeout((int) RETRY_INTERVAL.toMillis());
114+
connection.setReadTimeout((int) RETRY_INTERVAL.toMillis());
78115
connection.connect();
79-
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
116+
final int responseCode = connection.getResponseCode();
117+
connection.disconnect();
118+
return responseCode == HttpURLConnection.HTTP_OK;
80119
} catch (IOException e) {
81120
return false;
82121
}

jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServicePushTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void setUp() throws Exception {
7575

7676
// Setup OCI server
7777
remoteOciServer = new TestOciServer();
78+
remoteOciServer.start();
7879

7980
// Configure OCI server in image and JKube
8081
imageConfiguration = ImageConfiguration.builder()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<version.gradle-api-maven-plugin>0.0.7</version.gradle-api-maven-plugin>
9797
<version.groovy>3.0.23</version.groovy>
9898
<version.guava>33.4.0-jre</version.guava>
99-
<version.helm-java>0.0.15</version.helm-java>
99+
<version.helm-java>0.0.16</version.helm-java>
100100
<version.jackson>2.18.3</version.jackson>
101101
<version.jacoco>0.8.12</version.jacoco>
102102
<version.json-smart>2.5.2</version.json-smart> <!-- Transitive dependency required by citrus -->

0 commit comments

Comments
 (0)