Search in sources :

Example 1 with ContainerMatrixTestWithRunningESMongoTestsDescriptor

use of org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor in project graylog2-server by Graylog2.

the class ContainerMatrixHierarchicalTestEngine method execute.

@Override
public void execute(ExecutionRequest request) {
    request.getRootTestDescriptor().getChildren().forEach(descriptor -> {
        if (descriptor instanceof ContainerMatrixTestWithRunningESMongoTestsDescriptor) {
            GraylogBackend backend = RunningGraylogBackend.createStarted();
            RequestSpecification specification = requestSpec(backend);
            this.execute(request, ((ContainerMatrixTestsDescriptor) descriptor).getChildren(), backend, specification);
        } else if (descriptor instanceof ContainerMatrixTestsDescriptor) {
            ContainerMatrixTestsDescriptor containerMatrixTestsDescriptor = (ContainerMatrixTestsDescriptor) descriptor;
            SearchVersion esVersion = containerMatrixTestsDescriptor.getEsVersion();
            MongodbServer mongoVersion = containerMatrixTestsDescriptor.getMongoVersion();
            int[] extraPorts = containerMatrixTestsDescriptor.getExtraPorts();
            List<URL> mongoDBFixtures = containerMatrixTestsDescriptor.getMongoDBFixtures();
            PluginJarsProvider pluginJarsProvider = instantiateFactory(containerMatrixTestsDescriptor.getPluginJarsProvider());
            MavenProjectDirProvider mavenProjectDirProvider = instantiateFactory(containerMatrixTestsDescriptor.getMavenProjectDirProvider());
            if (Lifecycle.VM.equals(containerMatrixTestsDescriptor.getLifecycle())) {
                try (ContainerizedGraylogBackend backend = ContainerizedGraylogBackend.createStarted(esVersion, mongoVersion, extraPorts, mongoDBFixtures, pluginJarsProvider, mavenProjectDirProvider)) {
                    RequestSpecification specification = requestSpec(backend);
                    this.execute(request, ((ContainerMatrixTestsDescriptor) descriptor).getChildren(), backend, specification);
                } catch (Exception exception) {
                    throw new JUnitException("Error executing tests for engine " + getId(), exception);
                }
            } else if (Lifecycle.CLASS.equals(containerMatrixTestsDescriptor.getLifecycle())) {
                for (TestDescriptor td : containerMatrixTestsDescriptor.getChildren()) {
                    List<URL> fixtures = mongoDBFixtures;
                    if (td instanceof ContainerMatrixTestClassDescriptor) {
                        fixtures = ((ContainerMatrixTestClassDescriptor) td).getMongoFixtures();
                    }
                    try (ContainerizedGraylogBackend backend = ContainerizedGraylogBackend.createStarted(esVersion, mongoVersion, extraPorts, fixtures, pluginJarsProvider, mavenProjectDirProvider)) {
                        RequestSpecification specification = requestSpec(backend);
                        this.execute(request, Collections.singleton(td), backend, specification);
                    } catch (Exception exception) {
                        throw new JUnitException("Error executing tests for engine " + getId(), exception);
                    }
                }
            } else {
                LOG.error("Unknown lifecycle: " + containerMatrixTestsDescriptor.getLifecycle());
            }
        } else {
            LOG.error("All children of the root should be of type 'ContainerMatrixTestsDescriptor' or 'ContainerMatrixTestWithRunningESMongoTestsDescriptor'");
        }
        request.getEngineExecutionListener().executionFinished(descriptor, TestExecutionResult.successful());
    });
}
Also used : ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) RequestSpecification(io.restassured.specification.RequestSpecification) JUnitException(org.junit.platform.commons.JUnitException) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) JUnitException(org.junit.platform.commons.JUnitException) URL(java.net.URL) ContainerizedGraylogBackend(org.graylog.testing.completebackend.ContainerizedGraylogBackend) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) GraylogBackend(org.graylog.testing.completebackend.GraylogBackend) ContainerizedGraylogBackend(org.graylog.testing.completebackend.ContainerizedGraylogBackend) RunningGraylogBackend(org.graylog.testing.completebackend.RunningGraylogBackend) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) List(java.util.List) SearchVersion(org.graylog2.storage.SearchVersion) TestDescriptor(org.junit.platform.engine.TestDescriptor) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor)

Example 2 with ContainerMatrixTestWithRunningESMongoTestsDescriptor

use of org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor in project graylog2-server by Graylog2.

