BATCH-610:Merged change from 1.0.x to 1.1, fixes JdbcCurosItemReader issue

This commit is contained in:
lucasward
2008-05-02 15:18:18 +00:00
parent 43b9240241
commit 0cf7d45026
2 changed files with 81 additions and 60 deletions

View File

@@ -1,59 +1,79 @@
package org.springframework.batch.item;
import org.springframework.batch.item.sample.Foo;
/**
* Common tests for readers implementing both {@link ItemReader} and
* {@link ItemStream}. Expected input is five {@link Foo} objects with values 1
* to 5.
*/
public abstract class CommonItemStreamItemReaderTests extends CommonItemReaderTests {
protected ExecutionContext executionContext = new ExecutionContext();
/**
* Cast the reader to ItemStream.
*/
protected ItemStream testedAsStream() {
return (ItemStream) tested;
}
protected void setUp() throws Exception {
super.setUp();
testedAsStream().open(executionContext);
}
protected void tearDown() throws Exception {
super.tearDown();
testedAsStream().close(executionContext);
}
/**
* Restart scenario - read items, update execution context, create new
* reader and restore from restart data - the new input source should
* continue where the old one finished.
*/
public void testRestart() throws Exception {
testedAsStream().update(executionContext);
Foo foo1 = (Foo) tested.read();
assertEquals(1, foo1.getValue());
Foo foo2 = (Foo) tested.read();
assertEquals(2, foo2.getValue());
testedAsStream().update(executionContext);
// create new input source
tested = getItemReader();
testedAsStream().open(executionContext);
Foo fooAfterRestart = (Foo) tested.read();
assertEquals(3, fooAfterRestart.getValue());
}
}
package org.springframework.batch.item;
import org.springframework.batch.item.sample.Foo;
/**
* Common tests for readers implementing both {@link ItemReader} and
* {@link ItemStream}. Expected input is five {@link Foo} objects with values 1
* to 5.
*/
public abstract class CommonItemStreamItemReaderTests extends CommonItemReaderTests {
protected ExecutionContext executionContext = new ExecutionContext();
/**
* Cast the reader to ItemStream.
*/
protected ItemStream testedAsStream() {
return (ItemStream) tested;
}
protected void setUp() throws Exception {
super.setUp();
testedAsStream().open(executionContext);
}
protected void tearDown() throws Exception {
super.tearDown();
testedAsStream().close(executionContext);
}
/**
* Restart scenario - read items, update execution context, create new
* reader and restore from restart data - the new input source should
* continue where the old one finished.
*/
public void testRestart() throws Exception {
testedAsStream().update(executionContext);
Foo foo1 = (Foo) tested.read();
assertEquals(1, foo1.getValue());
Foo foo2 = (Foo) tested.read();
assertEquals(2, foo2.getValue());
testedAsStream().update(executionContext);
// create new input source
tested = getItemReader();
testedAsStream().open(executionContext);
Foo fooAfterRestart = (Foo) tested.read();
assertEquals(3, fooAfterRestart.getValue());
}
public void testReopen() throws Exception {
testedAsStream().update(executionContext);
Foo foo1 = (Foo) tested.read();
assertEquals(1, foo1.getValue());
Foo foo2 = (Foo) tested.read();
assertEquals(2, foo2.getValue());
testedAsStream().update(executionContext);
// create new input source
testedAsStream().close(executionContext);
testedAsStream().open(executionContext);
Foo fooAfterRestart = (Foo) tested.read();
assertEquals(3, fooAfterRestart.getValue());
}
}