RESOLVED - issue BATCH-1399: Expose StepExecutionAggregator as a strategy interface in PartitionStep

This commit is contained in:
dsyer
2009-09-11 09:34:30 +00:00
parent 046e1f8c12
commit 0cc68d71b8
6 changed files with 107 additions and 49 deletions

View File

@@ -12,9 +12,9 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
public class StepExecutionAggregatorTests {
public class DefaultStepExecutionAggregatorTests {
private StepExecutionAggregator aggregator = new StepExecutionAggregator();
private StepExecutionAggregator aggregator = new DefaultStepExecutionAggregator();
private JobExecution jobExecution = new JobExecution(11L);

View File

@@ -17,6 +17,7 @@ package org.springframework.batch.core.partition.support;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
@@ -128,4 +129,28 @@ public class PartitionStepTests {
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
}
@Test
public void testStepAggregator() throws Exception {
step.setStepExecutionAggregator(new DefaultStepExecutionAggregator() {
@Override
public void aggregate(StepExecution result, Collection<StepExecution> executions) {
super.aggregate(result, executions);
result.getExecutionContext().put("aggregated", true);
}
});
step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, remote));
step.setPartitionHandler(new PartitionHandler() {
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution)
throws Exception {
return Arrays.asList(stepExecution);
}
});
step.afterPropertiesSet();
JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters());
StepExecution stepExecution = jobExecution.createStepExecution("foo");
jobRepository.add(stepExecution);
step.execute(stepExecution);
assertEquals(true, stepExecution.getExecutionContext().get("aggregated"));
}
}

View File

@@ -95,7 +95,7 @@ public class TaskExecutorPartitionHandlerTests {
}
});
Collection<StepExecution> executions = handler.handle(stepExecutionSplitter, stepExecution);
new StepExecutionAggregator().aggregate(stepExecution, executions);
new DefaultStepExecutionAggregator().aggregate(stepExecution, executions);
assertEquals(1, count);
assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
}