LongRunningProcessClearTask extends LongRunningProcessTask<List<LongRunningProcessStatus>> { @Override public List<LongRunningProcessStatus> call() { ArrayList<LongRunningProcessStatus> res = new ArrayList<>(); for (UUID prodId : procIds) res.add(prepareProcessForRemoving(prodId)); removeProcessesFromMetadataStorage(); return res; } LongRunningProcessClearTask(List<UUID> procIds); @Override List<LongRunningProcessStatus> call();  }
@Test public void testCallProcessNotFound() { LongRunningProcessClearTask clearTask = createTask(UUID.randomUUID()); List<LongRunningProcessStatus> statuses = clearTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.NOT_FOUND, status.getState()); assertNull(status.getException()); assertEquals(0, metadataStorage.size()); }
@Test(expected = IllegalStateException.class) public void testCallProcessIsRunning() { UUID procId = UUID.randomUUID(); Future<?> fut = mock(Future.class); doReturn(false).when(fut).isDone(); metadataStorage.put(procId, fut); LongRunningProcessClearTask clearTask = createTask(procId); clearTask.call(); }
@Test public void testCallProcessIsDone() { UUID procId = UUID.randomUUID(); Future<?> fut = mock(Future.class); doReturn(true).when(fut).isDone(); metadataStorage.put(procId, fut); LongRunningProcessClearTask clearTask = createTask(procId); List<LongRunningProcessStatus> statuses = clearTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.DONE, status.getState()); assertNull(status.getException()); assertEquals(0, metadataStorage.size()); }
@Test public void testCallProcessIsDoneWithException() throws ExecutionException, InterruptedException { UUID procId = UUID.randomUUID(); Future<?> fut = mock(Future.class); doReturn(true).when(fut).isDone(); doThrow(RuntimeException.class).when(fut).get(); metadataStorage.put(procId, fut); LongRunningProcessClearTask clearTask = createTask(procId); List<LongRunningProcessStatus> statuses = clearTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.DONE, status.getState()); assertNotNull(status.getException()); assertTrue(status.getException() instanceof RuntimeException); assertEquals(0, metadataStorage.size()); }