BATCH-1713: re-hydrate step executions in job explorer
This commit is contained in:
@@ -78,12 +78,22 @@ public interface JobExplorer {
|
||||
JobInstance getJobInstance(Long instanceId);
|
||||
|
||||
/**
|
||||
* Retrieve job executions by their job instance. The corresponding step
|
||||
* executions may not be fully hydrated (e.g. their execution context may be
|
||||
* missing), depending on the implementation. Use
|
||||
* {@link #getStepExecution(Long, Long)} to hydrate them in that case.
|
||||
*
|
||||
* @param jobInstance the {@link JobInstance} to query
|
||||
* @return the set of all executions for the specified {@link JobInstance}
|
||||
*/
|
||||
List<JobExecution> getJobExecutions(JobInstance jobInstance);
|
||||
|
||||
/**
|
||||
* Retrieve running job executions. The corresponding step executions may
|
||||
* not be fully hydrated (e.g. their execution context may be missing),
|
||||
* depending on the implementation. Use
|
||||
* {@link #getStepExecution(Long, Long)} to hydrate them in that case.
|
||||
*
|
||||
* @param jobName the name of the job
|
||||
* @return the set of running executions for jobs with the specified name
|
||||
*/
|
||||
|
||||
@@ -77,6 +77,9 @@ public class SimpleJobExplorer implements JobExplorer {
|
||||
List<JobExecution> executions = jobExecutionDao.findJobExecutions(jobInstance);
|
||||
for (JobExecution jobExecution : executions) {
|
||||
getJobExecutionDependencies(jobExecution);
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
getStepExecutionDependencies(stepExecution);
|
||||
}
|
||||
}
|
||||
return executions;
|
||||
}
|
||||
@@ -92,6 +95,9 @@ public class SimpleJobExplorer implements JobExplorer {
|
||||
Set<JobExecution> executions = jobExecutionDao.findRunningJobExecutions(jobName);
|
||||
for (JobExecution jobExecution : executions) {
|
||||
getJobExecutionDependencies(jobExecution);
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
getStepExecutionDependencies(stepExecution);
|
||||
}
|
||||
}
|
||||
return executions;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,17 @@ import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.explore.support.SimpleJobExplorer;
|
||||
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
|
||||
import org.springframework.batch.core.repository.dao.JobExecutionDao;
|
||||
import org.springframework.batch.core.repository.dao.JobInstanceDao;
|
||||
@@ -44,7 +43,7 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleJobExplorerTests extends TestCase {
|
||||
public class SimpleJobExplorerTests {
|
||||
|
||||
private SimpleJobExplorer jobExplorer;
|
||||
|
||||
@@ -61,6 +60,7 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
|
||||
private JobExecution jobExecution = new JobExecution(jobInstance, 1234L);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
jobExecutionDao = createMock(JobExecutionDao.class);
|
||||
@@ -127,28 +127,33 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testFindRunningJobExecutions() throws Exception {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step");
|
||||
expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn(
|
||||
Collections.singleton(jobExecution));
|
||||
expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(
|
||||
jobInstance);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
expect(ecDao.getExecutionContext(jobExecution)).andReturn(null);
|
||||
expect(ecDao.getExecutionContext(stepExecution)).andReturn(null);
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao, ecDao);
|
||||
jobExplorer.findRunningJobExecutions("job");
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao, ecDao);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindJobExecutions() throws Exception {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step");
|
||||
expect(jobExecutionDao.findJobExecutions(jobInstance)).andReturn(
|
||||
Collections.singletonList(jobExecution));
|
||||
expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(
|
||||
jobInstance);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expect(ecDao.getExecutionContext(jobExecution)).andReturn(null);
|
||||
expect(ecDao.getExecutionContext(stepExecution)).andReturn(null);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao, ecDao);
|
||||
jobExplorer.getJobExecutions(jobInstance);
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao, ecDao);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,7 @@ log4j.rootCategory=INFO, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2} - %m%n
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
|
||||
|
||||
log4j.category.org.apache.activemq=ERROR
|
||||
log4j.category.org.springframework.batch=DEBUG
|
||||
@@ -10,7 +10,7 @@ log4j.category.org.springframework.batch.support=INFO
|
||||
log4j.category.org.springframework.batch.support.transaction.ResourcelessTransactionManager=DEBUG
|
||||
log4j.category.org.springframework.core.repository=DEBUG
|
||||
# log4j.category.org.springframework.transaction=INFO
|
||||
log4j.category.org.springframework.jdbc=DEBUG
|
||||
log4j.category.org.springframework.beans=DEBUG
|
||||
|
||||
# log4j.category.org.hibernate.SQL=DEBUG
|
||||
# for debugging datasource initialization
|
||||
|
||||
Reference in New Issue
Block a user