Search in sources :

Example 1 with TestContainer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer in project legend-engine by finos.

the class ServiceTestRunner method executeSingleExecutionTest.

private RichServiceTestResult executeSingleExecutionTest(PureSingleExecution execution, String testData, List<TestContainer> asserts, String noAssertMessage, PureModelContextData pureModelContextData, PureModel pureModel, Scope scope) throws IOException, JavaCompileException {
    if (asserts == null || asserts.isEmpty()) {
        scope.span().log(noAssertMessage);
        return new RichServiceTestResult(service.getPath(), Collections.emptyMap(), Collections.emptyMap(), null, null, null);
    } else {
        Runtime testRuntime = ServiceTestGenerationHelper.buildTestRuntime(execution.runtime, execution.mapping, testData, pureModelContextData, pureModel);
        RichIterable<? extends String> sqlStatements = extractSetUpSQLFromTestRuntime(testRuntime);
        PureSingleExecution testPureSingleExecution = shallowCopySingleExecution(execution);
        testPureSingleExecution.runtime = testRuntime;
        ExecutionPlan executionPlan = generatePlan(testPureSingleExecution);
        SingleExecutionPlan singleExecutionPlan = (SingleExecutionPlan) executionPlan;
        compilePlan(singleExecutionPlan);
        return executeTestAsserts(singleExecutionPlan, asserts, sqlStatements, scope);
    }
}
Also used : Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) ExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)

Example 2 with TestContainer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer in project legend-engine by finos.

the class ServiceTestRunner method executeTestAsserts.

