@Test
public void distributedAfter() throws IOException {

    JsonSecurityAnalysisResultExporter exporter = new JsonSecurityAnalysisResultExporter();
    try (Writer writer = Files.newBufferedWriter(workingDir.resolve("task_0_result.json"))) {
        exporter.export(resultForContingency("c1"), writer);
    }
    SecurityAnalysisExecutionInput input = new SecurityAnalysisExecutionInput();
    ExecutionHandler<SecurityAnalysisResult> handler3 = SecurityAnalysisExecutionHandlers.distributed(input, 2);
    assertThatExceptionOfType(ComputationException.class).isThrownBy(() -> {
        Command cmd = Mockito.mock(Command.class);
        handler3.after(workingDir, new DefaultExecutionReport(Collections.singletonList(new ExecutionError(cmd, 0, 42))));
    })
        .withMessageContaining("An error occurred during security analysis command execution")
        .withStackTraceContaining("Error during the execution in directory  /work exit codes: Task 0 : 42");
    try (Writer writer = Files.newBufferedWriter(workingDir.resolve("task_1_result.json"))) {
        exporter.export(resultForContingency("c2"), writer);
    }
    ExecutionHandler<SecurityAnalysisResult> handler = SecurityAnalysisExecutionHandlers.distributed(input, 2);
    SecurityAnalysisResult result = handler.after(workingDir, new DefaultExecutionReport());
    assertNotNull(result);
    assertTrue(result.getPreContingencyResult().isComputationOk());
    assertTrue(result.getPreContingencyResult().getLimitViolations().isEmpty());
    assertEquals(2, result.getPostContingencyResults().size());
    assertEquals("c1", result.getPostContingencyResults().get(0).getContingency().getId());
    assertEquals("c2", result.getPostContingencyResults().get(1).getContingency().getId());
}