DistributedSecurityAnalysis extends ExternalSecurityAnalysis { @Override public CompletableFuture<SecurityAnalysisResult> run(String workingVariantId, SecurityAnalysisParameters parameters, ContingenciesProvider contingenciesProvider) { LOGGER.debug("Starting distributed security analysis."); ExecutionEnvironment itoolsEnv = new ExecutionEnvironment(Collections.emptyMap(), "security_analysis_task_", config.isDebug()); SecurityAnalysisExecutionInput input = buildInput(workingVariantId, parameters, contingenciesProvider); List<Contingency> contingencies = contingenciesProvider.getContingencies(network); int actualTaskCount = Math.min(taskCount, Math.max(1, contingencies.size())); return computationManager.execute(itoolsEnv, SecurityAnalysisExecutionHandlers.distributed(input, actualTaskCount)); } DistributedSecurityAnalysis(ExternalSecurityAnalysisConfig config, Network network,
                                       ComputationManager computationManager, List<String> extensions, int taskCount); @Override CompletableFuture<SecurityAnalysisResult> run(String workingVariantId, SecurityAnalysisParameters parameters, ContingenciesProvider contingenciesProvider); @Override CompletableFuture<SecurityAnalysisResultWithLog> runWithLog(String workingVariantId, SecurityAnalysisParameters parameters, ContingenciesProvider contingenciesProvider);  }
@Test public void testDistributed() throws IOException { ExternalSecurityAnalysisConfig config = new ExternalSecurityAnalysisConfig(); SecurityAnalysis analysis = new DistributedSecurityAnalysis(config, network, cm, Collections.emptyList(), 5); analysis.run(VariantManagerConstants.INITIAL_VARIANT_ID, new SecurityAnalysisParameters(), contingencies); checkInvocationOnExecutionHandler(workingDir); checkWorkingDirContent(); }
@Test public void testExternal() throws IOException { ExternalSecurityAnalysisConfig config = new ExternalSecurityAnalysisConfig(); SecurityAnalysis analysis = new ExternalSecurityAnalysis(config, network, cm, Collections.emptyList(), 5); analysis.run(VariantManagerConstants.INITIAL_VARIANT_ID, new SecurityAnalysisParameters(), contingencies); ArgumentCaptor<ExecutionHandler> capt = ArgumentCaptor.forClass(ExecutionHandler.class); verify(cm, times(1)).execute(any(), capt.capture()); List<CommandExecution> cmd = capt.getValue().before(workingDir); checkWorkingDirContent(); assertEquals(1, cmd.size()); assertEquals(1, cmd.get(0).getExecutionCount()); }