@Prometheus(name = "service test execute", doc = "Execution duration summary within service test execution")
private RichServiceTestResult executeTestAsserts(SingleExecutionPlan executionPlan, List<TestContainer> asserts, RichIterable<? extends String> sqlStatements, Scope scope) throws IOException {
    long start = System.currentTimeMillis();
    if (ExecutionNodeTDSResultHelper.isResultTDS(executionPlan.rootExecutionNode) || (executionPlan.rootExecutionNode.isResultPrimitiveType() && "String".equals(executionPlan.rootExecutionNode.getDataTypeResultType()))) {
        // Java
        String packageName = "org.finos.legend.tests.generated";
        String className = "TestSuite";
        String javaCode = ServiceTestGenerationHelper.generateJavaForAsserts(asserts, this.service, this.pureModel, packageName, className);
        Class<?> assertsClass;
        RichServiceTestResult testRun;
        try {
            assertsClass = compileJavaForAsserts(packageName, className, javaCode);
        } catch (JavaCompileException e) {
            MetricsHandler.incrementErrorCount("test_execute", 0);
            throw new RuntimeException("Error compiling test asserts for " + this.service.getPath(), e);
        }
        scope.span().log("Java asserts generated and compiled");
        TestExecutionScope execScope = null;
        try {
            // Setup test database if needed
            if (sqlStatements != null) {
                execScope = TestExecutionScope.setupTestServer(sqlStatements, scope);
            }
            // Run tests
            Map<String, TestResult> results = Maps.mutable.empty();
            Map<String, Exception> assertExceptions = Maps.mutable.empty();
            for (Pair<TestContainer, Integer> tc : LazyIterate.zipWithIndex(asserts)) {
                // Build Param Map
                Map<String, Result> parameters = Maps.mutable.empty();
                if (this.service.execution instanceof PureExecution) {
                    parameters = ListIterate.zip(((PureExecution) this.service.execution).func.parameters, tc.getOne().parametersValues).toMap(p -> p.getOne().name, p -> // Condition evoked in case of studio-flow
                    p.getTwo() instanceof Collection ? new ConstantResult(ListIterate.collect(((Collection) p.getTwo()).values, v -> v.accept(new ValueSpecificationToResultVisitor()).getValue())) : // Condition evoked in case of pureIDE-flow
                    p.getTwo() instanceof PureList ? new ConstantResult(ListIterate.collect(((PureList) p.getTwo()).values, v -> v.accept(new ValueSpecificationToResultVisitor()).getValue())) : p.getTwo().accept(new ValueSpecificationToResultVisitor()));
                }
                // Execute Plan
                ExecutionState testExecutionState = new ExecutionState(parameters, Lists.mutable.withAll(executionPlan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(execScope == null ? -1 : execScope.getPort())), new InMemoryStoreExecutionState(new InMemoryStoreState()), new ServiceStoreExecutionState(new ServiceStoreState())));
                Result result = this.executor.execute(executionPlan, testExecutionState, null, null);
                org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result<Object> pureResult = result.accept(new ResultToPureResultVisitor());
                // Execute Assert
                String testName = ServiceTestGenerationHelper.getAssertMethodName(tc.getTwo());
                scope.span().setTag(testName, resultToString(pureResult, this.pureModel.getExecutionSupport()));
                TestResult testResult;
                try {
                    Boolean assertResult = (Boolean) assertsClass.getMethod(testName, org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result.class, ExecutionSupport.class).invoke(null, pureResult, pureModel.getExecutionSupport());
                    testResult = assertResult ? TestResult.SUCCESS : TestResult.FAILURE;
                    scope.span().setTag(testName + "_assert", assertResult);
                } catch (Exception e) {
                    StringWriter out = new StringWriter();
                    PrintWriter writer = new PrintWriter(out);
                    e.printStackTrace(writer);
                    e.printStackTrace();
                    testResult = TestResult.ERROR;
                    assertExceptions.put(testName, e);
                    scope.span().setTag(testName + "_assert", out.toString());
                }
                results.put(testName, testResult);
            }
            testRun = new RichServiceTestResult(service.getPath(), results, assertExceptions, null, executionPlan, javaCode);
            scope.span().log("Finished running tests " + results);
            MetricsHandler.observeServerOperation("test_execute", metricsContext, start, System.currentTimeMillis());
        } catch (Exception e) {
            LOGGER.error("Error running tests", e);
            MetricsHandler.incrementErrorCount("test_execute", 0);
            throw (e instanceof RuntimeException) ? (RuntimeException) e : new RuntimeException(e);
        } finally {
            if (execScope != null) {
                execScope.close();
            }
            MetricsHandler.observe("service test execute", start, System.currentTimeMillis());
        }
        return testRun;
    } else {
        return new RichServiceTestResult(this.service.getPath(), Collections.emptyMap(), Collections.emptyMap(), null, executionPlan, "");
    }
}
Also used : ServiceStoreState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreState) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) ExecutionNodeTDSResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeTDSResultHelper) LoggerFactory(org.slf4j.LoggerFactory) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) MutableList(org.eclipse.collections.api.list.MutableList) Maps(org.eclipse.collections.api.factory.Maps) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) RichIterable(org.eclipse.collections.api.RichIterable) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Map(java.util.Map) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) Root_meta_legend_service_metamodel_SingleExecutionTest(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_SingleExecutionTest) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PrintWriter(java.io.PrintWriter) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) ServiceExecutionExtension(org.finos.legend.engine.language.pure.dsl.service.generation.extension.ServiceExecutionExtension) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) ServiceLoader(java.util.ServiceLoader) Iterate(org.eclipse.collections.impl.utility.Iterate) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) Objects(java.util.Objects) ServiceTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) List(java.util.List) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) Optional(java.util.Optional) Scope(io.opentracing.Scope) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) InMemoryStoreState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreState) Assert(org.finos.legend.engine.shared.core.operational.Assert) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) KeyedExecutionParameter(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedExecutionParameter) Lists(org.eclipse.collections.api.factory.Lists) TestExecutionScope(org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope) PlanPlatform(org.finos.legend.engine.plan.platform.PlanPlatform) MutableMap(org.eclipse.collections.api.map.MutableMap) ServicePlanGenerator(org.finos.legend.engine.language.pure.dsl.service.generation.ServicePlanGenerator) JavaHelper(org.finos.legend.engine.plan.execution.nodes.helpers.platform.JavaHelper) Pair(org.eclipse.collections.api.tuple.Pair) MetricsHandler(org.finos.legend.engine.shared.core.operational.prometheus.MetricsHandler) Execution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Execution) Result(org.finos.legend.engine.plan.execution.result.Result) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) GlobalTracer(io.opentracing.util.GlobalTracer) IOException(java.io.IOException) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) ExecutionSupport(org.finos.legend.pure.m3.execution.ExecutionSupport) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) ExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) PureExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureExecution) Class(java.lang.Class) StringJavaSource(org.finos.legend.engine.shared.javaCompiler.StringJavaSource) Collections(java.util.Collections) org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions(org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) Result(org.finos.legend.engine.plan.execution.result.Result) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) InMemoryStoreState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreState) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) TestExecutionScope(org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) IOException(java.io.IOException) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) ServiceStoreState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreState) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) PureExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureExecution) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Example 3 with TestContainer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer in project legend-engine by finos.

