Skip to content

Commit 2781239

Browse files
committed
Merge pull request #226 from radcortez/master
Documentation to split and multiple-steps
2 parents c2d4ae2 + d91770d commit 2781239

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

batch/multiple-steps/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
<artifactId>multiple-steps</artifactId>
1313
<packaging>war</packaging>
14-
15-
<name>${project.artifactId}</name>
14+
<name>Batch Multiple Steps</name>
15+
<description>Batch JSL - Executing Multiple Steps</description>
1616

1717
<dependencies>
1818
<dependency>

batch/multiple-steps/src/test/java/org/javaee7/batch/multiple/steps/BatchMultipleStepsTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@
2121
import static org.junit.Assert.assertEquals;
2222

2323
/**
24+
* The Batch specification allows you to implement process workflows using a Job Specification Language (JSL). In this
25+
* sample, by using the +step+ element, it's possible to configure a job that runs multiple steps.
26+
*
27+
* One Chunk oriented Step and a Batchlet are configured in the file +myJob.xml+. They both execute in order of
28+
* declaration. First the Chunk oriented Step and finally the Batchlet Step.
29+
*
2430
* @author Roberto Cortez
2531
*/
2632
@RunWith(Arquillian.class)
2733
public class BatchMultipleStepsTest {
34+
/**
35+
* We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
36+
*
37+
* [source,file]
38+
* ----
39+
* /META-INF/batch-jobs/myjob.xml
40+
* ----
41+
*
42+
* The +myjob.xml+ file is needed for running the batch definition.
43+
*/
2844
@Deployment
2945
public static WebArchive createDeployment() {
3046
WebArchive war = ShrinkWrap.create(WebArchive.class)
@@ -36,6 +52,13 @@ public static WebArchive createDeployment() {
3652
return war;
3753
}
3854

55+
/**
56+
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
57+
* expected behaviour we need to query +JobOperator#getStepExecutions+ and the +Metric[]+ object available in the
58+
* step execution.
59+
*
60+
* @throws Exception an exception if the batch could not complete successfully.
61+
*/
3962
@Test
4063
public void testBatchMultipleSteps() throws Exception {
4164
JobOperator jobOperator = BatchRuntime.getJobOperator();
@@ -51,14 +74,17 @@ public void testBatchMultipleSteps() throws Exception {
5174

5275
if (stepExecution.getStepName().equals("step1")) {
5376
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
54-
System.out.println(metricsMap);
5577
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
5678
assertEquals(10L / 2, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
5779
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
5880
}
5981
}
82+
83+
// <1> Make sure all the steps were executed.
6084
assertEquals(2, stepExecutions.size());
85+
// <2> Make sure all the steps were executed in order of declaration.
6186
assertArrayEquals(new String[]{"step1", "step2"}, executedSteps.toArray());
87+
// <3> Job should be completed.
6288
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
6389
}
6490
}

batch/split/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
<artifactId>split</artifactId>
1313
<packaging>war</packaging>
14-
15-
<name>${project.artifactId}</name>
14+
<name>Batch Split</name>
15+
<description>Batch JSL - Splitting Steps</description>
1616

1717
<dependencies>
1818
<dependency>

batch/split/src/test/java/org/javaee7/batch/split/BatchSplitTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,29 @@
2323
import static org.junit.Assert.assertTrue;
2424

2525
/**
26+
* The Batch specification allows you to implement process workflows using a Job Specification Language (JSL). In this
27+
* sample, by using the +split+ element, it's possible to configure a job that runs parallel flows. A +split+ can only
28+
* contain +flow+ elements. These +flow+ elements can be used to implement separate executions to be processed by the
29+
* job.
30+
*
31+
* Three simple Batchlet's are configured in the file +myjob.xml+. +MyBatchlet1+ and +MyBatchlet2+ are setted up to
32+
* execute in parallel by using the +split+ and +flow+ elements. +MyBatchlet3+ is only going to execute after
33+
* +MyBatchlet1+ and +MyBatchlet2+ are both done with their job.
34+
*
2635
* @author Roberto Cortez
2736
*/
2837
@RunWith(Arquillian.class)
2938
public class BatchSplitTest {
39+
/**
40+
* We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
41+
*
42+
* [source,file]
43+
* ----
44+
* /META-INF/batch-jobs/myjob.xml
45+
* ----
46+
*
47+
* The +myjob.xml+ file is needed for running the batch definition.
48+
*/
3049
@Deployment
3150
public static WebArchive createDeployment() {
3251
WebArchive war = ShrinkWrap.create(WebArchive.class)
@@ -38,6 +57,12 @@ public static WebArchive createDeployment() {
3857
return war;
3958
}
4059

60+
/**
61+
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
62+
* expected behaviour we need to query +JobOperator#getStepExecutions+.
63+
*
64+
* @throws Exception an exception if the batch could not complete successfully.
65+
*/
4166
@Test
4267
public void testBatchSplit() throws Exception {
4368
JobOperator jobOperator = BatchRuntime.getJobOperator();
@@ -52,13 +77,19 @@ public void testBatchSplit() throws Exception {
5277
executedSteps.add(stepExecution.getStepName());
5378
}
5479

80+
// <1> Make sure all the steps were executed.
5581
assertEquals(3, stepExecutions.size());
5682
assertTrue(executedSteps.contains("step1"));
5783
assertTrue(executedSteps.contains("step2"));
5884
assertTrue(executedSteps.contains("step3"));
85+
86+
// <2> Steps 'step1' and 'step2' can appear in any order, since they were executed in parallel.
5987
assertTrue(executedSteps.get(0).equals("step1") || executedSteps.get(0).equals("step2"));
6088
assertTrue(executedSteps.get(1).equals("step1") || executedSteps.get(1).equals("step2"));
89+
// <3> Step 'step3' is always the last to be executed.
6190
assertTrue(executedSteps.get(2).equals("step3"));
91+
92+
// <4> Job should be completed.
6293
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
6394
}
6495
}

0 commit comments

Comments
 (0)