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

The following examples show how to use org.springframework.batch.core.JobExecution#setStartTime() . 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: JobExecutionUtils.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private static void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance, new JobParameters(), null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		if (BatchStatus.STOPPED.equals(status)) {
			jobExecution.setEndTime(new Date());
		}
		jobRepository.update(jobExecution);
	}
}
 
Example 2
Source File: DefaultTaskJobServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance,
				this.jobParameters, null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		jobRepository.update(jobExecution);
	}
}
 
Example 3
Source File: ProtocolListenerTest.java    From spring-boot-starter-batch-web with Apache License 2.0 6 votes vote down vote up
@Test
public void createProtocol() throws Exception {
	// Given
	JobExecution jobExecution = new JobExecution(1L,
			new JobParametersBuilder().addString("test", "value").toJobParameters());
	jobExecution.setJobInstance(new JobInstance(1L, "test-job"));
	jobExecution.setCreateTime(new Date());
	jobExecution.setStartTime(new Date());
	jobExecution.setEndTime(new Date());
	jobExecution.setExitStatus(new ExitStatus("COMPLETED_WITH_ERRORS", "This is a default exit message"));
	jobExecution.getExecutionContext().put("jobCounter", 1);
	StepExecution stepExecution = jobExecution.createStepExecution("test-step-1");
	stepExecution.getExecutionContext().put("stepCounter", 1);
	ProtocolListener protocolListener = new ProtocolListener();
	// When
	protocolListener.afterJob(jobExecution);
	// Then
	String output = this.outputCapture.toString();
	assertThat(output, containsString("Protocol for test-job"));
	assertThat(output, containsString("COMPLETED_WITH_ERRORS"));
}
 
Example 4
Source File: JobInstancesDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void createJobExecution(String name, BatchStatus status) {
	TaskExecution taskExecution = this.dao.createTaskExecution(name, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution = this.jobRepository.createJobExecution(this.jobRepository.createJobInstance(name, new JobParameters()), new JobParameters(), null);
	this.taskBatchDao.saveRelationship(taskExecution, jobExecution);
	jobExecution.setStatus(status);
	jobExecution.setStartTime(new Date());
	this.jobRepository.update(jobExecution);
}
 
Example 5
Source File: JobStepExecutionsDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void createJobExecution(String name, BatchStatus status) {
	TaskExecution taskExecution = this.dao.createTaskExecution(name, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution = this.jobRepository.createJobExecution(this.jobRepository.createJobInstance(name, new JobParameters()), new JobParameters(), null);
	StepExecution stepExecution = new StepExecution(name + "_STEP", jobExecution, jobExecution.getId());
	stepExecution.setId(null);
	jobRepository.add(stepExecution);
	this.taskBatchDao.saveRelationship(taskExecution, jobExecution);
	jobExecution.setStatus(status);
	jobExecution.setStartTime(new Date());
	this.jobRepository.update(jobExecution);
}
 
Example 6
Source File: JobExecutionsDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void createJobExecution(String name, BatchStatus status) {
	TaskExecution taskExecution = this.dao.createTaskExecution(name, new Date(), new ArrayList<>(), null);
	Map<String, JobParameter> jobParameterMap = new HashMap<>();
	jobParameterMap.put("-spring.cloud.data.flow.platformname", new JobParameter("default"));
	JobParameters jobParameters = new JobParameters(jobParameterMap);
	JobExecution jobExecution = this.jobRepository.createJobExecution(this.jobRepository.createJobInstance(name, new JobParameters()), jobParameters, null);
	this.taskBatchDao.saveRelationship(taskExecution, jobExecution);
	jobExecution.setStatus(status);
	jobExecution.setStartTime(new Date());
	this.jobRepository.update(jobExecution);
}
 
Example 7
Source File: JobExecutionMapperTest.java    From batchers with Apache License 2.0 5 votes vote down vote up
@Test
public void testToJobResultTo() throws Exception {
    //ARRANGE
    Date now = DateTime.now().toDate();
    JobInstance jobInstance = new JobInstance(JOB_ID, JOB_NAME);
    JobParameters jobParams = new JobParameters();

    JobExecution jobExecution = new JobExecution(jobInstance, jobParams);
    jobExecution.setStatus(BatchStatus.ABANDONED);
    jobExecution.setStartTime(new DateTime(now).minusSeconds(DURATION_IN_SECONDS).toDate());
    jobExecution.setEndTime(now);
    jobExecution.setId(JOB_EXECUTION_ID);
    Map.Entry<JobInstance, List<JobExecution>> entry = new Map.Entry<JobInstance, List<JobExecution>>() {
        @Override
        public JobInstance getKey() {
            return jobInstance;
        }

        @Override
        public List<JobExecution> getValue() {
            return Arrays.asList(jobExecution);
        }

        @Override
        public List<JobExecution> setValue(List<JobExecution> value) {
            return null;
        }

    };

    //ACT
    JobResult resultTo = mapper.toJobResultTo(entry);

    //ASSERT
    assertThat(resultTo.getJobExecutionResults()).hasSize(1);
    JobExecutionResult jobExecutionResult = resultTo.getJobExecutionResults().get(0);
    assertThat(jobExecutionResult.getStatus()).isEqualTo(BatchStatus.ABANDONED.toString());
    assertThat(jobExecutionResult.getDuration()).isEqualTo(DURATION_IN_SECONDS * 1000);
}