RESOLVED - issue BATCH-1391: Tidy up skip sample

This commit is contained in:
dsyer
2009-09-04 10:59:13 +00:00
parent 88e21bf234
commit 201985e925
3 changed files with 26 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
@@ -35,6 +35,9 @@
<include class="java.io.IOException" />
</skippable-exception-classes>
</chunk>
<no-rollback-exception-classes>
<include class="org.springframework.batch.item.validator.ValidationException" />
</no-rollback-exception-classes>
</tasklet>
</step>

View File

@@ -20,6 +20,7 @@ import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.sample.common.SkipCheckingListener;
import org.springframework.batch.sample.domain.trade.internal.TradeWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
@@ -163,6 +164,9 @@ public class SkipSampleFunctionalTests {
// to output
// System.err.println(simpleJdbcTemplate.queryForList("SELECT * FROM TRADE"));
assertEquals(5, simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1));
// 1 record skipped in processing second step
assertEquals(1, SkipCheckingListener.getProcessSkips());
// Both steps contained skips
assertEquals(2, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG"));
@@ -208,6 +212,7 @@ public class SkipSampleFunctionalTests {
* @return JobExecution, so that the test may validate the exit status
*/
public long launchJobWithIncrementer() {
SkipCheckingListener.resetProcessSkips();
try {
return this.jobOperator.startNextInstance("skipJob");
}

View File

@@ -17,6 +17,7 @@ import org.springframework.batch.sample.domain.trade.Trade;
public class SkipCheckingListener {
private static final Log logger = LogFactory.getLog(SkipCheckingListener.class);
private static int processSkips;
@AfterStep
public ExitStatus checkForSkips(StepExecution stepExecution) {
@@ -28,6 +29,21 @@ public class SkipCheckingListener {
return null;
}
}
/**
* Convenience method for testing
* @return the processSkips
*/
public static int getProcessSkips() {
return processSkips;
}
/**
* Convenience method for testing
*/
public static void resetProcessSkips() {
processSkips = 0;
}
@OnSkipInWrite
public void skipWrite(Trade trade, Throwable t) {
@@ -37,6 +53,7 @@ public class SkipCheckingListener {
@OnSkipInProcess
public void skipProcess(Trade trade, Throwable t) {
logger.debug("Skipped processing " + trade);
processSkips++;
}
@BeforeStep