Skip to content

Commit

Permalink
Add tolerance for PROCESS_SKIP_COUNT metric reflecting difference in …
Browse files Browse the repository at this point in the history
…"retry after rollback" behavior across Glassfish & WildFly. Suggest further changes which will fail in WildFly today (due to WildFly bug?)
  • Loading branch information
scottkurz committed Dec 14, 2014
1 parent 54a2719 commit af74951
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.javaee7.batch.chunk.exception;

import javax.batch.api.chunk.AbstractItemWriter;
import javax.batch.runtime.context.JobContext;
import javax.inject.Inject;
import javax.inject.Named;

import java.util.List;

/**
Expand All @@ -11,14 +14,36 @@
public class MyItemWriter extends AbstractItemWriter {
private static int retries = 0;

@Inject
JobContext ctx;

@Override
public void writeItems(List list) {

System.out.println("MyItemWriter.writeItems: " + list);

if (retries <= 3 && list.contains(new MyOutputRecord(8))) {
retries ++;
System.out.println("Throw UnsupportedOperationException in MyItemWriter");
throw new UnsupportedOperationException();
}
updateExitStatus(list);
}

System.out.println("MyItemWriter.writeItems: " + list);
/**
* For each record in list, appends id, plus ",", to current exit status
* @param list
*/
private void updateExitStatus(List list) {
String es = ctx.getExitStatus() == null ? "" : ctx.getExitStatus();
StringBuilder sb = new StringBuilder(es);

for (Object o : list) {
MyOutputRecord rec = (MyOutputRecord)o;
sb.append(rec.getId()).append(",");
}

System.out.println("MyItemWriter.updateExitStatus: " + sb.toString());
ctx.setExitStatus(sb.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ public void testBatchChunkException() throws Exception {
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());
// PROCESS_SKIP_COUNT disparity from difference between Glassfish and WildFly in retry-with-rollback processing of the skipped item?
long processSkipCount = metricsMap.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue();
assertTrue("Expecting value between 1 and 2 inclusive, but found: " + processSkipCount, processSkipCount>=1 && processSkipCount <=2);
// Next assertion currently failing in WildFly, counting '2' skipped writes
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());
String exitStatus = jobExecution.getExitStatus();
// Next assertion currently failing in WildFly, which includes item #8
assertEquals("1,2,3,4,5,7,9,10", exitStatus.substring(0, exitStatus.length()-1)); // Remove trailing comma
}
}

0 comments on commit af74951

Please sign in to comment.