IN PROGRESS - issue BATCH-201: Move responsibility for deciding if an exception terminates a batch to ExceptionHandler

http://opensource.atlassian.com/projects/spring/browse/BATCH-201

Nearly finished - ExceptionHandler is the owner of abnormal termination.
This commit is contained in:
dsyer
2007-11-20 18:55:15 +00:00
parent 2b175e21e7
commit 07be8cf6d8
27 changed files with 442 additions and 378 deletions

View File

@@ -162,7 +162,7 @@ public class SimpleJobExecutorFacadeTests extends TestCase {
try {
jobExecutorFacade.start(jobExecution);
} catch (NoSuchJobConfigurationException e) {
System.err.println("Shouldn't happen");
throw new IllegalStateException("Shouldn't happen");
}
}
}).start();

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.execution.launch;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.TestCase;
@@ -71,15 +70,15 @@ public class SimpleJobTests extends TestCase {
private ItemProvider provider;
private DefaultJobExecutor jobLifecycle = new DefaultJobExecutor();;
private DefaultJobExecutor jobExecutor = new DefaultJobExecutor();;
private DefaultStepExecutor stepLifecycle = new DefaultStepExecutor();
protected void setUp() throws Exception {
super.setUp();
jobLifecycle.setJobRepository(repository);
jobExecutor.setJobRepository(repository);
stepLifecycle.setRepository(repository);
jobLifecycle.setStepExecutorFactory(new StepExecutorFactory() {
jobExecutor.setStepExecutorFactory(new StepExecutorFactory() {
public StepExecutor getExecutor(StepConfiguration configuration) {
return stepLifecycle;
}
@@ -125,7 +124,7 @@ public class SimpleJobTests extends TestCase {
JobExecution jobExecutionContext = new JobExecution(job);
jobLifecycle.run(jobConfiguration, jobExecutionContext);
jobExecutor.run(jobConfiguration, jobExecutionContext);
assertEquals(BatchStatus.COMPLETED, job.getStatus());
assertEquals(3, processed.size());
assertTrue(processed.contains("foo"));
@@ -136,13 +135,14 @@ public class SimpleJobTests extends TestCase {
JobConfiguration jobConfiguration = new JobConfiguration();
JobIdentifier runtimeInformation = new SimpleJobIdentifier("real.job");
final List throwables = new ArrayList();
RepeatTemplate chunkOperations = new RepeatTemplate();
// Always handle the exception a check it is the right one...
chunkOperations.setExceptionHandler(new ExceptionHandler() {
public void handleExceptions(RepeatContext context, Collection throwables) {
assertEquals(1, throwables.size());
assertEquals("Try again Dummy!", ((Throwable) throwables.iterator().next()).getMessage());
public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException {
throwables.add(throwable);
assertEquals("Try again Dummy!", throwable.getMessage());
}
});
stepLifecycle.setChunkOperations(chunkOperations);
@@ -170,8 +170,8 @@ public class SimpleJobTests extends TestCase {
jobConfiguration.addStep(step);
JobInstance job = repository.findOrCreateJob(jobConfiguration, runtimeInformation);
JobExecution jobExecutionContext = new JobExecution(job);
jobLifecycle.run(jobConfiguration, jobExecutionContext);
JobExecution jobExecution = new JobExecution(job);
jobExecutor.run(jobConfiguration, jobExecution);
assertEquals(BatchStatus.COMPLETED, job.getStatus());
assertEquals(0, processed.size());
@@ -196,7 +196,7 @@ public class SimpleJobTests extends TestCase {
JobInstance job = repository.findOrCreateJob(jobConfiguration, runtimeInformation);
JobExecution jobExecutionContext = new JobExecution(job);
try {
jobLifecycle.run(jobConfiguration, jobExecutionContext);
jobExecutor.run(jobConfiguration, jobExecutionContext);
fail("Expected RuntimeException");
}
catch (RuntimeException e) {

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.execution.step.simple;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import junit.framework.TestCase;
@@ -55,9 +54,9 @@ public class SimpleStepExecutorFactoryTests extends TestCase {
SimpleStepConfiguration configuration = new SimpleStepConfiguration();
final List list = new ArrayList();
configuration.setExceptionHandler(new ExceptionHandler() {
public void handleExceptions(RepeatContext context,
Collection throwables) throws RuntimeException {
list.addAll(throwables);
public void handleException(RepeatContext context,
Throwable throwable) throws RuntimeException {
list.add(throwable);
throw new RuntimeException("Oops");
}
});

View File

@@ -143,7 +143,7 @@ public class RestartableItemProviderTaskletTests extends TestCase {
assertNotNull(data);
// restore from restart data (see asserts in mock classes)
module.restoreFrom(data);
System.err.println(data.getProperties());
//System.err.println(data.getProperties());
}
}