RESOLVED - issue BATCH-546: pull duplicates from TaskletStep and ItemOrientedStep into AbstractStep

This commit is contained in:
robokaso
2008-04-04 14:57:27 +00:00
parent 646965b32d
commit 9a222286b8
6 changed files with 300 additions and 357 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
import org.springframework.batch.core.step.skip.NeverSkipItemSkipPolicy;
import org.springframework.batch.item.AbstractItemReader;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
@@ -510,5 +511,20 @@ public class SimpleJobTests extends TestCase {
this.itemSkipPolicy = itemSkipPolicy;
}
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
// TODO Auto-generated method stub
return null;
}
protected void close(ExecutionContext ctx) throws Exception {
// TODO Auto-generated method stub
}
protected void open(ExecutionContext ctx) throws Exception {
// TODO Auto-generated method stub
}
}
}

View File

@@ -279,8 +279,10 @@ public class ItemOrientedStepTests extends TestCase {
});
itemOrientedStep.execute(stepExecution);
// context saved before processing starts and updated at the end
assertEquals(2, list.size());
// context saved before looping and updated once for every processing
// loop (once in this case) and finally in the abstract step (regardless
// of execution logic)
assertEquals(3, list.size());
}
public void testSuccessfulExecutionWithFailureOnSaveOfExecutionContext() throws Exception {
@@ -298,37 +300,16 @@ public class ItemOrientedStepTests extends TestCase {
});
try {
itemOrientedStep.execute(stepExecution);
fail("Expected BatchCriticalException");
fail();
}
catch (UnexpectedJobExecutionException e) {
catch (RuntimeException e) {
assertEquals("Fatal error detected during save of step execution context", e.getMessage());
assertEquals("foo", e.getCause().getMessage());
}
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
}
/*
* make sure a job that has been executed before, and is therefore being
* restarted, is restored.
*/
// public void testRestartedJob() throws Exception {
// String step = "stepName";
// // step.setStepExecutionCount(1);
// MockRestartableItemReader tasklet = new MockRestartableItemReader();
// stepExecutor.setItemReader(tasklet);
// stepConfiguration.setSaveExecutionContext(true);
// JobExecution jobExecution = new JobExecution(jobInstance);
// StepExecution stepExecution = new StepExecution(step, jobExecution);
//
// stepExecution
// .setExecutionContext(new
// ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
// // step.setLastExecution(stepExecution);
// stepExecutor.execute(stepExecution);
//
// assertTrue(tasklet.isRestoreFromCalled());
// assertTrue(tasklet.isRestoreFromCalledWithSomeContext());
// assertTrue(tasklet.isGetExecutionAttributesCalled());
// }
/*
* Test that a job that is being restarted, but has saveExecutionAttributes
* set to false, doesn't have restore or getExecutionAttributes called on
@@ -497,7 +478,6 @@ public class ItemOrientedStepTests extends TestCase {
}
public void update(ExecutionContext executionContext) {
// TODO Auto-generated method stub
executionContext.putString("foo", "bar");
}
};
@@ -547,7 +527,6 @@ public class ItemOrientedStepTests extends TestCase {
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
// step.setLastExecution(stepExecution);
try {
itemOrientedStep.execute(stepExecution);
@@ -556,7 +535,7 @@ public class ItemOrientedStepTests extends TestCase {
catch (JobInterruptedException ex) {
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertTrue("Message does not contain 'interrupted': " + msg, contains(msg, "interrupted"));
assertTrue("Message does not contain 'JobInterruptedException': " + msg, contains(msg, "JobInterruptedException"));
}
}
@@ -640,7 +619,7 @@ public class ItemOrientedStepTests extends TestCase {
itemOrientedStep.execute(stepExecution);
fail("Expected UnexpectedJobExecutionException");
}
catch (UnexpectedJobExecutionException ex) {
catch (RuntimeException ex) {
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertTrue("Message does not contain ResetFailedException: " + msg, contains(msg, "ResetFailedException"));
@@ -668,12 +647,12 @@ public class ItemOrientedStepTests extends TestCase {
itemOrientedStep.execute(stepExecution);
fail("Expected BatchCriticalException");
}
catch (UnexpectedJobExecutionException ex) {
catch (RuntimeException ex) {
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
assertTrue(msg.contains("Fatal error detected during commit"));
msg = ex.getMessage();
assertTrue("Message does not contain 'saving': " + msg, contains(msg, "saving"));
assertTrue(msg.contains("Fatal error detected during commit"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -703,7 +682,7 @@ public class ItemOrientedStepTests extends TestCase {
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'final': " + msg, contains(msg, "final"));
assertTrue("Message does not contain 'saving batch meta data': " + msg, contains(msg, "saving batch meta data"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -737,7 +716,7 @@ public class ItemOrientedStepTests extends TestCase {
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'close': " + msg, contains(msg, "close"));
assertTrue("Message does not contain 'closing': " + msg, contains(msg, "closing"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -792,9 +771,9 @@ public class ItemOrientedStepTests extends TestCase {
catch (RuntimeException expected) {
assertEquals("exception thrown in afterStep to signal failure", expected.getMessage());
}
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
}
private boolean contains(String str, String searchStr) {

View File

@@ -130,7 +130,7 @@ public class TaskletStepTests extends TestCase {
}
catch (RuntimeException e) {
assertNotNull(stepExecution.getStartTime());
assertEquals(ExitStatus.FAILED, stepExecution.getExitStatus());
assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
assertNotNull(stepExecution.getEndTime());
}
}
@@ -143,7 +143,7 @@ public class TaskletStepTests extends TestCase {
}
catch (Error e) {
assertNotNull(stepExecution.getStartTime());
assertEquals(ExitStatus.FAILED, stepExecution.getExitStatus());
assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
assertNotNull(stepExecution.getEndTime());
}
}