use of org.finos.legend.engine.plan.execution.service.test.TestResult 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);
}
use of org.finos.legend.engine.plan.execution.service.test.TestResult 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);
}
}
Aggregations