Skip to content

Commit da10693

Browse files
authored
Merge pull request quarkusio#47946 from holly-cummins/use-classloaders-not-startupactions
Refactor: Store QuarkusClassLoaders, not StartupActions in FacadeClassLoader map
2 parents 33f66e5 + c75536a commit da10693

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

test-framework/junit5/src/main/java/io/quarkus/test/junit/classloading/FacadeClassLoader.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public final class FacadeClassLoader extends ClassLoader implements Closeable {
6969
private static final Map<String, CuratedApplication> curatedApplications = new HashMap<>();
7070

7171
// JUnit discovery is single threaded, so no need for concurrency on this map
72-
private final Map<String, StartupAction> runtimeClassLoaders = new HashMap<>();
72+
private final Map<String, QuarkusClassLoader> runtimeClassLoaders = new HashMap<>();
7373
private static final String NO_PROFILE = "no-profile";
7474

7575
/*
@@ -439,8 +439,8 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla
439439
String profileKey = getProfileKey(profile);
440440

441441
try {
442-
StartupAction startupAction;
443442
String key;
443+
QuarkusClassLoader classLoader;
444444

445445
// We cannot directly access TestResourceUtil as long as we're in the core module, but the app classloaders can.
446446
// But, chicken-and-egg, we may not have an app classloader yet. However, if we don't, we won't need to worry about restarts, but this instance clearly cannot need a restart
@@ -450,8 +450,8 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla
450450
// If we make a classloader with a null profile, we get the problem of starting dev services multiple times, which is very bad (if temporary) - once that issue is fixed, could reconsider
451451
if (keyMakerClassLoader == null) {
452452
// Making a classloader uses the profile key to look up a curated application
453-
startupAction = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
454-
keyMakerClassLoader = startupAction.getClassLoader();
453+
classLoader = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
454+
keyMakerClassLoader = classLoader;
455455

456456
// We cannot use the startup action one because it's a base runtime classloader and so will not have the right access to application classes (they're in its banned list)
457457
final String resourceKey = requiredTestClass != null ? getResourceKey(requiredTestClass, profile) : null;
@@ -463,18 +463,15 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla
463463

464464
// The resource key might be null, and that's ok
465465
key = profileKey + resourceKey;
466-
startupAction = runtimeClassLoaders.get(key);
467-
if (startupAction == null) {
466+
classLoader = runtimeClassLoaders.get(key);
467+
if (classLoader == null) {
468468
// Making a classloader uses the profile key to look up a curated application
469-
startupAction = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
469+
classLoader = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
470470
}
471-
472471
}
473472

474-
// If we didn't have a classloader and didn't get a resource key
475-
runtimeClassLoaders.put(key, startupAction);
476-
477-
return startupAction.getClassLoader();
473+
runtimeClassLoaders.put(key, classLoader);
474+
return classLoader;
478475
} catch (RuntimeException e) {
479476
// Exceptions here get swallowed by the JUnit framework and we don't get any debug information unless we print it ourself
480477
e.printStackTrace();
@@ -543,13 +540,12 @@ private QuarkusClassLoader getOrCreateBaseClassLoader(String key, Class<?> requi
543540
return curatedApplication.getOrCreateBaseRuntimeClassLoader();
544541
}
545542

546-
private StartupAction getOrCreateRuntimeClassLoader(String key, Class<?> requiredTestClass, Class<?> profile)
543+
private QuarkusClassLoader getOrCreateRuntimeClassLoader(String key, Class<?> requiredTestClass, Class<?> profile)
547544
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException,
548545
IllegalAccessException, AppModelResolverException, BootstrapException, IOException {
549546
CuratedApplication curatedApplication = getOrCreateCuratedApplication(key, requiredTestClass);
550547
StartupAction startupAction = AppMakerHelper.getStartupAction(requiredTestClass,
551548
curatedApplication, profile);
552-
553549
QuarkusClassLoader loader = startupAction.getClassLoader();
554550

555551
Class<?> configProviderResolverClass = loader.loadClass(ConfigProviderResolver.class.getName());
@@ -561,7 +557,7 @@ private StartupAction getOrCreateRuntimeClassLoader(String key, Class<?> require
561557
configProviderResolverClass.getDeclaredMethod("setInstance", configProviderResolverClass)
562558
.invoke(null, testConfigProviderResolver);
563559

564-
return startupAction;
560+
return loader;
565561

566562
}
567563

0 commit comments

Comments
 (0)