BATCH-1529: added new exception type for skip policy errors

This commit is contained in:
dsyer
2010-04-05 07:57:49 +00:00
parent 1287b2f53e
commit 6473473d78
6 changed files with 171 additions and 8 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.batch.core.listener.SkipListenerSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.skip.SkipPolicy;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
@@ -202,6 +203,60 @@ public class FaultTolerantStepFactoryBeanTests {
testReadSkip();
}
/**
* Check items causing errors are skipped as expected.
*/
@Test
public void testReadSkipWithPolicyExceptionInReader() throws Exception {
// Should be ignored
factory.setSkipLimit(0);
factory.setSkipPolicy(new SkipPolicy() {
public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException {
throw new RuntimeException("Planned exception in SkipPolicy");
}
});
reader.setFailures("2");
Step step = (Step) factory.getObject();
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
assertEquals(0, stepExecution.getReadSkipCount());
assertEquals(1, stepExecution.getReadCount());
}
/**
* Check items causing errors are skipped as expected.
*/
@Test
public void testReadSkipWithPolicyExceptionInWriter() throws Exception {
// Should be ignored
factory.setSkipLimit(0);
factory.setSkipPolicy(new SkipPolicy() {
public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException {
throw new RuntimeException("Planned exception in SkipPolicy");
}
});
writer.setFailures("2");
Step step = (Step) factory.getObject();
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
assertEquals(0, stepExecution.getWriteSkipCount());
assertEquals(2, stepExecution.getReadCount());
}
/**
* Check to make sure that ItemStreamException can be skipped. (see
* BATCH-915)

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.skip;
import org.springframework.batch.core.listener.AbstractDoubleExceptionTests;
/**
* @author Dave Syer
*
*/
public class SkipPolicyFailedExceptionTests extends AbstractDoubleExceptionTests {
/* (non-Javadoc)
* @see org.springframework.batch.core.listener.AbstractDoubleExceptionTests#getException(java.lang.String, java.lang.RuntimeException, java.lang.Throwable)
*/
@Override
public Exception getException(String msg, RuntimeException cause, Throwable e) throws Exception {
return new SkipPolicyFailedException(msg, cause, e);
}
}