the class ServiceTestGenerationHelper method generateJavaForAsserts.

// Java
public static String generateJavaForAsserts(List<TestContainer> asserts, Service service, PureModel pureModel, String packageName, String className) {
    CompileContext compileContext = pureModel.getContext(service);
    ProcessorSupport processorSupport = pureModel.getExecutionSupport().getProcessorSupport();
    ProcessorContext processorContext = new ProcessorContext(processorSupport, false);
    processorContext.setInLineAllLambda(true);
    return "package " + packageName + ";\n" + "\n" + "import org.eclipse.collections.api.RichIterable;\n" + "import org.eclipse.collections.api.list.ListIterable;\n" + "import org.eclipse.collections.impl.factory.Lists;\n" + "import org.eclipse.collections.api.map.MutableMap;\n" + "import org.eclipse.collections.impl.map.mutable.UnifiedMap;\n" + "import org.eclipse.collections.impl.factory.Maps;\n" + "import org.finos.legend.pure.generated.*;\n" + "import org.finos.legend.pure.m3.execution.ExecutionSupport;\n" + "import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.CompiledSupport;\n" + "import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.*;\n" + "import java.util.Map;" + "" + "public class " + className + "\n" + "{\n" + "    private static Map localLambdas = UnifiedMap.newMap();\n" + LazyIterate.collect(asserts, tc -> (InstanceValue) tc._assert.accept(new ValueSpecificationBuilder(compileContext, Lists.mutable.empty(), new ProcessingContext("")))).collect(vs -> ValueSpecificationProcessor.createFunctionForLambda(null, (CoreInstance) vs._values().getAny(), processorSupport, processorContext)).zipWithIndex().collect(tuple -> "    public static boolean " + getAssertMethodName(tuple.getTwo()) + "(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result _res, ExecutionSupport es)\n" + "    {\n" + "        return " + tuple.getOne() + ".value(_res, es);\n" + "    }\n").makeString("", "\n", "}");
}
Also used : DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) MutableList(org.eclipse.collections.api.list.MutableList) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) MediaType(javax.ws.rs.core.MediaType) RichIterable(org.eclipse.collections.api.RichIterable) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) ProcessingContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext) ServiceLoader(java.util.ServiceLoader) Iterate(org.eclipse.collections.impl.utility.Iterate) StandardCharsets(java.nio.charset.StandardCharsets) PackageableElementType(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) Base64(java.util.Base64) List(java.util.List) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) Lists(org.eclipse.collections.impl.factory.Lists) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) Optional(java.util.Optional) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) UrlStreamExternalSource(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource) Function(java.util.function.Function) ConnectionFactoryExtension(org.finos.legend.engine.protocol.pure.v1.extension.ConnectionFactoryExtension) HelperRuntimeBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder) Pair(org.eclipse.collections.api.tuple.Pair) TestDatabaseAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.TestDatabaseAuthenticationStrategy) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder) ListIterate(org.eclipse.collections.impl.utility.ListIterate) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) DataProtocolHandler(org.finos.legend.engine.shared.core.url.DataProtocolHandler) org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions(org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) ValueSpecificationProcessor(org.finos.legend.pure.runtime.java.compiled.generation.processors.valuespecification.ValueSpecificationProcessor) ProcessingContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext)

Example 4 with TestContainer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer in project legend-engine by finos.

the class ServiceTestRunner method executeTests.

