RESOLVED - issue BATCH-920, BATCH-974: ChunkContext in StepContextRepeatCallback is unused
This commit is contained in:
@@ -2,14 +2,14 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
public class TestTasklet extends AbstractTestComponent implements Tasklet {
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
AttributeAccessor attributes) throws Exception {
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
executed = true;
|
||||
contribution.setExitStatus(ExitStatus.FINISHED);
|
||||
return RepeatStatus.FINISHED;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.scope.context;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ChunkContextTests {
|
||||
|
||||
private ChunkContext context = new ChunkContext(new StepContext(new JobExecution(new JobInstance(0L,
|
||||
new JobParameters(Collections.singletonMap("foo", new JobParameter("bar"))), "job"), 1L)
|
||||
.createStepExecution("foo")));
|
||||
|
||||
@Test
|
||||
public void testGetStepContext() {
|
||||
StepContext stepContext = context.getStepContext();
|
||||
assertNotNull(stepContext);
|
||||
assertEquals("bar", context.getStepContext().getJobParameters().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsComplete() {
|
||||
assertFalse(context.isComplete());
|
||||
context.setComplete();
|
||||
assertTrue(context.isComplete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
String value = context.toString();
|
||||
assertTrue("Wrong toString: "+value, value.contains("stepContext="));
|
||||
assertTrue("Wrong toString: "+value, value.contains("complete=false"));
|
||||
assertTrue("Wrong toString: "+value, value.contains("attributes=[]"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import org.junit.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.scope.context.StepContext;
|
||||
import org.springframework.batch.core.scope.context.StepContextRepeatCallback;
|
||||
import org.springframework.batch.core.scope.context.StepSynchronizationManager;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
@@ -49,8 +48,8 @@ public class StepContextRepeatCallbackTests {
|
||||
public void testDoInIteration() throws Exception {
|
||||
StepContextRepeatCallback callback = new StepContextRepeatCallback(stepExecution) {
|
||||
@Override
|
||||
public RepeatStatus doInStepContext(RepeatContext context, StepContext stepContext) throws Exception {
|
||||
assertEquals(Long.valueOf(123), stepContext.getStepExecution().getId());
|
||||
public RepeatStatus doInChunkContext(RepeatContext context, ChunkContext chunkContext) throws Exception {
|
||||
assertEquals(Long.valueOf(123), chunkContext.getStepContext().getStepExecution().getId());
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
};
|
||||
@@ -63,13 +62,13 @@ public class StepContextRepeatCallbackTests {
|
||||
StepSynchronizationManager.register(stepExecution);
|
||||
StepContextRepeatCallback callback = new StepContextRepeatCallback(stepExecution) {
|
||||
@Override
|
||||
public RepeatStatus doInStepContext(RepeatContext context, StepContext stepContext) throws Exception {
|
||||
public RepeatStatus doInChunkContext(RepeatContext context, ChunkContext chunkContext) throws Exception {
|
||||
if (addedAttribute) {
|
||||
removedAttribute = stepContext.hasAttribute("foo");
|
||||
stepContext.removeAttribute("foo");
|
||||
removedAttribute = chunkContext.hasAttribute("foo");
|
||||
chunkContext.removeAttribute("foo");
|
||||
} else {
|
||||
addedAttribute = true;
|
||||
stepContext.setAttribute("foo", "bar");
|
||||
chunkContext.setAttribute("foo", "bar");
|
||||
}
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -33,7 +32,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
*/
|
||||
public class ChunkOrientedTaskletTests {
|
||||
|
||||
private AttributeAccessor context = new RepeatContextSupport(null);
|
||||
private ChunkContext context = new ChunkContext(null);
|
||||
|
||||
@Test
|
||||
public void testHandle() throws Exception {
|
||||
|
||||
@@ -26,6 +26,7 @@ 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.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemStreamSupport;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
|
||||
@@ -127,7 +127,7 @@ public class TaskletStepExceptionTests {
|
||||
} });
|
||||
taskletStep.setTasklet(new Tasklet() {
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext attributes) throws Exception {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class TaskletStepExceptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
/*
|
||||
* Exception in afterStep is ignored (only logged).
|
||||
*/
|
||||
public void testAfterStepFAilure() throws Exception {
|
||||
@@ -189,7 +189,7 @@ public class TaskletStepExceptionTests {
|
||||
|
||||
taskletStep.setTasklet(new Tasklet() {
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext attributes) throws Exception {
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -207,6 +207,7 @@ public class TaskletStepExceptionTests {
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
taskletStep.setJobRepository(new UpdateCountingJobRepository() {
|
||||
boolean firstCall = true;
|
||||
|
||||
@Override
|
||||
public void update(StepExecution arg0) {
|
||||
if (firstCall) {
|
||||
@@ -216,7 +217,7 @@ public class TaskletStepExceptionTests {
|
||||
throw exception;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
taskletStep.execute(stepExecution);
|
||||
assertEquals(UNKNOWN, stepExecution.getStatus());
|
||||
assertTrue(stepExecution.getFailureExceptions().contains(taskletException));
|
||||
@@ -225,7 +226,7 @@ public class TaskletStepExceptionTests {
|
||||
|
||||
private static class ExceptionTasklet implements Tasklet {
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
throw taskletException;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user