use of javax.batch.operations.JobOperator in project javaee7-samples by javaee-samples.
the class BatchChunkExceptionTest method testBatchChunkException.
/**
* 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.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchChunkException() throws Exception {
JobOperator jobOperator = BatchRuntime.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());
assertEquals(1L, metricsMap.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue());
// There are a few differences between Glassfish and Wildfly. Needs investigation.
//assertEquals(1L, metricsMap.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
assertEquals(1L, ChunkExceptionRecorder.retryReadExecutions);
}
}
assertTrue(ChunkExceptionRecorder.chunkExceptionsCountDownLatch.await(0, TimeUnit.SECONDS));
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project javaee7-samples by javaee-samples.
the class BatchChunkOptionalProcessorTest method testBatchChunkOptionalProcessor.
/**
* 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 10 elements from numbers 1 to 10, and write the same elements. Commits are
* executed after 3 elements are read.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchChunkOptionalProcessor() throws Exception {
JobOperator jobOperator = BatchRuntime.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 same 10 read elements.
assertEquals(10L, 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(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project javaee7-samples by javaee-samples.
the class BatchChunkPartitionTest method testBatchChunkPartition.
/**
* 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 20 elements from numbers 1 to 20, but only write the odd
* elements. Elements from 1 to 10 will be processed in one partition and elements from 11 to 20 in another
* partition. Commits are executed after 3 elements are read by partition.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchChunkPartition() throws Exception {
JobOperator jobOperator = BatchRuntime.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 20 elements. Check +MyItemReader+.
assertEquals(20L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
// <2> The write count should be 10. Only half of the elements read are processed to be written.
assertEquals(10L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
// Number of elements by the item count value on myJob.xml, plus an additional transaction for the
// remaining elements by each partition.
long commitCount = (10L / 3 + (10 % 3 > 0 ? 1 : 0)) * 2;
// <3> The commit count should be 8. Checkpoint is on every 3rd read, 4 commits for read elements and 2 partitions.
assertEquals(commitCount, metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
}
}
// <4> Job should be completed.
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project javaee7-samples by javaee-samples.
the class BatchMultipleStepsTest method testBatchMultipleSteps.
/**
* 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 testBatchMultipleSteps() throws Exception {
JobOperator jobOperator = BatchRuntime.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("step1")) {
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
assertEquals(10L / 2, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
}
}
// <1> Make sure all the steps were executed.
assertEquals(2, stepExecutions.size());
// <2> Make sure all the steps were executed in order of declaration.
assertArrayEquals(new String[] { "step1", "step2" }, executedSteps.toArray());
// <3> Job should be completed.
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.operations.JobOperator in project javaee7-samples by javaee-samples.
the class BatchSplitTest method testBatchSplit.
/**
* 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+.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchSplit() throws Exception {
JobOperator jobOperator = BatchRuntime.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 all the steps were executed.
assertEquals(3, stepExecutions.size());
assertTrue(executedSteps.contains("step1"));
assertTrue(executedSteps.contains("step2"));
assertTrue(executedSteps.contains("step3"));
// <2> Steps 'step1' and 'step2' can appear in any order, since they were executed in parallel.
assertTrue(executedSteps.get(0).equals("step1") || executedSteps.get(0).equals("step2"));
assertTrue(executedSteps.get(1).equals("step1") || executedSteps.get(1).equals("step2"));
// <3> Step 'step3' is always the last to be executed.
assertTrue(executedSteps.get(2).equals("step3"));
// <4> Job should be completed.
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
Aggregations