PollableTaskCleanupService { public void finishZombieTasksWithError() { List<PollableTask> zombiePollableTasks; do { logger.debug("Fetching 5 zombie pollable tasks to clean up"); PageRequest pageable = PageRequest.of(0, 5); zombiePollableTasks = pollableTaskRepository.findZombiePollableTasks(pageable); for (PollableTask zombiePollableTask : zombiePollableTasks) { markAsFinishedWithError(zombiePollableTask); } } while (!zombiePollableTasks.isEmpty()); }  void finishZombieTasksWithError();  }
@Test public void testMarkZombieTasksAsFinishedWithErrorWithZombies() throws Exception { PollableTask pollableTask = pollableTaskService.createPollableTask(null, "test-pollable", null, 0, 1); PollableTask pollableTaskInPast = setPollableTaskCreatedDateInPast(pollableTask); assertFalse(isMarkedAsZombie(pollableTaskInPast)); pollableTaskCleanupService.finishZombieTasksWithError(); PollableTask pollableTaskAfterCleanup = pollableTaskService.getPollableTask(pollableTaskInPast.getId()); try { assertTrue(isMarkedAsZombie(pollableTaskAfterCleanup)); } catch(AssertionError ae) { logger.error("Make sure the server is configure in UTC"); throw ae; } }
@Test public void testMarkZombieTasksAsFinishedWithErrorWithoutZombies() throws Exception { PollableTask pollableTask = pollableTaskService.createPollableTask(null, "test-pollable", null, 0); pollableTaskService.finishTask(pollableTask.getId(), null, null, null); assertFalse(isMarkedAsZombie(pollableTask)); pollableTaskCleanupService.finishZombieTasksWithError(); PollableTask pollableTaskAfterCleanup = pollableTaskService.getPollableTask(pollableTask.getId()); assertFalse(isMarkedAsZombie(pollableTaskAfterCleanup)); }