Skip to content

Commit

Permalink
Patch up from quarkusio#44497 rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Dec 17, 2024
1 parent f0a0805 commit 95b196c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ default boolean disableApplicationLifecycleObservers() {
}

final class TestResourceEntry {
private final Class<?> clazz; //TODO was extends QuarkusTestResourceLifecycleManager but that class is inaccessible now
private final Class<?> clazz; //TODO was extends QuarkusTestResourceLifecycleManager but that class is in the wrong module now
private final Map<String, String> args;
private final boolean parallel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private QuarkusClassLoader getQuarkusClassLoader(String profileKey, Class requir
} else {
Method method = Class
.forName("io.quarkus.test.junit.TestResourceUtil", true, keyMakerClassLoader) // TODO use class, not string, but that would need us to be in a different module
.getMethod("getReloadGroupIdentifier", Class.class);
.getMethod("getReloadGroupIdentifier", Class.class, Class.class);

// TODO this is kind of annoying, can we find a nicer way?
// The resource checks assume that there's a useful TCCL and load the class with that TCCL to do reference equality checks and casting against resource classes
Expand All @@ -390,7 +390,7 @@ private QuarkusClassLoader getQuarkusClassLoader(String profileKey, Class requir
.setContextClassLoader(keyMakerClassLoader);

// we reload the test resources (and thus the application) if we changed test class and the new test class is not a nested class, and if we had or will have per-test test resources
resourceKey = (String) method.invoke(null, requiredTestClass); // TestResourceUtil.getResourcesKey(requiredTestClass);
resourceKey = (String) method.invoke(null, requiredTestClass, profile); // TestResourceUtil.getResourcesKey(requiredTestClass);
} finally {
Thread.currentThread().setContextClassLoader(original);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public int compare(TestResourceStartInfo o1, TestResourceStartInfo o2) {
}

private TestResourceStartInfo buildTestResourceEntry(TestResourceClassEntry entry) {
Class<? extends QuarkusTestResourceLifecycleManager> testResourceClass = entry.clazz;
Class<? extends QuarkusTestResourceLifecycleManager> testResourceClass = (Class<? extends QuarkusTestResourceLifecycleManager>) entry.clazz;
try {
return new TestResourceStartInfo(testResourceClass.getConstructor().newInstance(), entry.args,
entry.configAnnotation);
Expand Down Expand Up @@ -585,11 +585,11 @@ public static class TestResourceClassEntry {
private final Annotation configAnnotation;
private final TestResourceScope scope;

public TestResourceClassEntry(Class<? extends QuarkusTestResourceLifecycleManager> clazz, Map<String, String> args,
public TestResourceClassEntry(Class<?> clazz, Map<String, String> args,
Annotation configAnnotation,
boolean parallel,
TestResourceScope scope) {
this.clazz = clazz;
this.clazz = (Class<? extends QuarkusTestResourceLifecycleManager>) clazz;
this.args = args;
this.configAnnotation = configAnnotation;
this.parallel = parallel;
Expand Down Expand Up @@ -618,7 +618,7 @@ public boolean isParallel() {
return parallel;
}

public Class<? extends QuarkusTestResourceLifecycleManager> testResourceLifecycleManagerClass() {
public Class<?> testResourceLifecycleManagerClass() {
return clazz;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import jakarta.enterprise.inject.Alternative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ private TestResourceUtil() {
*/
public static boolean testResourcesRequireReload(QuarkusTestExtensionState state, Class<?> nextTestClass,
Class<? extends QuarkusTestProfile> nextTestClassProfile) {
QuarkusTestProfile profileInstance = null;
if (nextTestClassProfile != null) {
try {
profileInstance = nextTestClassProfile.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
QuarkusTestProfile profileInstance = instantiateProfile(nextTestClassProfile);
Set<TestResourceManager.TestResourceComparisonInfo> existingTestResources = existingTestResources(state);
Set<TestResourceManager.TestResourceComparisonInfo> nextTestResources = nextTestResources(nextTestClass,
profileInstance);
Expand Down Expand Up @@ -81,8 +74,20 @@ static Set<TestResourceManager.TestResourceComparisonInfo> nextTestResources(Cla
}

// Invoked reflectively from FacadeClassLoader
public static String getReloadGroupIdentifier(Class requiredTestClass) {
return TestResourceManager.getReloadGroupIdentifier(nextTestResources(requiredTestClass));
public static String getReloadGroupIdentifier(Class requiredTestClass, Class profileClass) {
return TestResourceManager
.getReloadGroupIdentifier(nextTestResources(requiredTestClass, instantiateProfile(profileClass)));
}

private static QuarkusTestProfile instantiateProfile(Class<? extends QuarkusTestProfile> nextTestClassProfile) {
if (nextTestClassProfile != null) {
try {
return nextTestClassProfile.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return null;
}

/**
Expand Down

0 comments on commit 95b196c

Please sign in to comment.