public List<RichServiceTestResult> executeTests() throws IOException, JavaCompileException {
    Execution serviceExecution = this.service.execution;
    if (serviceExecution instanceof PureMultiExecution) {
        List<RichServiceTestResult> results = Lists.mutable.empty();
        try (Scope scope = GlobalTracer.get().buildSpan("Generate Tests And Run For MultiExecution Service").startActive(true)) {
            MutableMap<String, KeyedExecutionParameter> executionsByKey = Iterate.groupByUniqueKey(((PureMultiExecution) serviceExecution).executionParameters, e -> e.key);
            for (KeyedSingleExecutionTest es : ((MultiExecutionTest) service.test).tests) {
                List<TestContainer> asserts = es.asserts;
                KeyedExecutionParameter e = executionsByKey.get(es.key);
                PureMultiExecution pureExecution = (PureMultiExecution) service.execution;
                PureSingleExecution pureSingleExecution = new PureSingleExecution();
                pureSingleExecution.func = pureExecution.func;
                pureSingleExecution.mapping = e.mapping;
                pureSingleExecution.runtime = e.runtime;
                pureSingleExecution.executionOptions = e.executionOptions;
                String noAssertMessage = "No test assert found for key - " + es.key + "!!";
                RichServiceTestResult richServiceTestResult = executeSingleExecutionTest(pureSingleExecution, es.data, asserts, noAssertMessage, pureModelContextData, pureModel, scope);
                richServiceTestResult.setOptionalMultiExecutionKey(es.key);
                results.add(richServiceTestResult);
            }
            return results;
        }
    } else if (serviceExecution instanceof PureSingleExecution) {
        try (Scope scope = GlobalTracer.get().buildSpan("Generate Single Pure Tests And Run").startActive(true)) {
            List<TestContainer> asserts = ((SingleExecutionTest) service.test).asserts;
            String noAssertMessage = "No test assert found !!";
            return Collections.singletonList(executeSingleExecutionTest((PureSingleExecution) service.execution, ((SingleExecutionTest) service.test).data, asserts, noAssertMessage, pureModelContextData, pureModel, scope));
        }
    } else {
        try (Scope scope = GlobalTracer.get().buildSpan("Generate Extra Service Execution Tests and Run").startActive(true)) {
            MutableList<ServiceExecutionExtension> serviceExecutionExtensions = Lists.mutable.withAll(ServiceLoader.load(ServiceExecutionExtension.class));
            Pair<ExecutionPlan, RichIterable<? extends String>> testExecutor = getExtraServiceExecutionPlan(serviceExecutionExtensions, serviceExecution, ((Root_meta_legend_service_metamodel_SingleExecutionTest) this.pureService._test())._data());
            ExecutionPlan executionPlan = testExecutor.getOne();
            Assert.assertTrue(executionPlan instanceof SingleExecutionPlan, () -> "Only Single Execution Plan supported");
            List<TestContainer> containers = getExtraServiceTestContainers(serviceExecutionExtensions, service.test);
            return Collections.singletonList(executeTestAsserts((SingleExecutionPlan) executionPlan, containers, testExecutor.getTwo(), scope));
        }
    }
}
Also used : PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) Root_meta_legend_service_metamodel_SingleExecutionTest(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_SingleExecutionTest) Execution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Execution) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) PureExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureExecution) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) ExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan) Scope(io.opentracing.Scope) TestExecutionScope(org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) MutableList(org.eclipse.collections.api.list.MutableList) KeyedExecutionParameter(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedExecutionParameter) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) Pair(org.eclipse.collections.api.tuple.Pair)

Example 5 with TestContainer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer in project legend-engine by finos.

the class ServiceParseTreeWalker method visitTestContainer.

private TestContainer visitTestContainer(ServiceParserGrammar.TestAssertContext ctx) {
    TestContainer testContainer = new TestContainer();
    testContainer.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    testContainer.parametersValues = this.visitTestParameters(ctx.testParameters());
    testContainer._assert = this.visitLambda(ctx.combinedExpression());
    return testContainer;
}
Also used : TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer)

Aggregations

PureSingleExecution (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution)4 List (java.util.List)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Pair (org.eclipse.collections.api.tuple.Pair)3 ExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan)3 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)3 EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)3 LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)3 TestContainer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer)3 Scope (io.opentracing.Scope)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ServiceLoader (java.util.ServiceLoader)2 RichIterable (org.eclipse.collections.api.RichIterable)2 Iterate (org.eclipse.collections.impl.utility.Iterate)2 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)2 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 TestExecutionScope (org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope)2 Runtime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime)2