BATCH-220: Complete rename StepHandler -> Tasklet
This commit is contained in:
@@ -42,7 +42,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ItemOrientedStepHandlerTests {
|
||||
public class ChunkOrientedTaskletTests {
|
||||
|
||||
private StubItemReader itemReader = new StubItemReader();
|
||||
|
||||
@@ -59,22 +59,22 @@ public class ItemOrientedStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testHandle() throws Exception {
|
||||
ItemOrientedStepHandler<String, String> handler = new ItemOrientedStepHandler<String, String>(itemReader,
|
||||
ChunkOrientedTasklet<String, String> handler = new ChunkOrientedTasklet<String, String>(itemReader,
|
||||
new PassthroughItemProcessor<String>(), itemWriter, repeatTemplate);
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
handler.handle(contribution, context);
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(2, itemReader.count);
|
||||
assertEquals("12", itemWriter.values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleCompositeItem() throws Exception {
|
||||
ItemOrientedStepHandler<String, String> handler = new ItemOrientedStepHandler<String, String>(itemReader,
|
||||
ChunkOrientedTasklet<String, String> handler = new ChunkOrientedTasklet<String, String>(itemReader,
|
||||
new AgrgegateItemProcessor(), itemWriter, repeatTemplate);
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
handler.handle(contribution, context);
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(2, itemReader.count);
|
||||
assertEquals("12", itemWriter.values);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.item.SkipLimitStepFactoryBean.StatefulRetryStepHandler;
|
||||
import org.springframework.batch.core.step.item.SkipLimitStepFactoryBean.StatefulRetryTasklet;
|
||||
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
|
||||
import org.springframework.batch.core.step.tasklet.BasicAttributeAccessor;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.batch.retry.support.RetryTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StatefulRetryStepHandlerTests {
|
||||
public class StatefulRetryTaskletTests {
|
||||
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
protected List<String> written = new ArrayList<String>();
|
||||
|
||||
private StatefulRetryStepHandler<Integer, String> handler;
|
||||
private StatefulRetryTasklet<Integer, String> handler;
|
||||
|
||||
private RepeatTemplate chunkOperations = new RepeatTemplate();
|
||||
|
||||
@@ -101,16 +101,16 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testBasicHandle() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, itemWriter, chunkOperations,
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, itemWriter, chunkOperations,
|
||||
retryTemplate, readSkipPolicy, writeSkipPolicy);
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
handler.handle(contribution, new BasicAttributeAccessor());
|
||||
handler.execute(contribution, new BasicAttributeAccessor());
|
||||
assertEquals(limit, contribution.getItemCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipOnRead() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(new ItemReader<Integer>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(new ItemReader<Integer>() {
|
||||
public Integer read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
BasicAttributeAccessor attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected SkipLimitExceededException");
|
||||
}
|
||||
catch (SkipLimitExceededException e) {
|
||||
@@ -131,7 +131,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testSkipSingleItemOnWrite() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
written.addAll(items);
|
||||
throw new RuntimeException("Barf!");
|
||||
@@ -141,14 +141,14 @@ public class StatefulRetryStepHandlerTests {
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
BasicAttributeAccessor attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("Barf!", e.getMessage());
|
||||
}
|
||||
assertTrue(attributes.hasAttribute("OUTPUT_BUFFER_KEY"));
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
assertEquals(1, contribution.getItemCount());
|
||||
assertEquals(1, contribution.getWriteSkipCount());
|
||||
assertEquals(1, written.size());
|
||||
@@ -156,7 +156,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testSkipMultipleItems() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
logger.debug("Writing items: "+items);
|
||||
written.addAll(items);
|
||||
@@ -170,7 +170,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
// Count to 3: (try + skip + skip)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException on i="+i);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -182,18 +182,18 @@ public class StatefulRetryStepHandlerTests {
|
||||
Chunk<String> chunk = (Chunk<String>) attributes.getAttribute("OUTPUT_BUFFER_KEY");
|
||||
assertEquals(1, chunk.getSkips().size());
|
||||
// The last recovery for this chunk...
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
|
||||
attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException on i=");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("Barf!", e.getMessage());
|
||||
}
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected SkipLimitExceededException");
|
||||
}
|
||||
catch (SkipLimitExceededException e) {
|
||||
@@ -21,12 +21,12 @@ import static org.junit.Assert.fail;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.step.tasklet.CallableStepHandlerAdapter;
|
||||
import org.springframework.batch.core.step.tasklet.CallableTaskletAdapter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
public class CallableStepHandlerAdapterTests {
|
||||
public class CallableTaskletAdapterTests {
|
||||
|
||||
private CallableStepHandlerAdapter adapter = new CallableStepHandlerAdapter();
|
||||
private CallableTaskletAdapter adapter = new CallableTaskletAdapter();
|
||||
|
||||
@Test
|
||||
public void testHandle() throws Exception {
|
||||
@@ -35,7 +35,7 @@ public class CallableStepHandlerAdapterTests {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
assertEquals(ExitStatus.FINISHED, adapter.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, adapter.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +39,7 @@ import org.springframework.batch.core.repository.dao.MapJobExecutionDao;
|
||||
import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -59,9 +59,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/core/repository/dao/sql-dao-test.xml")
|
||||
public class StepHandlerStepIntegrationTests {
|
||||
public class ChunkOrientedStepIntegrationTests {
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private Job job;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class StepHandlerStepIntegrationTests {
|
||||
jobRepositoryFactoryBean.afterPropertiesSet();
|
||||
jobRepository = (JobRepository) jobRepositoryFactoryBean.getObject();
|
||||
|
||||
step = new StepHandlerStep("stepName");
|
||||
step = new TaskletStep("stepName");
|
||||
step.setJobRepository(jobRepository);
|
||||
step.setTransactionManager(transactionManager);
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
@@ -112,7 +112,7 @@ public class StepHandlerStepIntegrationTests {
|
||||
@Test
|
||||
public void testStatusForCommitFailedException() throws Exception {
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(getReader(new String[] { "a", "b", "c" }),
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(getReader(new String[] { "a", "b", "c" }),
|
||||
new ItemWriter<String>() {
|
||||
public void write(List<? extends String> data) throws Exception {
|
||||
TransactionSynchronizationManager
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.tasklet;
|
||||
|
||||
import org.springframework.batch.core.step.item.ItemOrientedStepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.item.ChunkOrientedTasklet;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.PassthroughItemProcessor;
|
||||
@@ -25,13 +25,13 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
|
||||
/**
|
||||
* Simplest possible implementation of {@link StepHandler} with no skipping or
|
||||
* Simplest possible implementation of {@link Tasklet} with no skipping or
|
||||
* recovering or processing. Just delegates all calls to the provided
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleStepHandler<T> extends ItemOrientedStepHandler<T, T> {
|
||||
public class SimpleChunkOrientedTasklet<T> extends ChunkOrientedTasklet<T, T> {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -45,17 +45,17 @@ public class SimpleStepHandler<T> extends ItemOrientedStepHandler<T, T> {
|
||||
|
||||
/**
|
||||
* Creates a {@link PassthroughItemProcessor} and uses it to create an
|
||||
* instance of {@link ItemOrientedStepHandler}.
|
||||
* instance of {@link ChunkOrientedTasklet}.
|
||||
*/
|
||||
public SimpleStepHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
public SimpleChunkOrientedTasklet(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
super(itemReader, new PassthroughItemProcessor<T>(), itemWriter, repeatTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PassthroughItemProcessor} and uses it to create an
|
||||
* instance of {@link ItemOrientedStepHandler}.
|
||||
* instance of {@link ChunkOrientedTasklet}.
|
||||
*/
|
||||
public SimpleStepHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter, RepeatOperations repeatOperations) {
|
||||
public SimpleChunkOrientedTasklet(ItemReader<T> itemReader, ItemWriter<T> itemWriter, RepeatOperations repeatOperations) {
|
||||
super(itemReader, new PassthroughItemProcessor<T>(), itemWriter, repeatOperations);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.SimpleJobRepository;
|
||||
import org.springframework.batch.core.step.StepExecutionSynchronizer;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
|
||||
|
||||
public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private JobExecution jobExecution;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
new MapStepExecutionDao(), new MapExecutionContextDao());
|
||||
|
||||
JobSupport jobConfiguration = new JobSupport();
|
||||
step = new StepHandlerStep("interruptedStep");
|
||||
step = new TaskletStep("interruptedStep");
|
||||
jobConfiguration.addStep(step);
|
||||
jobConfiguration.setBeanName("testJob");
|
||||
jobExecution = jobRepository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
@@ -79,7 +79,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
// N.B, If we don't set the completion policy it might run forever
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
// do something non-trivial (and not Thread.sleep())
|
||||
double foo = 1;
|
||||
@@ -116,7 +116,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
Thread processingThread = createThread(stepExecution);
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
return null;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
public void testLockNotReleasedIfChunkFails() throws Exception {
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
throw new RuntimeException("Planned!");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerAdapter;
|
||||
import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
*/
|
||||
public class StepHandlerAdapterTests {
|
||||
|
||||
private StepHandlerAdapter tasklet = new StepHandlerAdapter();
|
||||
private MethodInvokingTaskletAdapter tasklet = new MethodInvokingTaskletAdapter();
|
||||
private Object result = null;
|
||||
|
||||
public ExitStatus execute() {
|
||||
@@ -47,20 +47,20 @@ public class StepHandlerAdapterTests {
|
||||
@Test
|
||||
public void testExecuteWithExitStatus() throws Exception {
|
||||
tasklet.setTargetMethod("execute");
|
||||
assertEquals(ExitStatus.NOOP, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.NOOP, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapResultWithNull() throws Exception {
|
||||
tasklet.setTargetMethod("process");
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapResultWithNonNull() throws Exception {
|
||||
tasklet.setTargetMethod("process");
|
||||
this.result = "foo";
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@ import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandException;
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandStepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandTasklet;
|
||||
import org.springframework.batch.core.step.tasklet.SystemProcessExitCodeMapper;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests for {@link SystemCommandStepHandler}.
|
||||
* Tests for {@link SystemCommandTasklet}.
|
||||
*/
|
||||
public class SystemCommandStepHandlerIntegrationTests {
|
||||
public class SystemCommandTaskletIntegrationTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SystemCommandStepHandlerIntegrationTests.class);
|
||||
private static final Log log = LogFactory.getLog(SystemCommandTaskletIntegrationTests.class);
|
||||
|
||||
private SystemCommandStepHandler tasklet = new SystemCommandStepHandler();
|
||||
private SystemCommandTasklet tasklet = new SystemCommandTasklet();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("systemCommandStep", new JobExecution(new JobInstance(
|
||||
1L, new JobParameters(), "systemCommandJob")));
|
||||
@@ -56,7 +56,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
tasklet.afterPropertiesSet();
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
ExitStatus exitStatus = tasklet.handle(null,null);
|
||||
ExitStatus exitStatus = tasklet.execute(null,null);
|
||||
|
||||
assertEquals(ExitStatus.FINISHED, exitStatus);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
tasklet.afterPropertiesSet();
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
ExitStatus exitStatus = tasklet.handle(null,null);
|
||||
ExitStatus exitStatus = tasklet.execute(null,null);
|
||||
|
||||
assertEquals(ExitStatus.FAILED, exitStatus);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
try {
|
||||
tasklet.handle(null,null);
|
||||
tasklet.execute(null,null);
|
||||
fail();
|
||||
}
|
||||
catch (SystemCommandException e) {
|
||||
@@ -108,7 +108,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
|
||||
stepExecution.setTerminateOnly();
|
||||
try {
|
||||
tasklet.handle(null,null);
|
||||
tasklet.execute(null,null);
|
||||
fail();
|
||||
}
|
||||
catch (JobInterruptedException e) {
|
||||
@@ -47,7 +47,7 @@ import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.SimpleJobRepository;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.batch.core.step.StepInterruptionPolicy;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
@@ -64,7 +64,7 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
|
||||
public class StepHandlerStepTests {
|
||||
public class TasketStepTests {
|
||||
|
||||
List<String> processed = new ArrayList<String>();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class StepHandlerStepTests {
|
||||
}
|
||||
};
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private Job job;
|
||||
|
||||
@@ -94,12 +94,12 @@ public class StepHandlerStepTests {
|
||||
return new ListItemReader<String>(Arrays.asList(args));
|
||||
}
|
||||
|
||||
private StepHandlerStep getStep(String[] strings) throws Exception {
|
||||
StepHandlerStep step = new StepHandlerStep("stepName");
|
||||
private TaskletStep getStep(String[] strings) throws Exception {
|
||||
TaskletStep step = new TaskletStep("stepName");
|
||||
// Only process one item:
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
|
||||
step.setStepHandler(new SimpleStepHandler<String>(getReader(strings), itemWriter, template));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(getReader(strings), itemWriter, template));
|
||||
step.setJobRepository(new JobRepositorySupport());
|
||||
step.setTransactionManager(transactionManager);
|
||||
return step;
|
||||
@@ -210,7 +210,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -235,7 +235,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -260,7 +260,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.registerStepExecutionListener(new StepExecutionListenerSupport() {
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return ExitStatus.FAILED.addExitDescription("FOO");
|
||||
@@ -287,7 +287,7 @@ public class StepHandlerStepTests {
|
||||
@Test
|
||||
public void testNonRestartedJob() throws Exception {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setStepHandler(new SimpleStepHandler<String>(tasklet, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
step.registerStream(tasklet);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -348,7 +348,7 @@ public class StepHandlerStepTests {
|
||||
@Test
|
||||
public void testNoSaveExecutionAttributesRestartableJob() {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setStepHandler(new SimpleStepHandler<String>(tasklet, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -369,7 +369,7 @@ public class StepHandlerStepTests {
|
||||
*/
|
||||
@Test
|
||||
public void testRestartJobOnNonRestartableTasklet() throws Exception {
|
||||
step.setStepHandler(new SimpleStepHandler<String>(new ItemReader<String>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(new ItemReader<String>() {
|
||||
public String read() throws Exception {
|
||||
return "foo";
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public class StepHandlerStepTests {
|
||||
executionContext.putString("foo", "bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
@@ -491,7 +491,7 @@ public class StepHandlerStepTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
step.setStepHandler(new SimpleStepHandler<String>(new MockRestartableItemReader() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(new MockRestartableItemReader() {
|
||||
public String read() throws Exception {
|
||||
throw new RuntimeException("FOO");
|
||||
}
|
||||
@@ -519,7 +519,7 @@ public class StepHandlerStepTests {
|
||||
executionContext.putString("foo", "bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.setStreams(new ItemStream[] { reader });
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
@@ -554,7 +554,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -582,7 +582,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -610,7 +610,7 @@ public class StepHandlerStepTests {
|
||||
throw new Error("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -638,7 +638,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.setTransactionManager(new ResourcelessTransactionManager() {
|
||||
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
|
||||
// Simulate failure on rollback when stream resets
|
||||
@@ -735,7 +735,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.registerStream(itemReader);
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
@@ -773,7 +773,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("CRASH!");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
Reference in New Issue
Block a user