RESOLVED: BATCH-1427: extracted FatalException into parent package instead of inner class.

This commit is contained in:
dsyer
2009-11-10 13:52:59 +00:00
parent 225547d8ae
commit 3d421d7841
11 changed files with 69 additions and 40 deletions

View File

@@ -50,7 +50,7 @@ public class ChunkElementParserTests {
public void testInheritSkippable() throws Exception {
Map<Class<? extends Throwable>, Boolean> skippable = getExceptionClasses("s1",
chunkElementParentAttributeParserTestsContext);
assertEquals(11, skippable.size());
assertEquals(12, skippable.size());
containsClassified(skippable, NullPointerException.class, true);
containsClassified(skippable, ArithmeticException.class, true);
containsClassified(skippable, CannotAcquireLockException.class, false);
@@ -61,7 +61,7 @@ public class ChunkElementParserTests {
public void testInheritSkippableWithNoMerge() throws Exception {
Map<Class<? extends Throwable>, Boolean> skippable = getExceptionClasses("s2",
chunkElementParentAttributeParserTestsContext);
assertEquals(9, skippable.size());
assertEquals(10, skippable.size());
containsClassified(skippable, NullPointerException.class, true);
assertFalse(skippable.containsKey(ArithmeticException.class));
containsClassified(skippable, CannotAcquireLockException.class, false);

View File

@@ -38,7 +38,7 @@ import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.item.FatalException;
import org.springframework.batch.core.step.item.FatalSkippableException;
import org.springframework.batch.core.step.item.FatalRuntimeException;
import org.springframework.batch.core.step.item.SkippableException;
import org.springframework.batch.core.step.item.SkippableRuntimeException;
@@ -427,10 +427,10 @@ public class StepParserTests {
skippable.put(SkippableRuntimeException.class, true);
skippable.put(SkippableException.class, true);
skippable.put(FatalRuntimeException.class, false);
skippable.put(FatalException.class, false);
skippable.put(FatalSkippableException.class, false);
Map<Class<? extends Throwable>, Boolean> retryable = new HashMap<Class<? extends Throwable>, Boolean>();
retryable.put(DeadlockLoserDataAccessException.class, true);
retryable.put(FatalException.class, true);
retryable.put(FatalSkippableException.class, true);
List<Class<? extends ItemStream>> streams = Arrays.asList(CompositeItemStream.class, TestReader.class);
List<Class<? extends RetryListener>> retryListeners = Arrays.asList(RetryListenerSupport.class,
DummyRetryListener.class);
@@ -463,9 +463,9 @@ public class StepParserTests {
Map<Class<? extends Throwable>, Boolean> skippable = new HashMap<Class<? extends Throwable>, Boolean>();
skippable.put(SkippableException.class, true);
skippable.put(FatalException.class, false);
skippable.put(FatalSkippableException.class, false);
Map<Class<? extends Throwable>, Boolean> retryable = new HashMap<Class<? extends Throwable>, Boolean>();
retryable.put(FatalException.class, true);
retryable.put(FatalSkippableException.class, true);
List<Class<CompositeItemStream>> streams = Arrays.asList(CompositeItemStream.class);
List<Class<DummyRetryListener>> retryListeners = Arrays.asList(DummyRetryListener.class);
List<Class<CompositeStepExecutionListener>> stepListeners = Arrays.asList(CompositeStepExecutionListener.class);

View File

@@ -47,8 +47,14 @@ public abstract class AbstractExceptionThrowingItemHandlerStub<T> {
public void setExceptionType(Class<? extends Throwable> exceptionType) throws Exception {
try {
exception = exceptionType.getConstructor(String.class);
} catch (NoSuchMethodException e) {
exception = exceptionType.getConstructor(Object.class);
}
catch (NoSuchMethodException e) {
try {
exception = exceptionType.getConstructor(String.class, Throwable.class);
}
catch (NoSuchMethodException ex) {
exception = exceptionType.getConstructor(Object.class);
}
}
}
@@ -58,7 +64,7 @@ public abstract class AbstractExceptionThrowingItemHandlerStub<T> {
protected void checkFailure(T item) throws Exception {
if (isFailure(item)) {
Throwable t = exception.newInstance("Intended Failure: " + item);
Throwable t = getException("Intended Failure: " + item);
if (t instanceof Exception) {
throw (Exception) t;
}
@@ -69,6 +75,13 @@ public abstract class AbstractExceptionThrowingItemHandlerStub<T> {
}
}
private Throwable getException(String string) throws Exception {
if (exception.getParameterTypes().length==1) {
return exception.newInstance(string);
}
return exception.newInstance(string, new RuntimeException("Planned"));
}
protected boolean isFailure(T item) {
return this.failures.contains(item);
}

View File

@@ -1,11 +0,0 @@
package org.springframework.batch.core.step.item;
/**
* @author Dan Garrette
* @since 2.0.2
*/
public class FatalException extends SkippableException {
public FatalException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,11 @@
package org.springframework.batch.core.step.item;
/**
* @author Dan Garrette
* @since 2.0.2
*/
public class FatalSkippableException extends SkippableException {
public FatalSkippableException(String message) {
super(message);
}
}

View File

@@ -21,6 +21,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.step.FatalException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -121,6 +122,15 @@ public class FaultTolerantExceptionClassesTests implements ApplicationContextAwa
assertEquals("[]", writer.getCommitted().toString());
}
@Test
public void testInternalFatalChecked() throws Exception {
writer.setExceptionType(FatalException.class);
StepExecution stepExecution = launchStep("skippableFatalStep");
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
assertEquals("[1, 2, 3]", writer.getWritten().toString());
assertEquals("[]", writer.getCommitted().toString());
}
@Test
public void testSkippableChecked() throws Exception {
writer.setExceptionType(SkippableException.class);
@@ -132,7 +142,7 @@ public class FaultTolerantExceptionClassesTests implements ApplicationContextAwa
@Test
public void testFatalChecked() throws Exception {
writer.setExceptionType(FatalException.class);
writer.setExceptionType(FatalSkippableException.class);
StepExecution stepExecution = launchStep("skippableFatalStep");
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
assertEquals("[1, 2, 3]", writer.getWritten().toString());
@@ -192,7 +202,7 @@ public class FaultTolerantExceptionClassesTests implements ApplicationContextAwa
@Test
public void testRetryableFatalChecked() throws Exception {
writer.setExceptionType(FatalException.class);
writer.setExceptionType(FatalSkippableException.class);
StepExecution stepExecution = launchStep("retryable");
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
// BATCH-1333: