PollableTaskService { @Transactional(propagation = Propagation.REQUIRES_NEW) public PollableTask finishTask(long id, String messageOverride, ExceptionHolder exceptionHolder, Integer expectedSubTaskNumberOverride) { PollableTask pollableTask = getPollableTask(id); pollableTask.setFinishedDate(DateTime.now()); if (exceptionHolder != null && exceptionHolder.getException() != null) { pollableTask.setErrorStack(Throwables.getStackTraceAsString(exceptionHolder.getException())); pollableTask.setErrorMessage(objectMapper.writeValueAsStringUnchecked(exceptionHolder)); } if (messageOverride != null) { pollableTask.setMessage(messageOverride); } if (expectedSubTaskNumberOverride != null) { pollableTask.setExpectedSubTaskNumber(expectedSubTaskNumberOverride); } return pollableTaskRepository.save(pollableTask); }  @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) PollableTask getPollableTask(long id); PollableTask createPollableTask(Long parentId, String name, String message, int expectedSubTaskNumber); @Transactional(propagation = Propagation.REQUIRES_NEW) PollableTask createPollableTask(Long parentId, String name, String message, int expectedSubTaskNumber, long timeout); @Transactional(propagation = Propagation.REQUIRES_NEW) PollableTask finishTask(long id, String messageOverride, ExceptionHolder exceptionHolder, Integer expectedSubTaskNumberOverride); @Transactional(propagation = Propagation.REQUIRES_NEW) PollableTask updateExpectedSubTaskNumber(long id, int expectedSubTaskNumber); PollableTask waitForPollableTask(Long pollableId); PollableTask waitForPollableTask(Long pollableId, long timeout); PollableTask waitForPollableTask(Long pollableId, long timeout, long sleepTime); List<PollableTask> getAllPollableTasksWithError(PollableTask pollableTask); final static Long NO_TIMEOUT; }
@Test public void testFinishTask() { PollableTask createPollableTask = pollableTaskService.createPollableTask(null, testIdWatcher.getEntityName("testFinishTask"), null, 2); assertNull(createPollableTask.getMessage()); assertEquals(2, createPollableTask.getExpectedSubTaskNumber()); String message = "<iframe src=\"https: pollableTaskService.finishTask(createPollableTask.getId(), message, null, null); PollableTask pollableTask = pollableTaskService.getPollableTask(createPollableTask.getId()); assertEquals(message, pollableTask.getMessage()); assertEquals(2, pollableTask.getExpectedSubTaskNumber()); pollableTaskService.finishTask(createPollableTask.getId(), null, null, 5); pollableTask = pollableTaskService.getPollableTask(createPollableTask.getId()); assertEquals(message, pollableTask.getMessage()); assertEquals(5, pollableTask.getExpectedSubTaskNumber()); }