From 117becfe5aa8db2ad42019eeb8ffa24b76a1495b Mon Sep 17 00:00:00 2001 From: robokaso Date: Thu, 20 Nov 2008 12:57:12 +0000 Subject: [PATCH] IN PROGRESS - BATCH-929: Deferrable Constraints cause unrecoverable errors reverted the previous changes, they wouldn't really solve the problem --- .../batch/core/repository/JobRepository.java | 28 ++----- .../support/SimpleJobRepository.java | 8 -- .../item/FaultTolerantStepFactoryBean.java | 17 +--- .../batch/core/step/tasklet/TaskletStep.java | 54 ++----------- .../batch/core/step/JobRepositorySupport.java | 9 --- .../FaultTolerantStepFactoryBeanTests.java | 4 - .../step/item/TaskletStepExceptionTests.java | 80 +++---------------- .../integration/JobRepositorySupport.java | 9 --- 8 files changed, 23 insertions(+), 186 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java index 1a747f091..76ca5e21f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java @@ -39,13 +39,11 @@ import org.springframework.batch.item.ExecutionContext; public interface JobRepository { /** - * Check if an instance of this job already exists with the parameters - * provided. + * Check if an instance of this job already exists with the parameters provided. * * @param jobName the name of the job * @param jobParameters the parameters to match - * @return true if a {@link JobInstance} already exists for this job name - * and job parameters + * @return true if a {@link JobInstance} already exists for this job name and job parameters */ boolean isJobInstanceExists(String jobName, JobParameters jobParameters); @@ -70,8 +68,8 @@ public interface JobRepository { * found and was already completed successfully. * */ - JobExecution createJobExecution(String jobName, JobParameters jobParameters) - throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException; + JobExecution createJobExecution(String jobName, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, + JobRestartException, JobInstanceAlreadyCompleteException; /** * Update the {@link JobExecution}. @@ -114,22 +112,6 @@ public interface JobRepository { */ void updateExecutionContext(StepExecution stepExecution); - /** - * Load the {@link ExecutionContext} of the given {@link StepExecution}. - * - * @param stepExecution the {@link StepExecution} containing the - * {@link ExecutionContext}. - */ - ExecutionContext getExecutionContext(StepExecution stepExecution); - - /** - * Load the {@link ExecutionContext} of the given {@link JobExecution}. - * - * @param jobExecution the {@link JobExecution} containing the - * {@link ExecutionContext}. - */ - ExecutionContext getExecutionContext(JobExecution jobExecution); - /** * @param stepName the name of the step execution that might have run. * @return the last execution of step for the given job instance. @@ -143,7 +125,7 @@ public interface JobRepository { int getStepExecutionCount(JobInstance jobInstance, String stepName); /** - * @param jobName the name of the job that might have run + * @param jobName the name of the job that might have run * @param jobParameters parameters identifying the {@link JobInstance} * @return the last execution of job if exists, null otherwise */ diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index 3d063fab5..d358b2039 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -336,12 +336,4 @@ public class SimpleJobRepository implements JobRepository { } - public ExecutionContext getExecutionContext(StepExecution stepExecution) { - return ecDao.getExecutionContext(stepExecution); - } - - public ExecutionContext getExecutionContext(JobExecution jobExecution) { - return ecDao.getExecutionContext(jobExecution); - } - } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java index a723b135f..3b005f1bf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java @@ -48,8 +48,6 @@ public class FaultTolerantStepFactoryBean extends SimpleStepFactoryBean> nonFatalCommitExceptionClasses = new HashSet>(); - private Collection> skippableExceptionClasses = new HashSet>(); private Collection> fatalExceptionClasses = new HashSet>(); @@ -79,17 +77,6 @@ public class FaultTolerantStepFactoryBean extends SimpleStepFactoryBean> nonFatalCommitExceptionClasses) { - this.nonFatalCommitExceptionClasses = nonFatalCommitExceptionClasses; - } - /** * Setter for the retry policy. If this is specified the other retry * properties are ignored (retryLimit, backOffPolicy, @@ -292,9 +279,7 @@ public class FaultTolerantStepFactoryBean extends SimpleStepFactoryBean { private final Collection failures; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java index 1773bc894..d8fbc830c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java @@ -3,19 +3,15 @@ */ package org.springframework.batch.core.step.item; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.springframework.batch.core.BatchStatus.COMPLETED; -import static org.springframework.batch.core.BatchStatus.FAILED; -import static org.springframework.batch.core.BatchStatus.STOPPED; -import static org.springframework.batch.core.BatchStatus.UNKNOWN; +import static org.junit.Assert.*; +import static org.springframework.batch.core.BatchStatus.*; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; +import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; @@ -25,7 +21,6 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.batch.item.ExecutionContext; @@ -46,13 +41,15 @@ import org.springframework.transaction.support.DefaultTransactionStatus; */ public class TaskletStepExceptionTests { - private TaskletStep taskletStep; + TaskletStep taskletStep; - private StepExecution stepExecution; + StepExecution stepExecution; - private UpdateCountingJobRepository jobRepository; + UpdateCountingJobRepository jobRepository; - private static RuntimeException taskletException = new RuntimeException(); + static RuntimeException taskletException = new RuntimeException(); + + static JobInterruptedException interruptedException = new JobInterruptedException(""); @Before public void init() { @@ -137,7 +134,7 @@ public class TaskletStepExceptionTests { } @Test - /* + /** * Exception in afterStep is ignored (only logged). */ public void testAfterStepFAilure() throws Exception { @@ -199,58 +196,12 @@ public class TaskletStepExceptionTests { assertEquals(exception, e.getCause()); } - /** - * If commit exception isn't fatal step shouldn't complete with UNKNOWN - * status and execution context should be rolled back. - */ - @Test - public void testNonFatalCommitError() throws Exception { - - class TestItemStream extends ItemStreamSupport { - private boolean called = false; - - @Override - public void update(ExecutionContext executionContext) throws ItemStreamException { - executionContext.put("key", "value"); - called = true; - } - - } - final TestItemStream stream = new TestItemStream(); - taskletStep.registerStream(stream); - - final RuntimeException commitException = new RuntimeException(); - taskletStep.setCommitSkipPolicy(new AlwaysSkipItemSkipPolicy()); - - taskletStep.setTransactionManager(new ResourcelessTransactionManager() { - @Override - protected void doCommit(DefaultTransactionStatus status) throws TransactionException { - throw commitException; - } - }); - - taskletStep.setTasklet(new Tasklet() { - - public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception { - return RepeatStatus.FINISHED; - } - - }); - - taskletStep.execute(stepExecution); - assertEquals("step won't refuse to restart", FAILED, stepExecution.getStatus()); - assertTrue("execution context modified", stream.called); - assertTrue("execution context rolled back", stepExecution.getExecutionContext().isEmpty()); - assertEquals("failed commit counted as rollback", 1, stepExecution.getRollbackCount()); - } - @Test public void testUpdateError() throws Exception { final RuntimeException exception = new RuntimeException(); taskletStep.setJobRepository(new UpdateCountingJobRepository() { boolean firstCall = true; - @Override public void update(StepExecution arg0) { if (firstCall) { @@ -260,7 +211,7 @@ public class TaskletStepExceptionTests { throw exception; } }); - + taskletStep.execute(stepExecution); assertEquals(UNKNOWN, stepExecution.getStatus()); assertTrue(stepExecution.getFailureExceptions().contains(taskletException)); @@ -321,16 +272,9 @@ public class TaskletStepExceptionTests { } public JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) { + // TODO Auto-generated method stub return null; } - - public ExecutionContext getExecutionContext(StepExecution stepExecution) { - return new ExecutionContext(); - } - - public ExecutionContext getExecutionContext(JobExecution jobExecution) { - return new ExecutionContext(); - } } } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java index 622391d4d..70d052345 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java @@ -23,7 +23,6 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.item.ExecutionContext; /** * @author Dave Syer @@ -88,12 +87,4 @@ public class JobRepositorySupport implements JobRepository { return null; } - public ExecutionContext getExecutionContext(StepExecution stepExecution) { - return null; - } - - public ExecutionContext getExecutionContext(JobExecution jobExecution) { - return null; - } - }