This is an automated email from the ASF dual-hosted git repository.
rishabhdaim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new a71cfa3f47 OAK-12296 : bump testcontainers version to 2.0.3 (#3002)
a71cfa3f47 is described below
commit a71cfa3f479a9d9e62ab71b307c912dd4376b625
Author: Rishabh Kumar <[email protected]>
AuthorDate: Mon Jul 6 23:45:17 2026 +0530
OAK-12296 : bump testcontainers version to 2.0.3 (#3002)
* OAK-12296 : bump testcontainers version to 2.0.3
* OAK-12296 : fixed the junit 4 compatibility issues
* OAK-12296 : fixed compatibulity issues with Junit 4
* OAK-12296 : fixed compatibulity issues with ES tests
* OAK-12296 : incorporated review comments to use withEnv override for
ElasticTestServer
---
oak-it-osgi/pom.xml | 2 +-
oak-parent/pom.xml | 2 +-
oak-run-commons/pom.xml | 4 +-
.../PipelinedMongoConnectionFailureIT.java | 38 +++++++++++-----
oak-run-elastic/pom.xml | 2 +-
.../jackrabbit/oak/index/IncrementalStoreTest.java | 2 +-
oak-search-elastic/pom.xml | 4 +-
.../plugins/index/elastic/ElasticTestServer.java | 51 +++++++++++++++++-----
.../src/test/resources/elasticsearch.yml | 24 ----------
oak-store-document/pom.xml | 4 +-
.../document/mongo/LeaseUpdateSocketTimeoutIT.java | 38 ++++++++++------
11 files changed, 102 insertions(+), 69 deletions(-)
diff --git a/oak-it-osgi/pom.xml b/oak-it-osgi/pom.xml
index 11a7092aeb..26a4020ae4 100644
--- a/oak-it-osgi/pom.xml
+++ b/oak-it-osgi/pom.xml
@@ -198,7 +198,7 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>elasticsearch</artifactId>
+ <artifactId>testcontainers-elasticsearch</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
diff --git a/oak-parent/pom.xml b/oak-parent/pom.xml
index bebef8dbcc..c68462c649 100644
--- a/oak-parent/pom.xml
+++ b/oak-parent/pom.xml
@@ -65,7 +65,7 @@
<tika.version>1.28.5</tika.version>
<derby.version>10.16.1.1</derby.version>
<jackson.version>2.19.4</jackson.version>
- <testcontainers.version>1.21.4</testcontainers.version>
+ <testcontainers.version>2.0.3</testcontainers.version>
<pax-exam.version>4.14.0</pax-exam.version>
<pax-url.version>2.6.17</pax-url.version>
<groovy.version>3.0.25</groovy.version>
diff --git a/oak-run-commons/pom.xml b/oak-run-commons/pom.xml
index 6b1fabfa51..812bb46395 100644
--- a/oak-run-commons/pom.xml
+++ b/oak-run-commons/pom.xml
@@ -212,13 +212,13 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>toxiproxy</artifactId>
+ <artifactId>testcontainers-toxiproxy</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>mongodb</artifactId>
+ <artifactId>testcontainers-mongodb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
diff --git
a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoConnectionFailureIT.java
b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoConnectionFailureIT.java
index 8abd3a1014..0c7b1a8fa6 100644
---
a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoConnectionFailureIT.java
+++
b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedMongoConnectionFailureIT.java
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.Clock;
import org.jetbrains.annotations.NotNull;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
@@ -90,17 +91,9 @@ public class PipelinedMongoConnectionFailureIT {
final boolean parallelDump;
final boolean testUpdateContent;
- @Rule
- public final Network network = Network.newNetwork();
- @Rule
- public final MongoDBContainer mongoDBContainer = new
MongoDBContainer(MongoDockerRule.getDockerImageName())
- .withNetwork(network)
- .withNetworkAliases("mongo")
- .withExposedPorts(MONGODB_DEFAULT_PORT);
- @Rule
- public final ToxiproxyContainer toxiproxy = new
ToxiproxyContainer(TOXIPROXY_IMAGE)
- .withStartupAttempts(3)
- .withNetwork(network);
+ private Network network;
+ private MongoDBContainer mongoDBContainer;
+ private ToxiproxyContainer toxiproxy;
@Rule
public final DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
@Rule
@@ -125,6 +118,16 @@ public class PipelinedMongoConnectionFailureIT {
@Before
public void before() throws Exception {
+ network = Network.newNetwork();
+ mongoDBContainer = new
MongoDBContainer(MongoDockerRule.getDockerImageName())
+ .withNetwork(network)
+ .withNetworkAliases("mongo")
+ .withExposedPorts(MONGODB_DEFAULT_PORT);
+ mongoDBContainer.start();
+ toxiproxy = new ToxiproxyContainer(TOXIPROXY_IMAGE)
+ .withStartupAttempts(3)
+ .withNetwork(network);
+ toxiproxy.start();
ToxiproxyClient toxiproxyClient = new
ToxiproxyClient(toxiproxy.getHost(), toxiproxy.getControlPort());
// For the logic under test
this.proxy = toxiproxyClient.createProxy("mongo", "0.0.0.0:8666",
"mongo:" + MONGODB_DEFAULT_PORT);
@@ -142,6 +145,19 @@ public class PipelinedMongoConnectionFailureIT {
}
}
+ @After
+ public void after() {
+ if (toxiproxy != null) {
+ toxiproxy.stop();
+ }
+ if (mongoDBContainer != null) {
+ mongoDBContainer.stop();
+ }
+ if (network != null) {
+ network.close();
+ }
+ }
+
@Test
public void mongoDisconnectTest() throws Exception {
// Testcontainers' MongoDBContainer starts a Mongo replica set of one
node. In this configuration we cannot
diff --git a/oak-run-elastic/pom.xml b/oak-run-elastic/pom.xml
index f5db86d1df..c874828178 100644
--- a/oak-run-elastic/pom.xml
+++ b/oak-run-elastic/pom.xml
@@ -256,7 +256,7 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>elasticsearch</artifactId>
+ <artifactId>testcontainers-elasticsearch</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
diff --git
a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java
b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java
index fce8528906..0048281d02 100644
---
a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java
+++
b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IncrementalStoreTest.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoDatabase;
import org.apache.commons.collections4.set.ListOrderedSet;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.Compression;
@@ -71,7 +72,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TemporaryFolder;
-import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import java.io.BufferedReader;
import java.io.File;
diff --git a/oak-search-elastic/pom.xml b/oak-search-elastic/pom.xml
index 9aa1ac1018..2bb76d77be 100644
--- a/oak-search-elastic/pom.xml
+++ b/oak-search-elastic/pom.xml
@@ -278,13 +278,13 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>elasticsearch</artifactId>
+ <artifactId>testcontainers-elasticsearch</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>toxiproxy</artifactId>
+ <artifactId>testcontainers-toxiproxy</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestServer.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestServer.java
index cf694cb673..81812e3933 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestServer.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestServer.java
@@ -25,13 +25,14 @@ import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
-import org.testcontainers.utility.MountableFile;
import co.elastic.clients.transport.Version;
import java.io.IOException;
import java.time.Duration;
+import java.util.concurrent.TimeUnit;
public class ElasticTestServer implements AutoCloseable {
private static final Logger LOG =
LoggerFactory.getLogger(ElasticTestServer.class);
@@ -39,6 +40,7 @@ public class ElasticTestServer implements AutoCloseable {
private static final ElasticTestServer SERVER = new ElasticTestServer();
private static volatile ElasticsearchContainer CONTAINER;
+ private static volatile Network network;
private ElasticTestServer() {
}
@@ -62,23 +64,26 @@ public class ElasticTestServer implements AutoCloseable {
return CONTAINER;
}
- @SuppressWarnings("resource")
private synchronized void setup() {
String esDockerImageVersion = ELASTIC_DOCKER_IMAGE_VERSION != null ?
ELASTIC_DOCKER_IMAGE_VERSION : Version.VERSION.toString();
LOG.info("Elasticsearch test Docker image version: {}.",
esDockerImageVersion);
checkIfDockerClientAvailable();
- Network network = Network.newNetwork();
+ network = Network.newNetwork();
CONTAINER = new
ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:" +
esDockerImageVersion)
.withEnv("ES_JAVA_OPTS", "-Xms1g -Xmx1g")
- .withCopyFileToContainer(
-
MountableFile.forClasspathResource("elasticsearch.yml"),
- "/usr/share/elasticsearch/config/elasticsearch.yml")
+ .withEnv("network.host", "0.0.0.0")
+ .withEnv("ingest.geoip.downloader.enabled", "false")
+ .withEnv("xpack.security.enabled", "false")
+ .withEnv("xpack.security.http.ssl.enabled", "false")
+ .withEnv("action.destructive_requires_name", "false")
.withNetwork(network)
.withNetworkAliases("elasticsearch")
+ .waitingFor(Wait.forHttp("/").forPort(9200).forStatusCode(200))
// Default is 30 seconds, which might not be enough on
environments with limited resources or network latency
.withStartupTimeout(Duration.ofMinutes(3))
.withStartupAttempts(3);
CONTAINER.start();
+ verifyConnectivity();
Slf4jLogConsumer logConsumer = new
Slf4jLogConsumer(LOG).withSeparateOutputStreams();
CONTAINER.followOutput(logConsumer);
@@ -86,15 +91,14 @@ public class ElasticTestServer implements AutoCloseable {
@Override
public void close() {
- if (this == SERVER) {
- // Closed with a shutdown hook
- return;
- }
-
if (CONTAINER != null) {
CONTAINER.stop();
}
CONTAINER = null;
+ if (network != null) {
+ network.close();
+ }
+ network = null;
}
private void checkIfDockerClientAvailable() {
@@ -108,6 +112,31 @@ public class ElasticTestServer implements AutoCloseable {
assumeNotNull(client);
}
+ private void verifyConnectivity() {
+ // Ensure the container is actually reachable before tests proceed.
+ try (ElasticConnection connection = ElasticConnection.newBuilder()
+ .withIndexPrefix("elastic_test_bootstrap")
+ .withConnectionParameters(ElasticConnection.DEFAULT_SCHEME,
CONTAINER.getHost(),
+
CONTAINER.getMappedPort(ElasticConnection.DEFAULT_PORT))
+ .build()) {
+ long deadline = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
+ while (System.nanoTime() < deadline) {
+ if (connection.isAvailable()) {
+ return;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalStateException("Interrupted while waiting
for Elasticsearch readiness", e);
+ }
+ }
+ throw new IllegalStateException("Elasticsearch test container
started but did not become reachable via HTTP");
+ } catch (IOException e) {
+ LOG.debug("Error closing bootstrap Elastic connection", e);
+ }
+ }
+
/**
* Launches an Elasticsearch Test Server to re-use among several test
executions.
*/
diff --git a/oak-search-elastic/src/test/resources/elasticsearch.yml
b/oak-search-elastic/src/test/resources/elasticsearch.yml
deleted file mode 100644
index c5b2dc7588..0000000000
--- a/oak-search-elastic/src/test/resources/elasticsearch.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-network.host: 0.0.0.0
-ingest.geoip.downloader.enabled: false
-xpack.security.enabled: false
-
-# In ES 8.0, by default it is no longer possible to use wildcards to delete
several indexes in a single operation.
-# This is used by the tests for cleanup, so we must set this to true
explicitly.
-#
https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html
-action.destructive_requires_name: false
\ No newline at end of file
diff --git a/oak-store-document/pom.xml b/oak-store-document/pom.xml
index 951ed303be..ba35496626 100644
--- a/oak-store-document/pom.xml
+++ b/oak-store-document/pom.xml
@@ -348,13 +348,13 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>toxiproxy</artifactId>
+ <artifactId>testcontainers-toxiproxy</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
- <artifactId>mongodb</artifactId>
+ <artifactId>testcontainers-mongodb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
diff --git
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/LeaseUpdateSocketTimeoutIT.java
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/LeaseUpdateSocketTimeoutIT.java
index 078a4afacc..8619f3daff 100644
---
a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/LeaseUpdateSocketTimeoutIT.java
+++
b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/LeaseUpdateSocketTimeoutIT.java
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.oak.stats.Clock;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.containers.Network;
@@ -59,19 +58,11 @@ public class LeaseUpdateSocketTimeoutIT {
private static final int LEASE_SO_TIMEOUT = 50;
- @Rule
- public Network network = Network.newNetwork();
+ private Network network;
- @Rule
- public MongoDBContainer mongoDBContainer = new
MongoDBContainer(MongoDockerRule.getDockerImageName())
- .withNetwork(network)
- .withNetworkAliases("mongo")
- .withExposedPorts(MONGODB_DEFAULT_PORT);
+ private MongoDBContainer mongoDBContainer;
- @Rule
- public ToxiproxyContainer tp = new ToxiproxyContainer(TOXIPROXY_IMAGE)
- .withStartupAttempts(3)
- .withNetwork(network);
+ private ToxiproxyContainer tp;
private Proxy proxy;
@@ -89,6 +80,16 @@ public class LeaseUpdateSocketTimeoutIT {
@Before
public void before() throws Exception {
+ network = Network.newNetwork();
+ mongoDBContainer = new
MongoDBContainer(MongoDockerRule.getDockerImageName())
+ .withNetwork(network)
+ .withNetworkAliases("mongo")
+ .withExposedPorts(MONGODB_DEFAULT_PORT);
+ mongoDBContainer.start();
+ tp = new ToxiproxyContainer(TOXIPROXY_IMAGE)
+ .withStartupAttempts(3)
+ .withNetwork(network);
+ tp.start();
clock = new Clock.Virtual();
clock.waitUntil(System.currentTimeMillis());
setClusterNodeInfoClock(clock);
@@ -103,7 +104,18 @@ public class LeaseUpdateSocketTimeoutIT {
@After
public void after() {
- store.dispose();
+ if (store != null) {
+ store.dispose();
+ }
+ if (tp != null) {
+ tp.stop();
+ }
+ if (mongoDBContainer != null) {
+ mongoDBContainer.stop();
+ }
+ if (network != null) {
+ network.close();
+ }
TestUtils.resetClusterNodeInfoClockToDefault();
}