IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)

http://jira.springframework.org/browse/BATCH-7

More Statistics removal
This commit is contained in:
dsyer
2008-01-31 14:45:39 +00:00
parent 93639e1928
commit c2ccb7ed02
14 changed files with 69 additions and 93 deletions

View File

@@ -17,14 +17,12 @@
package org.springframework.batch.io.file;
import java.io.IOException;
import java.util.Properties;
import junit.framework.TestCase;
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
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.mapping.FieldSetMapper;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.StreamException;
@@ -163,16 +161,16 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
inputSource.skip();
inputSource.read();
Properties statistics = inputSource.getStatistics();
String skipped = statistics.getProperty(DefaultFlatFileItemReader.SKIPPED_STATISTICS_NAME);
String read = statistics.getProperty(DefaultFlatFileItemReader.READ_STATISTICS_NAME);
StreamContext statistics = inputSource.getStreamContext();
long skipped = statistics.getLong(DefaultFlatFileItemReader.SKIPPED_STATISTICS_NAME);
long read = statistics.getLong(DefaultFlatFileItemReader.READ_STATISTICS_NAME);
// call unknown, which has no influence and therefore statistics should
// be the same
inputSource.getTransactionSynchronization().afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
statistics = inputSource.getStatistics();
assertEquals(skipped, statistics.getProperty(DefaultFlatFileItemReader.SKIPPED_STATISTICS_NAME));
assertEquals(read, statistics.getProperty(DefaultFlatFileItemReader.READ_STATISTICS_NAME));
statistics = inputSource.getStreamContext();;
assertEquals(skipped, statistics.getLong(DefaultFlatFileItemReader.SKIPPED_STATISTICS_NAME));
assertEquals(read, statistics.getLong(DefaultFlatFileItemReader.READ_STATISTICS_NAME));
}
public void testRestartFromNullData() throws Exception {
@@ -225,8 +223,8 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
assertEquals("[testLine5]", inputSource.read().toString());
assertEquals("[testLine6]", inputSource.read().toString());
Properties statistics = inputSource.getStatistics();
assertEquals("6", statistics.getProperty(DefaultFlatFileItemReader.READ_STATISTICS_NAME));
StreamContext statistics = inputSource.getStreamContext();
assertEquals(6, statistics.getLong(DefaultFlatFileItemReader.READ_STATISTICS_NAME));
}
}

View File

@@ -21,7 +21,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.Properties;
import junit.framework.TestCase;
@@ -345,6 +344,8 @@ public class FlatFileItemWriterTests extends TestCase {
inputSource.write("testLine7");
inputSource.write("testLine8");
// get statistics
StreamContext statistics = inputSource.getStreamContext();
// close template
inputSource.close();
@@ -353,10 +354,8 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals("testLine" + i, readLine());
}
// get statistics
Properties statistics = inputSource.getStatistics();
// 3 lines were written to the file after restart
assertEquals("3", statistics.getProperty(FlatFileItemWriter.WRITTEN_STATISTICS_NAME));
assertEquals(3, statistics.getLong(FlatFileItemWriter.WRITTEN_STATISTICS_NAME));
}
@@ -373,10 +372,11 @@ public class FlatFileItemWriterTests extends TestCase {
public void testDefaultStreamContext() throws Exception {
inputSource = new FlatFileItemWriter();
inputSource.open();
StreamContext streamContext = inputSource.getStreamContext();
assertNotNull(streamContext);
assertEquals(1, streamContext.getProperties().size());
assertEquals("0", streamContext.getProperties().getProperty(FlatFileItemWriter.RESTART_DATA_NAME));
assertEquals(3, streamContext.getProperties().size());
assertEquals(0, streamContext.getLong(FlatFileItemWriter.RESTART_DATA_NAME));
}
private void commit() {

View File

@@ -29,7 +29,7 @@ import org.springframework.transaction.support.TransactionSynchronization;
*
* @author Robert Kasanicky
*/
public class StaxEventReaderItemReaderTests extends TestCase {
public class StaxEventItemReaderTests extends TestCase {
// object under test
private StaxEventItemReader source;
@@ -216,9 +216,13 @@ public class StaxEventReaderItemReaderTests extends TestCase {
assertEquals(NUMBER_OF_RECORDS, extractRecordCountFrom(source.getStatistics()));
}
public void testClose() throws Exception{
public void testCloseWithoutOpen() throws Exception{
source.close();
// No error!
}
MockStaxEventReaderItemReader newSource = new MockStaxEventReaderItemReader();
public void testClose() throws Exception{
MockStaxEventItemReader newSource = new MockStaxEventItemReader();
Resource resource = new ByteArrayResource(xml.getBytes());
newSource.setResource(resource);
@@ -229,7 +233,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
assertNotNull(item);
assertTrue(newSource.isOpenCalled());
newSource.destroy();
newSource.destroy(); // includes close()
newSource.setOpenCalled(false);
//calling read again should require re-initialization because of close
item = newSource.read();
@@ -375,7 +379,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
}
private static class MockStaxEventReaderItemReader extends StaxEventItemReader {
private static class MockStaxEventItemReader extends StaxEventItemReader {
private boolean openCalled = false;