Skip to content

Commit

Permalink
Merge pull request quarkusio#16791 from stuartwdouglas/16762
Browse files Browse the repository at this point in the history
Continuous testing ClassLoading fixes
  • Loading branch information
geoand authored Apr 27, 2021
2 parents 1bd986e + 89a570e commit d1071b8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,23 @@ public void quarkusStarting() {
});

Map<String, Map<UniqueId, TestResult>> resultsByClass = new HashMap<>();

launcher.execute(testPlan, new TestExecutionListener() {

@Override
public void executionStarted(TestIdentifier testIdentifier) {
String className = "";
Class<?> clazz = null;
if (testIdentifier.getSource().isPresent()) {
if (testIdentifier.getSource().get() instanceof MethodSource) {
className = ((MethodSource) testIdentifier.getSource().get()).getClassName();
clazz = ((MethodSource) testIdentifier.getSource().get()).getJavaClass();
} else if (testIdentifier.getSource().get() instanceof ClassSource) {
className = ((ClassSource) testIdentifier.getSource().get()).getClassName();
clazz = ((ClassSource) testIdentifier.getSource().get()).getJavaClass();
}
}
if (clazz != null) {
className = clazz.getName();
Thread.currentThread().setContextClassLoader(clazz.getClassLoader());
}
for (TestRunListener listener : listeners) {
listener.testStarted(testIdentifier, className);
}
Expand Down Expand Up @@ -513,7 +517,8 @@ public String apply(Class<?> aClass) {
}

}
cl = testApplication.createRuntimeClassLoader(Collections.emptyMap(), transformedClasses);
cl = testApplication.createRuntimeClassLoader(testApplication.getAugmentClassLoader(), Collections.emptyMap(),
transformedClasses);
for (String i : unitTestClasses) {
try {
qtClasses.add(cl.loadClass(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void runTests(ClassScanResult classScanResult, boolean reRunFailures) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Thread.currentThread().setContextClassLoader(testApplication.getAugmentClassLoader());
try {
try {
runInternal(classScanResult, reRunFailures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public void init() {
try {
testCuratedApplication = curatedApplication.getQuarkusBootstrap().clonedBuilder()
.setMode(QuarkusBootstrap.Mode.TEST)
.setDisableClasspathCache(true)
.setDisableClasspathCache(false)
.setIsolateDeployment(true)
.setBaseClassLoader(getClass().getClassLoader())
.setTest(true)
.setAuxiliaryApplication(true)
.addAdditionalApplicationArchive(new AdditionalDependency(
Expand Down
17 changes: 14 additions & 3 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@
<parentFirstArtifact>io.quarkus:quarkus-class-change-agent</parentFirstArtifact>
<parentFirstArtifact>org.jacoco:org.jacoco.agent:runtime</parentFirstArtifact>
<parentFirstArtifact>io.quarkus:quarkus-bootstrap-gradle-resolver</parentFirstArtifact>

<!-- RestAssured uses groovy, which seems to do some things with soft references that
prevent the ClassLoader from being GC'ed, see https://github.com/quarkusio/quarkus/issues/12498 -->
<parentFirstArtifact>org.codehaus.groovy:groovy</parentFirstArtifact>

<!-- Load the junit engine parent first, so it is shared between the outer dev mode
process and the test application-->
<parentFirstArtifact>org.junit.platform:junit-platform-launcher</parentFirstArtifact>
<parentFirstArtifact>org.apiguardian:apiguardian-api</parentFirstArtifact>
<parentFirstArtifact>org.junit.platform:junit-platform-engine</parentFirstArtifact>
<parentFirstArtifact>org.opentest4j:opentest4j</parentFirstArtifact>
<parentFirstArtifact>org.junit.platform:junit-platform-commons</parentFirstArtifact>

</parentFirstArtifacts>
<runnerParentFirstArtifacts>
<runnerParentFirstArtifact>org.graalvm.sdk:graal-sdk</runnerParentFirstArtifact>
Expand All @@ -163,9 +176,7 @@
<runnerParentFirstArtifact>org.wildfly.common:wildfly-common</runnerParentFirstArtifact>
<!-- This is needed because it contains some jar handling classes -->
<runnerParentFirstArtifact>io.smallrye.common:smallrye-common-io</runnerParentFirstArtifact>
<!-- RestAssured uses groovy, which seems to do some things with soft references that
prevent the ClassLoader from being GC'ed, see https://github.com/quarkusio/quarkus/issues/12498 -->
<runnerParentFirstArtifact>org.codehaus.groovy:groovy</runnerParentFirstArtifact>

</runnerParentFirstArtifacts>
<excludedArtifacts>
<excludedArtifact>io.smallrye:smallrye-config</excludedArtifact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ private void addCpElement(QuarkusClassLoader.Builder builder, AppArtifact dep, C
public synchronized QuarkusClassLoader getAugmentClassLoader() {
if (augmentClassLoader == null) {
//first run, we need to build all the class loaders
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder("Augmentation Class Loader",
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder(
"Augmentation Class Loader: " + quarkusBootstrap.getMode(),
quarkusBootstrap.getBaseClassLoader(), !quarkusBootstrap.isIsolateDeployment());
builder.addClassLoaderEventListeners(quarkusBootstrap.getClassLoaderEventListeners());
//we want a class loader that can load the deployment artifacts and all their dependencies, but not
Expand Down Expand Up @@ -203,7 +204,8 @@ public synchronized QuarkusClassLoader getAugmentClassLoader() {
*/
public synchronized QuarkusClassLoader getBaseRuntimeClassLoader() {
if (baseRuntimeClassLoader == null) {
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder("Quarkus Base Runtime ClassLoader",
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder(
"Quarkus Base Runtime ClassLoader: " + quarkusBootstrap.getMode(),
quarkusBootstrap.getBaseClassLoader(), false);
builder.addClassLoaderEventListeners(quarkusBootstrap.getClassLoaderEventListeners());

Expand Down Expand Up @@ -257,8 +259,9 @@ private static boolean isHotReloadable(AppArtifact a, Set<Path> hotReloadPaths)

public QuarkusClassLoader createDeploymentClassLoader() {
//first run, we need to build all the class loaders
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder("Deployment Class Loader",
getAugmentClassLoader(), false)
QuarkusClassLoader.Builder builder = QuarkusClassLoader
.builder("Deployment Class Loader: " + quarkusBootstrap.getMode(),
getAugmentClassLoader(), false)
.addClassLoaderEventListeners(quarkusBootstrap.getClassLoaderEventListeners())
.setAggregateParentResources(true);

Expand All @@ -283,8 +286,14 @@ public QuarkusClassLoader createDeploymentClassLoader() {
}

public QuarkusClassLoader createRuntimeClassLoader(Map<String, byte[]> resources, Map<String, byte[]> transformedClasses) {
QuarkusClassLoader.Builder builder = QuarkusClassLoader.builder("Quarkus Runtime ClassLoader",
getBaseRuntimeClassLoader(), false)
return createRuntimeClassLoader(getBaseRuntimeClassLoader(), resources, transformedClasses);
}

public QuarkusClassLoader createRuntimeClassLoader(ClassLoader base, Map<String, byte[]> resources,
Map<String, byte[]> transformedClasses) {
QuarkusClassLoader.Builder builder = QuarkusClassLoader
.builder("Quarkus Runtime ClassLoader: " + quarkusBootstrap.getMode(),
getBaseRuntimeClassLoader(), false)
.setAggregateParentResources(true);
builder.setTransformedClasses(transformedClasses);

Expand Down

0 comments on commit d1071b8

Please sign in to comment.