Skip to content

Commit 40cc5b6

Browse files
committed
Added documentation to chunk-simple-nobeans project.
1 parent b2bca78 commit 40cc5b6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

batch/chunk-simple-nobeans/pom.xml

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

1111
<artifactId>chunk-simple-nobeans</artifactId>
1212
<packaging>war</packaging>
13-
14-
<name>${project.artifactId}</name>
13+
<name>Batch Chunk Simple No Beans</name>
14+
<description>Chunk Processing - Read, Process, Write</description>
1515

1616
<dependencies>
1717
<dependency>

batch/chunk-simple-nobeans/src/test/java/org/javaee7/batch/samples/chunk/simple/nobeans/BatchChunkSimpleNoBeansTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,31 @@
1717
import static org.junit.Assert.assertEquals;
1818

1919
/**
20+
* The Batch specification provides a Chunk Oriented processing style. This style is defined by enclosing into a
21+
* transaction a set of reads, process and write operations via +javax.batch.api.chunk.ItemReader+,
22+
* +javax.batch.api.chunk.ItemProcessor+ and +javax.batch.api.chunk.ItemWriter+. Items are read one at a time, processed
23+
* and aggregated. The transaction is then committed when the defined +checkpoint-policy+ is triggered.
24+
*
25+
* include::myJob.xml[]
26+
*
27+
* A very simple job is defined in the +myJob.xml+ file. Just a single step with a reader, a processor and writer.
28+
*
2029
* @author Roberto Cortez
2130
*/
2231
@RunWith(Arquillian.class)
2332
public class BatchChunkSimpleNoBeansTest {
33+
/**
34+
* We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
35+
*
36+
* [source,file]
37+
* ----
38+
* /META-INF/batch-jobs/myjob.xml
39+
* ----
40+
*
41+
* The +myjob.xml+ file is needed for running the batch definition. This sample is also missing the +beans.xml+ for
42+
* CDI discovery, since for Java EE 7 this file is now optional, but you need to annotated batch dependent beans
43+
* with +@Dependent+.
44+
*/
2445
@Deployment
2546
public static WebArchive createDeployment() {
2647
WebArchive war = ShrinkWrap.create(WebArchive.class)
@@ -31,6 +52,15 @@ public static WebArchive createDeployment() {
3152
return war;
3253
}
3354

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 the +Metric[]+ object available in the step execution.
58+
*
59+
* The batch process itself will read and process 10 elements from numbers 1 to 10, but only write the odd
60+
* elements. Commits are executed after 3 elements are read.
61+
*
62+
* @throws Exception an exception if the batch could not complete successfully.
63+
*/
3464
@Test
3565
public void testBatchChunkSimpleNoBeans() throws Exception {
3666
JobOperator jobOperator = BatchRuntime.getJobOperator();
@@ -44,12 +74,17 @@ public void testBatchChunkSimpleNoBeans() throws Exception {
4474
if (stepExecution.getStepName().equals("myStep")) {
4575
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
4676

77+
// <1> The read count should be 10 elements. Check +MyItemReader+.
4778
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
79+
// <2> The write count should be 5. Only half of the elements read are processed to be written.
4880
assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
49-
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
81+
// <3> The commit count should be 4. Checkpoint is on every 3rd read, 4 commits for read elements.
82+
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0),
83+
metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
5084
}
5185
}
5286

87+
// <4> Job should be completed.
5388
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
5489
}
5590
}

0 commit comments

Comments
 (0)