RESOLVED - BATCH-34: Support for multiple I/O files in a single jobRun for a particular scheduleDate.
multiResourceJob used as sample also for output
This commit is contained in:
@@ -53,7 +53,7 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
|
||||
//auto-injected attributes
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private Resource fileLocator;
|
||||
private FlatFileItemReader<Trade> inputSource;
|
||||
protected FlatFileItemReader<Trade> itemReader;
|
||||
private LineTokenizer lineTokenizer;
|
||||
|
||||
@Autowired
|
||||
@@ -71,16 +71,17 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
|
||||
public void onSetUp() throws Exception {
|
||||
simpleJdbcTemplate.update("delete from TRADE");
|
||||
fileLocator = new ClassPathResource("data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt");
|
||||
inputSource = new FlatFileItemReader<Trade>();
|
||||
itemReader = new FlatFileItemReader<Trade>();
|
||||
|
||||
FieldSetMapper<Trade> mapper = new TradeFieldSetMapper();
|
||||
DefaultLineMapper<Trade> lineMapper = new DefaultLineMapper<Trade>();
|
||||
lineMapper.setLineTokenizer(lineTokenizer);
|
||||
lineMapper.setFieldSetMapper(mapper);
|
||||
inputSource.setLineMapper(lineMapper);
|
||||
itemReader.setLineMapper(lineMapper);
|
||||
|
||||
|
||||
inputSource.setResource(fileLocator);
|
||||
itemReader.setResource(fileLocator);
|
||||
itemReader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +90,6 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
|
||||
inputSource.open(new ExecutionContext());
|
||||
|
||||
simpleJdbcTemplate.getJdbcOperations().query(
|
||||
"SELECT ID, ISIN, QUANTITY, PRICE, CUSTOMER FROM trade ORDER BY id",
|
||||
@@ -97,7 +97,7 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade;
|
||||
try {
|
||||
trade = inputSource.read();
|
||||
trade = itemReader.read();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e.getMessage());
|
||||
@@ -110,7 +110,7 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
|
||||
|
||||
});
|
||||
|
||||
assertNull(inputSource.read());
|
||||
assertNull(itemReader.read());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,6 +17,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration()
|
||||
public class MultiResourceJobFunctionalTests extends FixedLengthImportJobFunctionalTests {
|
||||
|
||||
/**
|
||||
* Context: 5 items overall, min. 2 items per output file, commitInterval=3,
|
||||
* => two files created, with 3 items in the first and two in second.
|
||||
*/
|
||||
@Override
|
||||
protected void validatePostConditions() throws Exception {
|
||||
File file1 = new File("target/test-outputs/multiResourceOutput.txt.1");
|
||||
File file2 = new File("target/test-outputs/multiResourceOutput.txt.2");
|
||||
assertTrue(file1.exists());
|
||||
assertTrue(file2.exists());
|
||||
|
||||
BufferedReader reader1 = new BufferedReader(new FileReader(file1));
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
assertEquals(itemReader.read().toString(), reader1.readLine());
|
||||
}
|
||||
assertNull(reader1.readLine());
|
||||
|
||||
BufferedReader reader2 = new BufferedReader(new FileReader(file2));
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
assertEquals(itemReader.read().toString(), reader2.readLine());
|
||||
}
|
||||
assertNull(reader2.readLine());
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setJob(@Qualifier("multiResourceJob") Job job) {
|
||||
|
||||
Reference in New Issue
Block a user