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:
@@ -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