Search in sources :

Example 1 with TestSupport

use of io.quarkus.deployment.dev.testing.TestSupport in project quarkus by quarkusio.

the class TestsProcessor method toggleTestRunner.

@BuildStep(onlyIf = IsDevelopment.class)
void toggleTestRunner(LaunchModeBuildItem launchModeBuildItem, BuildProducer<DevConsoleRouteBuildItem> routeProducer) {
    Optional<TestSupport> ts = TestSupport.instance();
    if (testsDisabled(launchModeBuildItem, ts)) {
        return;
    }
    routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle", "POST", new Handler<>() {

        @Override
        public void handle(RoutingContext event) {
            if (ts.get().isStarted()) {
                ts.get().stop();
            } else {
                ts.get().start();
            }
            Json.JsonObjectBuilder object = Json.object();
            object.put("running", ts.get().isRunning());
            event.response().putHeader("Content-Type", "application/json; charset=utf-8").end(object.build());
        }
    }));
    routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle-broken-only", "POST", new Handler<>() {

        @Override
        public void handle(RoutingContext event) {
            boolean brokenOnlyMode = ts.get().toggleBrokenOnlyMode();
            Json.JsonObjectBuilder object = Json.object();
            object.put("brokenOnlyMode", brokenOnlyMode);
            event.response().putHeader("Content-Type", "application/json; charset=utf-8").end(object.build());
        }
    }));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) TestSupport(io.quarkus.deployment.dev.testing.TestSupport) Handler(io.vertx.core.Handler) Json(io.quarkus.vertx.http.runtime.devmode.Json) DevConsoleRouteBuildItem(io.quarkus.devconsole.spi.DevConsoleRouteBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with TestSupport

use of io.quarkus.deployment.dev.testing.TestSupport in project quarkus by quarkusio.

the class IsolatedTestModeMain method setupRuntimeCompilation.

private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path applicationRoot) throws Exception {
    System.setProperty("quarkus.test.display-test-output", "true");
    if (!context.getAllModules().isEmpty()) {
        ServiceLoader<CompilationProvider> serviceLoader = ServiceLoader.load(CompilationProvider.class);
        List<CompilationProvider> compilationProviders = new ArrayList<>();
        for (CompilationProvider provider : serviceLoader) {
            compilationProviders.add(provider);
            context.getAllModules().forEach(moduleInfo -> moduleInfo.addSourcePaths(provider.handledSourcePaths()));
        }
        QuarkusCompiler compiler;
        try {
            compiler = new QuarkusCompiler(curatedApplication, compilationProviders, context);
        } catch (Exception e) {
            throw new RuntimeException("Failed to create compiler", e);
        }
        TestSupport testSupport = new TestSupport(curatedApplication, compilationProviders, context, DevModeType.TEST_ONLY);
        RuntimeUpdatesProcessor processor = new RuntimeUpdatesProcessor(applicationRoot, context, compiler, DevModeType.TEST_ONLY, this::regenerateApplication, new BiConsumer<DevModeContext.ModuleInfo, String>() {

            @Override
            public void accept(DevModeContext.ModuleInfo moduleInfo, String s) {
            }
        }, new BiFunction<String, byte[], byte[]>() {

            @Override
            public byte[] apply(String s, byte[] bytes) {
                return ClassTransformingBuildStep.transform(s, bytes);
            }
        }, testSupport);
        for (HotReplacementSetup service : ServiceLoader.load(HotReplacementSetup.class, curatedApplication.getBaseRuntimeClassLoader())) {
            hotReplacementSetups.add(service);
            service.setupHotDeployment(processor);
            processor.addHotReplacementSetup(service);
        }
        return processor;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) TestSupport(io.quarkus.deployment.dev.testing.TestSupport) HotReplacementSetup(io.quarkus.dev.spi.HotReplacementSetup) IOException(java.io.IOException)

Example 3 with TestSupport

use of io.quarkus.deployment.dev.testing.TestSupport in project quarkus by quarkusio.

the class IsolatedDevModeMain method setupRuntimeCompilation.

private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path appRoot, DevModeType devModeType) throws Exception {
    if (!context.getAllModules().isEmpty()) {
        ServiceLoader<CompilationProvider> serviceLoader = ServiceLoader.load(CompilationProvider.class);
        List<CompilationProvider> compilationProviders = new ArrayList<>();
        for (CompilationProvider provider : serviceLoader) {
            compilationProviders.add(provider);
            context.getAllModules().forEach(moduleInfo -> moduleInfo.addSourcePaths(provider.handledSourcePaths()));
        }
        QuarkusCompiler compiler = new QuarkusCompiler(curatedApplication, compilationProviders, context);
        TestSupport testSupport = null;
        if (devModeType == DevModeType.LOCAL) {
            testSupport = new TestSupport(curatedApplication, compilationProviders, context, devModeType);
        }
        RuntimeUpdatesProcessor processor = new RuntimeUpdatesProcessor(appRoot, context, compiler, devModeType, this::restartCallback, null, new BiFunction<String, byte[], byte[]>() {

            @Override
            public byte[] apply(String s, byte[] bytes) {
                return ClassTransformingBuildStep.transform(s, bytes);
            }
        }, testSupport);
        for (HotReplacementSetup service : ServiceLoader.load(HotReplacementSetup.class, curatedApplication.getBaseRuntimeClassLoader())) {
            hotReplacementSetups.add(service);
            service.setupHotDeployment(processor);
            processor.addHotReplacementSetup(service);
        }
        for (DeploymentFailedStartHandler service : ServiceLoader.load(DeploymentFailedStartHandler.class, curatedApplication.getAugmentClassLoader())) {
            processor.addDeploymentFailedStartHandler(new Runnable() {

                @Override
                public void run() {
                    ClassLoader old = Thread.currentThread().getContextClassLoader();
                    try {
                        Thread.currentThread().setContextClassLoader(curatedApplication.getAugmentClassLoader());
                        service.handleFailedInitialStart();
                    } finally {
                        Thread.currentThread().setContextClassLoader(old);
                    }
                }
            });
        }
        DevConsoleManager.setQuarkusBootstrap(curatedApplication.getQuarkusBootstrap());
        DevConsoleManager.setHotReplacementContext(processor);
        return processor;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) TestSupport(io.quarkus.deployment.dev.testing.TestSupport) HotReplacementSetup(io.quarkus.dev.spi.HotReplacementSetup) DeploymentFailedStartHandler(io.quarkus.dev.spi.DeploymentFailedStartHandler) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader)

Aggregations

TestSupport (io.quarkus.deployment.dev.testing.TestSupport)3 HotReplacementSetup (io.quarkus.dev.spi.HotReplacementSetup)2 ArrayList (java.util.ArrayList)2 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 DeploymentFailedStartHandler (io.quarkus.dev.spi.DeploymentFailedStartHandler)1 DevConsoleRouteBuildItem (io.quarkus.devconsole.spi.DevConsoleRouteBuildItem)1 Json (io.quarkus.vertx.http.runtime.devmode.Json)1 Handler (io.vertx.core.Handler)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 IOException (java.io.IOException)1