OPEN - issue BATCH-498: Skip method should get ExecutionContext as an argument

Removed Skippable interface.  TODO: beef up configuration of step factory with skips.
This commit is contained in:
dsyer
2008-03-25 17:41:00 +00:00
parent dba4209d7e
commit ea4e6f9ab1
12 changed files with 101 additions and 331 deletions

View File

@@ -3,7 +3,6 @@ package org.springframework.batch.item.database;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.Skippable;
import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
@@ -162,45 +161,11 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
}
/**
* Rollback scenario with skip - input source rollbacks to last commit
* point.
* @throws Exception
*/
public void testRollbackAndSkip() throws Exception {
if (!(reader instanceof Skippable)) {
return;
}
Foo foo1 = (Foo) reader.read();
commit();
Foo foo2 = (Foo) reader.read();
Assert.state(!foo2.equals(foo1));
Foo foo3 = (Foo) reader.read();
Assert.state(!foo2.equals(foo3));
getAsSkippable(reader).skip();
rollback();
assertEquals(foo2, reader.read());
Foo foo4 = (Foo) reader.read();
assertEquals(4, foo4.getValue());
}
/**
* Rollback scenario with skip and restart - input source rollbacks to last
* Rollback scenario with restart - input source rollbacks to last
* commit point.
* @throws Exception
*/
public void testRollbackSkipAndRestart() throws Exception {
if (!(reader instanceof Skippable)) {
return;
}
public void testRollbackAndRestart() throws Exception {
getAsItemStream(reader).open(executionContext);
@@ -214,8 +179,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
Foo foo3 = (Foo) reader.read();
Assert.state(!foo2.equals(foo3));
getAsSkippable(reader).skip();
rollback();
getAsItemStream(reader).update(executionContext);
@@ -226,8 +189,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
getAsItemStream(reader).open(executionContext);
assertEquals(foo2, reader.read());
Foo foo4 = (Foo) reader.read();
assertEquals(4, foo4.getValue());
assertEquals(foo3, reader.read());
}
private void commit() {
@@ -238,10 +200,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
reader.reset();
}
private Skippable getAsSkippable(ItemReader source) {
return (Skippable) source;
}
private ItemStream getAsItemStream(ItemReader source) {
return (ItemStream) source;
}

View File

@@ -83,11 +83,11 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
}
/**
* Test skip and skipRollback functionality
* Test rollback functionality
*
* @throws IOException
*/
public void testSkip() throws Exception {
public void testReset() throws Exception {
reader.close(null);
reader.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
@@ -100,21 +100,13 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
reader.mark();
// read next record
reader.read(); // # 3
// mark record as skipped
reader.skip();
// read next records
reader.reset();
// we should now process all records after first commit point, that are
// not marked as skipped
assertEquals("[testLine4]", reader.read().toString());
// we should now process all records after first commit point
assertEquals("[testLine3]", reader.read().toString());
// TODO update
// Map statistics = template.getStatistics();
// assertEquals("6",
// statistics.get(FlatFileInputTemplate.READ_STATISTICS_NAME));
// assertEquals("2",
// statistics.get(FlatFileInputTemplate.SKIPPED_STATISTICS_NAME));
// TODO update and assert ExecutionContext
}
@@ -123,7 +115,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
*
* @throws IOException
*/
public void testSkipFirstChunk() throws Exception {
public void testFailOnFirstChunk() throws Exception {
reader.close(null);
reader.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
@@ -133,8 +125,6 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
reader.read(); // #1
reader.read(); // #2
reader.read(); // #3
// mark record as skipped
reader.skip();
// rollback
reader.reset();
// read next record

View File

@@ -22,8 +22,6 @@ import org.springframework.batch.item.AbstractItemReader;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.Skippable;
import org.springframework.batch.item.support.DelegatingItemReader;
/**
* Unit test for {@link DelegatingItemReader}
@@ -71,12 +69,7 @@ public class DelegatingItemReaderTests extends TestCase {
assertSame("domain object is provided by the input template", this, result);
}
public void testSkip() throws Exception {
itemProvider.skip();
assertEquals("after skip", itemProvider.read());
}
private static class MockItemReader extends AbstractItemReader implements ItemReader, ItemStream, Skippable {
private static class MockItemReader extends AbstractItemReader implements ItemReader, ItemStream {
private Object value;
@@ -98,10 +91,6 @@ public class DelegatingItemReaderTests extends TestCase {
public void open(ExecutionContext executionContext) {
}
public void skip() {
value = "after skip";
}
public void mark() {
}

View File

@@ -148,20 +148,6 @@ public class StaxEventItemReaderTests extends TestCase {
source.update(executionContext);
}
/**
* Skipping marked records after rollback.
*/
public void testSkip() {
source.open(executionContext);
List first = (List) source.read();
source.skip();
List second = (List) source.read();
assertFalse(first.equals(second));
source.reset();
assertEquals(second, source.read());
}
/**
* Rollback to last commited record.
*/