Skip to content

Commit af74951

Browse files
committed
Add tolerance for PROCESS_SKIP_COUNT metric reflecting difference in "retry after rollback" behavior across Glassfish & WildFly. Suggest further changes which will fail in WildFly today (due to WildFly bug?)
1 parent 54a2719 commit af74951

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

batch/chunk-exception/src/main/java/org/javaee7/batch/chunk/exception/MyItemWriter.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.javaee7.batch.chunk.exception;
22

33
import javax.batch.api.chunk.AbstractItemWriter;
4+
import javax.batch.runtime.context.JobContext;
5+
import javax.inject.Inject;
46
import javax.inject.Named;
7+
58
import java.util.List;
69

710
/**
@@ -11,14 +14,36 @@
1114
public class MyItemWriter extends AbstractItemWriter {
1215
private static int retries = 0;
1316

17+
@Inject
18+
JobContext ctx;
19+
1420
@Override
1521
public void writeItems(List list) {
22+
23+
System.out.println("MyItemWriter.writeItems: " + list);
24+
1625
if (retries <= 3 && list.contains(new MyOutputRecord(8))) {
1726
retries ++;
1827
System.out.println("Throw UnsupportedOperationException in MyItemWriter");
1928
throw new UnsupportedOperationException();
2029
}
30+
updateExitStatus(list);
31+
}
2132

22-
System.out.println("MyItemWriter.writeItems: " + list);
33+
/**
34+
* For each record in list, appends id, plus ",", to current exit status
35+
* @param list
36+
*/
37+
private void updateExitStatus(List list) {
38+
String es = ctx.getExitStatus() == null ? "" : ctx.getExitStatus();
39+
StringBuilder sb = new StringBuilder(es);
40+
41+
for (Object o : list) {
42+
MyOutputRecord rec = (MyOutputRecord)o;
43+
sb.append(rec.getId()).append(",");
44+
}
45+
46+
System.out.println("MyItemWriter.updateExitStatus: " + sb.toString());
47+
ctx.setExitStatus(sb.toString());
2348
}
2449
}

batch/chunk-exception/src/test/java/org/javaee7/batch/chunk/exception/BatchChunkExceptionTest.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,19 @@ public void testBatchChunkException() throws Exception {
119119
if (stepExecution.getStepName().equals("myStep")) {
120120
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
121121

122-
assertEquals(1L, metricsMap.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue());
123-
// There are a few differences between Glassfish and Wildfly. Needs investigation.
124-
//assertEquals(1L, metricsMap.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
122+
// PROCESS_SKIP_COUNT disparity from difference between Glassfish and WildFly in retry-with-rollback processing of the skipped item?
123+
long processSkipCount = metricsMap.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue();
124+
assertTrue("Expecting value between 1 and 2 inclusive, but found: " + processSkipCount, processSkipCount>=1 && processSkipCount <=2);
125+
// Next assertion currently failing in WildFly, counting '2' skipped writes
126+
assertEquals(1L, metricsMap.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
125127
assertEquals(1L, ChunkExceptionRecorder.retryReadExecutions);
126128
}
127129
}
128130

129131
assertTrue(ChunkExceptionRecorder.chunkExceptionsCountDownLatch.await(0, TimeUnit.SECONDS));
130132
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
133+
String exitStatus = jobExecution.getExitStatus();
134+
// Next assertion currently failing in WildFly, which includes item #8
135+
assertEquals("1,2,3,4,5,7,9,10", exitStatus.substring(0, exitStatus.length()-1)); // Remove trailing comma
131136
}
132137
}

0 commit comments

Comments
 (0)