BATCH-1579: probe a bit with some unit tests, but not finding any issues
This commit is contained in:
@@ -43,6 +43,7 @@ import org.springframework.batch.core.JobExecutionListener;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.UnexpectedJobExecutionException;
|
||||
@@ -387,6 +388,29 @@ public class SimpleJobTests {
|
||||
assertFalse(step2.passedInStepContext.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartWithNullParameter() throws Exception {
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", null).toJobParameters();
|
||||
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
|
||||
jobInstance = jobExecution.getJobInstance();
|
||||
|
||||
step1.setAllowStartIfComplete(true);
|
||||
final RuntimeException exception = new RuntimeException("Foo!");
|
||||
step2.setProcessException(exception);
|
||||
|
||||
job.execute(jobExecution);
|
||||
Throwable e = jobExecution.getAllFailureExceptions().get(0);
|
||||
assertSame(exception, e);
|
||||
|
||||
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
|
||||
job.execute(jobExecution);
|
||||
e = jobExecution.getAllFailureExceptions().get(0);
|
||||
assertSame(exception, e);
|
||||
assertTrue(step1.passedInStepContext.isEmpty());
|
||||
assertFalse(step2.passedInStepContext.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterruptWithListener() throws Exception {
|
||||
step1.setProcessException(new JobInterruptedException("job interrupted!"));
|
||||
@@ -408,7 +432,7 @@ public class SimpleJobTests {
|
||||
* Execution context should be restored on restart.
|
||||
*/
|
||||
@Test
|
||||
public void testRestartScenario() throws Exception {
|
||||
public void testRestartAndExecutionContextRestored() throws Exception {
|
||||
|
||||
job.setRestartable(true);
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class SimpleJobLauncherTests {
|
||||
run(ExitStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test(expected=JobParametersInvalidException.class)
|
||||
@Test(expected = JobParametersInvalidException.class)
|
||||
public void testRunWithValidator() throws Exception {
|
||||
|
||||
job.setJobParametersValidator(new DefaultJobParametersValidator(new String[] { "missing-and-required" },
|
||||
@@ -98,6 +98,32 @@ public class SimpleJobLauncherTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunRestartableJobInstanceTwice() throws Exception {
|
||||
job = new JobSupport("foo") {
|
||||
@Override
|
||||
public boolean isRestartable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobExecution execution) {
|
||||
execution.setExitStatus(ExitStatus.COMPLETED);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
testRun();
|
||||
reset(jobRepository);
|
||||
expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(
|
||||
new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
|
||||
expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(
|
||||
new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
|
||||
replay(jobRepository);
|
||||
jobLauncher.run(job, jobParameters);
|
||||
verify(jobRepository);
|
||||
}
|
||||
|
||||
/*
|
||||
* Non-restartable JobInstance can be run only once - attempt to run
|
||||
* existing non-restartable JobInstance causes error.
|
||||
@@ -231,7 +257,7 @@ public class SimpleJobLauncherTests {
|
||||
jobLauncher.setJobRepository(jobRepository);
|
||||
jobLauncher.afterPropertiesSet(); // no error
|
||||
}
|
||||
|
||||
|
||||
private void run(ExitStatus exitStatus) throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(null, null);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ
|
||||
|
||||
private static final long DATE = 777;
|
||||
|
||||
protected JobInstanceDao dao = new MapJobInstanceDao();
|
||||
protected JobInstanceDao dao;
|
||||
|
||||
private String fooJob = "foo";
|
||||
|
||||
@@ -61,6 +61,29 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ
|
||||
assertEquals(new Date(DATE), retrievedParams.getDate("dateKey"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and retrieve a job instance.
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testCreateAndRetrieveWithNullParameter() throws Exception {
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", null).toJobParameters();
|
||||
|
||||
JobInstance fooInstance = dao.createJobInstance(fooJob, jobParameters);
|
||||
assertNotNull(fooInstance.getId());
|
||||
assertEquals(fooJob, fooInstance.getJobName());
|
||||
assertEquals(jobParameters, fooInstance.getJobParameters());
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(fooJob, jobParameters);
|
||||
JobParameters retrievedParams = retrievedInstance.getJobParameters();
|
||||
assertEquals(fooInstance, retrievedInstance);
|
||||
assertEquals(fooJob, retrievedInstance.getJobName());
|
||||
assertEquals(jobParameters, retrievedParams);
|
||||
|
||||
assertEquals(null, retrievedParams.getString("foo"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and retrieve a job instance.
|
||||
*/
|
||||
@@ -211,7 +234,7 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ
|
||||
}
|
||||
|
||||
public void testGetJobInstanceByExecutionId() {
|
||||
|
||||
// TODO: test this (or maybe the method isn't needed or has wrong signature)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user