BATCH-365: Moved reset and mark to ItemReader interface.
This commit is contained in:
@@ -16,7 +16,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
ItemReader source;
|
||||
ItemReader itemReader;
|
||||
|
||||
static {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
@@ -25,7 +25,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
source = createItemReader();
|
||||
itemReader = createItemReader();
|
||||
}
|
||||
|
||||
private ItemReader createItemReader() throws Exception{
|
||||
@@ -41,24 +41,24 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
* Regular scenario - read all rows and eventually return null.
|
||||
*/
|
||||
public void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(source).afterPropertiesSet();
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
Foo foo3 = (Foo) source.read();
|
||||
Foo foo3 = (Foo) itemReader.read();
|
||||
assertEquals(3, foo3.getValue());
|
||||
|
||||
Foo foo4 = (Foo) source.read();
|
||||
Foo foo4 = (Foo) itemReader.read();
|
||||
assertEquals(4, foo4.getValue());
|
||||
|
||||
Foo foo5 = (Foo) source.read();
|
||||
Foo foo5 = (Foo) itemReader.read();
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
assertNull(source.read());
|
||||
assertNull(itemReader.read());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,20 +67,20 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
|
||||
ExecutionContext streamContext = getAsRestartable(itemReader).getExecutionContext();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
itemReader = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
Foo fooAfterRestart = (Foo) itemReader.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
}
|
||||
|
||||
@@ -89,22 +89,22 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testInvalidRestore() throws Exception {
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
|
||||
ExecutionContext streamContext = getAsRestartable(itemReader).getExecutionContext();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
itemReader = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -119,9 +119,9 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
ExecutionContext streamContext = new ExecutionContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
}
|
||||
|
||||
@@ -130,28 +130,28 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
|
||||
Foo foo3 = (Foo) source.read();
|
||||
Foo foo3 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
assertEquals(foo2, source.read());
|
||||
assertEquals(foo2, itemReader.read());
|
||||
}
|
||||
|
||||
|
||||
private void commit() {
|
||||
((ItemStream) source).mark();
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
((ItemStream) source).reset();
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected ItemReader source;
|
||||
protected ItemReader itemReader;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,12 +31,12 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
|
||||
protected void onSetUp()throws Exception{
|
||||
super.onSetUp();
|
||||
source = createItemReader();
|
||||
getAsInitializingBean(source).afterPropertiesSet();
|
||||
itemReader = createItemReader();
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
}
|
||||
|
||||
protected void onTearDown()throws Exception {
|
||||
getAsDisposableBean(source).destroy();
|
||||
getAsDisposableBean(itemReader).destroy();
|
||||
super.onTearDown();
|
||||
}
|
||||
|
||||
@@ -44,24 +44,24 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
* Regular scenario - read all rows and eventually return null.
|
||||
*/
|
||||
public void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(source).afterPropertiesSet();
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
Foo foo3 = (Foo) source.read();
|
||||
Foo foo3 = (Foo) itemReader.read();
|
||||
assertEquals(3, foo3.getValue());
|
||||
|
||||
Foo foo4 = (Foo) source.read();
|
||||
Foo foo4 = (Foo) itemReader.read();
|
||||
assertEquals(4, foo4.getValue());
|
||||
|
||||
Foo foo5 = (Foo) source.read();
|
||||
Foo foo5 = (Foo) itemReader.read();
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
assertNull(source.read());
|
||||
assertNull(itemReader.read());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,20 +70,20 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
*/
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
|
||||
ExecutionContext streamContext = getAsRestartable(itemReader).getExecutionContext();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
itemReader = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
Foo fooAfterRestart = (Foo) itemReader.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
}
|
||||
|
||||
@@ -92,22 +92,22 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
*/
|
||||
public void testInvalidRestore() throws Exception {
|
||||
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
|
||||
ExecutionContext streamContext = getAsRestartable(itemReader).getExecutionContext();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
itemReader = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -122,9 +122,9 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
ExecutionContext streamContext = new ExecutionContext();
|
||||
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
getAsRestartable(itemReader).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
}
|
||||
|
||||
@@ -133,28 +133,28 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
Foo foo2 = (Foo) source.read();
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
|
||||
Foo foo3 = (Foo) source.read();
|
||||
Foo foo3 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
assertEquals(foo2, source.read());
|
||||
assertEquals(foo2, itemReader.read());
|
||||
}
|
||||
|
||||
|
||||
private void commit() {
|
||||
((ItemStream) source).mark();
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
((ItemStream) source).reset();
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
|
||||
@@ -225,11 +225,11 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
((ItemStream) reader).mark();
|
||||
reader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
((ItemStream) reader).reset();
|
||||
reader.reset();
|
||||
}
|
||||
|
||||
private Skippable getAsSkippable(ItemReader source) {
|
||||
|
||||
@@ -168,25 +168,6 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testCommit() {
|
||||
manager.register("foo", new ItemStreamAdapter() {
|
||||
public boolean isMarkSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void mark() {
|
||||
list.add("bar");
|
||||
}
|
||||
});
|
||||
TransactionStatus status = manager.getTransaction("foo");
|
||||
manager.commit(status);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
@@ -202,25 +183,6 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#rollback(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testRollback() {
|
||||
manager.register("foo", new ItemStreamAdapter() {
|
||||
public boolean isMarkSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
list.add("bar");
|
||||
}
|
||||
});
|
||||
TransactionStatus status = manager.getTransaction("foo");
|
||||
manager.rollback(status);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#rollback(org.springframework.transaction.TransactionStatus)}.
|
||||
|
||||
Reference in New Issue
Block a user