RESOLVED - BATCH-875: Pull jobRepository.save() out of Step implementations and put it in the driving Job
This commit is contained in:
@@ -499,7 +499,7 @@ public class SimpleJobTests {
|
||||
passedInStepContext = new ExecutionContext(stepExecution.getExecutionContext());
|
||||
stepExecution.getExecutionContext().putString("stepKey", "stepValue");
|
||||
stepExecution.getJobExecution().getExecutionContext().putString("jobKey", "jobValue");
|
||||
jobRepository.add(stepExecution);
|
||||
jobRepository.update(stepExecution);
|
||||
jobRepository.updateExecutionContext(stepExecution);
|
||||
|
||||
if (exception instanceof RuntimeException) {
|
||||
|
||||
@@ -87,6 +87,7 @@ public class RestartIntegrationTests {
|
||||
// Two attempts
|
||||
assertEquals(2, afterMaster-beforeMaster);
|
||||
// One failure and two successes
|
||||
System.out.println(afterPartition);
|
||||
assertEquals(3, afterPartition-beforePartition);
|
||||
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class PartitionStepTests {
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
StepExecution stepExecution = new JobExecution(0L).createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// one master and two workers
|
||||
assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size());
|
||||
@@ -91,6 +92,7 @@ public class PartitionStepTests {
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
StepExecution stepExecution = new JobExecution(0L).createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// one master and two workers
|
||||
assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size());
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.springframework.batch.core.partition.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -37,7 +38,12 @@ public class SimpleStepExecutionSplitterTests {
|
||||
@Test
|
||||
public void testSimpleStepExecutionProviderJobRepositoryStep() throws Exception {
|
||||
SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step);
|
||||
assertEquals(2, provider.split(stepExecution, 2).size());
|
||||
Set<StepExecution> execs = provider.split(stepExecution, 2);
|
||||
assertEquals(2, execs.size());
|
||||
|
||||
for (StepExecution execution : execs) {
|
||||
assertNotNull("step execution partition is saved", execution.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -132,6 +132,7 @@ public class AbstractStepTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tested.setJobRepository(repository);
|
||||
repository.add(execution);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -155,6 +155,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
Step step = (Step) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals(0, stepExecution.getSkipCount());
|
||||
@@ -192,6 +193,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
Step step = (Step) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals(2, stepExecution.getSkipCount());
|
||||
@@ -246,6 +248,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
AbstractStep step = (AbstractStep) factory.getObject();
|
||||
step.setName("mytest");
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals(2, recovered.size());
|
||||
@@ -310,6 +313,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
AbstractStep step = (AbstractStep) factory.getObject();
|
||||
step.setName("mytest");
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals(2, recovered.size());
|
||||
@@ -358,6 +362,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
Step step = (Step) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
|
||||
@@ -410,6 +415,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
Step step = (Step) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
String message = stepExecution.getFailureExceptions().get(0).getMessage();
|
||||
assertTrue("Wrong message: " + message, message.contains("Write error - planned but not skippable."));
|
||||
@@ -452,6 +458,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
AbstractStep step = (AbstractStep) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
|
||||
@@ -500,6 +507,7 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
AbstractStep step = (AbstractStep) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class TaskletStepExceptionTests {
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(exception));
|
||||
assertEquals(1, jobRepository.getUpdateCount());
|
||||
assertEquals(2, jobRepository.getUpdateCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,7 @@ public class TaskletStepExceptionTests {
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(exception));
|
||||
assertEquals(1, jobRepository.getUpdateCount());
|
||||
assertEquals(2, jobRepository.getUpdateCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +129,7 @@ public class TaskletStepExceptionTests {
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(COMPLETED, stepExecution.getStatus());
|
||||
assertFalse(stepExecution.getFailureExceptions().contains(exception));
|
||||
assertEquals(3, jobRepository.getUpdateCount());
|
||||
assertEquals(4, jobRepository.getUpdateCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +149,7 @@ public class TaskletStepExceptionTests {
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(taskletException));
|
||||
assertFalse(stepExecution.getFailureExceptions().contains(exception));
|
||||
assertEquals(1, jobRepository.getUpdateCount());
|
||||
assertEquals(2, jobRepository.getUpdateCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,7 +167,7 @@ public class TaskletStepExceptionTests {
|
||||
assertEquals(FAILED, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(taskletException));
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(exception));
|
||||
assertEquals(1, jobRepository.getUpdateCount());
|
||||
assertEquals(2, jobRepository.getUpdateCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,12 +200,17 @@ public class TaskletStepExceptionTests {
|
||||
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
taskletStep.setJobRepository(new UpdateCountingJobRepository() {
|
||||
boolean firstCall = true;
|
||||
@Override
|
||||
public void update(StepExecution arg0) {
|
||||
if (firstCall) {
|
||||
firstCall = false;
|
||||
return;
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(UNKNOWN, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(taskletException));
|
||||
|
||||
@@ -130,8 +130,8 @@ public class ChunkOrientedStepIntegrationTests {
|
||||
put("foo", "bar");
|
||||
}
|
||||
});
|
||||
// step.setLastExecution(stepExecution);
|
||||
|
||||
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
|
||||
StepExecution lastStepExecution = jobRepository.getLastStepExecution(jobExecution.getJobInstance(), step.getName());
|
||||
|
||||
@@ -49,13 +49,15 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
private ItemWriter<Object> itemWriter;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
MapJobInstanceDao.clear();
|
||||
MapJobExecutionDao.clear();
|
||||
MapStepExecutionDao.clear();
|
||||
|
||||
JobRepository jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
|
||||
jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
|
||||
new MapStepExecutionDao(), new MapExecutionContextDao());
|
||||
|
||||
JobSupport job = new JobSupport();
|
||||
@@ -169,6 +171,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals("Planned!", stepExecution.getFailureExceptions().get(0).getMessage());
|
||||
@@ -182,6 +185,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
Thread processingThread = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
}
|
||||
catch (JobInterruptedException e) {
|
||||
|
||||
@@ -186,7 +186,7 @@ public class TaskletStepTests {
|
||||
|
||||
JobExecution jobExecution = repository.createJobExecution(job.getName(), jobInstance.getJobParameters());
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(1, processed.size());
|
||||
}
|
||||
@@ -806,7 +806,7 @@ public class TaskletStepTests {
|
||||
public void update(StepExecution stepExecution) {
|
||||
updateCount++;
|
||||
if (updateCount <= 3) {
|
||||
assertEquals(updateCount, stepExecution.getReadCount());
|
||||
assertEquals(updateCount, stepExecution.getReadCount() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,11 +814,11 @@ public class TaskletStepTests {
|
||||
|
||||
private static class JobRepositoryFailedUpdateStub extends JobRepositorySupport {
|
||||
|
||||
private boolean firstCall = true;
|
||||
private int called = 0;
|
||||
|
||||
public void update(StepExecution stepExecution) {
|
||||
if (firstCall) {
|
||||
firstCall = false;
|
||||
called++;
|
||||
if (called == 3) {
|
||||
throw new DataAccessResourceFailureException("stub exception");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user