From fbe0443175e35f18617bfd0e56f7f23022bc663d Mon Sep 17 00:00:00 2001 From: lucasward Date: Tue, 16 Sep 2008 22:15:26 +0000 Subject: [PATCH] IN PROGRESS - issue BATCH-825: Modify JobLauncher contract to not throw exception on job failure. http://jira.springframework.org/browse/BATCH-825 Job, Step, and JobLauncher will not throw an exception if the job fails during processing, but rather will return the execution with an appropriate status and list of exceptions encountered. --- .../batch/sample/RestartFunctionalTests.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java index e29505d16..d5f706acc 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java @@ -24,6 +24,8 @@ import javax.sql.DataSource; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; @@ -69,21 +71,19 @@ public class RestartFunctionalTests extends AbstractBatchLauncherTests { int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); - try { - runJobForRestartTest(); - fail("First run of the job is expected to fail."); - } - catch (UnexpectedJobExecutionException expected) { - // expected - assertTrue("Not planned exception: " + expected.getMessage(), expected.getMessage().toLowerCase().indexOf( + JobExecution jobExecution = runJobForRestartTest(); + assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); + + Throwable expected = jobExecution.getAllFailureExceptions().get(0); + assertTrue("Not planned exception: " + expected.getMessage(), expected.getMessage().toLowerCase().indexOf( "planned") >= 0); - } int medium = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); // assert based on commit interval = 2 assertEquals(before + 2, medium); - runJobForRestartTest(); + jobExecution = runJobForRestartTest(); + assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); @@ -91,10 +91,10 @@ public class RestartFunctionalTests extends AbstractBatchLauncherTests { } // load the application context and launch the job - private void runJobForRestartTest() throws Exception { + private JobExecution runJobForRestartTest() throws Exception { // The second time we run the job it needs to be a new instance so we // need to make the parameters unique... - getLauncher().run(getJob(), new DefaultJobParametersConverter().getJobParameters(PropertiesConverter + return getLauncher().run(getJob(), new DefaultJobParametersConverter().getJobParameters(PropertiesConverter .stringToProperties("force.new.job.parameters=true"))); }