Skip to content

Commit

Permalink
Use runtime classloader even in normal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Jul 26, 2023
1 parent 776a20c commit 2c4ddb4
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<db2-jdbc.version>11.5.8.0</db2-jdbc.version>
<shrinkwrap.version>1.2.6</shrinkwrap.version>
<rest-assured.version>5.3.0</rest-assured.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<junit.jupiter.version>5.10.0</junit.jupiter.version>
<junit-pioneer.version>1.5.0</junit-pioneer.version>
<infinispan.version>14.0.11.Final</infinispan.version>
<infinispan.protostream.version>4.6.2.Final</infinispan.protostream.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class CoreQuarkusTestExtension {
protected static final String TEST_LOCATION = "test-location";
protected static final String TEST_CLASS = "test-class";

protected static Class currentJUnitTestClass;

/// end copied

private static final Logger log = Logger.getLogger(CoreQuarkusTestExtension.class);
Expand Down Expand Up @@ -94,10 +92,17 @@ public PrepareResult(AugmentAction augmentAction, QuarkusTestProfile profileInst
}
}

// Re-used from AbstractJvmQuarkusTestExtension
protected PrepareResult createAugmentor(Class requiredTestClass, Class<? extends QuarkusTestProfile> profile,
Collection<Runnable> shutdownTasks) throws Exception {

Path testClassLocation = getTestClassesLocation(requiredTestClass);
return createAugmentor(testClassLocation, profile, shutdownTasks);
}

// Re-used from AbstractJvmQuarkusTestExtension
protected PrepareResult createAugmentor(Path testClassLocation, Class<? extends QuarkusTestProfile> profile,
Collection<Runnable> shutdownTasks) throws Exception {

// I think the required test class is just an example, since the augmentor is only
// created once per test profile
final PathList.Builder rootBuilder = PathList.builder();
Expand All @@ -108,9 +113,6 @@ protected PrepareResult createAugmentor(Class requiredTestClass, Class<? extends
}
};

currentJUnitTestClass = requiredTestClass;

final Path testClassLocation;
final Path appClassLocation;
final Path projectRoot = Paths.get("")
.normalize()
Expand Down Expand Up @@ -175,7 +177,7 @@ protected PrepareResult createAugmentor(Class requiredTestClass, Class<? extends
}
}

