From 5d62e4d4364c0eec031bc173024cff3567ad1c8b Mon Sep 17 00:00:00 2001 From: dsyer Date: Sat, 6 Dec 2008 14:06:54 +0000 Subject: [PATCH] BATCH-956: remove pause and wait features --- .../batch/core/BatchStatus.java | 6 +-- .../batch/core/JobExecution.java | 23 ----------- .../batch/core/StepExecution.java | 23 ----------- .../batch/core/job/AbstractJob.java | 20 +++------ .../job/flow/support/state/PauseState.java | 41 ------------------- .../batch/core/launch/JobOperator.java | 2 - .../launch/support/SimpleJobLauncher.java | 7 +--- .../launch/support/SimpleJobOperator.java | 7 ---- .../core/partition/support/PartitionStep.java | 4 -- .../batch/core/BatchStatusTests.java | 10 ++--- .../batch/core/JobExecutionTests.java | 32 --------------- .../batch/core/StepExecutionTests.java | 39 +++--------------- .../batch/core/job/flow/FlowJobTests.java | 28 ------------- .../core/launch/SimpleJobLauncherTests.java | 18 -------- .../support/SimpleJobOperatorTests.java | 20 ++------- .../sample/launch/RemoteLauncherTests.java | 4 +- 16 files changed, 27 insertions(+), 257 deletions(-) delete mode 100644 spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/BatchStatus.java b/spring-batch-core/src/main/java/org/springframework/batch/core/BatchStatus.java index 309dd5239..71b56df69 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/BatchStatus.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/BatchStatus.java @@ -34,7 +34,7 @@ public enum BatchStatus { * (through the order defined by {@link #upgradeTo(BatchStatus)}). Higher * values than STARTED signify more serious failure. */ - COMPLETED, STARTING, WAITING, STARTED, FAILED, STOPPING, STOPPED, UNKNOWN; + COMPLETED, STARTING, STARTED, FAILED, STOPPING, STOPPED, UNKNOWN; public static BatchStatus max(BatchStatus status1, BatchStatus status2) { if (status1.isLessThan(status2)) { @@ -50,10 +50,10 @@ public enum BatchStatus { /** * Convenience method to decide if a status indicates work is in progress. * - * @return true if the status is STARTING, STARTED or WAITING + * @return true if the status is STARTING, STARTED */ public boolean isRunning() { - return this == STARTING || this == STARTED || this == WAITING; + return this == STARTING || this == STARTED; } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java index ad7ee34c5..2146a83d6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java @@ -208,29 +208,6 @@ public class JobExecution extends Entity { status = BatchStatus.STOPPING; } - /** - * Signal that this job execution wishes to wait for work to complete, and - * no more processing will take place on the current thread. A failed - * execution stays failed. - */ - public void pauseAndWait() { - if (!status.isUnsuccessful()) { - status = BatchStatus.WAITING; - } - } - - /** - * Test if the {@link JobExecution} has been paused and is waiting for work - * to be done. - * - * @see #pauseAndWait() - * - * @return true if this instance is waiting - */ - public boolean isWaiting() { - return status == BatchStatus.WAITING; - } - /** * Sets the {@link ExecutionContext} for this execution * diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index c88ea0fb5..ada1c277d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -273,29 +273,6 @@ public class StepExecution extends Entity { this.status = this.status.upgradeTo(status); } - /** - * Signal that this job execution wishes to wait for work to complete, and - * no more processing will take place on the current thread. A failed - * execution stays failed. - */ - public void pauseAndWait() { - if (!status.isUnsuccessful()) { - status = BatchStatus.WAITING; - } - } - - /** - * Test if the {@link JobExecution} has been paused and is waiting for work - * to be done. - * - * @see #pauseAndWait() - * - * @return true if this instance is waiting - */ - public boolean isWaiting() { - return status == BatchStatus.WAITING; - } - /** * @return the name of the step */ diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index bfa15b44a..299f11aac 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -217,22 +217,14 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea if (execution.getStatus() != BatchStatus.STOPPING) { execution.setStartTime(new Date()); - // If paused we need to retain the status so that subclasses can - // handle the resume, otherwise we mark it as started... - if (!execution.isWaiting()) { - updateStatus(execution, BatchStatus.STARTED); - } + updateStatus(execution, BatchStatus.STARTED); listener.beforeJob(execution); StepExecution lastStepExecution = doExecute(execution); if (lastStepExecution != null) { - if (!execution.isWaiting()) { - // If the subclass wants to pause don't change the - // status. - execution.setStatus(lastStepExecution.getStatus()); - } + execution.upgradeStatus(lastStepExecution.getStatus()); execution.setExitStatus(lastStepExecution.getExitStatus()); } } @@ -343,16 +335,16 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea * Given a step and configuration, return true if the step should start, * false if it should not, and throw an exception if the job should finish. * @param lastStepExecution the last step execution - * @param jobInstance - * @param step + * @param jobInstance + * @param step * * @throws StartLimitExceededException if the start limit has been exceeded * for this step * @throws JobRestartException if the job is in an inconsistent state from * an earlier failure */ - private boolean shouldStart(StepExecution lastStepExecution, JobInstance jobInstance, Step step) throws JobRestartException, - StartLimitExceededException { + private boolean shouldStart(StepExecution lastStepExecution, JobInstance jobInstance, Step step) + throws JobRestartException, StartLimitExceededException { BatchStatus stepStatus; if (lastStepExecution == null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java deleted file mode 100644 index 06e10d907..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.springframework.batch.core.job.flow.support.state; - -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.job.flow.FlowExecution; -import org.springframework.batch.core.job.flow.FlowExecutor; - -/** - * @author Dave Syer - * - */ -public class PauseState extends AbstractState { - - /** - * @param name - */ - public PauseState(String name) { - super(name); - } - - @Override - public String handle(FlowExecutor executor) throws Exception { - - JobExecution jobExecution = executor.getJobExecution(); - - // This state is just a toggle for the status of the job execution. If - // not already paused we pause it, and expect the flow to respect the - // status. - synchronized (jobExecution) { - if (!jobExecution.isWaiting()) { - jobExecution.pauseAndWait(); - return FlowExecution.PAUSED; - } - - // ...otherwise set the status to show that it has resumed - jobExecution.setStatus(BatchStatus.STARTED); - return FlowExecution.COMPLETED; - } - } - -} \ No newline at end of file diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java index 3d6502ca8..e703c5a30 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java @@ -75,8 +75,6 @@ public interface JobOperator { boolean stop(long executionId) throws NoSuchJobExecutionException; - boolean pause(long executionId) throws NoSuchJobExecutionException; - String getSummary(long executionId) throws NoSuchJobExecutionException; Map getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java index 0c35fb20a..9bafeacfb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java @@ -84,12 +84,7 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean { final JobExecution jobExecution; JobExecution lastExecution = jobRepository.getLastJobExecution(job.getName(), jobParameters); if (lastExecution != null) { - if (lastExecution.isWaiting()) { - jobExecution = lastExecution; - // this execution will be continued => delete the end time - jobExecution.setEndTime(null); - } - else if (!job.isRestartable()) { + if (!job.isRestartable()) { throw new JobRestartException("JobInstance already exists and is not restartable"); } else { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index c0dbfc8b7..5d3bc8c74 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -368,13 +368,6 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { return true; } - public boolean pause(long executionId) throws NoSuchJobExecutionException { - JobExecution jobExecution = findExecutionById(executionId); - jobExecution.pauseAndWait(); - jobRepository.update(jobExecution); - return true; - } - private JobExecution findExecutionById(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = jobExplorer.getJobExecution(executionId); 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 9cdf877ce..eb0268599 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 @@ -81,10 +81,6 @@ public class PartitionStep extends AbstractStep { throw new JobExecutionException("Partition handler returned an unsuccessful step"); } - if (stepExecution.getStatus() != BatchStatus.COMPLETED) { - stepExecution.pauseAndWait(); - } - } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java index d6069a0bd..acee2777e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/BatchStatusTests.java @@ -15,7 +15,11 @@ */ package org.springframework.batch.core; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -60,8 +64,6 @@ public class BatchStatusTests { assertEquals(BatchStatus.COMPLETED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.STARTING)); assertEquals(BatchStatus.STARTED, BatchStatus.STARTING.upgradeTo(BatchStatus.STARTED)); assertEquals(BatchStatus.STARTED, BatchStatus.STARTED.upgradeTo(BatchStatus.STARTING)); - assertEquals(BatchStatus.COMPLETED, BatchStatus.COMPLETED.upgradeTo(BatchStatus.WAITING)); - assertEquals(BatchStatus.STARTED, BatchStatus.STARTED.upgradeTo(BatchStatus.WAITING)); } @Test @@ -70,7 +72,6 @@ public class BatchStatusTests { assertFalse(BatchStatus.COMPLETED.isRunning()); assertTrue(BatchStatus.STARTED.isRunning()); assertTrue(BatchStatus.STARTING.isRunning()); - assertTrue(BatchStatus.WAITING.isRunning()); } @Test @@ -79,7 +80,6 @@ public class BatchStatusTests { assertFalse(BatchStatus.COMPLETED.isUnsuccessful()); assertFalse(BatchStatus.STARTED.isUnsuccessful()); assertFalse(BatchStatus.STARTING.isUnsuccessful()); - assertFalse(BatchStatus.WAITING.isUnsuccessful()); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java index 2ab0a249b..4be3a5b12 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java @@ -107,38 +107,6 @@ public class JobExecutionTests { assertEquals(BatchStatus.COMPLETED, execution.getStatus()); } - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWait() { - execution.pauseAndWait(); - assertEquals(BatchStatus.WAITING, execution.getStatus()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWaitWhenFailed() { - execution.setStatus(BatchStatus.FAILED); - execution.pauseAndWait(); - assertEquals(BatchStatus.FAILED, execution.getStatus()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWaitWhenStarted() { - execution.setStatus(BatchStatus.STARTED); - execution.pauseAndWait(); - assertEquals(BatchStatus.WAITING, execution.getStatus()); - } - /** * Test method for * {@link org.springframework.batch.core.JobExecution#getStatus()}. diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java index 9454e0c86..cb2b39eb0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java @@ -15,7 +15,12 @@ */ package org.springframework.batch.core; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Date; import java.util.HashSet; @@ -275,38 +280,6 @@ public class StepExecutionTests { assertEquals(exception, execution.getFailureExceptions().get(0)); } - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWait() { - execution.pauseAndWait(); - assertEquals(BatchStatus.WAITING, execution.getStatus()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWaitWhenFailed() { - execution.setStatus(BatchStatus.FAILED); - execution.pauseAndWait(); - assertEquals(BatchStatus.FAILED, execution.getStatus()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.JobExecution#pauseAndWait()}. - */ - @Test - public void testPauseAndWaitWhenStarted() { - execution.setStatus(BatchStatus.STARTED); - execution.pauseAndWait(); - assertEquals(BatchStatus.WAITING, execution.getStatus()); - } - /** * Test method for * {@link org.springframework.batch.core.JobExecution#getStatus()}. diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java index 71e5543ab..bd1714a17 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java @@ -38,7 +38,6 @@ import org.springframework.batch.core.job.flow.support.StateTransition; import org.springframework.batch.core.job.flow.support.state.DecisionState; import org.springframework.batch.core.job.flow.support.state.EndState; import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider; -import org.springframework.batch.core.job.flow.support.state.PauseState; import org.springframework.batch.core.job.flow.support.state.StepState; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; @@ -250,33 +249,6 @@ public class FlowJobTests { } - @Test - public void testPauseFlow() throws Throwable { - - SimpleFlow flow = new SimpleFlow("job"); - Collection transitions = new ArrayList(); - transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "*", "pause")); - transitions.add(StateTransition.createStateTransition(new PauseState("pause"), "*", "step2")); - transitions.add(StateTransition.createEndStateTransition(new StepState(new StubStep("step2")), "*")); - flow.setStateTransitions(transitions); - job.setFlow(flow); - - job.execute(jobExecution); - if (!jobExecution.getAllFailureExceptions().isEmpty()) { - throw jobExecution.getAllFailureExceptions().get(0); - } - assertEquals(BatchStatus.WAITING, jobExecution.getStatus()); - assertEquals(1, jobExecution.getStepExecutions().size()); - - job.execute(jobExecution); - if (!jobExecution.getAllFailureExceptions().isEmpty()) { - throw jobExecution.getAllFailureExceptions().get(0); - } - assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); - assertEquals(2, jobExecution.getStepExecutions().size()); - - } - /** * @author Dave Syer * diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java index 0122726bf..13a2e679f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java @@ -186,24 +186,6 @@ public class SimpleJobLauncherTests { jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); // no error } - - /** - * Same execution is used if the last found has PAUSED status. - */ - @Test - public void testResumePausedInstance() throws Exception { - long id = 9; - JobExecution jobExecution = new JobExecution(null, id); - jobExecution.pauseAndWait(); - expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(jobExecution); - replay(jobRepository); - - jobLauncher.afterPropertiesSet(); - JobExecution returned = jobLauncher.run(job, jobParameters); - assertEquals(jobExecution, returned); - - verify(jobRepository); - } private boolean contains(String str, String searchStr) { return str.indexOf(searchStr) != -1; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java index 92949dc0c..cdb8c71d4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java @@ -15,10 +15,13 @@ */ package org.springframework.batch.core.launch.support; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.easymock.EasyMock.*; import java.util.Arrays; import java.util.Collection; @@ -390,19 +393,4 @@ public class SimpleJobOperatorTests { assertEquals(BatchStatus.STOPPING, jobExecution.getStatus()); } - @Test - public void testPause() throws Exception{ - JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName()); - JobExecution jobExecution = new JobExecution(jobInstance, 111L); - jobExplorer.getJobExecution(111L); - expectLastCall().andReturn(jobExecution); - jobRepository.update(jobExecution); - replay(jobExplorer); - replay(jobRepository); - jobOperator.pause(111L); - verify(jobExplorer); - verify(jobRepository); - assertEquals(BatchStatus.WAITING, jobExecution.getStatus()); - } - } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java index 0863abae7..be8ce392f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java @@ -94,7 +94,7 @@ public class RemoteLauncherTests { // doesn't work with HSQL) Thread.sleep(SLEEP_INTERVAL); // assertEquals(1, launcher.getRunningExecutions("loopJob").size()); - launcher.pause(executionId); + launcher.stop(executionId); Thread.sleep(SLEEP_INTERVAL); // assertEquals(0, launcher.getRunningExecutions("loopJob").size()); @@ -103,7 +103,7 @@ public class RemoteLauncherTests { assertEquals("Picked up the same execution after pause and resume", executionId, resumedId); Thread.sleep(SLEEP_INTERVAL); - launcher.pause(executionId); + launcher.stop(executionId); Thread.sleep(SLEEP_INTERVAL); // assertEquals(0, launcher.getRunningExecutions("loopJob").size());