RESOLVED - issue BATCH-1050: SimpleJobExplorer doesn't retrieve StepExecutions of running JobExecutions using MapStepExecutionDao
Make StepExecutionDao interface clearer from the point of view of adding step executions to a JobExecution.
This commit is contained in:
@@ -46,6 +46,9 @@ public class MapJobExplorerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testRunningJobExecution() throws Exception {
|
||||
|
||||
MapJobRepositoryFactoryBean.clear();
|
||||
|
||||
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
|
||||
MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean();
|
||||
ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
|
||||
@@ -55,6 +58,7 @@ public class MapJobExplorerIntegrationTests {
|
||||
jobLauncher.setJobRepository(jobRepository);
|
||||
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
jobLauncher.afterPropertiesSet();
|
||||
|
||||
SimpleJob job = new SimpleJob("job");
|
||||
TaskletStep step = new TaskletStep("step");
|
||||
step.setTasklet(new Tasklet() {
|
||||
@@ -71,12 +75,16 @@ public class MapJobExplorerIntegrationTests {
|
||||
job.addStep(step);
|
||||
job.setJobRepository(jobRepository);
|
||||
job.afterPropertiesSet();
|
||||
|
||||
jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters());
|
||||
|
||||
Thread.sleep(500L);
|
||||
JobExplorer explorer = (JobExplorer) new MapJobExplorerFactoryBean().getObject();
|
||||
Set<JobExecution> executions = explorer.findRunningJobExecutions("job");
|
||||
assertEquals(1, executions.size());
|
||||
assertEquals(1, executions.iterator().next().getStepExecutions().size());
|
||||
|
||||
block = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.batch.core.exlore.support;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
@@ -69,7 +70,8 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
public void testGetJobExecution() throws Exception {
|
||||
expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution);
|
||||
expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance);
|
||||
expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
jobExplorer.getJobExecution(123L);
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
@@ -87,7 +89,8 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
public void testGetStepExecution() throws Exception {
|
||||
expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution);
|
||||
expect(stepExecutionDao.getStepExecution(jobExecution, 123L)).andReturn(null);
|
||||
expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, stepExecutionDao);
|
||||
jobExplorer.getStepExecution(jobExecution.getId(), 123L);
|
||||
verify(jobExecutionDao, stepExecutionDao);
|
||||
@@ -97,7 +100,8 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
public void testFindRunningJobExecutions() throws Exception {
|
||||
expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn(Collections.singleton(jobExecution));
|
||||
expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance);
|
||||
expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
jobExplorer.findRunningJobExecutions("job");
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
@@ -107,7 +111,8 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
public void testFindJobExecutions() throws Exception {
|
||||
expect(jobExecutionDao.findJobExecutions(jobInstance)).andReturn(Collections.singletonList(jobExecution));
|
||||
expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance);
|
||||
expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null);
|
||||
stepExecutionDao.addStepExecutions(jobExecution);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
jobExplorer.getJobExecutions(jobInstance);
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
|
||||
@@ -21,9 +21,9 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -131,8 +131,9 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
stepExecution.setRollbackCount(3);
|
||||
dao.saveStepExecution(stepExecution);
|
||||
|
||||
List<StepExecution> retrieved = dao.getStepExecutions(jobExecution);
|
||||
assertStepExecutionsAreEqual(stepExecution, retrieved.get(0));
|
||||
dao.addStepExecutions(jobExecution);
|
||||
Collection<StepExecution> retrieved = jobExecution.getStepExecutions();
|
||||
assertStepExecutionsAreEqual(stepExecution, retrieved.iterator().next());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -229,8 +230,9 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionsWhenNoneExist() throws Exception {
|
||||
assertEquals("empty list is returned if no stepExecutions exist for given jobExecution", Collections
|
||||
.emptyList(), dao.getStepExecutions(jobExecution));
|
||||
int count = jobExecution.getStepExecutions().size();
|
||||
dao.addStepExecutions(jobExecution);
|
||||
assertEquals("Incorrect size of collection", count, jobExecution.getStepExecutions().size());
|
||||
}
|
||||
|
||||
private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) {
|
||||
|
||||
Reference in New Issue
Block a user