@Override public long getStepExecutionId() { return stepExecution.getId(); }
@Override public boolean equals(Object obj) { Object jobExecutionId = getJobExecutionId(); if (jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { return super.equals(obj); } StepExecution other = (StepExecution) obj; return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId())) && getId().equals(other.getId()); }
@Override public int hashCode() { Object jobExecutionId = getJobExecutionId(); Long id = getId(); return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0); }
@Override public void updateExecutionContext(StepExecution stepExecution) { validateStepExecution(stepExecution); Assert.notNull(stepExecution.getId(), "StepExecution must already be saved (have an id assigned)"); ecDao.updateExecutionContext(stepExecution); }
@Override public ExecutionContext getExecutionContext(StepExecution stepExecution) { return copy(contexts.get(ContextKey.step(stepExecution.getId()))); }
@Override public void saveExecutionContext(StepExecution stepExecution) { Long executionId = stepExecution.getId(); ExecutionContext executionContext = stepExecution.getExecutionContext(); Assert.notNull(executionId, "ExecutionId must not be null."); Assert.notNull(executionContext, "The ExecutionContext must not be null."); String serializedContext = serializeContext(executionContext); persistSerializedContext(executionId, serializedContext, INSERT_STEP_EXECUTION_CONTEXT); }
@Override public Map<Long, String> getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); Map<Long, String> map = new LinkedHashMap<>(); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { map.put(stepExecution.getId(), stepExecution.toString()); } return map; }
@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); }
@Override public void updateExecutionContext(StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); if (executionContext != null) { contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext)); } }
@Override public void updateExecutionContext(StepExecution stepExecution) { Assert.state(stepExecution.getId() != null, "StepExecution must already be saved"); saved = stepExecution.getExecutionContext(); }
@Override public void add(StepExecution stepExecution) { if (stepExecution.getId() == null) { stepExecution.setId(counter); counter++; } }
@Override public RepeatStatus doInChunkContext(RepeatContext context, ChunkContext chunkContext) throws Exception { assertEquals(Long.valueOf(123), chunkContext.getStepContext().getStepExecution().getId()); return RepeatStatus.FINISHED; } };
@Test public void testStepExecution() { assertNull(new StepExecution("step", null).getId()); }
@Test public void testHashCodeWithNullIds() throws Exception { assertTrue("Hash code not same as parent", new Entity(execution.getId()).hashCode() != blankExecution .hashCode()); }
@Test public void testHashCode() throws Exception { assertTrue("Hash code same as parent", new Entity(execution.getId()).hashCode() != execution.hashCode()); }
@Test public void testSimpleStepExecutionProviderJobRepositoryStep() throws Exception { SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(), new SimplePartitioner()); Set<StepExecution> execs = splitter.split(stepExecution, 2); assertEquals(2, execs.size()); for (StepExecution execution : execs) { assertNotNull("step execution partition is saved", execution.getId()); } }
@Test public void testStepExecutionWithNullId() { assertNull(new StepExecution("stepName", new JobExecution(new JobInstance(null,"foo"), null)).getId()); }
@Test public void testGetStepExecution() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobInterruptedException, UnexpectedJobExecutionException { // Prepare the jobRepository for the test JobExecution jobExecution = jobRepository.createJobExecution("myJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("flowStep"); jobRepository.add(stepExecution); // Executed on the remote end in remote partitioning use case StepExecution jobExplorerStepExecution = jobExplorer.getStepExecution(jobExecution.getId(), stepExecution.getId()); flowStep.execute(jobExplorerStepExecution); assertEquals(BatchStatus.COMPLETED, jobExplorerStepExecution.getStatus()); }