Search in sources :

Example 1 with SingleTestRun

use of org.finos.legend.engine.plan.execution.service.test.SingleTestRun in project legend-engine by finos.

the class ServiceModeling method executeTests.

private static TestRun executeTests(Service service, Root_meta_legend_service_metamodel_Service pureService, Pair<PureModelContextData, PureModel> pureModelPairs, String pureVersion, String metricsContext) throws IOException, JavaCompileException {
    MutableList<PlanGeneratorExtension> extensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
    RichIterable<? extends Root_meta_pure_router_extension_RouterExtension> routerExtensions = extensions.flatCollect(e -> e.getExtraRouterExtensions(pureModelPairs.getTwo()));
    MutableList<PlanTransformer> planTransformers = extensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers);
    ServiceTestRunner runner = new ServiceTestRunner(service, pureService, pureModelPairs.getOne(), pureModelPairs.getTwo(), objectMapper, planExecutor, routerExtensions, planTransformers, pureVersion, metricsContext);
    RichServiceTestResult richServiceTestResult = runner.executeTests().get(0);
    Map<String, Boolean> results = Maps.mutable.empty();
    for (Map.Entry<String, org.finos.legend.engine.test.runner.shared.TestResult> entry : richServiceTestResult.getResults().entrySet()) {
        Boolean testResult = entry.getValue().equals(org.finos.legend.engine.test.runner.shared.TestResult.SUCCESS);
        results.put(entry.getKey(), testResult);
    }
    return new SingleTestRun(richServiceTestResult.getExecutionPlan(), new JavaCode(richServiceTestResult.getJavaCodeString()), results);
}
Also used : PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) ServiceTestRunner(org.finos.legend.engine.test.runner.service.ServiceTestRunner) JavaCode(org.finos.legend.engine.plan.execution.service.test.JavaCode) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) Map(java.util.Map) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun)

Example 2 with SingleTestRun

use of org.finos.legend.engine.plan.execution.service.test.SingleTestRun in project legend-engine by finos.

the class ServiceModeling method testService.

@Prometheus(name = "service test model resolve", doc = "Model resolution duration summary within service test execution")
public List<TestResult> testService(MutableList<CommonProfile> profiles, PureModelContext context, String metricsContext) {
    try {
        long start = System.currentTimeMillis();
        PureModelContextData data = ((PureModelContextData) context).shallowCopy();
        Service service = (Service) Iterate.detect(data.getElements(), e -> e instanceof Service);
        PureModelContextData dataWithoutService = PureModelContextData.newBuilder().withOrigin(data.getOrigin()).withSerializer(data.getSerializer()).withElements(LazyIterate.select(data.getElements(), e -> e != service)).build();
        PureModel pureModel = new PureModel(dataWithoutService, profiles, deploymentMode);
        Pair<PureModelContextData, PureModel> pureModelAndData = Tuples.pair(dataWithoutService, pureModel);
        long end = System.currentTimeMillis();
        MetricsHandler.observe("service test model resolve", start, end);
        MetricsHandler.observeServerOperation("model_resolve", metricsContext, start, end);
        if (service.execution instanceof PureMultiExecution) {
            throw new UnsupportedOperationException("MultiExecutions not yet supported");
        }
        Root_meta_legend_service_metamodel_Service pureService = compileService(service, pureModel.getContext(service));
        TestRun testRun = executeTests(service, pureService, pureModelAndData, PureClientVersions.production, metricsContext);
        if (!(testRun instanceof SingleTestRun)) {
            throw new UnsupportedOperationException("Expected a single test run result");
        }
        return ((SingleTestRun) testRun).results.entrySet().stream().map(x -> new TestResult(x.getKey(), x.getValue())).collect(Collectors.toList());
    } catch (IOException | JavaCompileException e) {
        MetricsHandler.incrementErrorCount("model_resolve", 0);
        throw new RuntimeException(e);
    }
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) CommonProfile(org.pac4j.core.profile.CommonProfile) TestRun(org.finos.legend.engine.plan.execution.service.test.TestRun) Lists(org.eclipse.collections.api.factory.Lists) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) MutableList(org.eclipse.collections.api.list.MutableList) PackageableElementSecondPassBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.PackageableElementSecondPassBuilder) 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) Tuples(org.eclipse.collections.impl.tuple.Tuples) Package(org.finos.legend.pure.m3.coreinstance.Package) Pair(org.eclipse.collections.api.tuple.Pair) MetricsHandler(org.finos.legend.engine.shared.core.operational.prometheus.MetricsHandler) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) Relational(org.finos.legend.engine.plan.execution.stores.relational.plugin.Relational) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus) PackageableElementFirstPassBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.PackageableElementFirstPassBuilder) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) PureClientVersions(org.finos.legend.engine.protocol.pure.PureClientVersions) Iterate(org.eclipse.collections.impl.utility.Iterate) Collectors(java.util.stream.Collectors) JavaCode(org.finos.legend.engine.plan.execution.service.test.JavaCode) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) InMemory(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemory) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) List(java.util.List) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) ServiceTestRunner(org.finos.legend.engine.test.runner.service.ServiceTestRunner) 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) DeploymentMode(org.finos.legend.engine.shared.core.deployment.DeploymentMode) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) ServiceStore(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStore) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) IOException(java.io.IOException) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) TestRun(org.finos.legend.engine.plan.execution.service.test.TestRun) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Aggregations

Map (java.util.Map)2 JavaCode (org.finos.legend.engine.plan.execution.service.test.JavaCode)2 SingleTestRun (org.finos.legend.engine.plan.execution.service.test.SingleTestRun)2 TestResult (org.finos.legend.engine.plan.execution.service.test.TestResult)2 PlanGeneratorExtension (org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension)2 PlanTransformer (org.finos.legend.engine.plan.generation.transformers.PlanTransformer)2 RichServiceTestResult (org.finos.legend.engine.test.runner.service.RichServiceTestResult)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1 ServiceLoader (java.util.ServiceLoader)1 Collectors (java.util.stream.Collectors)1 RichIterable (org.eclipse.collections.api.RichIterable)1 Lists (org.eclipse.collections.api.factory.Lists)1 MutableList (org.eclipse.collections.api.list.MutableList)1 Pair (org.eclipse.collections.api.tuple.Pair)1 Maps (org.eclipse.collections.impl.factory.Maps)1 Tuples (org.eclipse.collections.impl.tuple.Tuples)1 Iterate (org.eclipse.collections.impl.utility.Iterate)1 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)1