testClassLocation = getTestClassesLocation(requiredTestClass);
// testClassLocation = getTestClassesLocation(requiredTestClass);
System.out.println("test class location is " + testClassLocation);
appClassLocation = getAppClassLocationForTestLocation(testClassLocation.toString());
System.out.println("app class location is " + appClassLocation);
Expand Down Expand Up @@ -279,7 +281,7 @@ protected PrepareResult createAugmentor(Class requiredTestClass, Class<? extends
.isAuxiliaryApplication());
final Map<String, Object> props = new HashMap<>();
props.put(TEST_LOCATION, testClassLocation);
props.put(TEST_CLASS, requiredTestClass);
// TODO surely someone reads this? props.put(TEST_CLASS, requiredTestClass);
// TODO what's going on here with the profile?
Class<? extends QuarkusTestProfile> quarkusTestProfile = profile;
PrepareResult result = new PrepareResult(curatedApplication
Expand All @@ -301,7 +303,8 @@ public ClassLoader doJavaStart(Class testClass, CuratedApplication curatedApplic
QuarkusTestProfile profileInstance = result.profileInstance;

testHttpEndpointProviders = TestHttpEndpointProvider.load();
System.out.println("CORE MAKER SEES CLASS OF STARTUP " + StartupAction.class.getClassLoader());
System.out.println(
"CORE MAKER SEES CLASS OF STARTUP " + StartupAction.class.getClassLoader());

System.out.println("HOLLY about to make app for " + testClass);
StartupAction startupAction = augmentAction.createInitialRuntimeApplication();
Expand All @@ -312,15 +315,43 @@ public ClassLoader doJavaStart(Class testClass, CuratedApplication curatedApplic

}

public ClassLoader doJavaStart(Path location, CuratedApplication curatedApplication) throws Exception {
Class<? extends QuarkusTestProfile> profile = null;
// TODO do we want any of these?
Collection shutdownTasks = new HashSet();
PrepareResult result = createAugmentor(location, profile, shutdownTasks);
AugmentAction augmentAction = result.augmentAction;
QuarkusTestProfile profileInstance = result.profileInstance;

testHttpEndpointProviders = TestHttpEndpointProvider.load();
System.out.println(
"CORE MAKER SEES CLASS OF STARTUP " + StartupAction.class.getClassLoader());

System.out.println("HOLLY about to make app for " + location);
StartupAction startupAction = augmentAction.createInitialRuntimeApplication();
// TODO this seems to be safe to do because the classloaders are the same
startupAction.store();
System.out.println("HOLLY did store " + startupAction);
return startupAction.getClassLoader();

}

// TODO can we defer this and move it back to the junit5 module?
public static class TestBuildChainFunction implements Function<Map<String, Object>, List<Consumer<BuildChainBuilder>>> {

@Override
public List<Consumer<BuildChainBuilder>> apply(Map<String, Object> stringObjectMap) {
Path testLocation = (Path) stringObjectMap.get(TEST_LOCATION);
// the index was written by the extension
Index testClassesIndex = TestClassIndexer.readIndex(testLocation, (Class<?>) stringObjectMap.get(TEST_CLASS));

Class<?> testClass = (Class<?>) stringObjectMap.get(TEST_CLASS);
// TODO is this at all safe?

Index testClassesIndex;
if (testClass != null) {
testClassesIndex = TestClassIndexer.readIndex(testLocation, testClass);
} else {
testClassesIndex = TestClassIndexer.readIndex(testLocation);
}
List<Consumer<BuildChainBuilder>> allCustomizers = new ArrayList<>(1);
Consumer<BuildChainBuilder> defaultCustomizer = new Consumer<BuildChainBuilder>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ModuleTestRunner {

public ModuleTestRunner(TestSupport testSupport, CuratedApplication testApplication,
DevModeContext.ModuleInfo moduleInfo) {
System.out.println("HOLLY making module test runner");
this.testSupport = testSupport;
this.testApplication = testApplication;
this.moduleInfo = moduleInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static Index readIndex(Class<?> testClass) {
return readIndex(getTestClassesLocation(testClass), testClass);
}

public static Index readIndex(Path testLocation) {
return indexTestClasses(testLocation);
}

public static Index readIndex(Path testClassLocation, Class<?> testClass) {
Path path = indexPath(testClassLocation, testClass);
if (path.toFile().exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class TestSupport implements TestController {

public TestSupport(CuratedApplication curatedApplication, List<CompilationProvider> compilationProviders,
DevModeContext context, DevModeType devModeType) {
System.out.println("HOLLY making test support");
this.curatedApplication = curatedApplication;
this.compilationProviders = compilationProviders;
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
Expand Down Expand Up @@ -323,9 +322,9 @@ private boolean isRuntimeArtifact(ArtifactKey key) {
}

private void visitRuntimeDependencies(List<DependencyNode> list) {
System.out.println(list.size() + "HOLLY will visit " + Arrays.toString(list.toArray()));
// System.out.println(list.size() + "HOLLY will visit " + Arrays.toString(list.toArray()));
for (DependencyNode n : list) {
System.out.println("HOLLY visiting " + n);
// System.out.println("HOLLY visiting " + n);
visitRuntimeDependency(n);
}
}
Expand All @@ -348,9 +347,9 @@ private void visitRuntimeDependency(DependencyNode node) {
}

try {
System.out.println("about to get " + node + ".>" + artifact);
// System.out.println("about to get " + node + ".>" + artifact);
final ExtensionDependency extDep = getExtensionDependencyOrNull(node, artifact);
System.out.println("got " + extDep);
// System.out.println("got " + extDep);

if (dep == null) {
WorkspaceModule module = null;
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<assertj.version>3.24.2</assertj.version>
<eclipse-minimal-json.version>0.9.5</eclipse-minimal-json.version>
<jboss-logging.version>3.5.1.Final</jboss-logging.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<junit.jupiter.version>5.10.0</junit.jupiter.version>
<maven-core.version>3.9.3</maven-core.version><!-- Keep in sync with sisu.version -->
<sisu.version>0.3.5</sisu.version><!-- Keep in sync with maven-core.version -->
<maven-plugin-annotations.version>3.7.1</maven-plugin-annotations.version>
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/extension-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<maven-plugin-plugin.version>3.8.1</maven-plugin-plugin.version>
<jackson-bom.version>2.15.2</jackson-bom.version>
<smallrye-beanbag.version>1.3.2</smallrye-beanbag.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<junit.jupiter.version>5.10.0</junit.jupiter.version>
</properties>
<build>
<testResources>
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<assertj.version>3.24.2</assertj.version>
<jackson-bom.version>2.15.2</jackson-bom.version>
<jakarta.enterprise.cdi-api.version>4.0.1</jakarta.enterprise.cdi-api.version>
<junit.version>5.9.3</junit.version>
<junit.version>5.10.0-M1</junit.version>
<commons-compress.version>1.23.0</commons-compress.version>
<jboss-logging.version>3.5.1.Final</jboss-logging.version>
<mockito.version>5.3.1</mockito.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
junit.jupiter.extensions.autodetection.enabled=true
junit.jupiter.testclass.order.default=io.quarkus.test.junit.util.QuarkusTestProfileAwareClassOrderer
junit.platform.launcher.interceptors.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public static boolean hasPerTestResources(Class<?> requiredTestClass) {
return false;
}

protected static class PrepareResult {
protected final AugmentAction augmentAction;
protected final QuarkusTestProfile profileInstance;
public static class PrepareResult {
public final AugmentAction augmentAction;
public final QuarkusTestProfile profileInstance;
protected final CuratedApplication curatedApplication;
protected final Path testClassLocation;

Expand Down
Loading

0 comments on commit 2c4ddb4

Please sign in to comment.