BATCH-1770 - added step BatchStatus.UNKNOWN to SimpleJobLauncher before
starting the job
This commit is contained in:
@@ -16,26 +16,33 @@
|
||||
|
||||
package org.springframework.batch.core.launch;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.JobParametersInvalidException;
|
||||
import org.springframework.batch.core.JobParametersValidator;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.DefaultJobParametersValidator;
|
||||
import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
@@ -262,4 +269,36 @@ public class SimpleJobLauncherTests {
|
||||
private boolean contains(String str, String searchStr) {
|
||||
return str.indexOf(searchStr) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to support BATCH-1770 -> throw in parent thread JobRestartException when
|
||||
* a stepExecution is UNKNOWN
|
||||
*/
|
||||
@Test(expected=JobRestartException.class)
|
||||
public void testRunStepStatusUnknown() throws Exception {
|
||||
//try and restart a job where the step execution is UNKNOWN
|
||||
//setup
|
||||
String jobName = "test_job";
|
||||
JobRepository jobRepository = mock(JobRepository.class);
|
||||
JobParameters parameters = new JobParametersBuilder().addLong("runtime", System.currentTimeMillis()).toJobParameters();
|
||||
JobExecution jobExecution = mock(JobExecution.class);
|
||||
Job job = mock(Job.class);
|
||||
JobParametersValidator validator = mock(JobParametersValidator.class);
|
||||
StepExecution stepExecution = mock(StepExecution.class);
|
||||
|
||||
when(job.getName()).thenReturn(jobName);
|
||||
when(job.isRestartable()).thenReturn(true);
|
||||
when(job.getJobParametersValidator()).thenReturn(validator);
|
||||
when(jobRepository.getLastJobExecution(jobName, parameters)).thenReturn(jobExecution);
|
||||
when(stepExecution.getStatus()).thenReturn(BatchStatus.UNKNOWN);
|
||||
when(jobExecution.getStepExecutions()).thenReturn(Arrays.asList(stepExecution));
|
||||
|
||||
//setup launcher
|
||||
jobLauncher = new SimpleJobLauncher();
|
||||
jobLauncher.setJobRepository(jobRepository);
|
||||
|
||||
//run
|
||||
jobLauncher.run(job, parameters);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user