forked from langmi/spring-batch-examples
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example for groking http://forum.springsource.org/showthread.php?1206…
- Loading branch information
Showing
5 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
playground/src/main/resources/spring/batch/job/parallel-flows-job.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2011 Michael R. Lange <michael.r.lange@langmi.de>. | ||
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. | ||
--> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> | ||
|
||
<description> | ||
Test for issue with parallel flows seen at | ||
http://forum.springsource.org/showthread.php?120629-Parallel-steps-issue-in-a-job | ||
</description> | ||
<!-- | ||
inline xmlns, otherwise it would look like | ||
'batch:job, batch:step, etc.' | ||
--> | ||
|
||
<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" /> | ||
|
||
<job id="parallelFlowsJob" xmlns="http://www.springframework.org/schema/batch"> | ||
<split id="parallelProcessing" task-executor="taskExecutor"> | ||
<flow> | ||
<step id="step1" parent="file1Step" /> | ||
</flow> | ||
<flow> | ||
<step id="step2" parent="file2Step" /> | ||
</flow> | ||
<flow> | ||
<step id="step3" parent="file3Step" /> | ||
</flow> | ||
</split> | ||
</job> | ||
|
||
<step id="file1Step" xmlns="http://www.springframework.org/schema/batch"> | ||
<tasklet> | ||
<chunk reader="itemReader1" processor="itemProcessor" writer="itemWriter" commit-interval="5" /> | ||
</tasklet> | ||
</step> | ||
|
||
<step id="file2Step" xmlns="http://www.springframework.org/schema/batch"> | ||
<tasklet> | ||
<chunk reader="itemReader2" processor="itemProcessor" writer="itemWriter" commit-interval="5" /> | ||
</tasklet> | ||
</step> | ||
|
||
<step id="file3Step" xmlns="http://www.springframework.org/schema/batch"> | ||
<tasklet> | ||
<chunk reader="itemReader3" processor="itemProcessor" writer="itemWriter" commit-interval="5" /> | ||
</tasklet> | ||
</step> | ||
|
||
<bean id="itemReader1" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> | ||
<property name="resource" value="#{jobParameters['input.file.1']}" /> | ||
<property name="lineMapper"> | ||
<bean class="org.springframework.batch.item.file.mapping.PassThroughLineMapper" /> | ||
</property> | ||
<property name="strict" value="true" /> | ||
</bean> | ||
|
||
<bean id="itemReader2" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> | ||
<property name="resource" value="#{jobParameters['input.file.2']}" /> | ||
<property name="lineMapper"> | ||
<bean class="org.springframework.batch.item.file.mapping.PassThroughLineMapper" /> | ||
</property> | ||
<property name="strict" value="true" /> | ||
</bean> | ||
|
||
<bean id="itemReader3" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> | ||
<property name="resource" value="#{jobParameters['input.file.3']}" /> | ||
<property name="lineMapper"> | ||
<bean class="org.springframework.batch.item.file.mapping.PassThroughLineMapper" /> | ||
</property> | ||
<property name="strict" value="true" /> | ||
</bean> | ||
|
||
<bean id="itemProcessor" class="de.langmi.spring.batch.examples.playground.SimpleItemProcessor" /> | ||
|
||
<bean id="itemWriter" class="de.langmi.spring.batch.examples.playground.SimpleItemWriter" /> | ||
|
||
</beans> |
63 changes: 63 additions & 0 deletions
63
...mi/spring/batch/examples/playground/parallel/flows/ParallelFlowsJobConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright 2011 Michael R. Lange <michael.r.lange@langmi.de>. | ||
* | ||
* 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 de.langmi.spring.batch.examples.playground.parallel.flows; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.batch.core.BatchStatus; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParameter; | ||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.test.JobLauncherTestUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* JobConfigurationTest. | ||
* | ||
* @author Michael R. Lange <michael.r.lange@langmi.de> | ||
*/ | ||
@ContextConfiguration(locations = { | ||
"classpath*:spring/batch/job/parallel-flows-job.xml", | ||
"classpath*:spring/batch/setup/**/*.xml"}) | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
public class ParallelFlowsJobConfigurationTest { | ||
|
||
/** JobLauncherTestUtils Bean. */ | ||
@Autowired | ||
private JobLauncherTestUtils jobLauncherTestUtils; | ||
|
||
/** Launch Test. */ | ||
@Test | ||
public void launchJob() throws Exception { | ||
// Job parameters | ||
Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>(); | ||
jobParametersMap.put("time", new JobParameter(System.currentTimeMillis())); | ||
jobParametersMap.put("input.file.1", new JobParameter("file:src/test/resources/input/parallel-flows/input1.txt")); | ||
jobParametersMap.put("input.file.2", new JobParameter("file:src/test/resources/input/parallel-flows/input2.txt")); | ||
jobParametersMap.put("input.file.3", new JobParameter("file:src/test/resources/input/parallel-flows/input3.txt")); | ||
|
||
// launch the job | ||
JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap)); | ||
|
||
// assert job run status | ||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
playground/src/test/resources/input/parallel-flows/input1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 |
20 changes: 20 additions & 0 deletions
20
playground/src/test/resources/input/parallel-flows/input2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 |
20 changes: 20 additions & 0 deletions
20
playground/src/test/resources/input/parallel-flows/input3.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 |