BAEL-2168 Java EE 7 batch processing (#5861)
* review changes * Fixed public static count * review comments
This commit is contained in:
committed by
Josh Cummings
parent
547f99925f
commit
b0f62f4eca
@@ -7,6 +7,7 @@ import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.Metric;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
public class BatchTestHelper {
|
||||
private static final int MAX_TRIES = 40;
|
||||
@@ -68,6 +69,16 @@ public class BatchTestHelper {
|
||||
return jobExecution;
|
||||
}
|
||||
|
||||
public static long getCommitCount(StepExecution stepExecution) {
|
||||
Map<Metric.MetricType, Long> metricsMap = getMetricsMap(stepExecution.getMetrics());
|
||||
return metricsMap.get(Metric.MetricType.COMMIT_COUNT);
|
||||
}
|
||||
|
||||
public static long getProcessSkipCount(StepExecution stepExecution) {
|
||||
Map<Metric.MetricType, Long> metricsMap = getMetricsMap(stepExecution.getMetrics());
|
||||
return metricsMap.get(Metric.MetricType.PROCESS_SKIP_COUNT);
|
||||
}
|
||||
|
||||
public static Map<Metric.MetricType, Long> getMetricsMap(Metric[] metrics) {
|
||||
Map<Metric.MetricType, Long> metricsMap = new HashMap<>();
|
||||
for (Metric metric : metrics) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
class CustomCheckPointUnitTest {
|
||||
@Test
|
||||
public void givenChunk_whenCustomCheckPoint_thenCommitCount_3() throws Exception {
|
||||
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("customCheckPoint", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
@@ -23,9 +23,10 @@ class CustomCheckPointUnitTest {
|
||||
for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) {
|
||||
if (stepExecution.getStepName()
|
||||
.equals("firstChunkStep")) {
|
||||
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
|
||||
assertEquals(3L, metricsMap.get(Metric.MetricType.COMMIT_COUNT)
|
||||
.longValue());
|
||||
jobOperator.getStepExecutions(executionId)
|
||||
.stream()
|
||||
.map(BatchTestHelper::getCommitCount)
|
||||
.forEach(count -> assertEquals(3L, count.longValue()));
|
||||
}
|
||||
}
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.Metric;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleBatchLetUnitTest {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -23,7 +24,6 @@ class SimpleErrorChunkUnitTest {
|
||||
Long executionId = jobOperator.start("simpleErrorChunk", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestFailed(jobExecution);
|
||||
System.out.println(jobExecution.getBatchStatus());
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ class SimpleErrorChunkUnitTest {
|
||||
for (StepExecution stepExecution : stepExecutions) {
|
||||
if (stepExecution.getStepName()
|
||||
.equals("errorStep")) {
|
||||
Map<MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
|
||||
long skipCount = metricsMap.get(MetricType.PROCESS_SKIP_COUNT)
|
||||
.longValue();
|
||||
assertTrue("Skip count=" + skipCount, skipCount == 1l || skipCount == 2l);
|
||||
jobOperator.getStepExecutions(executionId)
|
||||
.stream()
|
||||
.map(BatchTestHelper::getProcessSkipCount)
|
||||
.forEach(skipCount -> assertEquals(1L, skipCount.longValue()));
|
||||
}
|
||||
}
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
|
||||
Reference in New Issue
Block a user