AsyncJobStatusCurator extends AbstractHibernateCurator<AsyncJobStatus> { public List<AsyncJobStatus> getJobsInState(Collection<JobState> states) { if (states != null && !states.isEmpty()) { String jpql = "SELECT aj FROM AsyncJobStatus aj WHERE aj.state IN (:states)"; return this.getEntityManager() .createQuery(jpql, AsyncJobStatus.class) .setParameter("states", states) .getResultList(); } return new ArrayList<>(); } 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 testGetJobsInStateSingleState() { int perState = 3; this.createJobsInStates("test_job-", perState, JobState.values()); List<AsyncJobStatus> result; int counter = 0; for (JobState state : JobState.values()) { result = this.asyncJobCurator.getJobsInState(state); assertNotNull(result); assertEquals(perState, result.size()); for (AsyncJobStatus status : result) { assertEquals("test_job-" + ++counter, status.getName()); } } }
@Test public void testGetJobsInStateMultiState() { int perState = 3; int statesPerLoop = 2; this.createJobsInStates("test_job-", perState, JobState.values()); List<AsyncJobStatus> result; int counter = 0; JobState[] states = JobState.values(); int extra = states.length % statesPerLoop; int max = states.length - extra; for (int i = 0; i < max; i += statesPerLoop) { JobState[] group = Arrays.copyOfRange(states, i, i + statesPerLoop); result = this.asyncJobCurator.getJobsInState(group); assertNotNull(result); assertEquals(perState * statesPerLoop, result.size()); for (AsyncJobStatus status : result) { assertEquals("test_job-" + ++counter, status.getName()); } } }
@Test public void testGetJobsInStateSingleStateAsCollection() { int perState = 3; this.createJobsInStates("test_job-", perState, JobState.values()); List<AsyncJobStatus> result; int counter = 0; for (JobState state : JobState.values()) { result = this.asyncJobCurator.getJobsInState(Arrays.asList(state)); assertNotNull(result); assertEquals(perState, result.size()); for (AsyncJobStatus status : result) { assertEquals("test_job-" + ++counter, status.getName()); } } }
@Test public void testGetJobsInStateMultiStateAsCollection() { int perState = 3; int statesPerLoop = 2; this.createJobsInStates("test_job-", perState, JobState.values()); List<AsyncJobStatus> result; int counter = 0; JobState[] states = JobState.values(); int extra = states.length % statesPerLoop; int max = states.length - extra; for (int i = 0; i < max; i += statesPerLoop) { JobState[] group = Arrays.copyOfRange(states, i, i + statesPerLoop); result = this.asyncJobCurator.getJobsInState(Arrays.asList(group)); assertNotNull(result); assertEquals(perState * statesPerLoop, result.size()); for (AsyncJobStatus status : result) { assertEquals("test_job-" + ++counter, status.getName()); } } }