the class ContainerMatrixTestEngine method discover.

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    JupiterConfiguration configuration = new CachingJupiterConfiguration(new DefaultJupiterConfiguration(discoveryRequest.getConfigurationParameters()));
    final ContainerMatrixEngineDescriptor engineDescriptor = new ContainerMatrixEngineDescriptor(uniqueId, "Graylog Container Matrix Tests", configuration);
    Reflections reflections = new Reflections("org.graylog", "org.graylog2");
    final Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(ContainerMatrixTestsConfiguration.class);
    final Set<Integer> extraPorts = getExtraPorts(annotated);
    final List<URL> mongoDBFixtures = getMongoDBFixtures(annotated);
    if (testAgainstRunningESMongoDB()) {
        // if you test from inside an IDE against running containers
        ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestWithRunningESMongoTestsDescriptor(engineDescriptor, extraPorts, mongoDBFixtures);
        new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
        engineDescriptor.addChild(testsDescriptor);
    } else {
        // for full tests, create all combinations of tests. First differentiate for maven builds.
        getMavenProjectDirProvider(annotated).forEach(mavenProjectDirProvider -> getPluginJarsProvider(annotated).forEach(pluginJarsProvider -> {
            MavenProjectDirProvider mpdp = instantiateFactory(mavenProjectDirProvider);
            PluginJarsProvider pjp = instantiateFactory(pluginJarsProvider);
            // now add all grouped tests for Lifecycle.VM
            getSearchServerVersions(annotated).stream().map(SearchServer::getSearchVersion).forEach(searchVersion -> getMongoVersions(annotated).forEach(mongoVersion -> {
                ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestsDescriptor(engineDescriptor, Lifecycle.VM, mavenProjectDirProvider, mpdp.getUniqueId(), pluginJarsProvider, pjp.getUniqueId(), searchVersion, mongoVersion, extraPorts, mongoDBFixtures);
                new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
                engineDescriptor.addChild(testsDescriptor);
            }));
            // add separate test classes (Lifecycle.CLASS)
            getSearchServerVersions(annotated).stream().map(SearchServer::getSearchVersion).forEach(esVersion -> getMongoVersions(annotated).forEach(mongoVersion -> {
                ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestsDescriptor(engineDescriptor, Lifecycle.CLASS, mavenProjectDirProvider, mpdp.getUniqueId(), pluginJarsProvider, pjp.getUniqueId(), esVersion, mongoVersion, extraPorts, new ArrayList<>());
                new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
                engineDescriptor.addChild(testsDescriptor);
            }));
        }));
    }
    return engineDescriptor;
}
Also used : Arrays(java.util.Arrays) ThrowableCollector(org.junit.platform.engine.support.hierarchical.ThrowableCollector) URL(java.net.URL) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Reflections(org.reflections.Reflections) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) ContainerMatrixTestsConfiguration(org.graylog.testing.containermatrix.annotations.ContainerMatrixTestsConfiguration) ContainerMatrixTestsDiscoverySelectorResolver(org.junit.jupiter.engine.discovery.ContainerMatrixTestsDiscoverySelectorResolver) LinkedList(java.util.LinkedList) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Lifecycle(org.graylog.testing.completebackend.Lifecycle) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Resources(com.google.common.io.Resources) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) ContainerMatrixEngineDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor) Set(java.util.Set) HierarchicalTestExecutorService(org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutorService) UniqueId(org.junit.platform.engine.UniqueId) Collectors(java.util.stream.Collectors) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) JupiterThrowableCollectorFactory(org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory) AnnotationSupport(org.junit.platform.commons.support.AnnotationSupport) List(java.util.List) Stream(java.util.stream.Stream) ContainerMatrixHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.ContainerMatrixHierarchicalTestEngine) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Paths(java.nio.file.Paths) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) ContainerMatrixEngineDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) URL(java.net.URL) ContainerMatrixTestsDiscoverySelectorResolver(org.junit.jupiter.engine.discovery.ContainerMatrixTestsDiscoverySelectorResolver) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Reflections(org.reflections.Reflections) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor)

Aggregations

URL (java.net.URL)2 List (java.util.List)2 MavenProjectDirProvider (org.graylog.testing.completebackend.MavenProjectDirProvider)2 PluginJarsProvider (org.graylog.testing.completebackend.PluginJarsProvider)2 ContainerMatrixTestWithRunningESMongoTestsDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor)2 ContainerMatrixTestsDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor)2 TestDescriptor (org.junit.platform.engine.TestDescriptor)2 Resources (com.google.common.io.Resources)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 ContainerizedGraylogBackend (org.graylog.testing.completebackend.ContainerizedGraylogBackend)1