LongRunningProcessStartTask extends LongRunningProcessTask<List<UUID>> { @Override public List<UUID> call() { ArrayList<UUID> res = new ArrayList<>(); try { for (LongRunningProcess proc : processes) { Future<?> fut = runTask(proc.getTask()); UUID procId = saveProcMetadata(fut); res.add(procId); } } catch (Exception e) { stopAllProcessesAndClearMetadata(res); throw e; } return res; } LongRunningProcessStartTask(List<LongRunningProcess> processes); @Override List<UUID> call();  }
@Test public void testCall() throws ExecutionException, InterruptedException { LongRunningProcess proc = new LongRunningProcess(UUID.randomUUID(), () -> {}); LongRunningProcessStartTask task = createTask(proc); List<UUID> procIds = task.call(); assertEquals(1, procIds.size()); UUID procId = procIds.get(0); assertNotNull(metadataStorage.get(procId)); Future<?> fut = metadataStorage.get(procId); fut.get(); assertEquals(true, fut.isDone()); }
@Test(expected = ExecutionException.class) public void testCallWithException() throws ExecutionException, InterruptedException { LongRunningProcess proc = new LongRunningProcess(UUID.randomUUID(), () -> { throw new RuntimeException(); }); LongRunningProcessStartTask task = createTask(proc); List<UUID> procIds = task.call(); assertEquals(1, procIds.size()); UUID procId = procIds.get(0); assertNotNull(metadataStorage.get(procId)); Future<?> fut = metadataStorage.get(procId); fut.get(); }