RESOLVED - issue BATCH-373: jobExecution.getJobInstance().getJob() return null when re-run
http://jira.springframework.org/browse/BATCH-373 added testcase and fixed the bug
This commit is contained in:
@@ -190,6 +190,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
jobInstance.setLastExecution(lastExecution);
|
||||
jobInstance.setStepNames(getStepNames(job));
|
||||
jobInstance.setJob(job);
|
||||
}
|
||||
else if (jobs.size() == 0) {
|
||||
// no job found, create one
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.springframework.batch.execution.repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Repository tests using JDBC DAOs (rather than mocks).
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SimpleJobRepositoryIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.addResourcePathToPackagePath(getClass(), "dao/sql-dao-test.xml") };
|
||||
}
|
||||
|
||||
private SimpleJobRepository jobRepository;
|
||||
|
||||
public void setJobRepository(SimpleJobRepository jobRepository) {
|
||||
this.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create two job executions for same job+parameters tuple. Check both
|
||||
* executions belong to the same job instance and job.
|
||||
*/
|
||||
public void testCreateAndFind() throws Exception {
|
||||
|
||||
JobSupport job = new JobSupport("testJob");
|
||||
job.setRestartable(true);
|
||||
|
||||
Map stringParams = new HashMap() {
|
||||
{
|
||||
put("stringKey", "stringValue");
|
||||
}
|
||||
};
|
||||
Map longParams = new HashMap() {
|
||||
{
|
||||
put("longKey", new Long(1));
|
||||
}
|
||||
};
|
||||
Map dateParams = new HashMap() {
|
||||
{
|
||||
put("dateKey", new Date(1));
|
||||
}
|
||||
};
|
||||
JobParameters jobParams = new JobParameters(stringParams, longParams, dateParams);
|
||||
|
||||
JobExecution firstExecution = jobRepository.createJobExecution(job, jobParams);
|
||||
|
||||
assertEquals(job, firstExecution.getJobInstance().getJob());
|
||||
|
||||
jobRepository.saveOrUpdate(firstExecution);
|
||||
firstExecution.stop();
|
||||
jobRepository.saveOrUpdate(firstExecution);
|
||||
JobExecution secondExecution = jobRepository.createJobExecution(job, jobParams);
|
||||
|
||||
assertEquals(firstExecution.getJobInstance(), secondExecution.getJobInstance());
|
||||
assertEquals(job, secondExecution.getJobInstance().getJob());
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,12 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="data-source-context.xml" />
|
||||
|
||||
<bean id="jobRepository" class="org.springframework.batch.execution.repository.SimpleJobRepository">
|
||||
<constructor-arg ref="jobInstanceDao" />
|
||||
<constructor-arg ref="jobExecutionDao" />
|
||||
<constructor-arg ref="stepExecutionDao" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobInstanceDao" class="org.springframework.batch.execution.repository.dao.JdbcJobInstanceDao" >
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
|
||||
Reference in New Issue
Block a user