LongRunningProcessPingTask extends LongRunningProcessTask<List<LongRunningProcessStatus>> { @Override public List<LongRunningProcessStatus> call() { ArrayList<LongRunningProcessStatus> statuses = new ArrayList<>(); for (UUID procId : procIds) statuses.add(getProcessStatus(procId)); return statuses; } LongRunningProcessPingTask(List<UUID> procIds); @Override List<LongRunningProcessStatus> call();  }
@Test public void testCallProcessNotFound() { LongRunningProcessPingTask pingTask = createTask(UUID.randomUUID()); List<LongRunningProcessStatus> statuses = pingTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.NOT_FOUND, status.getState()); assertNull(status.getException()); assertEquals(0, metadataStorage.size()); }
@Test public void testCallProcessIsRunning() { UUID procId = UUID.randomUUID(); Future<?> fut = mock(Future.class); doReturn(false).when(fut).isDone(); metadataStorage.put(procId, fut); LongRunningProcessPingTask pingTask = createTask(procId); List<LongRunningProcessStatus> statuses = pingTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.RUNNING, status.getState()); assertNull(status.getException()); assertEquals(1, metadataStorage.size()); }
@Test public void testCallProcessIsDone() { UUID procId = UUID.randomUUID(); Future<?> fut = mock(Future.class); doReturn(true).when(fut).isDone(); metadataStorage.put(procId, fut); LongRunningProcessPingTask pingTask = createTask(procId); List<LongRunningProcessStatus> statuses = pingTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.DONE, status.getState()); assertNull(status.getException()); assertEquals(1, 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); LongRunningProcessPingTask pingTask = createTask(procId); List<LongRunningProcessStatus> statuses = pingTask.call(); assertEquals(1, statuses.size()); LongRunningProcessStatus status = statuses.get(0); assertEquals(LongRunningProcessState.DONE, status.getState()); assertNotNull(status.getException()); assertTrue(status.getException() instanceof RuntimeException); assertEquals(1, metadataStorage.size()); }