From d19145d0af064a04c2b86c097cabd1b3eb55af0e Mon Sep 17 00:00:00 2001 From: dsyer Date: Thu, 13 Nov 2008 08:58:32 +0000 Subject: [PATCH] Tweak step execution aggregation --- .../batch/core/partition/support/PartitionStep.java | 8 +++++++- .../partition/support/StepExecutionAggregator.java | 2 -- .../support/StepExecutionAggregatorTests.java | 10 ++++++++++ .../repository/dao/AbstractStepExecutionDaoTests.java | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java index eda473cb1..9454bddc4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java @@ -74,7 +74,13 @@ public class PartitionStep extends AbstractStep { // Wait for task completion and then aggregate the results Collection executions = partitionHandler.handle(stepExecutionSplitter, stepExecution); aggregator.aggregate(stepExecution, executions); - if (stepExecution.getStatus()!=BatchStatus.COMPLETED) { + + if (stepExecution.getJobExecution().isPaused()) { + return; + } + + // If anything failed or had a problem we need to crap out + if (stepExecution.getStatus() != BatchStatus.COMPLETED) { throw new JobExecutionException("Partition handler returned an incomplete step"); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java index e5980b490..21c1c509b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java @@ -33,8 +33,6 @@ public class StepExecutionAggregator { if (executions == null || executions.isEmpty()) { throw new IllegalArgumentException("Cannot aggregate empty or null executions: " + executions); } - // Start with assumption that it is complete... - result.setStatus(BatchStatus.COMPLETED); for (StepExecution stepExecution : executions) { BatchStatus status = stepExecution.getStatus(); result.setStatus(BatchStatus.max(result.getStatus(), status)); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java index d306f1320..97943e75e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java @@ -43,6 +43,16 @@ public class StepExecutionAggregatorTests { assertEquals(BatchStatus.COMPLETED, result.getStatus()); } + @Test + public void testAggregateStatusFromFailure() { + result.setStatus(BatchStatus.FAILED); + stepExecution1.setStatus(BatchStatus.COMPLETED); + stepExecution2.setStatus(BatchStatus.COMPLETED); + aggregator.aggregate(result, Arrays. asList(stepExecution1, stepExecution2)); + assertNotNull(result); + assertEquals(BatchStatus.FAILED, result.getStatus()); + } + @Test public void testAggregateStatusIncomplete() { stepExecution1.setStatus(BatchStatus.COMPLETED); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java index fb38e56c3..5b46b296a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java @@ -105,6 +105,8 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona assertStepExecutionsAreEqual(stepExecution, retrieved); assertNotNull(retrieved.getVersion()); + assertNotNull(retrieved.getJobExecution()); + assertNotNull(retrieved.getJobExecution().getId()); assertNull(dao.getStepExecution(jobExecution, "not-existing step")); }