Java Code Examples for org.springframework.batch.core.JobExecution#getStepExecutions()

The following examples show how to use org.springframework.batch.core.JobExecution#getStepExecutions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobExecutionEvent.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for the StepExecution to initialize the DTO.
 * @param original the StepExecution to build this DTO around.
 */
public JobExecutionEvent(JobExecution original) {
	this.jobParameters = new JobParametersEvent(
			original.getJobParameters().getParameters());
	this.jobInstance = new JobInstanceEvent(original.getJobInstance().getId(),
			original.getJobInstance().getJobName());
	for (StepExecution stepExecution : original.getStepExecutions()) {
		this.stepExecutions.add(new StepExecutionEvent(stepExecution));
	}
	this.status = original.getStatus();
	this.startTime = original.getStartTime();
	this.createTime = original.getCreateTime();
	this.endTime = original.getEndTime();
	this.lastUpdated = original.getLastUpdated();
	this.exitStatus = new ExitStatus(original.getExitStatus());
	this.executionContext = original.getExecutionContext();
	this.failureExceptions = original.getFailureExceptions();
	this.jobConfigurationName = original.getJobConfigurationName();
	this.setId(original.getId());
	this.setVersion(original.getVersion());
}
 
Example 2
Source File: DeciderJobIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenNumberGeneratorDecider_whenDeciderRuns_thenStatusIsNotify() throws Exception {
    JobExecution jobExecution = jobLauncherTestUtils.launchJob();
    Collection<StepExecution> actualStepExecutions = jobExecution.getStepExecutions();
    ExitStatus actualJobExitStatus = jobExecution.getExitStatus();

    assertEquals("COMPLETED", actualJobExitStatus.getExitCode()
        .toString());
    assertEquals(2, actualStepExecutions.size());
    boolean notifyStepDidRun = false;
    Iterator<StepExecution> iterator = actualStepExecutions.iterator();
    while (iterator.hasNext() && !notifyStepDidRun) {
        if (iterator.next()
            .getStepName()
            .equals("Notify step")) {
            notifyStepDidRun = true;
        }
    }
    assertTrue(notifyStepDidRun);
}
 
Example 3
Source File: SpringBatchIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenReferenceOutput_whenStep1Executed_thenSuccess() throws Exception {

    // given
    FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT);
    FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT);

    // when
    JobExecution jobExecution = jobLauncherTestUtils.launchStep("step1", defaultJobParameters());
    Collection<StepExecution> actualStepExecutions = jobExecution.getStepExecutions();
    ExitStatus actualJobExitStatus = jobExecution.getExitStatus();

    // then
    assertThat(actualStepExecutions.size(), is(1));
    assertThat(actualJobExitStatus.getExitCode(), is("COMPLETED"));
    AssertFile.assertFileEquals(expectedResult, actualResult);
}
 
Example 4
Source File: ComposedRunnerVisitorTests.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private Collection<StepExecution> getStepExecutions() {
	JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
	List<JobInstance> jobInstances = jobExplorer.findJobInstancesByJobName("job", 0, 1);
	assertEquals(1, jobInstances.size());
	JobInstance jobInstance = jobInstances.get(0);
	List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
	assertEquals(1, jobExecutions.size());
	JobExecution jobExecution = jobExecutions.get(0);
	return jobExecution.getStepExecutions();
}
 
Example 5
Source File: ComposedRunnerVisitorTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Collection<StepExecution> getStepExecutions() {
	JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
	List<JobInstance> jobInstances = jobExplorer.findJobInstancesByJobName("job", 0, 1);
	assertEquals(1, jobInstances.size());
	JobInstance jobInstance = jobInstances.get(0);
	List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
	assertEquals(1, jobExecutions.size());
	JobExecution jobExecution = jobExecutions.get(0);
	return jobExecution.getStepExecutions();
}
 
Example 6
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException {
	Collection<String> stepNames = new LinkedHashSet<>();
	for (JobExecution jobExecution : listJobExecutionsForJob(jobName, null, 0, 100)) {
		for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
			stepNames.add(stepExecution.getStepName());
		}
	}
	return Collections.unmodifiableList(new ArrayList<>(stepNames));
}
 
Example 7
Source File: SpringBatchIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenStep2Executed_thenSuccess() {

    // when
    JobExecution jobExecution = jobLauncherTestUtils.launchStep("step2", defaultJobParameters());
    Collection<StepExecution> actualStepExecutions = jobExecution.getStepExecutions();
    ExitStatus actualExitStatus = jobExecution.getExitStatus();

    // then
    assertThat(actualStepExecutions.size(), is(1));
    assertThat(actualExitStatus.getExitCode(), is("COMPLETED"));
    actualStepExecutions.forEach(stepExecution -> {
        assertThat(stepExecution.getWriteCount(), is(8));
    });
}
 
Example 8
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
@Override
public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException {

	JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
	if (jobExecution == null) {
		throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId);
	}

	stepExecutionDao.addStepExecutions(jobExecution);

	return jobExecution.getStepExecutions();

}