Skip to content

Commit

Permalink
Make Testcontainers parent first again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gsmet committed Aug 14, 2024
1 parent be411d9 commit ae4a8de
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-classloader-commons</artifactId>
</dependency>
<!-- Uncomment this dependency to have Testcontainers loaded parent first -->
<!-- Make sure you build with -Denforcer.skip after that -->
<!--
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
-->
<dependency>
<groupId>org.aesh</groupId>
<artifactId>readline</artifactId>
Expand Down
18 changes: 18 additions & 0 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@

<!-- Make use of byteman frictionless -->
<parentFirstArtifact>org.jboss.byteman:byteman</parentFirstArtifact>

<!--
Testcontainers support: Testcontainers start a lot of threads that are long lived,
leaking class loaders like crazy.
-->
<parentFirstArtifact>org.testcontainers:testcontainers</parentFirstArtifact>
<parentFirstArtifact>com.github.docker-java:docker-java-api</parentFirstArtifact>
<parentFirstArtifact>com.github.docker-java:docker-java-transport-zerodep</parentFirstArtifact>
<parentFirstArtifact>org.rnorth.duct-tape:duct-tape</parentFirstArtifact>
</parentFirstArtifacts>
<runnerParentFirstArtifacts>
<runnerParentFirstArtifact>org.graalvm.sdk:nativeimage</runnerParentFirstArtifact>
Expand Down Expand Up @@ -257,6 +266,15 @@
<runnerParentFirstArtifact>io.github.crac:org-crac</runnerParentFirstArtifact>
<!-- Make use of byteman frictionless -->
<runnerParentFirstArtifact>org.jboss.byteman:byteman</runnerParentFirstArtifact>

<!--
Testcontainers support: Testcontainers start a lot of threads that are long lived,
leaking class loaders like crazy.
-->
<runnerParentFirstArtifact>org.testcontainers:testcontainers</runnerParentFirstArtifact>
<runnerParentFirstArtifact>com.github.docker-java:docker-java-api</runnerParentFirstArtifact>
<runnerParentFirstArtifact>com.github.docker-java:docker-java-transport-zerodep</runnerParentFirstArtifact>
<runnerParentFirstArtifact>org.rnorth.duct-tape:duct-tape</runnerParentFirstArtifact>
</runnerParentFirstArtifacts>
<excludedArtifacts>
<excludedArtifact>io.smallrye:smallrye-config</excludedArtifact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.utility.DockerImageName;

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

container.start();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread()
.setContextClassLoader(((QuarkusClassLoader) originalClassLoader).getPlatformClassLoader());
container.start();
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
try {
return parent.loadClass(name);
} catch (ClassNotFoundException ignore) {
log.tracef("Class %s not found in parent first load from %s", name, parent);
log.warnf("Class %s not found in parent first load from %s", name, parent);
}
}
ClassPathElement classPathElement = classPathResourceIndex.getFirstClassPathElement(resourceName);
Expand Down

0 comments on commit ae4a8de

Please sign in to comment.