Fixed broken unit tests and sample jobs from move away from Tasklet.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.domain.StepInterruptedException;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
@@ -28,6 +30,10 @@ import org.springframework.batch.repeat.RepeatContext;
|
||||
*/
|
||||
public class ThreadStepInterruptionPolicy implements StepInterruptionPolicy {
|
||||
|
||||
protected static final Log logger = LogFactory
|
||||
.getLog(ThreadStepInterruptionPolicy.class);
|
||||
|
||||
|
||||
/**
|
||||
* Returns if the current job lifecycle has been interrupted by checking if
|
||||
* the current thread is interrupted.
|
||||
@@ -45,7 +51,11 @@ public class ThreadStepInterruptionPolicy implements StepInterruptionPolicy {
|
||||
* @return true if the job has been interrupted
|
||||
*/
|
||||
private boolean isInterrupted(RepeatContext context) {
|
||||
return Thread.currentThread().isInterrupted() || context.isTerminateOnly();
|
||||
boolean interrupted = (Thread.currentThread().isInterrupted() || context.isTerminateOnly());
|
||||
if(interrupted){
|
||||
logger.error("Step interrupted");
|
||||
}
|
||||
return interrupted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.execution.repository.SimpleJobRepository;
|
||||
import org.springframework.batch.execution.repository.dao.MapJobDao;
|
||||
import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.step.simple.AbstractStep;
|
||||
import org.springframework.batch.execution.step.simple.SimpleStep;
|
||||
import org.springframework.batch.execution.step.simple.RepeatOperationsStep;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -76,8 +76,8 @@ public class SimpleJobTests extends TestCase {
|
||||
return getStep(new String[] { arg0, arg1 });
|
||||
}
|
||||
|
||||
private AbstractStep getStep(String[] args) throws Exception {
|
||||
SimpleStep step = new SimpleStep();
|
||||
private RepeatOperationsStep getStep(String[] args) throws Exception {
|
||||
RepeatOperationsStep step = new RepeatOperationsStep();
|
||||
List items = TransactionAwareProxyFactory.createTransactionalList();
|
||||
items.addAll(Arrays.asList(args));
|
||||
provider = new ListItemReader(items);
|
||||
@@ -123,7 +123,7 @@ public class SimpleJobTests extends TestCase {
|
||||
chunkOperations.setExceptionHandler(new ExceptionHandler() {
|
||||
public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException {
|
||||
throwables.add(throwable);
|
||||
assertEquals("Try again Dummy!", throwable.getMessage());
|
||||
assertEquals("Error!", throwable.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -132,16 +132,15 @@ public class SimpleJobTests extends TestCase {
|
||||
* is recovered ("skipped") on the second attempt (see retry policy
|
||||
* definition above)...
|
||||
*/
|
||||
AbstractStep step = getStep(new String[] { "foo", "bar", "spam" });
|
||||
RepeatOperationsStep step = getStep(new String[] { "foo", "bar", "spam" });
|
||||
|
||||
|
||||
// Tasklet module = getTasklet(new String[] { "foo", "bar", "spam" });
|
||||
// RepeatOperationsStep step = new RepeatOperationsStep();
|
||||
// step.setTasklet(module);
|
||||
// step.setChunkOperations(chunkOperations);
|
||||
step.setChunkOperations(chunkOperations);
|
||||
step.setItemWriter(new AbstractItemWriter() {
|
||||
public void write(Object data) throws Exception {
|
||||
throw new RuntimeException("Try again Dummy!");
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
|
||||
@@ -26,6 +26,10 @@ import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.ItemReaderAdapter;
|
||||
import org.springframework.batch.item.writer.ItemWriterAdapter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.interceptor.RepeatInterceptorAdapter;
|
||||
@@ -39,16 +43,23 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
|
||||
*/
|
||||
public class RepeatOperationsStepTests extends TestCase {
|
||||
|
||||
RepeatOperationsStep configuration = new RepeatOperationsStep();
|
||||
RepeatOperationsStep repeatStep = new RepeatOperationsStep();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
repeatStep.setItemReader(new ItemReaderAdapter());
|
||||
repeatStep.setItemWriter(new ItemWriterAdapter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.RepeatOperationsStep#getChunkOperations()}.
|
||||
*/
|
||||
public void testSetChunkOperations() {
|
||||
assertNull(configuration.getChunkOperations());
|
||||
assertNull(repeatStep.getChunkOperations());
|
||||
RepeatTemplate executor = new RepeatTemplate();
|
||||
configuration.setChunkOperations(executor);
|
||||
assertEquals(executor, configuration.getChunkOperations());
|
||||
repeatStep.setChunkOperations(executor);
|
||||
assertEquals(executor, repeatStep.getChunkOperations());
|
||||
|
||||
}
|
||||
|
||||
@@ -56,10 +67,10 @@ public class RepeatOperationsStepTests extends TestCase {
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.RepeatOperationsStep#getChunkOperations()}.
|
||||
*/
|
||||
public void testSetStepOperations() {
|
||||
assertNull(configuration.getChunkOperations());
|
||||
assertNull(repeatStep.getChunkOperations());
|
||||
RepeatTemplate executor = new RepeatTemplate();
|
||||
configuration.setStepOperations(executor);
|
||||
assertEquals(executor, configuration.getStepOperations());
|
||||
repeatStep.setStepOperations(executor);
|
||||
assertEquals(executor, repeatStep.getStepOperations());
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +84,13 @@ public class RepeatOperationsStepTests extends TestCase {
|
||||
});
|
||||
repeatTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
RepeatOperationsStep configuration = new RepeatOperationsStep();
|
||||
configuration.setItemReader(new ItemReader(){
|
||||
public Object read() throws Exception {
|
||||
throw new NullPointerException();
|
||||
}});
|
||||
configuration.setItemWriter(new ItemWriter(){
|
||||
public void write(Object item) throws Exception {
|
||||
}});
|
||||
configuration.setChunkOperations(repeatTemplate);
|
||||
configuration.setJobRepository(new JobRepositorySupport());
|
||||
configuration.setTransactionManager(new ResourcelessTransactionManager());
|
||||
@@ -106,6 +124,13 @@ public class RepeatOperationsStepTests extends TestCase {
|
||||
});
|
||||
stepTemplate.setCompletionPolicy(new SimpleCompletionPolicy(1));
|
||||
RepeatOperationsStep configuration = new RepeatOperationsStep();
|
||||
configuration.setItemReader(new ItemReader(){
|
||||
public Object read() throws Exception {
|
||||
return new Object();
|
||||
}});
|
||||
configuration.setItemWriter(new ItemWriter(){
|
||||
public void write(Object item) throws Exception {
|
||||
}});
|
||||
configuration.setChunkOperations(chunkTemplate);
|
||||
configuration.setStepOperations(stepTemplate);
|
||||
configuration.setJobRepository(new JobRepositorySupport());
|
||||
|
||||
@@ -441,7 +441,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
|
||||
public Object read() throws Exception {
|
||||
StepSynchronizationManager.getContext().setAttribute("TASKLET_TEST", this);
|
||||
return ExitStatus.FINISHED;
|
||||
return "item";
|
||||
}
|
||||
|
||||
public boolean isRestoreFromCalledWithSomeContext() {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
processingThread.start();
|
||||
|
||||
Thread.sleep(500);
|
||||
Thread.sleep(100);
|
||||
|
||||
processingThread.interrupt();
|
||||
|
||||
|
||||
@@ -20,24 +20,29 @@
|
||||
<bean id="test-job"
|
||||
class="org.springframework.batch.core.domain.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
<constructor-arg value="foo,bar,spam" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.launch.EmptyItemWriter" />
|
||||
</property>
|
||||
<property name="jobRepository" >
|
||||
<bean class="org.springframework.batch.execution.step.simple.JobRepositorySupport" />
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.simple.SimpleStep">
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="streamManager">
|
||||
<bean class="org.springframework.batch.item.stream.SimpleStreamManager" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemReader"
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
<constructor-arg value="foo,bar,spam" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter"
|
||||
class="org.springframework.batch.execution.launch.EmptyItemWriter" />
|
||||
|
||||
<bean id="jobRepository"
|
||||
class="org.springframework.batch.execution.step.simple.JobRepositorySupport" />
|
||||
|
||||
|
||||
<bean id="test-job-with-name"
|
||||
class="org.springframework.batch.core.domain.JobSupport">
|
||||
<property name="name" value="foo" />
|
||||
@@ -58,7 +63,7 @@
|
||||
p:name="spam" />
|
||||
|
||||
<bean id="test-job-with-parent-and-bean-name" parent="abstract-job"
|
||||
p:beanName="bucket" />
|
||||
p:name="bucket" />
|
||||
|
||||
<bean id="parent-job"
|
||||
class="org.springframework.batch.core.domain.JobSupport" />
|
||||
|
||||
Reference in New Issue
Block a user