RESOLVED - issue BATCH-268: retry configuration for ItemOrientedTasklet

http://jira.springframework.org/browse/BATCH-268

The retry only works if you have an ItemStream as an ItemReader (so that you get a proper rollback).  Applied the patch and fixed it up to fit the new m5 way of looking at things.
This commit is contained in:
dsyer
2008-02-11 17:23:57 +00:00
parent 0824f1aeb3
commit 2ce3013ac1
21 changed files with 338 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
package org.springframework.batch.sample;
import org.springframework.batch.sample.item.reader.GeneratingItemReader;
import org.springframework.batch.sample.item.writer.RetrySampleItemWriter;
/**
* Checks that expected number of items have been processed.
*
* @author Robert Kasanicky
*/
public class RetrySampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
private GeneratingItemReader itemGenerator;
private RetrySampleItemWriter itemProcessor;
protected String[] getConfigLocations() {
return new String[] {"jobs/retrySample.xml"};
}
protected void validatePostConditions() throws Exception {
//items processed = items read + 2 exceptions
assertEquals(itemGenerator.getLimit()+2, itemProcessor.getCounter());
}
public void setItemGenerator(GeneratingItemReader itemGenerator) {
this.itemGenerator = itemGenerator;
}
public void setItemProcessor(RetrySampleItemWriter itemProcessor) {
this.itemProcessor = itemProcessor;
}
}

View File

@@ -0,0 +1,31 @@
package org.springframework.batch.sample.item.reader;
import junit.framework.TestCase;
/**
* Tests for {@link GeneratingItemReader}.
*
* @author Robert Kasanicky
*/
public class GeneratingItemReaderTests extends TestCase {
private GeneratingItemReader reader = new GeneratingItemReader();
/**
* Generates a given number of not-null records,
* consecutive calls return null.
*/
public void testRead() throws Exception {
int counter = 0;
int limit = 10;
reader.setLimit(limit);
while (reader.read() != null) {
counter++;
}
assertEquals(null, reader.read());
assertEquals(limit, counter);
assertEquals(counter, reader.getCounter());
}
}

View File

@@ -0,0 +1,35 @@
package org.springframework.batch.sample.item.writer;
import junit.framework.TestCase;
/**
* Tests for {@link RetrySampleItemWriter}.
*
* @author Robert Kasanicky
*/
public class RetrySampleItemWriterTests extends TestCase {
private RetrySampleItemWriter processor = new RetrySampleItemWriter();
/**
* Processing throws exception on 2nd and 3rd call.
*/
public void testProcess() throws Exception {
Object item = null;
processor.write(item);
for (int i = 0; i < 2; i++) {
try {
processor.write(item);
fail();
}
catch (RuntimeException e) {
// expected
}
}
processor.write(item);
assertEquals(4, processor.getCounter());
}
}