Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 6, 2021
1 parent 299f027 commit 4728311
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,40 +133,7 @@ public void start(boolean runTests) {
if (context.getApplicationRoot().getTest().isPresent()) {
started = true;
runTests = true;
if (testCuratedApplication == null) {
testCuratedApplication = curatedApplication.getQuarkusBootstrap().clonedBuilder()
.setMode(QuarkusBootstrap.Mode.TEST)
.setDisableClasspathCache(true)
.setIsolateDeployment(true)
.setTest(true)
.setAuxiliaryApplication(true)
.addAdditionalApplicationArchive(new AdditionalDependency(
Paths.get(context.getApplicationRoot().getTest().get().getClassesPath()), true,
true))
.build()
.bootstrap();
compiler = new QuarkusCompiler(testCuratedApplication, compilationProviders, context);
testRunner = new TestRunner(context, testCuratedApplication, new Consumer<TestRunResults>() {
@Override
public void accept(TestRunResults testRunResults) {
synchronized (TestSupport.this) {
TestSupport.this.testRunResults = testRunResults;
for (CompletableFuture<TestRunResults> i : resultsListeners) {
i.complete(testRunResults);
}
resultsListeners.clear();
}
ContinuousTestingWebsocketListener.setLastState(
new ContinuousTestingWebsocketListener.State(true, testRunner.isRunning(),
testRunResults.getTestsPassed() +
testRunResults.getTestsFailed() +
testRunResults.getTestsSkipped(),
testRunResults.getTestsPassed(),
testRunResults.getTestsFailed(), testRunResults.getTestsSkipped()));

}
}, testState);
}
init();
for (Runnable i : startListeners) {
i.run();
}
Expand All @@ -184,6 +151,48 @@ public void accept(TestRunResults testRunResults) {
}
}

public void init() {
if (testCuratedApplication == null) {
try {
testCuratedApplication = curatedApplication.getQuarkusBootstrap().clonedBuilder()
.setMode(QuarkusBootstrap.Mode.TEST)
.setDisableClasspathCache(true)
.setIsolateDeployment(true)
.setTest(true)
.setAuxiliaryApplication(true)
.addAdditionalApplicationArchive(new AdditionalDependency(
Paths.get(context.getApplicationRoot().getTest().get().getClassesPath()), true,
true))
.build()
.bootstrap();
compiler = new QuarkusCompiler(testCuratedApplication, compilationProviders, context);
testRunner = new TestRunner(context, testCuratedApplication, new Consumer<TestRunResults>() {
@Override
public void accept(TestRunResults testRunResults) {
synchronized (TestSupport.this) {
TestSupport.this.testRunResults = testRunResults;
for (CompletableFuture<TestRunResults> i : resultsListeners) {
i.complete(testRunResults);
}
resultsListeners.clear();
}
ContinuousTestingWebsocketListener.setLastState(
new ContinuousTestingWebsocketListener.State(true, testRunner.isRunning(),
testRunResults.getTestsPassed() +
testRunResults.getTestsFailed() +
testRunResults.getTestsSkipped(),
testRunResults.getTestsPassed(),
testRunResults.getTestsFailed(), testRunResults.getTestsSkipped()));

}
}, testState);

} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

public synchronized void stop() {
if (started) {
started = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -24,12 +25,14 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.LogRecord;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
Expand Down Expand Up @@ -378,6 +381,17 @@ private static List<Class<?>> discoverTestClasses(DevModeContext devModeContext)
throw new RuntimeException(e);
}
}
ret.sort(Comparator.comparing(new Function<Class<?>, String>() {
@Override
public String apply(Class<?> aClass) {
ClassInfo def = index.getClassByName(DotName.createSimple(aClass.getName()));
AnnotationInstance testProfile = def.classAnnotation(DotName.createSimple("io.quarkus.test.junit.TestProfile"));
if (testProfile == null) {
return "";
}
return testProfile.value().asClass().name().toString();
}
}));
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ ServiceStartBuildItem startTesting(TestConfig config) {
if (config.enabled == TestConfig.Mode.ENABLED) {
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().start();
} else if (config.enabled == TestConfig.Mode.PAUSED) {
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().start(false);
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().pause();
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().init();
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().stop();
}
RuntimeUpdatesProcessor.INSTANCE.getTestSupport().setTags(config.includeTags.orElse(Collections.emptyList()),
config.excludeTags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.app.RunningQuarkusApplication;
import io.quarkus.bootstrap.app.StartupAction;
import io.quarkus.bootstrap.classloading.ClassPathElement;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.runner.Timing;
import io.quarkus.bootstrap.utils.BuildToolHelper;
import io.quarkus.builder.BuildChainBuilder;
import io.quarkus.builder.BuildContext;
import io.quarkus.builder.BuildStep;
import io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem;
import io.quarkus.deployment.builditem.TestAnnotationBuildItem;
import io.quarkus.deployment.builditem.TestClassBeanBuildItem;
import io.quarkus.deployment.builditem.TestClassPredicateBuildItem;
Expand Down Expand Up @@ -1144,7 +1147,23 @@ public boolean test(String className) {
}
}).produces(TestClassPredicateBuildItem.class)
.build();

buildChainBuilder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
//we need to make sure all hot reloadable classes are application classes
context.produce(new ApplicationClassPredicateBuildItem(new Predicate<String>() {
@Override
public boolean test(String s) {
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread()
.getContextClassLoader();
//if the class file is present in this (and not the parent) CL then it is an application class
List<ClassPathElement> res = cl
.getElementsWithResource(s.replace(".", "/") + ".class", true);
return !res.isEmpty();
}
}));
}
}).produces(ApplicationClassPredicateBuildItem.class).build();
buildChainBuilder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
Expand Down

0 comments on commit 4728311

Please sign in to comment.