Skip to content

Commit 29e5a81

Browse files
committed
Make Testcontainers parent first again
To avoid long lived threads being attached to child class loaders. It was done at some point but was reverted because of the ducttape dependency not being parent first. I think it's worth another try by including this dependency.
1 parent a9697f8 commit 29e5a81

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

core/deployment/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
<groupId>io.quarkus</groupId>
1919
<artifactId>quarkus-classloader-commons</artifactId>
2020
</dependency>
21+
<!-- Uncomment this dependency to have Testcontainers loaded parent first -->
22+
<!-- Make sure you build with -Denforcer.skip after that -->
23+
<!--
24+
<dependency>
25+
<groupId>org.testcontainers</groupId>
26+
<artifactId>testcontainers</artifactId>
27+
</dependency>
28+
-->
2129
<dependency>
2230
<groupId>org.aesh</groupId>
2331
<artifactId>readline</artifactId>

core/runtime/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@
217217

218218
<!-- Make use of byteman frictionless -->
219219
<parentFirstArtifact>org.jboss.byteman:byteman</parentFirstArtifact>
220+
221+
<!--
222+
Testcontainers support: Testcontainers start a lot of threads that are long lived,
223+
leaking class loaders like crazy.
224+
-->
225+
<parentFirstArtifact>org.testcontainers:testcontainers</parentFirstArtifact>
226+
<parentFirstArtifact>com.github.docker-java:docker-java-api</parentFirstArtifact>
227+
<parentFirstArtifact>com.github.docker-java:docker-java-transport-zerodep</parentFirstArtifact>
228+
<parentFirstArtifact>org.rnorth.duct-tape:duct-tape</parentFirstArtifact>
220229
</parentFirstArtifacts>
221230
<runnerParentFirstArtifacts>
222231
<runnerParentFirstArtifact>org.graalvm.sdk:nativeimage</runnerParentFirstArtifact>
@@ -257,6 +266,15 @@
257266
<runnerParentFirstArtifact>io.github.crac:org-crac</runnerParentFirstArtifact>
258267
<!-- Make use of byteman frictionless -->
259268
<runnerParentFirstArtifact>org.jboss.byteman:byteman</runnerParentFirstArtifact>
269+
270+
<!--
271+
Testcontainers support: Testcontainers start a lot of threads that are long lived,
272+
leaking class loaders like crazy.
273+
-->
274+
<runnerParentFirstArtifact>org.testcontainers:testcontainers</runnerParentFirstArtifact>
275+
<runnerParentFirstArtifact>com.github.docker-java:docker-java-api</runnerParentFirstArtifact>
276+
<runnerParentFirstArtifact>com.github.docker-java:docker-java-transport-zerodep</runnerParentFirstArtifact>
277+
<runnerParentFirstArtifact>org.rnorth.duct-tape:duct-tape</runnerParentFirstArtifact>
260278
</runnerParentFirstArtifacts>
261279
<excludedArtifacts>
262280
<excludedArtifact>io.smallrye:smallrye-config</excludedArtifact>

extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
1717
import org.testcontainers.utility.DockerImageName;
1818

19+
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
1920
import io.quarkus.datasource.common.runtime.DataSourceUtil;
2021
import io.quarkus.datasource.common.runtime.DatabaseKind;
2122
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceContainerConfig;
@@ -77,7 +78,14 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
7778
containerConfig.getCommand().ifPresent(container::setCommand);
7879
containerConfig.getInitScriptPath().ifPresent(container::withInitScript);
7980

80-
container.start();
81+
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
82+
try {
83+
Thread.currentThread()
84+
.setContextClassLoader(((QuarkusClassLoader) originalClassLoader).getPlatformClassLoader());
85+
container.start();
86+
} finally {
87+
Thread.currentThread().setContextClassLoader(originalClassLoader);
88+
}
8189

8290
LOG.info("Dev Services for PostgreSQL started.");
8391

independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
517517
try {
518518
return parent.loadClass(name);
519519
} catch (ClassNotFoundException ignore) {
520-
log.tracef("Class %s not found in parent first load from %s", name, parent);
520+
log.warnf("Class %s not found in parent first load from %s", name, parent);
521521
}
522522
}
523523
ClassPathElement classPathElement = classPathResourceIndex.getFirstClassPathElement(resourceName);

0 commit comments

Comments
 (0)