/** * @return number of executions of the step within given job instance */ @Override public int getStepExecutionCount(JobInstance jobInstance, String stepName) { int count = 0; List<JobExecution> jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); for (JobExecution jobExecution : jobExecutions) { stepExecutionDao.addStepExecutions(jobExecution); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (stepName.equals(stepExecution.getStepName())) { count++; } } } return count; }
/** * Long exit descriptions are truncated on both save and update. */ @Transactional @Test public void testTruncateExitDescription() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.append("too long exit description"); } String longDescription = sb.toString(); ExitStatus exitStatus = ExitStatus.FAILED.addExitDescription(longDescription); stepExecution.setExitStatus(exitStatus); ((JdbcStepExecutionDao) dao).setExitMessageLength(250); dao.saveStepExecution(stepExecution); StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, stepExecution.getId()); assertTrue("Exit description should be truncated", retrievedAfterSave.getExitStatus().getExitDescription() .length() < stepExecution.getExitStatus().getExitDescription().length()); dao.updateStepExecution(stepExecution); StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, stepExecution.getId()); assertTrue("Exit description should be truncated", retrievedAfterUpdate.getExitStatus().getExitDescription() .length() < stepExecution.getExitStatus().getExitDescription().length()); }
@Override public void addAll(Collection<StepExecution> stepExecutions) { Assert.notNull(stepExecutions, "Attempt to save a null collection of step executions"); for (StepExecution stepExecution : stepExecutions) { validateStepExecution(stepExecution); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); } stepExecutionDao.saveStepExecutions(stepExecutions); ecDao.saveExecutionContexts(stepExecutions); }
@Transactional @Test public void testSaveAndFindExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7); stepExecution.setWriteSkipCount(5); stepExecution.setRollbackCount(3); dao.saveStepExecution(stepExecution); dao.addStepExecutions(jobExecution); Collection<StepExecution> retrieved = jobExecution.getStepExecutions(); assertStepExecutionsAreEqual(stepExecution, retrieved.iterator().next()); }
tested.saveStepExecution(stepExecution); assertNotNull(stepExecution.getId()); tested.addStepExecutions(jobExecution); assertEquals(1, jobExecution.getStepExecutions().size()); StepExecution repoStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId()); assertEquals(stepExecution.getId(), repoStepExecution.getId()); assertEquals(BatchStatus.STARTED, repoStepExecution.getStatus()); tested.updateStepExecution(repoStepExecution); StepExecution updatedStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId()); assertEquals(stepExecution.getId(), updatedStepExecution.getId()); assertEquals(BatchStatus.COMPLETED, updatedStepExecution.getStatus()); tested.addStepExecutions(jobExecution);
@Override public void add(StepExecution stepExecution) { validateStepExecution(stepExecution); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecutionDao.saveStepExecution(stepExecution); ecDao.saveExecutionContext(stepExecution); }
@Override public StepExecution getStepExecution(Long jobExecutionId, Long executionId) { JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId); if (jobExecution == null) { return null; } getJobExecutionDependencies(jobExecution); StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, executionId); getStepExecutionDependencies(stepExecution); return stepExecution; }
@Override public void update(StepExecution stepExecution) { validateStepExecution(stepExecution); Assert.notNull(stepExecution.getId(), "StepExecution must already be saved (have an id assigned)"); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecutionDao.updateStepExecution(stepExecution); checkForInterruption(stepExecution); }
/** * Exception should be raised when the version of update argument doesn't * match the version of persisted entity. */ @Transactional @Test public void testConcurrentModificationException() { step = new StepSupport("foo"); StepExecution exec1 = new StepExecution(step.getName(), jobExecution); dao.saveStepExecution(exec1); StepExecution exec2 = new StepExecution(step.getName(), jobExecution); exec2.setId(exec1.getId()); exec2.incrementVersion(); assertEquals(new Integer(0), exec1.getVersion()); assertEquals(exec1.getVersion(), exec2.getVersion()); dao.updateStepExecution(exec1); assertEquals(new Integer(1), exec1.getVersion()); try { dao.updateStepExecution(exec2); fail(); } catch (OptimisticLockingFailureException e) { // expected } }
@Transactional @Test public void testSaveAndGetExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7); stepExecution.setProcessSkipCount(2); stepExecution.setWriteSkipCount(5); stepExecution.setProcessSkipCount(11); stepExecution.setRollbackCount(3); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecution.setReadCount(17); stepExecution.setFilterCount(15); stepExecution.setWriteCount(13); dao.saveStepExecution(stepExecution); StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecution.getId()); assertStepExecutionsAreEqual(stepExecution, retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); }
@Transactional @Test public void testSaveAndGetExecutions() { List<StepExecution> stepExecutions = new ArrayList<>(); for (int i = 0; i < 3; i++) { StepExecution se = new StepExecution("step" + i, jobExecution); se.setStatus(BatchStatus.STARTED); se.setReadSkipCount(i); se.setProcessSkipCount(i); se.setWriteSkipCount(i); se.setProcessSkipCount(i); se.setRollbackCount(i); se.setLastUpdated(new Date(System.currentTimeMillis())); se.setReadCount(i); se.setFilterCount(i); se.setWriteCount(i); stepExecutions.add(se); } dao.saveStepExecutions(stepExecutions); for (int i = 0; i < 3; i++) { StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecutions.get(i).getId()); assertStepExecutionsAreEqual(stepExecutions.get(i), retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); } }
/** * To-be-saved execution must not already have an id. */ @Transactional @Test public void testSaveExecutionWithIdAlreadySet() { stepExecution.setId((long) 7); try { dao.saveStepExecution(stepExecution); fail(); } catch (IllegalArgumentException e) { // expected } }
@Transactional @Test public void testSaveAndGetNonExistentExecution() { assertNull(dao.getStepExecution(jobExecution, 45677L)); }
@Override public void updateExecutionContext(StepExecution stepExecution) { stepExecutionDao.updateStepExecution(stepExecution); }
/** * Modifications to saved entity do not affect the persisted object. */ @Test public void testPersistentCopy() { StepExecutionDao tested = new MapStepExecutionDao(); JobExecution jobExecution = new JobExecution(77L); StepExecution stepExecution = new StepExecution("stepName", jobExecution); assertNull(stepExecution.getEndTime()); tested.saveStepExecution(stepExecution); stepExecution.setEndTime(new Date()); StepExecution retrieved = tested.getStepExecution(jobExecution, stepExecution.getId()); assertNull(retrieved.getEndTime()); stepExecution.setEndTime(null); tested.updateStepExecution(stepExecution); stepExecution.setEndTime(new Date()); StepExecution stored = tested.getStepExecution(jobExecution, stepExecution.getId()); assertNull(stored.getEndTime()); }
@Override @Nullable public JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) { JobInstance jobInstance = jobInstanceDao.getJobInstance(jobName, jobParameters); if (jobInstance == null) { return null; } JobExecution jobExecution = jobExecutionDao.getLastJobExecution(jobInstance); if (jobExecution != null) { jobExecution.setExecutionContext(ecDao.getExecutionContext(jobExecution)); stepExecutionDao.addStepExecutions(jobExecution); } return jobExecution; }
/** * To-be-saved execution must not already have a version. */ @Transactional @Test public void testSaveExecutionWithVersionAlreadySet() { stepExecution.incrementVersion(); try { dao.saveStepExecution(stepExecution); fail(); } catch (IllegalArgumentException e) { // expected } }
@Test public void testGetStepExecutionMissing() throws Exception { when(jobExecutionDao.getJobExecution(jobExecution.getId())).thenReturn(jobExecution); when(stepExecutionDao.getStepExecution(jobExecution, 123L)) .thenReturn(null); assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L)); }
@Override public void saveExecutionContext(StepExecution stepExecution) { stepExecution.incrementVersion(); stepExecutionDao.updateStepExecution(stepExecution); }
@Transactional @Test(expected = IllegalArgumentException.class) public void testSaveNullCollectionThrowsException() { dao.saveStepExecutions(null); }