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

The following examples show how to use org.springframework.batch.core.JobExecution#getExitStatus() . 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: SpringBatchRetryIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenEndpointFailsTwicePasses3rdTime_thenSuccess() throws Exception {
    FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT);
    FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT);

    //fails for first two calls and passes third time onwards
    when(httpResponse.getEntity())
      .thenReturn(new StringEntity("{ \"age\":10, \"postCode\":\"430222\" }"));
    when(closeableHttpClient.execute(any()))
      .thenThrow(new ConnectTimeoutException("Timeout count 1"))
      .thenThrow(new ConnectTimeoutException("Timeout count 2"))
      .thenReturn(httpResponse);

    JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters());
    JobInstance actualJobInstance = jobExecution.getJobInstance();
    ExitStatus actualJobExitStatus = jobExecution.getExitStatus();

    assertThat(actualJobInstance.getJobName(), is("retryBatchJob"));
    assertThat(actualJobExitStatus.getExitCode(), is("COMPLETED"));
    AssertFile.assertFileEquals(expectedResult, actualResult);
}
 
Example 4
Source File: SpringBatchIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenReferenceOutput_whenJobExecuted_thenSuccess() throws Exception {
    // given
    FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT);
    FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT);

    // when
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters());
    JobInstance actualJobInstance = jobExecution.getJobInstance();
    ExitStatus actualJobExitStatus = jobExecution.getExitStatus();

    // then
    assertThat(actualJobInstance.getJobName(), is("transformBooksRecords"));
    assertThat(actualJobExitStatus.getExitCode(), is("COMPLETED"));
    AssertFile.assertFileEquals(expectedResult, actualResult);
}
 
Example 5
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 6
Source File: SpringBatchRetryIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenEndpointAlwaysFail_thenJobFails() throws Exception {
    when(closeableHttpClient.execute(any()))
      .thenThrow(new ConnectTimeoutException("Endpoint is down"));

    JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters());
    JobInstance actualJobInstance = jobExecution.getJobInstance();
    ExitStatus actualJobExitStatus = jobExecution.getExitStatus();

    assertThat(actualJobInstance.getJobName(), is("retryBatchJob"));
    assertThat(actualJobExitStatus.getExitCode(), is("FAILED"));
    assertThat(actualJobExitStatus.getExitDescription(), containsString("org.apache.http.conn.ConnectTimeoutException"));
}
 
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));
    });
}