IN PROGRESS - issue BATCH-894: RFC: move ExitStatus up into Core?
Remove continuable from ExitStatus
This commit is contained in:
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -29,39 +28,21 @@ import org.springframework.batch.core.ExitStatus;
|
||||
*/
|
||||
public class ExitStatusTests {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusBooleanInt() {
|
||||
ExitStatus status = new ExitStatus(true, "10");
|
||||
assertTrue(status.isContinuable());
|
||||
ExitStatus status = new ExitStatus("10");
|
||||
assertEquals("10", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsContinuable() {
|
||||
ExitStatus status = ExitStatus.EXECUTING;
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("EXECUTING", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsFinished() {
|
||||
ExitStatus status = ExitStatus.FINISHED;
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals("COMPLETED", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -72,18 +53,18 @@ public class ExitStatusTests {
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsWithSameProperties() throws Exception {
|
||||
assertEquals(ExitStatus.EXECUTING, new ExitStatus(true, "EXECUTING"));
|
||||
assertEquals(ExitStatus.EXECUTING, new ExitStatus("EXECUTING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsSelf() {
|
||||
ExitStatus status = new ExitStatus(true, "test");
|
||||
ExitStatus status = new ExitStatus("test");
|
||||
assertEquals(status, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertEquals(new ExitStatus(true, "test"), new ExitStatus(true, "test"));
|
||||
assertEquals(new ExitStatus("test"), new ExitStatus("test"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,30 +87,14 @@ public class ExitStatusTests {
|
||||
assertEquals(ExitStatus.EXECUTING.toString().hashCode(), ExitStatus.EXECUTING.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(boolean)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAndBoolean() {
|
||||
assertTrue(ExitStatus.EXECUTING.and(true).isContinuable());
|
||||
assertFalse(ExitStatus.EXECUTING.and(false).isContinuable());
|
||||
ExitStatus status = new ExitStatus(false, "CUSTOM_CODE", "CUSTOM_DESCRIPTION");
|
||||
assertTrue(status.and(true).getExitCode() == "CUSTOM_CODE");
|
||||
assertTrue(status.and(true).getExitDescription() == "CUSTOM_DESCRIPTION");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusStillContinuable() {
|
||||
assertTrue(ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).isContinuable());
|
||||
assertFalse(ExitStatus.EXECUTING.and(ExitStatus.FINISHED).isContinuable());
|
||||
assertTrue(ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).getExitCode().equals(
|
||||
ExitStatus.EXECUTING.getExitCode()));
|
||||
public void testAndExitStatusStillExecutable() {
|
||||
assertEquals(ExitStatus.EXECUTING.getExitCode(), ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,8 +124,17 @@ public class ExitStatusTests {
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomContinuableAddedToContinuable() {
|
||||
assertEquals("CUSTOM", ExitStatus.EXECUTING.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM"))
|
||||
.getExitCode());
|
||||
assertEquals("CUSTOM", ExitStatus.EXECUTING.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM")).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomCompletedAddedToCompleted() {
|
||||
assertEquals("COMPLETED_CUSTOM", ExitStatus.FINISHED.and(ExitStatus.EXECUTING.replaceExitCode("COMPLETED_CUSTOM")).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +163,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCode() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -197,7 +170,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCodeToExistingStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO").replaceExitCode("BAR");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("BAR", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -205,7 +177,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCodeToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode(ExitStatus.EXECUTING.getExitCode());
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals(ExitStatus.EXECUTING.getExitCode(), status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -213,7 +184,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitDescription() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@@ -221,7 +191,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitDescriptionToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo").addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@@ -233,7 +202,7 @@ public class ExitStatusTests {
|
||||
|
||||
@Test
|
||||
public void testAddExitCodeWithDescription() throws Exception {
|
||||
ExitStatus status = new ExitStatus(true, "BAR", "Bar").replaceExitCode("FOO");
|
||||
ExitStatus status = new ExitStatus("BAR", "Bar").replaceExitCode("FOO");
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
assertEquals("Bar", status.getExitDescription());
|
||||
}
|
||||
@@ -250,7 +219,6 @@ public class ExitStatusTests {
|
||||
Object object = SerializationUtils.deserialize(bytes);
|
||||
assertTrue(object instanceof ExitStatus);
|
||||
ExitStatus restored = (ExitStatus) object;
|
||||
assertTrue(restored.isContinuable());
|
||||
assertEquals(status.getExitCode(), restored.getExitCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -29,11 +33,12 @@ import org.junit.Test;
|
||||
*/
|
||||
public class JobExecutionTests {
|
||||
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"), new Long(12));
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"),
|
||||
new Long(12));
|
||||
|
||||
@Test
|
||||
public void testJobExecution() {
|
||||
assertNull(new JobExecution(new JobInstance(null,null,"foo")).getId());
|
||||
assertNull(new JobExecution(new JobInstance(null, null, "foo")).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +165,7 @@ public class JobExecutionTests {
|
||||
@Test
|
||||
public void testGetExitCode() {
|
||||
assertEquals(ExitStatus.UNKNOWN, execution.getExitStatus());
|
||||
execution.setExitStatus(new ExitStatus(true, "23"));
|
||||
execution.setExitStatus(new ExitStatus("23"));
|
||||
assertEquals("23", execution.getExitStatus().getExitCode());
|
||||
}
|
||||
|
||||
@@ -175,7 +180,7 @@ public class JobExecutionTests {
|
||||
execution.createStepExecution("step");
|
||||
assertEquals(1, execution.getStepExecutions().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStop() throws Exception {
|
||||
StepExecution stepExecution = execution.createStepExecution("step");
|
||||
@@ -192,11 +197,11 @@ public class JobExecutionTests {
|
||||
|
||||
@Test
|
||||
public void testToStringWithNullJob() throws Exception {
|
||||
execution = new JobExecution(new JobInstance(null,null,"foo"));
|
||||
execution = new JobExecution(new JobInstance(null, null, "foo"));
|
||||
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
@@ -205,9 +210,9 @@ public class JobExecutionTests {
|
||||
assertNotNull(deserialize.createStepExecution("foo"));
|
||||
assertNotNull(deserialize.getFailureExceptions());
|
||||
}
|
||||
|
||||
public void testFailureExceptions(){
|
||||
|
||||
|
||||
public void testFailureExceptions() {
|
||||
|
||||
RuntimeException exception = new RuntimeException();
|
||||
assertEquals(0, execution.getFailureExceptions().size());
|
||||
execution.addFailureException(exception);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SimpleJobTests {
|
||||
private JobExecutionDao jobExecutionDao;
|
||||
|
||||
private StepExecutionDao stepExecutionDao;
|
||||
|
||||
|
||||
private ExecutionContextDao ecDao;
|
||||
|
||||
private List<Serializable> list = new ArrayList<Serializable>();
|
||||
@@ -163,7 +163,7 @@ public class SimpleJobTests {
|
||||
@Test
|
||||
public void testExitStatusReturned() throws JobExecutionException {
|
||||
|
||||
final ExitStatus customStatus = new ExitStatus(true, "test");
|
||||
final ExitStatus customStatus = new ExitStatus("test");
|
||||
|
||||
Step testStep = new Step() {
|
||||
|
||||
@@ -260,7 +260,7 @@ public class SimpleJobTests {
|
||||
step2.setStartLimit(5);
|
||||
final RuntimeException exception = new RuntimeException("Foo!");
|
||||
step1.setProcessException(exception);
|
||||
|
||||
|
||||
job.execute(jobExecution);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(exception, jobExecution.getAllFailureExceptions().get(0));
|
||||
@@ -306,11 +306,11 @@ public class SimpleJobTests {
|
||||
step1.setStartLimit(0);
|
||||
|
||||
job.execute(jobExecution);
|
||||
|
||||
|
||||
assertEquals(1, jobExecution.getFailureExceptions().size());
|
||||
Throwable ex = jobExecution.getFailureExceptions().get(0);
|
||||
assertTrue("Wrong message in exception: " + ex.getMessage(), ex.getMessage()
|
||||
.indexOf("start limit exceeded") >= 0);
|
||||
assertTrue("Wrong message in exception: " + ex.getMessage(),
|
||||
ex.getMessage().indexOf("start limit exceeded") >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,7 +340,7 @@ public class SimpleJobTests {
|
||||
public void testNotExecutedIfAlreadyStopped() throws Exception {
|
||||
jobExecution.stop();
|
||||
job.execute(jobExecution);
|
||||
|
||||
|
||||
assertEquals(0, list.size());
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.NOOP);
|
||||
ExitStatus exitStatus = jobExecution.getExitStatus();
|
||||
@@ -430,9 +430,9 @@ public class SimpleJobTests {
|
||||
job.execute(jobExecution);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
Throwable expected = jobExecution.getAllFailureExceptions().get(0);
|
||||
assertTrue("Wrong exception "+expected, expected instanceof JobInterruptedException);
|
||||
assertTrue("Wrong exception " + expected, expected instanceof JobInterruptedException);
|
||||
assertEquals("JobExecution interrupted.", expected.getMessage());
|
||||
|
||||
|
||||
assertNull("Second step was not supposed to be executed", step2.passedInStepContext);
|
||||
}
|
||||
|
||||
@@ -490,7 +490,9 @@ public class SimpleJobTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.step.StepSupport#execute(org.springframework.batch.core.StepExecution)
|
||||
*
|
||||
* @seeorg.springframework.batch.core.step.StepSupport#execute(org.
|
||||
* springframework.batch.core.StepExecution)
|
||||
*/
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException,
|
||||
UnexpectedJobExecutionException {
|
||||
|
||||
@@ -36,7 +36,8 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#setListeners(org.springframework.batch.core.StepExecutionListener[])}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#setListeners(org.springframework.batch.core.StepExecutionListener[])}
|
||||
* .
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() {
|
||||
@@ -50,13 +51,14 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
return ExitStatus.EXECUTING;
|
||||
}
|
||||
} });
|
||||
assertFalse(listener.afterStep(null).isContinuable());
|
||||
assertEquals(ExitStatus.FAILED, listener.afterStep(null));
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#register(org.springframework.batch.core.StepExecutionListener)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#register(org.springframework.batch.core.StepExecutionListener)}
|
||||
* .
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new StepExecutionListenerSupport() {
|
||||
@@ -65,13 +67,14 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
return ExitStatus.FAILED;
|
||||
}
|
||||
});
|
||||
assertFalse(listener.afterStep(null).isContinuable());
|
||||
assertEquals(ExitStatus.FAILED, listener.afterStep(null));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}
|
||||
* .
|
||||
*/
|
||||
public void testOpen() {
|
||||
listener.register(new StepExecutionListenerSupport() {
|
||||
|
||||
@@ -237,7 +237,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ExitStatus status = stepExecution.getExitStatus();
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals(ExitStatus.FINISHED, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ExitStatus status = stepExecution.getExitStatus();
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals(ExitStatus.FAILED.getExitCode(), status.getExitCode());
|
||||
String description = status.getExitDescription();
|
||||
assertTrue("Description does not include 'FOO': " + description, description.indexOf("FOO") >= 0);
|
||||
}
|
||||
@@ -323,9 +323,9 @@ public class TaskletStepTests {
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
step.execute(stepExecution);
|
||||
Throwable e = stepExecution.getFailureExceptions().get(0);
|
||||
Throwable e = stepExecution.getFailureExceptions().get(0);
|
||||
assertEquals("Fatal error detected during save of step execution context", e.getMessage());
|
||||
assertEquals("foo", e.getCause().getMessage());
|
||||
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
|
||||
@@ -452,7 +452,7 @@ public class TaskletStepTests {
|
||||
@Test
|
||||
public void testAfterStep() throws Exception {
|
||||
|
||||
final ExitStatus customStatus = new ExitStatus(false, "custom code");
|
||||
final ExitStatus customStatus = new ExitStatus("COMPLETED_CUSTOM");
|
||||
|
||||
step.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() {
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
@@ -520,7 +520,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusForInterruptedException() throws Exception{
|
||||
public void testStatusForInterruptedException() throws Exception {
|
||||
|
||||
StepInterruptionPolicy interruptionPolicy = new StepInterruptionPolicy() {
|
||||
|
||||
@@ -551,7 +551,7 @@ public class TaskletStepTests {
|
||||
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertTrue("Message does not contain 'JobInterruptedException': " + msg, contains(msg,
|
||||
"JobInterruptedException"));
|
||||
"JobInterruptedException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -702,7 +702,7 @@ public class TaskletStepTests {
|
||||
// step.setLastExecution(stepExecution);
|
||||
|
||||
step.execute(stepExecution);
|
||||
// The job actually completed, but the streams couldn't be closed.
|
||||
// The job actually completed, but the streams couldn't be closed.
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertEquals("", msg);
|
||||
@@ -756,7 +756,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception in {@link StepExecutionListener#afterStep(StepExecution)}
|
||||
* Exception in {@link StepExecutionListener#afterStep(StepExecution)}
|
||||
* doesn't cause step failure.
|
||||
* @throws JobInterruptedException
|
||||
*/
|
||||
@@ -774,19 +774,18 @@ public class TaskletStepTests {
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModifyingExecutionContextMidProcessCausesException() throws Exception{
|
||||
public void testModifyingExecutionContextMidProcessCausesException() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
final ExecutionContext ec = stepExecution.getExecutionContext();
|
||||
step.setTasklet(new Tasklet(){
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
AttributeAccessor attributes) throws Exception {
|
||||
step.setTasklet(new Tasklet() {
|
||||
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
ec.putString("test", "test");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
assertEquals(1, stepExecution.getFailureExceptions().size());
|
||||
@@ -810,11 +809,11 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class JobRepositoryFailedUpdateStub extends JobRepositorySupport {
|
||||
|
||||
|
||||
private int called = 0;
|
||||
|
||||
|
||||
public void update(StepExecution stepExecution) {
|
||||
called++;
|
||||
if (called == 3) {
|
||||
|
||||
Reference in New Issue
Block a user