use of javax.batch.runtime.StepExecution in project javaee7-samples by javaee-samples.
the class BatchChunkSimpleNoBeansTest method testBatchChunkSimpleNoBeans.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we need to query the +javax.batch.runtime.Metric+ object available in the step execution.
*
* The batch process itself will read and process 10 elements from numbers 1 to 10, but only write the odd
* elements. Commits are executed after 3 elements are read.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchChunkSimpleNoBeans() throws Exception {
JobOperator jobOperator = getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
for (StepExecution stepExecution : stepExecutions) {
if (stepExecution.getStepName().equals("myStep")) {
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
// <1> The read count should be 10 elements. Check +MyItemReader+.
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
// <2> The write count should be 5. Only half of the elements read are processed to be written.
assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
// <3> The commit count should be 4. Checkpoint is on every 3rd read, 4 commits for read elements.
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
}
}
// <4> Job should be completed.
assertEquals(COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.runtime.StepExecution in project javaee7-samples by javaee-samples.
the class ChunkSimpleTest method testChunkSimple.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we need to query the +javax.batch.runtime.Metric+ object available in the step execution.
*
* The batch process itself will read and process 10 elements from numbers 1 to 10, but only write the odd
* elements. Commits are executed after 3 elements are read.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testChunkSimple() throws Exception {
JobOperator jobOperator = getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
for (StepExecution stepExecution : stepExecutions) {
if (stepExecution.getStepName().equals("myStep")) {
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
// <1> The read count should be 10 elements. Check +MyItemReader+.
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
// <2> The write count should be 5. Only half of the elements read are processed to be written.
assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
// <3> The commit count should be 4. Checkpoint is on every 3rd read, 4 commits for read elements.
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
}
}
// <4> Job should be completed.
assertEquals(jobExecution.getBatchStatus(), COMPLETED);
}
use of javax.batch.runtime.StepExecution in project javaee7-samples by javaee-samples.
the class BatchFlowTest method testBatchFlow.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we need to query +javax.batch.operations.JobOperator#getStepExecutions+ and the
* +javax.batch.runtime.Metric+ object available in the step execution.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchFlow() throws Exception {
JobOperator jobOperator = getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
List<String> executedSteps = new ArrayList<>();
for (StepExecution stepExecution : stepExecutions) {
executedSteps.add(stepExecution.getStepName());
if (stepExecution.getStepName().equals("step2")) {
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
System.out.println(metricsMap);
assertEquals(5L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
assertEquals(5L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
assertEquals(5L / 3 + (5 % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
}
}
// <1> Make sure all the steps were executed.
assertEquals(3, stepExecutions.size());
// <2> Make sure all the steps were executed in order of declaration.
assertArrayEquals(new String[] { "step1", "step2", "step3" }, executedSteps.toArray());
// <3> Job should be completed.
assertEquals(COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.runtime.StepExecution in project javaee7-samples by javaee-samples.
the class BatchDecisionTest method testBatchDecision.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we need to query +javax.batch.operations.JobOperator#getStepExecutions+ and the
* +javax.batch.runtime.Metric+ object available in the step execution.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchDecision() throws Exception {
JobOperator jobOperator = getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
List<String> executedSteps = new ArrayList<>();
for (StepExecution stepExecution : stepExecutions) {
executedSteps.add(stepExecution.getStepName());
}
// <1> Make sure that only two steps were executed.
assertEquals(2, stepExecutions.size());
// <2> Make sure that only the expected steps were executed an in order.
assertArrayEquals(new String[] { "step1", "step3" }, executedSteps.toArray());
// <3> Make sure that this step was never executed.
assertFalse(executedSteps.contains("step2"));
// <4> Job should be completed.
assertEquals(COMPLETED, jobExecution.getBatchStatus());
}
Aggregations