AsyncJobStatusCurator extends AbstractHibernateCurator<AsyncJobStatus> { public List<AsyncJobStatus> getNonTerminalJobs() { Collection<JobState> states = Arrays.stream(JobState.values()) .filter(s -> !s.isTerminal()) .collect(Collectors.toSet()); return this.getJobsInState(states); } AsyncJobStatusCurator(); List<AsyncJobStatus> getJobsInState(Collection<JobState> states); List<AsyncJobStatus> getJobsInState(JobState... states); List<AsyncJobStatus> getNonTerminalJobs(); List<AsyncJobStatus> findJobs(AsyncJobStatusQueryBuilder queryBuilder); long getJobCount(AsyncJobStatusQueryBuilder queryBuilder); int deleteJobs(AsyncJobStatusQueryBuilder queryBuilder); int updateJobState(AsyncJobStatusQueryBuilder queryBuilder, JobState state); List<String> fetchJobIdsByArguments(String jobKey, Map<String, String> arguments); static final int MAX_JOB_ARGUMENTS_PER_QUERY; }
@Test public void testGetJobsInNonTerminalStates() { int perState = 3; this.createJobsInStates("test_job-", perState, JobState.values()); List<JobState> nonTerminals = new LinkedList<>(); for (JobState state : JobState.values()) { if (!state.isTerminal()) { nonTerminals.add(state); } } List<AsyncJobStatus> result = this.asyncJobCurator.getNonTerminalJobs(); assertNotNull(result); assertEquals(perState * nonTerminals.size(), result.size()); for (AsyncJobStatus status : result) { assertTrue(nonTerminals.contains(status.getState())); } }