/** * Constructor with mandatory properties. * * @param stepName the step to which this execution belongs * @param jobExecution the current job execution * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { this(stepName, jobExecution); Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); setId(id); jobExecution.addStepExecution(this); }
/** * Create a {@link StepExecution} with the parameters provided. * * @param jobExecution instance of {@link JobExecution}. * @param stepName the name for the {@link StepExecution}. * @param executionId the id for the {@link StepExecution}. * @return a {@link StepExecution} with the given {@link JobExecution}. */ public static StepExecution createStepExecution(JobExecution jobExecution, String stepName, Long executionId) { StepExecution stepExecution = jobExecution.createStepExecution(stepName); stepExecution.setId(executionId); return stepExecution; }
@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@Override public void add(StepExecution stepExecution) { if (stepExecution.getId() == null) { stepExecution.setId(counter); counter++; } }
/** * 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 } }
@Test public void testGetStepExecutionSummariesSunnyDay() throws Exception { jobParameters = new JobParameters(); JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null); jobExecution.createStepExecution("step1"); jobExecution.createStepExecution("step2"); jobExecution.getStepExecutions().iterator().next().setId(21L); when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution); Map<Long, String> value = jobOperator.getStepExecutionSummaries(111L); assertEquals(2, value.size()); }
@Test public void testUpdateStepExecutionSetsLastUpdated(){ StepExecution stepExecution = new StepExecution("stepName", jobExecution); stepExecution.setId(2343L); long before = System.currentTimeMillis(); jobRepository.update(stepExecution); assertNotNull(stepExecution.getLastUpdated()); long lastUpdated = stepExecution.getLastUpdated().getTime(); assertTrue(lastUpdated > (before - 1000)); }
@Test public void testTransactionalSaveUpdate() throws Exception { final StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); return null; } }); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }
@Test public void testInterrupted(){ jobExecution.setStatus(BatchStatus.STOPPING); StepExecution stepExecution = new StepExecution("stepName", jobExecution); stepExecution.setId(323L); jobRepository.update(stepExecution); assertTrue(stepExecution.isTerminateOnly()); }
private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) { Assert.isNull(stepExecution.getId(), "to-be-saved (not updated) StepExecution can't already have an id assigned"); Assert.isNull(stepExecution.getVersion(), "to-be-saved (not updated) StepExecution can't already have a version assigned"); validateStepExecution(stepExecution); stepExecution.setId(stepExecutionIncrementer.nextLongValue()); stepExecution.incrementVersion(); //Should be 0 List<Object[]> parameters = new ArrayList<>(); String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription()); Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(), stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() }; Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP }; parameters.add(0, Arrays.copyOf(parameterValues,parameterValues.length)); parameters.add(1, Arrays.copyOf(parameterTypes,parameterTypes.length)); return parameters; }
@Test public void testSaveUpdate() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }
/** * 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 } }
@Before public void setUp() throws Exception { JobExecution jobExecution = new JobExecution(1L, new JobParametersBuilder().addString("key", "value").toJobParameters()); stepExecution = new StepExecution("testStep", jobExecution); stepExecution.setId(5L); stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setExitStatus(new ExitStatus("customExitStatus")); stepExecution.setCommitCount(1); stepExecution.setFilterCount(2); stepExecution.setProcessSkipCount(3); stepExecution.setReadCount(4); stepExecution.setReadSkipCount(5); stepExecution.setRollbackCount(6); stepExecution.setWriteCount(7); stepExecution.setWriteSkipCount(8); executionContext = new ExecutionContext(); stepExecution.setExecutionContext(executionContext); Properties properties = new Properties(); properties.put("key", "value"); stepContext = new JsrStepContext(stepExecution, properties); stepContext.setTransientUserData("This is my transient data"); }
@Before public void setUp() throws Exception { JobExecution jobExecution = new JobExecution(1L, new JobParametersBuilder().addString("key", "value").toJobParameters()); stepExecution = new StepExecution("testStep", jobExecution); stepExecution.setId(5L); stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setExitStatus(new ExitStatus("customExitStatus")); stepExecution.setCommitCount(1); stepExecution.setFilterCount(2); stepExecution.setProcessSkipCount(3); stepExecution.setReadCount(4); stepExecution.setReadSkipCount(5); stepExecution.setRollbackCount(6); stepExecution.setWriteCount(7); stepExecution.setWriteSkipCount(8); stepExecution.setStartTime(new Date(0)); stepExecution.setEndTime(new Date(10000000)); stepExecution.getExecutionContext().put(executionContextUserSupport.getKey("batch_jsr_persistentUserData"), "persisted data"); jsrStepExecution = new JsrStepExecution(stepExecution); }
/** * Create a {@link StepExecution} with the parameters provided. * * @param stepName the stepName for the {@link StepExecution} * @param executionId the id for the {@link StepExecution} * @return a {@link StepExecution} with the given {@link JobExecution} */ public static StepExecution createStepExecution(JobExecution jobExecution, String stepName, Long executionId) { StepExecution stepExecution = jobExecution.createStepExecution(stepName); stepExecution.setId(executionId); return stepExecution; }
/** * Constructor with mandatory properties. * * @param stepName the step to which this execution belongs * @param jobExecution the current job execution * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { this(stepName, jobExecution); Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); setId(id); jobExecution.addStepExecution(this); }
/** * Constructor with mandatory properties. * * @param stepName the step to which this execution belongs * @param jobExecution the current job execution * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { this(stepName, jobExecution); Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); setId(id); jobExecution.addStepExecution(this); }
/** * Constructor with mandatory properties. * * @param stepName the step to which this execution belongs * @param jobExecution the current job execution * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { this(stepName, jobExecution); Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); setId(id); jobExecution.addStepExecution(this); }
/** * Constructor with mandatory properties. * * @param stepName the step to which this execution belongs * @param jobExecution the current job execution * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { this(stepName, jobExecution); Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); setId(id); jobExecution.addStepExecution(this); }