OPEN - issue BATCH-770: Make ItemTransformer a first class citizen and rename as ItemProcessor
Done first pass. Some tests needed.
This commit is contained in:
@@ -19,6 +19,7 @@ import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -42,7 +43,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNameAware {
|
||||
public abstract class AbstractStepFactoryBean<T,S> implements FactoryBean, BeanNameAware {
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -52,7 +53,7 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
|
||||
private ItemReader<? extends T> itemReader;
|
||||
|
||||
private ItemWriter<? super T> itemWriter;
|
||||
private ItemWriter<? super S> itemWriter;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@@ -68,6 +69,11 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
|
||||
private StepListener[] listeners = new StepListener[0];
|
||||
|
||||
private ItemProcessor<? super T, ? extends S> itemProcessor = new ItemProcessor<T, S>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public S process(T item) throws Exception {return (S)item;}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -121,10 +127,17 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
/**
|
||||
* @param itemWriter the itemWriter to set
|
||||
*/
|
||||
public void setItemWriter(ItemWriter<? super T> itemWriter) {
|
||||
public void setItemWriter(ItemWriter<? super S> itemWriter) {
|
||||
this.itemWriter = itemWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemProcessor the itemProcessor to set
|
||||
*/
|
||||
public void setItemProcessor(ItemProcessor<? super T, ? extends S> itemProcessor) {
|
||||
this.itemProcessor = itemProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* The streams to inject into the {@link Step}. Any instance of
|
||||
* {@link ItemStream} can be used, and will then receive callbacks at the
|
||||
@@ -167,10 +180,18 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
* Protected getter for the {@link ItemWriter} for subclasses to use
|
||||
* @return the itemWriter
|
||||
*/
|
||||
protected ItemWriter<? super T> getItemWriter() {
|
||||
protected ItemWriter<? super S> getItemWriter() {
|
||||
return itemWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected getter for the {@link ItemProcessor} for subclasses to use
|
||||
* @return the itemProcessor
|
||||
*/
|
||||
protected ItemProcessor<? super T, ? extends S> getItemProcessor() {
|
||||
return itemProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for {@link JobRepository}.
|
||||
*
|
||||
@@ -198,7 +219,8 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected getter for the {@link TransactionAttribute} for subclasses only.
|
||||
* Protected getter for the {@link TransactionAttribute} for subclasses
|
||||
* only.
|
||||
* @return the transactionAttribute
|
||||
*/
|
||||
protected TransactionAttribute getTransactionAttribute() {
|
||||
@@ -227,7 +249,6 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
Assert.notNull(transactionManager, "TransactionManager must be provided");
|
||||
jobRepositoryValidator.validate(jobRepository);
|
||||
|
||||
step.setItemHandler(new SimpleItemHandler<T>(itemReader, itemWriter));
|
||||
step.setTransactionManager(transactionManager);
|
||||
if (transactionAttribute!=null) {
|
||||
step.setTransactionAttribute(transactionAttribute);
|
||||
@@ -239,7 +260,8 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
step.setStreams(streams);
|
||||
|
||||
ItemReader<? extends T> itemReader = getItemReader();
|
||||
ItemWriter<? super T> itemWriter = getItemWriter();
|
||||
ItemWriter<? super S> itemWriter = getItemWriter();
|
||||
ItemProcessor<? super T, ? extends S> itemProcessor = getItemProcessor();
|
||||
|
||||
// Since we are going to wrap these things with listener callbacks we
|
||||
// need to register them here because the step will not know we did
|
||||
@@ -250,6 +272,12 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
if (itemReader instanceof StepExecutionListener) {
|
||||
step.registerStepExecutionListener((StepExecutionListener) itemReader);
|
||||
}
|
||||
if (itemProcessor instanceof ItemStream) {
|
||||
step.registerStream((ItemStream) itemProcessor);
|
||||
}
|
||||
if (itemProcessor instanceof StepExecutionListener) {
|
||||
step.registerStepExecutionListener((StepExecutionListener) itemProcessor);
|
||||
}
|
||||
if (itemWriter instanceof ItemStream) {
|
||||
step.registerStream((ItemStream) itemWriter);
|
||||
}
|
||||
@@ -266,8 +294,7 @@ public abstract class AbstractStepFactoryBean<T> implements FactoryBean, BeanNam
|
||||
setItemWriter(itemWriter);
|
||||
|
||||
step.setStepExecutionListeners(stepListeners);
|
||||
//TODO: Why is setItemHandler called twice?
|
||||
step.setItemHandler(new SimpleItemHandler<T>(itemReader, itemWriter));
|
||||
step.setItemHandler(new ItemOrientedStepHandler<T,S>(itemReader, itemProcessor, itemWriter));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.MarkFailedException;
|
||||
import org.springframework.batch.item.ResetFailedException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
* Simplest possible implementation of {@link ItemHandler} with no skipping or
|
||||
* recovering. Just delegates all calls to the provided {@link ItemReader} and
|
||||
* {@link ItemWriter}.
|
||||
*
|
||||
* Provides extension points by protected {@link #read(StepContribution)} and
|
||||
* {@link #write(Object, StepContribution)} methods that can be overriden to
|
||||
* provide more sophisticated behavior (e.g. skipping).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemOrientedStepHandler<T, S> implements ItemHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private ItemReader<? extends T> itemReader;
|
||||
|
||||
private ItemProcessor<? super T, ? extends S> itemProcessor;
|
||||
|
||||
private ItemWriter<? super S> itemWriter;
|
||||
|
||||
/**
|
||||
* @param itemReader
|
||||
* @param itemProcessor
|
||||
* @param itemWriter
|
||||
*/
|
||||
public ItemOrientedStepHandler(ItemReader<? extends T> itemReader, ItemProcessor<? super T, ? extends S> itemProcessor,
|
||||
ItemWriter<? super S> itemWriter) {
|
||||
super();
|
||||
this.itemReader = itemReader;
|
||||
this.itemProcessor = itemProcessor;
|
||||
this.itemWriter = itemWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next item from {@link #read(StepContribution)} and if not null
|
||||
* pass the item to {@link #write(Object, StepContribution)}.
|
||||
*
|
||||
* @see org.springframework.batch.core.step.item.ItemHandler#handle(org.springframework.batch.core.StepContribution)
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution) throws Exception {
|
||||
T item = read(contribution);
|
||||
if (item == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
contribution.incrementItemCount();
|
||||
write(item, contribution);
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contribution current context
|
||||
* @return next item for writing
|
||||
*/
|
||||
protected T read(StepContribution contribution) throws Exception {
|
||||
return doRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final T doRead() throws Exception {
|
||||
return itemReader.read();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param item the item to write
|
||||
* @param contribution current context
|
||||
*/
|
||||
protected void write(T item, StepContribution contribution) throws Exception {
|
||||
doWrite(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final void doWrite(T item) throws Exception {
|
||||
S processed = itemProcessor.process(item);
|
||||
if (processed != null) {
|
||||
// TODO: increment filtered item count
|
||||
itemWriter.write(processed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MarkFailedException
|
||||
* @see org.springframework.batch.item.ItemReader#mark()
|
||||
*/
|
||||
public void mark() throws MarkFailedException {
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResetFailedException
|
||||
* @see org.springframework.batch.item.ItemReader#reset()
|
||||
*/
|
||||
public void reset() throws ResetFailedException {
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClearFailedException
|
||||
* @see org.springframework.batch.item.ItemWriter#clear()
|
||||
*/
|
||||
public void clear() throws ClearFailedException {
|
||||
itemWriter.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FlushFailedException
|
||||
* @see org.springframework.batch.item.ItemWriter#flush()
|
||||
*/
|
||||
public void flush() throws FlushFailedException {
|
||||
itemWriter.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class RepeatOperationsStepFactoryBean<T> extends AbstractStepFactoryBean<T> {
|
||||
public class RepeatOperationsStepFactoryBean<T,S> extends AbstractStepFactoryBean<T,S> {
|
||||
|
||||
private RepeatOperations chunkOperations = new RepeatTemplate();
|
||||
|
||||
|
||||
@@ -15,126 +15,25 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.MarkFailedException;
|
||||
import org.springframework.batch.item.ResetFailedException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.item.support.PassthroughItemProcessor;
|
||||
|
||||
/**
|
||||
* Simplest possible implementation of {@link ItemHandler} with no skipping or
|
||||
* recovering. Just delegates all calls to the provided {@link ItemReader} and
|
||||
* {@link ItemWriter}.
|
||||
*
|
||||
* Provides extension points by protected {@link #read(StepContribution)} and
|
||||
* {@link #write(Object, StepContribution)} methods that can be overriden to
|
||||
* provide more sophisticated behavior (e.g. skipping).
|
||||
* recovering or processing. Just delegates all calls to the provided
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SimpleItemHandler<T> implements ItemHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private ItemReader<? extends T> itemReader;
|
||||
|
||||
private ItemWriter<? super T> itemWriter;
|
||||
public class SimpleItemHandler<T> extends ItemOrientedStepHandler<T, T> {
|
||||
|
||||
/**
|
||||
* @param itemReader
|
||||
* @param itemWriter
|
||||
* Creates a {@link PassthroughItemProcessor} and uses it to create an
|
||||
* instance of {@link ItemOrientedStepHandler}.
|
||||
*/
|
||||
public SimpleItemHandler(ItemReader<? extends T> itemReader, ItemWriter<? super T> itemWriter) {
|
||||
super();
|
||||
this.itemReader = itemReader;
|
||||
this.itemWriter = itemWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next item from {@link #read(StepContribution)} and if not null
|
||||
* pass the item to {@link #write(Object, StepContribution)}.
|
||||
*
|
||||
* @see org.springframework.batch.core.step.item.ItemHandler#handle(org.springframework.batch.core.StepContribution)
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution) throws Exception {
|
||||
T item = read(contribution);
|
||||
if (item == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
contribution.incrementItemCount();
|
||||
write(item, contribution);
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contribution current context
|
||||
* @return next item for writing
|
||||
*/
|
||||
protected T read(StepContribution contribution) throws Exception {
|
||||
return doRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final T doRead() throws Exception {
|
||||
return itemReader.read();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param item the item to write
|
||||
* @param contribution current context
|
||||
*/
|
||||
protected void write(T item, StepContribution contribution) throws Exception {
|
||||
doWrite(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final void doWrite(T item) throws Exception {
|
||||
itemWriter.write(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MarkFailedException
|
||||
* @see org.springframework.batch.item.ItemReader#mark()
|
||||
*/
|
||||
public void mark() throws MarkFailedException {
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResetFailedException
|
||||
* @see org.springframework.batch.item.ItemReader#reset()
|
||||
*/
|
||||
public void reset() throws ResetFailedException {
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClearFailedException
|
||||
* @see org.springframework.batch.item.ItemWriter#clear()
|
||||
*/
|
||||
public void clear() throws ClearFailedException {
|
||||
itemWriter.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FlushFailedException
|
||||
* @see org.springframework.batch.item.ItemWriter#flush()
|
||||
*/
|
||||
public void flush() throws FlushFailedException {
|
||||
itemWriter.flush();
|
||||
public SimpleItemHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
super(itemReader, new PassthroughItemProcessor<T>(), itemWriter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStepFactoryBean<T> extends AbstractStepFactoryBean<T> {
|
||||
public class SimpleStepFactoryBean<T,S> extends AbstractStepFactoryBean<T,S> {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
|
||||
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
|
||||
import org.springframework.batch.item.ItemKeyGenerator;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.retry.RecoveryCallback;
|
||||
@@ -51,7 +52,7 @@ import org.springframework.batch.support.SubclassExceptionClassifier;
|
||||
* @author Robert Kasanicky
|
||||
*
|
||||
*/
|
||||
public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
public class SkipLimitStepFactoryBean<T,S> extends SimpleStepFactoryBean<T,S> {
|
||||
|
||||
private int skipLimit = 0;
|
||||
|
||||
@@ -267,7 +268,7 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
}
|
||||
}
|
||||
});
|
||||
StatefulRetryItemHandler<T> itemHandler = new StatefulRetryItemHandler<T>(getItemReader(), getItemWriter(),
|
||||
StatefulRetryItemHandler<T,S> itemHandler = new StatefulRetryItemHandler<T,S>(getItemReader(), getItemProcessor(), getItemWriter(),
|
||||
retryTemplate, itemKeyGenerator, readSkipPolicy, writeSkipPolicy);
|
||||
itemHandler.setSkipListeners(BatchListenerFactoryHelper.getSkipListeners(getListeners()));
|
||||
|
||||
@@ -276,7 +277,7 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
}
|
||||
else {
|
||||
// This is the default in ItemOrientedStep anyway...
|
||||
step.setItemHandler(new SimpleItemHandler<T>(getItemReader(), getItemWriter()));
|
||||
step.setItemHandler(new ItemOrientedStepHandler<T,S>(getItemReader(), getItemProcessor(), getItemWriter()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -305,7 +306,7 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private static class StatefulRetryItemHandler<T> extends SimpleItemHandler<T> {
|
||||
private static class StatefulRetryItemHandler<T,S> extends ItemOrientedStepHandler<T,S> {
|
||||
|
||||
final private RetryOperations retryOperations;
|
||||
|
||||
@@ -323,10 +324,10 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
* @param retryTemplate
|
||||
* @param itemKeyGenerator
|
||||
*/
|
||||
public StatefulRetryItemHandler(ItemReader<? extends T> itemReader, ItemWriter<? super T> itemWriter,
|
||||
public StatefulRetryItemHandler(ItemReader<? extends T> itemReader, ItemProcessor<? super T, ? extends S> itemProcessor, ItemWriter<? super S> itemWriter,
|
||||
RetryOperations retryTemplate, ItemKeyGenerator itemKeyGenerator, ItemSkipPolicy readSkipPolicy,
|
||||
ItemSkipPolicy writeSkipPolicy) {
|
||||
super(itemReader, itemWriter);
|
||||
super(itemReader, itemProcessor, itemWriter);
|
||||
this.retryOperations = retryTemplate;
|
||||
this.itemKeyGenerator = itemKeyGenerator;
|
||||
this.readSkipPolicy = readSkipPolicy;
|
||||
|
||||
@@ -15,12 +15,18 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -38,15 +44,12 @@ import org.springframework.batch.item.support.AbstractItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -107,15 +110,17 @@ public class ItemOrientedStepIntegrationTests {
|
||||
@Test
|
||||
public void testStatusForCommitFailedException() throws Exception {
|
||||
|
||||
step.setItemHandler(new SimpleItemHandler<String>(getReader(new String[] { "a", "b", "c" }), new AbstractItemWriter<String>() {
|
||||
public void write(String data) throws Exception {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
public void beforeCommit(boolean readOnly) {
|
||||
throw new RuntimeException("Simulate commit failure");
|
||||
step.setItemHandler(new SimpleItemHandler<String>(getReader(new String[] { "a", "b", "c" }),
|
||||
new AbstractItemWriter<String>() {
|
||||
public void write(String data) throws Exception {
|
||||
TransactionSynchronizationManager
|
||||
.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
public void beforeCommit(boolean readOnly) {
|
||||
throw new RuntimeException("Simulate commit failure");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job, new JobParameters());
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
|
||||
*/
|
||||
public class RepeatOperationsStepFactoryBeanTests extends TestCase {
|
||||
|
||||
private RepeatOperationsStepFactoryBean<String> factory = new RepeatOperationsStepFactoryBean<String>();
|
||||
private RepeatOperationsStepFactoryBean<String,String> factory = new RepeatOperationsStepFactoryBean<String,String>();
|
||||
|
||||
private List<String> list;
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ChunkListener;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.job.AbstractJob;
|
||||
import org.springframework.batch.core.job.SimpleJob;
|
||||
import org.springframework.batch.core.listener.ItemListenerSupport;
|
||||
@@ -85,16 +85,16 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
MapStepExecutionDao.clear();
|
||||
}
|
||||
|
||||
private SimpleStepFactoryBean<String> getStepFactory(String arg) throws Exception {
|
||||
private SimpleStepFactoryBean<String,String> getStepFactory(String arg) throws Exception {
|
||||
return getStepFactory(new String[] { arg });
|
||||
}
|
||||
|
||||
private SimpleStepFactoryBean<String> getStepFactory(String arg0, String arg1) throws Exception {
|
||||
private SimpleStepFactoryBean<String,String> getStepFactory(String arg0, String arg1) throws Exception {
|
||||
return getStepFactory(new String[] { arg0, arg1 });
|
||||
}
|
||||
|
||||
private SimpleStepFactoryBean<String> getStepFactory(String[] args) throws Exception {
|
||||
SimpleStepFactoryBean<String> factory = new SimpleStepFactoryBean<String>();
|
||||
private SimpleStepFactoryBean<String,String> getStepFactory(String[] args) throws Exception {
|
||||
SimpleStepFactoryBean<String,String> factory = new SimpleStepFactoryBean<String,String>();
|
||||
|
||||
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
|
||||
items.addAll(Arrays.asList(args));
|
||||
@@ -129,7 +129,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
public void testSimpleConcurrentJob() throws Exception {
|
||||
|
||||
job.setSteps(new ArrayList<Step>());
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory("foo", "bar");
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory("foo", "bar");
|
||||
factory.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
factory.setThrottleLimit(1);
|
||||
|
||||
@@ -163,7 +163,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
* is recovered ("skipped") on the second attempt (see retry policy
|
||||
* definition above)...
|
||||
*/
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
|
||||
factory.setItemWriter(new AbstractItemWriter<String>() {
|
||||
public void write(String data) throws Exception {
|
||||
@@ -196,7 +196,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExceptionTerminates() throws Exception {
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
factory.setBeanName("exceptionStep");
|
||||
factory.setItemWriter(new AbstractItemWriter<String>() {
|
||||
public void write(String data) throws Exception {
|
||||
@@ -219,7 +219,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExceptionHandler() throws Exception {
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
|
||||
factory.setBeanName("exceptionStep");
|
||||
factory.setExceptionHandler(new SimpleLimitExceptionHandler(1));
|
||||
factory.setItemWriter(new AbstractItemWriter<String>() {
|
||||
@@ -245,7 +245,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
String[] items = new String[] { "1", "2", "3", "4", "5", "6", "7" };
|
||||
int commitInterval = 3;
|
||||
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory(items);
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory(items);
|
||||
class CountingChunkListener implements ChunkListener {
|
||||
int beforeCount = 0;
|
||||
|
||||
@@ -284,7 +284,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCommitIntervalMustBeGreaterThanZero() throws Exception {
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory("foo");
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory("foo");
|
||||
// nothing wrong here
|
||||
factory.getObject();
|
||||
|
||||
@@ -304,7 +304,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCommitIntervalAndCompletionPolicyBothSet() throws Exception {
|
||||
SimpleStepFactoryBean<String> factory = getStepFactory("foo");
|
||||
SimpleStepFactoryBean<String,String> factory = getStepFactory("foo");
|
||||
|
||||
// but exception expected after setting commit interval and completion
|
||||
// policy
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private SkipLimitStepFactoryBean<String> factory = new SkipLimitStepFactoryBean<String>();
|
||||
private SkipLimitStepFactoryBean<String,String> factory = new SkipLimitStepFactoryBean<String,String>();
|
||||
|
||||
private Class<?>[] skippableExceptions = new Class[] { SkippableException.class, SkippableRuntimeException.class };
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private SkipLimitStepFactoryBean<Object> factory = new SkipLimitStepFactoryBean<Object>();
|
||||
private SkipLimitStepFactoryBean<Object,Object> factory = new SkipLimitStepFactoryBean<Object,Object>();
|
||||
|
||||
private List<Object> recovered = new ArrayList<Object>();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ 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.item.ItemOrientedStep;
|
||||
import org.springframework.batch.core.step.item.SimpleItemHandler;
|
||||
import org.springframework.batch.item.support.AbstractItemReader;
|
||||
import org.springframework.batch.item.support.AbstractItemWriter;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
@@ -46,7 +44,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
private JobExecution jobExecution;
|
||||
|
||||
private AbstractItemWriter<Object> itemWriter;
|
||||
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user