BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)
http://jira.springframework.org/browse/BATCH-7 Rename Restartable to ItemStream
This commit is contained in:
@@ -8,9 +8,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -76,12 +76,12 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -98,7 +98,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -107,7 +107,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -120,9 +120,9 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -165,13 +165,13 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private static class MockKeyGenerator implements KeyGenerator{
|
||||
|
||||
static RestartData restartData;
|
||||
static StreamContext streamContext;
|
||||
List keys;
|
||||
List restartKeys;
|
||||
|
||||
@@ -180,7 +180,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
//restart data properties cannot be empty.
|
||||
props.setProperty("", "");
|
||||
|
||||
restartData = new GenericRestartData(props);
|
||||
streamContext = new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
public MockKeyGenerator() {
|
||||
@@ -198,13 +198,13 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
restartKeys.add(new Foo(5, "5", 5));
|
||||
}
|
||||
|
||||
public RestartData getKeyAsRestartData(Object key) {
|
||||
return restartData;
|
||||
public StreamContext getKeyAsRestartData(Object key) {
|
||||
return streamContext;
|
||||
}
|
||||
|
||||
public List restoreKeys(RestartData restartData) {
|
||||
public List restoreKeys(StreamContext streamContext) {
|
||||
|
||||
assertEquals(MockKeyGenerator.restartData, restartData);
|
||||
assertEquals(MockKeyGenerator.streamContext, streamContext);
|
||||
return restartKeys;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, Restartable, DisposableBean, InitializingBean{
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, ItemStream, DisposableBean, InitializingBean{
|
||||
|
||||
DrivingQueryItemReader inputSource;
|
||||
FooDao fooDao = new SingleKeyFooDao();
|
||||
@@ -27,11 +27,11 @@ class FooItemReader extends AbstractItemReader implements ItemReader, Restartabl
|
||||
}
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
return inputSource.getRestartData();
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
inputSource.restoreFrom(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -63,16 +63,16 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
|
||||
public void testCreateRestartData() throws Exception {
|
||||
|
||||
RestartData restartData = mapper.createRestartData(key);
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = mapper.createRestartData(key);
|
||||
Properties props = streamContext.getProperties();
|
||||
assertEquals("1", props.getProperty(KEY + "0"));
|
||||
assertEquals("2", props.getProperty(KEY + "1"));
|
||||
}
|
||||
|
||||
public void testCreateRestartDataFromEmptyKeys() throws Exception {
|
||||
|
||||
RestartData restartData = mapper.createRestartData(new HashMap());
|
||||
assertEquals(0, restartData.getProperties().size());
|
||||
StreamContext streamContext = mapper.createRestartData(new HashMap());
|
||||
assertEquals(0, streamContext.getProperties().size());
|
||||
}
|
||||
|
||||
public void testCreateSetter() throws Exception {
|
||||
@@ -80,8 +80,8 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(KEY + "0", "1");
|
||||
props.setProperty(KEY + "1", "2");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
PreparedStatementSetter setter = mapper.createSetter(restartData);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
PreparedStatementSetter setter = mapper.createSetter(streamContext);
|
||||
ps = (PreparedStatement)psControl.getMock();
|
||||
|
||||
ps.setString(1, "1");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
@@ -49,9 +49,9 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
Properties props = new Properties();
|
||||
props.setProperty(ColumnMapRestartDataRowMapper.KEY + "0", "3");
|
||||
props.setProperty(ColumnMapRestartDataRowMapper.KEY + "1", "3");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
|
||||
List keys = keyStrategy.restoreKeys(restartData);
|
||||
List keys = keyStrategy.restoreKeys(streamContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
Map key = (Map)keys.get(0);
|
||||
@@ -68,8 +68,8 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
key.put("ID", new Long(3));
|
||||
key.put("VALUE", new Integer(3));
|
||||
|
||||
RestartData restartData = keyStrategy.getKeyAsRestartData(key);
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = keyStrategy.getKeyAsRestartData(key);
|
||||
Properties props = streamContext.getProperties();
|
||||
|
||||
assertEquals(2, props.size());
|
||||
assertEquals("3", props.get(ColumnMapRestartDataRowMapper.KEY + "0"));
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.springframework.batch.io.driving.support;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
@@ -44,9 +44,9 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty(SingleColumnJdbcKeyGenerator.RESTART_KEY, "3");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
|
||||
List keys = keyStrategy.restoreKeys(restartData);
|
||||
List keys = keyStrategy.restoreKeys(streamContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
assertEquals(new Long(4), keys.get(0));
|
||||
@@ -55,8 +55,8 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
public void testGetKeyAsRestartData(){
|
||||
|
||||
RestartData restartData = keyStrategy.getKeyAsRestartData(new Long(3));
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = keyStrategy.getKeyAsRestartData(new Long(3));
|
||||
Properties props = streamContext.getProperties();
|
||||
|
||||
assertEquals(1, props.size());
|
||||
assertEquals("3", props.get(SingleColumnJdbcKeyGenerator.RESTART_KEY));
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.transform.LineTokenizer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -204,8 +204,8 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
inputSource.read();
|
||||
|
||||
// get restart data
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
assertEquals("4", (String) restartData.getProperties().getProperty(
|
||||
StreamContext streamContext = inputSource.getRestartData();
|
||||
assertEquals("4", (String) streamContext.getProperties().getProperty(
|
||||
DefaultFlatFileItemReader.READ_STATISTICS_NAME));
|
||||
// close input
|
||||
inputSource.close();
|
||||
@@ -214,7 +214,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// init for restart
|
||||
inputSource.open();
|
||||
inputSource.restoreFrom(restartData);
|
||||
inputSource.restoreFrom(streamContext);
|
||||
|
||||
// read remaining records
|
||||
assertEquals("[testLine5]", inputSource.read().toString());
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -320,7 +320,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
commit();
|
||||
|
||||
// get restart data
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
StreamContext restartData = inputSource.getRestartData();
|
||||
// close template
|
||||
inputSource.close();
|
||||
|
||||
@@ -373,10 +373,10 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
public void testDefaultRestartData() throws Exception {
|
||||
inputSource = new FlatFileItemWriter();
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
assertNotNull(restartData);
|
||||
assertEquals(1, restartData.getProperties().size());
|
||||
assertEquals("0", restartData.getProperties().getProperty(FlatFileItemWriter.RESTART_DATA_NAME));
|
||||
StreamContext streamContext = inputSource.getRestartData();
|
||||
assertNotNull(streamContext);
|
||||
assertEquals(1, streamContext.getProperties().size());
|
||||
assertEquals("0", streamContext.getProperties().getProperty(FlatFileItemWriter.RESTART_DATA_NAME));
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.util.Properties;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -85,12 +85,12 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -107,7 +107,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -116,7 +116,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -129,9 +129,9 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -170,8 +170,8 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
|
||||
@@ -6,9 +6,9 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -92,12 +92,12 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -114,7 +114,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -123,7 +123,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -136,9 +136,9 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -217,12 +217,12 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
|
||||
rollback();
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
assertEquals(foo2, source.read());
|
||||
Foo foo4 = (Foo) source.read();
|
||||
@@ -245,8 +245,8 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
return (Skippable) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
|
||||
@@ -16,8 +16,8 @@ import javax.xml.stream.events.XMLEvent;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.xml.StaxEventItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -117,13 +117,13 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() {
|
||||
source.read();
|
||||
RestartData restartData = source.getRestartData();
|
||||
assertEquals("1", restartData.getProperties().
|
||||
StreamContext streamContext = source.getRestartData();
|
||||
assertEquals("1", streamContext.getProperties().
|
||||
getProperty("StaxEventReaderItemReader.recordcount"));
|
||||
List expectedAfterRestart = (List) source.read();
|
||||
|
||||
source = createNewInputSouce();
|
||||
source.restoreFrom(restartData);
|
||||
source.restoreFrom(streamContext);
|
||||
List afterRestart = (List) source.read();
|
||||
assertEquals(expectedAfterRestart.size(), afterRestart.size());
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
setProperty("StaxEventReaderItemReader.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
}};
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(props));
|
||||
source.restoreFrom(new GenericStreamContext(props));
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -148,7 +148,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
source = createNewInputSouce();
|
||||
source.open();
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(new Properties()));
|
||||
source.restoreFrom(new GenericStreamContext(new Properties()));
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import junit.framework.TestCase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.batch.io.xml.StaxEventItemWriter;
|
||||
import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -92,11 +92,11 @@ public class StaxEventWriterItemWriterTests extends TestCase {
|
||||
// write records
|
||||
writer.write(record);
|
||||
writer.getSynchronization().afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
|
||||
RestartData restartData = writer.getRestartData();
|
||||
StreamContext streamContext = writer.getRestartData();
|
||||
|
||||
// create new writer from saved restart data and continue writing
|
||||
writer = createItemWriter();
|
||||
writer.restoreFrom(restartData);
|
||||
writer.restoreFrom(streamContext);
|
||||
writer.write(record);
|
||||
writer.destroy();
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.item.reader.DelegatingItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
itemProvider.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
itemProvider.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
assertEquals("bar", itemProvider.read());
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
assertEquals("after skip", itemProvider.read());
|
||||
}
|
||||
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, Restartable, Skippable {
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, ItemStream, Skippable {
|
||||
|
||||
private Object value;
|
||||
|
||||
@@ -102,11 +102,11 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return new GenericRestartData(PropertiesConverter.stringToProperties("value=foo"));
|
||||
public StreamContext getRestartData() {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.CompositeItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeItemWriter}
|
||||
@@ -75,7 +75,7 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
}};
|
||||
itemProcessor.setItemWriters(itemProcessors);
|
||||
|
||||
RestartData rd = itemProcessor.getRestartData();
|
||||
StreamContext rd = itemProcessor.getRestartData();
|
||||
itemProcessor.restoreFrom(rd);
|
||||
|
||||
for (Iterator iterator = itemProcessors.iterator(); iterator.hasNext();) {
|
||||
@@ -120,7 +120,7 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
* Stub for testing restart. Checks the restart data received is the same that was returned by
|
||||
* <code>getRestartData()</code>
|
||||
*/
|
||||
private static class ItemWriterStub implements ItemWriter, Restartable, StatisticsProvider {
|
||||
private static class ItemWriterStub implements ItemWriter, ItemStream, StatisticsProvider {
|
||||
|
||||
private static final String RESTART_KEY = "restartData";
|
||||
private static final String STATS_KEY = "stats";
|
||||
@@ -130,14 +130,14 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
private final int hashCode = this.hashCode();
|
||||
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
Properties props = new Properties(){{
|
||||
setProperty(RESTART_KEY, String.valueOf(hashCode));
|
||||
}};
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (Integer.valueOf(data.getProperties().getProperty(RESTART_KEY)).intValue() != hashCode()) {
|
||||
fail("received restart data is not the same which was saved");
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.write("foo");
|
||||
assertEquals("bar:foo", list.get(0));
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
public void testRestoreFromWithoutRestartable() throws Exception {
|
||||
processor.setDelegate(null);
|
||||
try {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -130,7 +130,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class MockOutputSource implements ItemWriter, StatisticsProvider, Restartable, Skippable {
|
||||
public class MockOutputSource implements ItemWriter, StatisticsProvider, ItemStream, Skippable {
|
||||
|
||||
private String value;
|
||||
|
||||
@@ -152,11 +152,11 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return new GenericRestartData(PropertiesConverter.stringToProperties("value=foo"));
|
||||
public StreamContext getRestartData() {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user