IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)
http://jira.springframework.org/browse/BATCH-7 Remove Statistics* - use StreamContext instead.
This commit is contained in:
@@ -15,21 +15,20 @@ import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
|
||||
private static final String KEY = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + ".KEY.";
|
||||
private static final String KEY = ColumnMapStreamContextRowMapper.KEY_PREFIX;
|
||||
|
||||
ColumnMapStreamContextRowMapper mapper;
|
||||
private ColumnMapStreamContextRowMapper mapper;
|
||||
|
||||
Map key;
|
||||
private Map key;
|
||||
|
||||
MockControl psControl = MockControl.createControl(PreparedStatement.class);
|
||||
PreparedStatement ps;
|
||||
private MockControl psControl = MockControl.createControl(PreparedStatement.class);
|
||||
private PreparedStatement ps;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -44,7 +43,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
public void testCreateRestartDataWithInvalidType() throws Exception {
|
||||
|
||||
try{
|
||||
mapper.createRestartData(new Object());
|
||||
mapper.createStreamContext(new Object());
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
@@ -54,7 +53,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
public void testCreateRestartDataWithNull(){
|
||||
|
||||
try{
|
||||
mapper.createRestartData(null);
|
||||
mapper.createStreamContext(null);
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
@@ -62,8 +61,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testCreateRestartData() throws Exception {
|
||||
|
||||
StreamContext streamContext = mapper.createRestartData(key);
|
||||
StreamContext streamContext = mapper.createStreamContext(key);
|
||||
Properties props = streamContext.getProperties();
|
||||
assertEquals("1", props.getProperty(KEY + "0"));
|
||||
assertEquals("2", props.getProperty(KEY + "1"));
|
||||
@@ -71,7 +69,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
|
||||
public void testCreateRestartDataFromEmptyKeys() throws Exception {
|
||||
|
||||
StreamContext streamContext = mapper.createRestartData(new HashMap());
|
||||
StreamContext streamContext = mapper.createStreamContext(new HashMap());
|
||||
assertEquals(0, streamContext.getProperties().size());
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
public void testRestoreKeys(){
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty(ColumnMapStreamContextRowMapper.KEY + "0", "3");
|
||||
props.setProperty(ColumnMapStreamContextRowMapper.KEY + "1", "3");
|
||||
props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "0", "3");
|
||||
props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "1", "3");
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
|
||||
List keys = keyStrategy.restoreKeys(streamContext);
|
||||
@@ -72,8 +72,8 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
Properties props = streamContext.getProperties();
|
||||
|
||||
assertEquals(2, props.size());
|
||||
assertEquals("3", props.get(ColumnMapStreamContextRowMapper.KEY + "0"));
|
||||
assertEquals("3", props.get(ColumnMapStreamContextRowMapper.KEY + "1"));
|
||||
assertEquals("3", props.get(ColumnMapStreamContextRowMapper.KEY_PREFIX + "0"));
|
||||
assertEquals("3", props.get(ColumnMapStreamContextRowMapper.KEY_PREFIX + "1"));
|
||||
}
|
||||
|
||||
public void testGetNullKeyAsStreamContext(){
|
||||
|
||||
@@ -27,6 +27,7 @@ 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.item.StreamContext;
|
||||
import org.springframework.batch.item.StreamException;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -179,12 +180,16 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
|
||||
}
|
||||
|
||||
public void testRestartWithNullReader() throws Exception {
|
||||
public void testRestartBeforeOpen() throws Exception {
|
||||
inputSource = new DefaultFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
// do not open the template...
|
||||
inputSource.restoreFrom(inputSource.getStreamContext());
|
||||
try {
|
||||
inputSource.restoreFrom(inputSource.getStreamContext());
|
||||
} catch (StreamException e) {
|
||||
assertTrue("Message does not contain open: "+e.getMessage(), e.getMessage().contains("open"));
|
||||
}
|
||||
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,15 +24,12 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.item.reader.DelegatingItemReader;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* Unit test for {@link DelegatingItemReader}
|
||||
*
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemReaderTests extends TestCase {
|
||||
@@ -48,24 +45,25 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
itemProvider.setItemReader(source);
|
||||
}
|
||||
|
||||
public void testAfterPropertiesSet()throws Exception{
|
||||
//shouldn't throw an exception since the input source is set
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
// shouldn't throw an exception since the input source is set
|
||||
itemProvider.afterPropertiesSet();
|
||||
}
|
||||
|
||||
public void testNullItemReader(){
|
||||
try{
|
||||
public void testNullItemReader() {
|
||||
try {
|
||||
itemProvider.setItemReader(null);
|
||||
itemProvider.afterPropertiesSet();
|
||||
fail();
|
||||
}catch(Exception ex){
|
||||
}
|
||||
catch (Exception ex) {
|
||||
assertTrue(ex instanceof IllegalArgumentException);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses input template to provide the domain object.
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testNext() throws Exception {
|
||||
Object result = itemProvider.read();
|
||||
@@ -82,7 +80,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forwared restart data to input template
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
itemProvider.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
@@ -94,7 +92,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
assertEquals("after skip", itemProvider.read());
|
||||
}
|
||||
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, ItemStream, Skippable {
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, ItemStream, Skippable {
|
||||
|
||||
private Object value;
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -55,7 +53,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
assertEquals(1, list.size());
|
||||
assertEquals("test:foo", list.get(0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets restart data from the input template
|
||||
*/
|
||||
@@ -66,7 +64,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forward restart data to input template
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
@@ -76,7 +74,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forward restart data to input template
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testGetStreamContextWithoutItemStream() throws Exception {
|
||||
processor.setDelegate(null);
|
||||
@@ -91,7 +89,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forward restart data to input template
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromWithoutRestartable() throws Exception {
|
||||
processor.setDelegate(null);
|
||||
@@ -103,7 +101,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testSkip() {
|
||||
processor.skip();
|
||||
assertEquals(1, list.size());
|
||||
@@ -123,14 +121,14 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class MockOutputSource implements ItemWriter, StatisticsProvider, ItemStream, Skippable {
|
||||
public class MockOutputSource implements ItemWriter, ItemStream, Skippable {
|
||||
|
||||
private String value;
|
||||
|
||||
@@ -139,7 +137,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void write(Object output) {
|
||||
list.add(value+":"+output);
|
||||
list.add(value + ":" + output);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -161,7 +159,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void skip() {
|
||||
list.add("after skip");
|
||||
list.add("after skip");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.statistics;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStatisticsServiceTests extends TestCase {
|
||||
|
||||
private SimpleStatisticsService service = new SimpleStatisticsService();
|
||||
|
||||
public void testRegistration() throws Exception {
|
||||
service.register("FOO", new StubStatisticsProvider());
|
||||
assertEquals("bar", service.getStatistics("FOO").getProperty("foo"));
|
||||
}
|
||||
|
||||
public void testAggregation() throws Exception {
|
||||
service.register("FOO", new StubStatisticsProvider());
|
||||
service.register("FOO", new StubStatisticsProvider("spam=bucket"));
|
||||
assertEquals("bar", service.getStatistics("FOO").getProperty("foo"));
|
||||
assertEquals("bucket", service.getStatistics("FOO").getProperty("spam"));
|
||||
}
|
||||
|
||||
public void testDoubleAggregationOrder() throws Exception {
|
||||
StubStatisticsProvider provider = new StubStatisticsProvider();
|
||||
service.register("FOO", provider);
|
||||
service.register("FOO", provider);
|
||||
assertEquals(1, service.getStatistics("FOO").size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private class StubStatisticsProvider implements StatisticsProvider {
|
||||
String values = "foo=bar";
|
||||
|
||||
public StubStatisticsProvider(String values) {
|
||||
super();
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public StubStatisticsProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Properties getStatistics() {
|
||||
return PropertiesConverter.stringToProperties(values);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user