BATCH-956: remove pause and wait features

This commit is contained in:
dsyer
2008-12-06 14:06:54 +00:00
parent 6cf0720768
commit 5d62e4d436
16 changed files with 27 additions and 257 deletions

View File

@@ -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;
}
/**

View File

@@ -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
*

View File

@@ -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
*/

View File

@@ -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) {

View File

@@ -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;
}
}
}

View File

@@ -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<Long, String> getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException;

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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()}.

View File

@@ -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()}.

View File

@@ -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<StateTransition> transitions = new ArrayList<StateTransition>();
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
*

View File

@@ -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;

View File

@@ -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());
}
}

View File

@@ -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());