diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java index 5d81d0974..a646e9187 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java @@ -225,7 +225,6 @@ public class TaskletStep extends AbstractStep { ExceptionHolder fatalException = new ExceptionHolder(); StepContribution contribution = stepExecution.createStepContribution(); - stepExecution.getExecutionContext().clearDirtyFlag(); // Before starting a new transaction, check for // interruption. @@ -264,14 +263,6 @@ public class TaskletStep extends AbstractStep { Thread.currentThread().interrupt(); } - // Check to make sure the ExecutionContext hasn't be - // modified outside a chunk boundary. Doing so will cause - // potential rollback issues. - if (stepExecution.getExecutionContext().isDirty()) { - throw new IllegalStateException( - "The ExecutionContext cannot be modified outside of the ItemStream.update() method"); - } - stream.update(stepExecution.getExecutionContext()); try { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java index 489eae631..218596ebd 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java @@ -24,6 +24,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; @@ -106,9 +107,9 @@ public class AsyncTaskletStepTests { step.execute(stepExecution); - // Fails (BATCH-917). -// assertEquals(20, processed.size()); -// assertEquals(20, stepExecution.getReadCount()); + assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); + assertEquals(25, processed.size()); + assertEquals(25, stepExecution.getReadCount()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java index 08dfbb93a..d01f8e6c8 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java @@ -16,10 +16,7 @@ package org.springframework.batch.core.step.tasklet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.Serializable; import java.util.ArrayList; @@ -35,7 +32,6 @@ 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; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.job.JobSupport; @@ -55,12 +51,10 @@ import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamSupport; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.core.AttributeAccessor; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.transaction.TransactionException; import org.springframework.transaction.support.DefaultTransactionStatus; @@ -775,22 +769,23 @@ public class TaskletStepTests { } - @Test - public void testModifyingExecutionContextMidProcessCausesException() throws Exception { - StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance)); - final ExecutionContext ec = stepExecution.getExecutionContext(); - step.setTasklet(new Tasklet() { - public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception { - ec.putString("test", "test"); - return RepeatStatus.FINISHED; - } - }); - - step.execute(stepExecution); - assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); - assertEquals(1, stepExecution.getFailureExceptions().size()); - assertTrue(stepExecution.getFailureExceptions().get(0) instanceof IllegalStateException); - } +// This doesn't make sense for concurrent tasklet execution scenario. +// @Test +// public void testModifyingExecutionContextMidProcessCausesException() throws Exception { +// StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance)); +// final ExecutionContext ec = stepExecution.getExecutionContext(); +// step.setTasklet(new Tasklet() { +// public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception { +// ec.putString("test", "test"); +// return RepeatStatus.FINISHED; +// } +// }); +// +// step.execute(stepExecution); +// assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); +// assertEquals(1, stepExecution.getFailureExceptions().size()); +// assertTrue(stepExecution.getFailureExceptions().get(0) instanceof IllegalStateException); +// } private boolean contains(String str, String searchStr) { return str.indexOf(searchStr) != -1;