infrastructure and core should have no more generics warnings (remaining are easymock deprecations)

This commit is contained in:
robokaso
2008-07-24 10:48:13 +00:00
parent a07daf3d3a
commit 66736f2ac2
23 changed files with 176 additions and 222 deletions

View File

@@ -354,8 +354,8 @@ public class SimpleJobTests extends TestCase {
public void testInterruptWithListener() throws Exception {
step1.setProcessException(new JobInterruptedException("job interrupted!"));
MockControl control = MockControl.createStrictControl(JobExecutionListener.class);
JobExecutionListener listener = (JobExecutionListener) control.getMock();
MockControl<JobExecutionListener> control = MockControl.createStrictControl(JobExecutionListener.class);
JobExecutionListener listener = control.getMock();
listener.beforeJob(jobExecution);
control.setVoidCallable();
listener.onInterrupt(jobExecution);

View File

@@ -31,7 +31,7 @@ import org.springframework.beans.factory.InitializingBean;
* Mock {@link ItemWriter} that will throw an exception when a certain
* number of items have been written.
*/
public class EmptyItemWriter implements ItemWriter, InitializingBean {
public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
private boolean failed = false;
@@ -52,7 +52,7 @@ public class EmptyItemWriter implements ItemWriter, InitializingBean {
this.failurePoint = failurePoint;
}
public void write(Object data) {
public void write(T data) {
if (!failed && list.size() == failurePoint) {
failed = true;
throw new RuntimeException("Failed processing: [" + data + "]");

View File

@@ -39,7 +39,7 @@ public class SimpleJobLauncherTests extends TestCase {
private SimpleJobLauncher jobLauncher;
private MockControl repositoryControl = MockControl.createControl(JobRepository.class);
private MockControl<JobRepository> repositoryControl = MockControl.createControl(JobRepository.class);
private Job job = new JobSupport("foo") {
public void execute(JobExecution execution) {
@@ -56,7 +56,7 @@ public class SimpleJobLauncherTests extends TestCase {
super.setUp();
jobLauncher = new SimpleJobLauncher();
jobRepository = (JobRepository) repositoryControl.getMock();
jobRepository = repositoryControl.getMock();
jobLauncher.setJobRepository(jobRepository);
}

View File

@@ -27,7 +27,7 @@ import junit.framework.TestCase;
*/
public class CompositeChunkListenerTests extends TestCase {
MockControl listenerControl = MockControl.createControl(ChunkListener.class);
MockControl<ChunkListener> listenerControl = MockControl.createControl(ChunkListener.class);
ChunkListener listener;
CompositeChunkListener compositeListener;
@@ -35,7 +35,7 @@ public class CompositeChunkListenerTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
listener = (ChunkListener)listenerControl.getMock();
listener = listenerControl.getMock();
compositeListener = new CompositeChunkListener();
compositeListener.register(listener);
}

View File

@@ -27,7 +27,7 @@ import org.springframework.batch.core.listener.CompositeItemReadListener;
*/
public class CompositeItemReadListenerTests extends TestCase {
MockControl listenerControl = MockControl.createControl(ItemReadListener.class);
MockControl<ItemReadListener> listenerControl = MockControl.createControl(ItemReadListener.class);
ItemReadListener listener;
CompositeItemReadListener compositeListener;
@@ -35,7 +35,7 @@ public class CompositeItemReadListenerTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
listener = (ItemReadListener)listenerControl.getMock();
listener = listenerControl.getMock();
compositeListener = new CompositeItemReadListener();
compositeListener.register(listener);
}

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.core.ItemWriteListener;
*/
public class CompositeItemWriteListenerTests extends TestCase {
MockControl listenerControl = MockControl.createControl(ItemWriteListener.class);
MockControl<ItemWriteListener> listenerControl = MockControl.createControl(ItemWriteListener.class);
ItemWriteListener listener;
CompositeItemWriteListener compositeListener;
@@ -34,7 +34,7 @@ public class CompositeItemWriteListenerTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
listener = (ItemWriteListener)listenerControl.getMock();
listener = listenerControl.getMock();
compositeListener = new CompositeItemWriteListener();
compositeListener.register(listener);
}

View File

@@ -17,12 +17,12 @@ import org.springframework.util.ClassUtils;
public class JdbcCursorItemReaderPreparedStatementIntegrationTests extends
AbstractTransactionalDataSourceSpringContextTests {
JdbcCursorItemReader itemReader;
JdbcCursorItemReader<Foo> itemReader;
protected void onSetUpInTransaction() throws Exception {
super.onSetUpInTransaction();
itemReader = new JdbcCursorItemReader();
itemReader = new JdbcCursorItemReader<Foo>();
itemReader.setDataSource(super.getJdbcTemplate().getDataSource());
itemReader.setSql("select ID, NAME, VALUE from T_FOOS where ID > ? and ID < ?");
itemReader.setIgnoreWarnings(true);
@@ -50,9 +50,9 @@ public class JdbcCursorItemReaderPreparedStatementIntegrationTests extends
public void testRead() throws Exception{
itemReader.open(new ExecutionContext());
Foo foo = (Foo)itemReader.read();
Foo foo = itemReader.read();
assertEquals(2, foo.getId());
foo = (Foo)itemReader.read();
foo = itemReader.read();
assertEquals(3, foo.getId());
assertNull(itemReader.read());
}

View File

@@ -79,8 +79,8 @@ public class ItemOrientedStepIntegrationTests extends AbstractDependencyInjectio
this.dataSource = dataSource;
}
private ItemReader getReader(String[] args) {
return new ListItemReader(Arrays.asList(args));
private ItemReader<String> getReader(String[] args) {
return new ListItemReader<String>(Arrays.asList(args));
}
protected void onSetUp() throws Exception {
@@ -124,8 +124,8 @@ public class ItemOrientedStepIntegrationTests extends AbstractDependencyInjectio
public void testStatusForCommitFailedException() throws Exception {
step.setItemHandler(new SimpleItemHandler(getReader(new String[] { "a", "b", "c" }), new AbstractItemWriter() {
public void write(Object data) throws Exception {
step.setItemHandler(new SimpleItemHandler<String>(getReader(new String[] { "a", "b", "c" }), new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
processed.add((String) data);
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
public void beforeCommit(boolean readOnly) {

View File

@@ -67,9 +67,9 @@ public class ItemOrientedStepTests extends TestCase {
private List<Serializable> list = new ArrayList<Serializable>();
ItemWriter itemWriter = new AbstractItemWriter() {
public void write(Object data) throws Exception {
processed.add((String) data);
ItemWriter<String> itemWriter = new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
processed.add(data);
}
};
@@ -80,20 +80,20 @@ public class ItemOrientedStepTests extends TestCase {
private JobInstance jobInstance;
private ResourcelessTransactionManager transactionManager;
private ExecutionContext foobarEc = new ExecutionContext() {
{
put("foo", "bar");
}
};
private ItemReader getReader(String[] args) {
return new ListItemReader(Arrays.asList(args));
private ItemReader<String> getReader(String[] args) {
return new ListItemReader<String>(Arrays.asList(args));
}
private AbstractStep getStep(String[] strings) throws Exception {
ItemOrientedStep step = new ItemOrientedStep("stepName");
step.setItemHandler(new SimpleItemHandler(getReader(strings), itemWriter));
step.setItemHandler(new SimpleItemHandler<String>(getReader(strings), itemWriter));
step.setJobRepository(new JobRepositorySupport());
step.setTransactionManager(transactionManager);
return step;
@@ -168,22 +168,15 @@ public class ItemOrientedStepTests extends TestCase {
public void testIncrementRollbackCount() {
ItemReader itemReader = new AbstractItemReader() {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public Object read() throws Exception {
int counter = 0;
counter++;
if (counter == 1) {
throw new RuntimeException();
}
return ExitStatus.CONTINUABLE;
public String read() throws Exception {
throw new RuntimeException();
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -198,22 +191,16 @@ public class ItemOrientedStepTests extends TestCase {
public void testExitCodeDefaultClassification() throws Exception {
ItemReader itemReader = new AbstractItemReader() {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public Object read() throws Exception {
int counter = 0;
counter++;
public String read() throws Exception {
throw new RuntimeException();
if (counter == 1) {
throw new RuntimeException();
}
return ExitStatus.CONTINUABLE;
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -228,22 +215,16 @@ public class ItemOrientedStepTests extends TestCase {
public void testExitCodeCustomClassification() throws Exception {
ItemReader itemReader = new AbstractItemReader() {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public Object read() throws Exception {
int counter = 0;
counter++;
public String read() throws Exception {
throw new RuntimeException();
if (counter == 1) {
throw new RuntimeException();
}
return ExitStatus.CONTINUABLE;
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
itemOrientedStep.registerStepExecutionListener(new StepExecutionListenerSupport() {
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
return ExitStatus.FAILED.addExitDescription("FOO");
@@ -269,7 +250,7 @@ public class ItemOrientedStepTests extends TestCase {
*/
public void testNonRestartedJob() throws Exception {
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemHandler(new SimpleItemHandler(tasklet, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(tasklet, itemWriter));
itemOrientedStep.registerStream(tasklet);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -327,7 +308,7 @@ public class ItemOrientedStepTests extends TestCase {
*/
public void testNoSaveExecutionAttributesRestartableJob() {
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemHandler(new SimpleItemHandler(tasklet, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(tasklet, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -347,8 +328,8 @@ public class ItemOrientedStepTests extends TestCase {
* Restartable.
*/
public void testRestartJobOnNonRestartableTasklet() throws Exception {
itemOrientedStep.setItemHandler(new SimpleItemHandler(new AbstractItemReader() {
public Object read() throws Exception {
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(new AbstractItemReader<String>() {
public String read() throws Exception {
return "foo";
}
}, itemWriter));
@@ -360,7 +341,7 @@ public class ItemOrientedStepTests extends TestCase {
public void testStreamManager() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
public Object read() throws Exception {
public String read() throws Exception {
return "foo";
}
@@ -368,7 +349,7 @@ public class ItemOrientedStepTests extends TestCase {
executionContext.putString("foo", "bar");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(reader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(reader, itemWriter));
itemOrientedStep.registerStream(reader);
JobExecution jobExecution = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecution);
@@ -463,8 +444,8 @@ public class ItemOrientedStepTests extends TestCase {
return null;
}
});
itemOrientedStep.setItemHandler(new SimpleItemHandler(new MockRestartableItemReader() {
public Object read() throws Exception {
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(new MockRestartableItemReader() {
public String read() throws Exception {
throw new RuntimeException("FOO");
}
}, itemWriter));
@@ -482,7 +463,7 @@ public class ItemOrientedStepTests extends TestCase {
public void testDirectlyInjectedStreamWhichIsAlsoReader() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
public Object read() throws Exception {
public String read() throws Exception {
return "foo";
}
@@ -490,7 +471,7 @@ public class ItemOrientedStepTests extends TestCase {
executionContext.putString("foo", "bar");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(reader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(reader, itemWriter));
itemOrientedStep.setStreams(new ItemStream[] { reader });
JobExecution jobExecution = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecution);
@@ -515,22 +496,16 @@ public class ItemOrientedStepTests extends TestCase {
itemOrientedStep.setInterruptionPolicy(interruptionPolicy);
ItemReader itemReader = new AbstractItemReader() {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public Object read() throws Exception {
int counter = 0;
counter++;
public String read() throws Exception {
throw new RuntimeException();
if (counter == 1) {
throw new RuntimeException();
}
return ExitStatus.CONTINUABLE;
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -551,13 +526,13 @@ public class ItemOrientedStepTests extends TestCase {
public void testStatusForNormalFailure() throws Exception {
ItemReader itemReader = new AbstractItemReader() {
public Object read() throws Exception {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public String read() throws Exception {
// Trigger a rollback
throw new RuntimeException("Foo");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -578,13 +553,13 @@ public class ItemOrientedStepTests extends TestCase {
public void testStatusForErrorFailure() throws Exception {
ItemReader itemReader = new AbstractItemReader() {
public Object read() throws Exception {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public String read() throws Exception {
// Trigger a rollback
throw new Error("Foo");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
@@ -605,13 +580,13 @@ public class ItemOrientedStepTests extends TestCase {
public void testStatusForResetFailedException() throws Exception {
ItemReader itemReader = new AbstractItemReader() {
public Object read() throws Exception {
ItemReader<String> itemReader = new AbstractItemReader<String>() {
public String read() throws Exception {
// Trigger a rollback
throw new RuntimeException("Foo");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
itemOrientedStep.setTransactionManager(new ResourcelessTransactionManager() {
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
// Simulate failure on rollback when stream resets
@@ -690,8 +665,7 @@ public class ItemOrientedStepTests extends TestCase {
String msg = stepExecution.getExitStatus().getExitDescription();
assertEquals("", msg);
msg = ex.getMessage();
assertTrue("Message does not contain 'closing step': " + msg, contains(msg,
"closing step"));
assertTrue("Message does not contain 'closing step': " + msg, contains(msg, "closing step"));
// The original rollback was caused by this one:
assertEquals("Bar", ex.getCause().getMessage());
}
@@ -706,7 +680,7 @@ public class ItemOrientedStepTests extends TestCase {
throw new RuntimeException("Bar");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(itemReader, itemWriter));
itemOrientedStep.registerStream(itemReader);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
@@ -738,12 +712,12 @@ public class ItemOrientedStepTests extends TestCase {
*/
public void testRestartAfterFailureInFirstChunk() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
public Object read() throws Exception {
public String read() throws Exception {
// fail on the very first item
throw new RuntimeException("CRASH!");
}
};
itemOrientedStep.setItemHandler(new SimpleItemHandler(reader, itemWriter));
itemOrientedStep.setItemHandler(new SimpleItemHandler<String>(reader, itemWriter));
itemOrientedStep.registerStream(reader);
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), new JobExecution(jobInstance));
@@ -805,7 +779,7 @@ public class ItemOrientedStepTests extends TestCase {
return str.indexOf(searchStr) != -1;
}
private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader, StepExecutionListener {
private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader<String>, StepExecutionListener {
private boolean getExecutionAttributesCalled = false;
@@ -813,7 +787,7 @@ public class ItemOrientedStepTests extends TestCase {
private boolean restoreFromCalledWithSomeContext = false;
public Object read() throws Exception {
public String read() throws Exception {
return "item";
}

View File

@@ -51,7 +51,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
private final SkipWriterStub writer = new SkipWriterStub();
private ItemSkipPolicyItemHandler handler = new ItemSkipPolicyItemHandler(new SkipReaderStub(), writer);
private ItemSkipPolicyItemHandler<Holder> handler = new ItemSkipPolicyItemHandler<Holder>(new SkipReaderStub(), writer);
private StepContribution contribution = new StepContribution(new JobExecution(new JobInstance(new Long(11),
new JobParameters(), "jobName")).createStepExecution(new StepSupport("foo")));
@@ -138,7 +138,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
assertEquals(2, contribution.getSkipCount());
assertEquals(1, TransactionSynchronizationManager.getResourceMap().size());
Set<Object> removed = (Set) TransactionSynchronizationManager.getResourceMap().values().iterator().next();
Set<Object> removed = (Set<Object>) TransactionSynchronizationManager.getResourceMap().values().iterator().next();
// one skipped item was detected on read
assertEquals(1, removed.size());
// mark() should remove the set of removed keys

View File

@@ -19,7 +19,7 @@ import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.MarkFailedException;
import org.springframework.batch.item.ResetFailedException;
public class MockItemReader implements ItemReader {
public class MockItemReader implements ItemReader<String> {
private final int returnItemCount;
@@ -42,7 +42,7 @@ public class MockItemReader implements ItemReader {
public void close() {
}
public Object read() {
public String read() {
if(fail) {
fail = false;
throw new RuntimeException();

View File

@@ -39,7 +39,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
*/
public class RepeatOperationsStepFactoryBeanTests extends TestCase {
private RepeatOperationsStepFactoryBean factory = new RepeatOperationsStepFactoryBean();
private RepeatOperationsStepFactoryBean<String> factory = new RepeatOperationsStepFactoryBean<String>();
private List<String> list;
@@ -47,8 +47,8 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase {
protected void setUp() throws Exception {
factory.setBeanName("RepeatOperationsStep");
factory.setItemReader(new ListItemReader(new ArrayList<String>()));
factory.setItemWriter(new EmptyItemWriter());
factory.setItemReader(new ListItemReader<String>(new ArrayList<String>()));
factory.setItemWriter(new EmptyItemWriter<String>());
factory.setJobRepository(new JobRepositorySupport());
factory.setTransactionManager(new ResourcelessTransactionManager());
}
@@ -63,8 +63,8 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase {
public void testStepOperationsWithoutChunkListener() throws Exception {
factory.setItemReader(new ListItemReader(new ArrayList<String>()));
factory.setItemWriter(new EmptyItemWriter());
factory.setItemReader(new ListItemReader<String>(new ArrayList<String>()));
factory.setItemWriter(new EmptyItemWriter<String>());
factory.setJobRepository(new JobRepositorySupport());
factory.setTransactionManager(new ResourcelessTransactionManager());

View File

@@ -62,13 +62,13 @@ public class SimpleStepFactoryBeanTests extends TestCase {
private List<String> written = new ArrayList<String>();
private ItemWriter writer = new AbstractItemWriter() {
public void write(Object data) throws Exception {
written.add((String) data);
private ItemWriter<String> writer = new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
written.add(data);
}
};
private ItemReader reader;
private ItemReader<String> reader;
private AbstractJob job = new SimpleJob() {
{
@@ -84,21 +84,20 @@ public class SimpleStepFactoryBeanTests extends TestCase {
MapStepExecutionDao.clear();
}
private SimpleStepFactoryBean getStepFactory(String arg) throws Exception {
private SimpleStepFactoryBean<String> getStepFactory(String arg) throws Exception {
return getStepFactory(new String[] { arg });
}
private SimpleStepFactoryBean getStepFactory(String arg0, String arg1) throws Exception {
private SimpleStepFactoryBean<String> getStepFactory(String arg0, String arg1) throws Exception {
return getStepFactory(new String[] { arg0, arg1 });
}
@SuppressWarnings("unchecked")
private SimpleStepFactoryBean getStepFactory(String[] args) throws Exception {
SimpleStepFactoryBean factory = new SimpleStepFactoryBean();
private SimpleStepFactoryBean<String> getStepFactory(String[] args) throws Exception {
SimpleStepFactoryBean<String> factory = new SimpleStepFactoryBean<String>();
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(args));
reader = new ListItemReader(items);
reader = new ListItemReader<String>(items);
factory.setItemReader(reader);
factory.setItemWriter(writer);
@@ -129,7 +128,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
public void testSimpleConcurrentJob() throws Exception {
job.setSteps(new ArrayList<Step>());
SimpleStepFactoryBean factory = getStepFactory("foo", "bar");
SimpleStepFactoryBean<String> factory = getStepFactory("foo", "bar");
factory.setTaskExecutor(new SimpleAsyncTaskExecutor());
factory.setThrottleLimit(1);
@@ -163,10 +162,10 @@ public class SimpleStepFactoryBeanTests extends TestCase {
* is recovered ("skipped") on the second attempt (see retry policy
* definition above)...
*/
SimpleStepFactoryBean factory = getStepFactory(new String[] { "foo", "bar", "spam" });
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setItemWriter(new AbstractItemWriter() {
public void write(Object data) throws Exception {
factory.setItemWriter(new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
throw new RuntimeException("Error!");
}
});
@@ -196,10 +195,10 @@ public class SimpleStepFactoryBeanTests extends TestCase {
}
public void testExceptionTerminates() throws Exception {
SimpleStepFactoryBean factory = getStepFactory(new String[] { "foo", "bar", "spam" });
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setBeanName("exceptionStep");
factory.setItemWriter(new AbstractItemWriter() {
public void write(Object data) throws Exception {
factory.setItemWriter(new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
throw new RuntimeException("Foo");
}
});
@@ -219,13 +218,13 @@ public class SimpleStepFactoryBeanTests extends TestCase {
}
public void testExceptionHandler() throws Exception {
SimpleStepFactoryBean factory = getStepFactory(new String[] { "foo", "bar", "spam" });
SimpleStepFactoryBean<String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setBeanName("exceptionStep");
factory.setExceptionHandler(new SimpleLimitExceptionHandler(1));
factory.setItemWriter(new AbstractItemWriter() {
factory.setItemWriter(new AbstractItemWriter<String>() {
int count = 0;
public void write(Object data) throws Exception {
public void write(String data) throws Exception {
if (count++ == 0) {
throw new RuntimeException("Foo");
}
@@ -245,7 +244,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
String[] items = new String[] { "1", "2", "3", "4", "5", "6", "7" };
int commitInterval = 3;
SimpleStepFactoryBean factory = getStepFactory(items);
SimpleStepFactoryBean<String> factory = getStepFactory(items);
class CountingChunkListener implements ChunkListener {
int beforeCount = 0;
@@ -284,7 +283,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
* @throws Exception
*/
public void testCommitIntervalMustBeGreaterThanZero() throws Exception {
SimpleStepFactoryBean factory = getStepFactory("foo");
SimpleStepFactoryBean<String> factory = getStepFactory("foo");
// nothing wrong here
factory.getObject();
@@ -304,7 +303,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
* @throws Exception
*/
public void testCommitIntervalAndCompletionPolicyBothSet() throws Exception {
SimpleStepFactoryBean factory = getStepFactory("foo");
SimpleStepFactoryBean<String> factory = getStepFactory("foo");
// but exception expected after setting commit interval and completion
// policy

View File

@@ -39,7 +39,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
protected final Log logger = LogFactory.getLog(getClass());
private SkipLimitStepFactoryBean factory = new SkipLimitStepFactoryBean();
private SkipLimitStepFactoryBean<String> factory = new SkipLimitStepFactoryBean<String>();
private Class<?>[] skippableExceptions = new Class[] { SkippableException.class, SkippableRuntimeException.class };
@@ -129,7 +129,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
public void testFatalException() throws Exception {
factory.setFatalExceptionClasses(new Class[] { FatalRuntimeException.class });
factory.setItemWriter(new SkipWriterStub() {
public void write(Object item) {
public void write(String item) {
throw new FatalRuntimeException("Ouch!");
}
});
@@ -305,7 +305,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
/**
* Simple item reader that supports skip functionality.
*/
private static class SkipReaderStub implements ItemReader {
private static class SkipReaderStub implements ItemReader<String> {
protected final Log logger = LogFactory.getLog(getClass());
@@ -328,7 +328,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
this.failures = failures;
}
public Object read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
public String read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
counter++;
if (counter >= items.length) {
logger.debug("Returning null at count=" + counter);
@@ -359,7 +359,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
/**
* Simple item writer that supports skip functionality.
*/
private static class SkipWriterStub implements ItemWriter {
private static class SkipWriterStub implements ItemWriter<String> {
protected final Log logger = LogFactory.getLog(getClass());
@@ -391,7 +391,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
flushIndex = written.size() - 1;
}
public void write(Object item) throws Exception {
public void write(String item) throws Exception {
if (failures.contains(item)) {
logger.debug("Throwing write exception on [" + item + "]");
throw new SkippableRuntimeException("exception in writer");

View File

@@ -58,11 +58,11 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
protected final Log logger = LogFactory.getLog(getClass());
private SkipLimitStepFactoryBean factory = new SkipLimitStepFactoryBean();
private SkipLimitStepFactoryBean<Object> factory = new SkipLimitStepFactoryBean<Object>();
private List<Object> recovered = new ArrayList<Object>();
private List<String> processed = new ArrayList<String>();
private List<Object> processed = new ArrayList<Object>();
int count = 0;
@@ -71,8 +71,8 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
JobExecution jobExecution;
private ItemWriter<String> processor = new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
private ItemWriter<Object> processor = new AbstractItemWriter<Object>() {
public void write(Object data) throws Exception {
processed.add(data);
}
};
@@ -89,7 +89,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
factory.setBeanName("step");
factory.setItemReader(new ListItemReader<String>(new ArrayList<String>()));
factory.setItemReader(new ListItemReader<Object>(new ArrayList<Object>()));
factory.setItemWriter(processor);
factory.setJobRepository(repository);
factory.setTransactionManager(new ResourcelessTransactionManager());
@@ -120,13 +120,12 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
public void testSuccessfulRetryWithReadFailure() throws Exception {
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
List<Object> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "a", "b", "c" }));
ItemReader<String> provider = new ListItemReader<String>(items) {
public String read() {
String item = super.read();
ItemReader<Object> provider = new ListItemReader<Object>(items) {
public Object read() {
Object item = super.read();
count++;
if (count == 2) {
throw new RuntimeException("Temporary error - retry for success.");
@@ -149,15 +148,14 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
assertEquals(3, stepExecution.getItemCount().intValue());
}
@SuppressWarnings("unchecked")
public void testSkipAndRetry() throws Exception {
factory.setSkippableExceptionClasses(new Class[] { Exception.class });
factory.setSkipLimit(2);
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
List<Object> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e", "f" }));
ItemReader<String> provider = new ListItemReader<String>(items) {
public String read() {
String item = super.read();
ItemReader<Object> provider = new ListItemReader<Object>(items) {
public Object read() {
Object item = super.read();
count++;
if ("b".equals(item) || "d".equals(item)) {
throw new RuntimeException("Read error - planned but skippable.");
@@ -178,7 +176,6 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
assertEquals(4, stepExecution.getItemCount().intValue());
}
@SuppressWarnings("unchecked")
public void testSkipAndRetryWithWriteFailure() throws Exception {
factory.setSkippableExceptionClasses(new Class[] { RetryException.class });
@@ -189,18 +186,18 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
}
} });
factory.setSkipLimit(2);
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
List<Object> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e", "f" }));
ItemReader<String> provider = new ListItemReader<String>(items) {
public String read() {
String item = super.read();
ItemReader<Object> provider = new ListItemReader<Object>(items) {
public Object read() {
Object item = super.read();
logger.debug("Read Called! Item: [" + item + "]");
count++;
return item;
}
};
ItemWriter itemWriter = new AbstractItemWriter() {
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
if ("b".equals(item) || "d".equals(item)) {
@@ -225,22 +222,21 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
assertEquals(17, count);
}
@SuppressWarnings("unchecked")
public void testRetryWithNoSkip() throws Exception {
factory.setRetryableExceptionClasses(new Class[] { Exception.class });
factory.setRetryLimit(4);
factory.setSkipLimit(0);
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
List<Object> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "b" }));
ItemReader<String> provider = new ListItemReader<String>(items) {
public String read() {
String item = super.read();
ItemReader<Object> provider = new ListItemReader<Object>(items) {
public Object read() {
Object item = super.read();
count++;
return item;
}
};
ItemWriter<String> itemWriter = new AbstractItemWriter<String>() {
public void write(String item) throws Exception {
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");
}
@@ -264,21 +260,20 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
assertEquals(0, stepExecution.getItemCount().intValue());
}
@SuppressWarnings("unchecked")
public void testRetryPolicy() throws Exception {
factory.setRetryPolicy(new SimpleRetryPolicy(4));
factory.setSkipLimit(0);
List<String> items = TransactionAwareProxyFactory.createTransactionalList();
List<Object> items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "b" }));
ItemReader<String> provider = new ListItemReader<String>(items) {
public String read() {
String item = super.read();
ItemReader<Object> provider = new ListItemReader<Object>(items) {
public Object read() {
Object item = super.read();
count++;
return item;
}
};
ItemWriter<String> itemWriter = new AbstractItemWriter<String>() {
public void write(String item) throws Exception {
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");
}
@@ -308,14 +303,14 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
// set the cache limit lower than the number of unique un-recovered
// errors expected
factory.setCacheCapacity(2);
ItemReader provider = new AbstractItemReader() {
ItemReader<Object> provider = new AbstractItemReader<Object>() {
public Object read() {
Object item = new Object();
count++;
return item;
}
};
ItemWriter itemWriter = new AbstractItemWriter() {
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");

View File

@@ -44,7 +44,7 @@ public class StepExecutorInterruptionTests extends TestCase {
private JobExecution jobExecution;
private AbstractItemWriter itemWriter;
private AbstractItemWriter<Object> itemWriter;
private StepExecution stepExecution;
@@ -63,11 +63,11 @@ public class StepExecutorInterruptionTests extends TestCase {
jobExecution = jobRepository.createJobExecution(jobConfiguration, new JobParameters());
step.setJobRepository(jobRepository);
step.setTransactionManager(new ResourcelessTransactionManager());
itemWriter = new AbstractItemWriter() {
itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
}
};
step.setItemHandler(new SimpleItemHandler(new AbstractItemReader() {
step.setItemHandler(new SimpleItemHandler<Object>(new AbstractItemReader<Object>() {
public Object read() throws Exception {
return null;
}
@@ -107,7 +107,7 @@ public class StepExecutorInterruptionTests extends TestCase {
Thread processingThread = createThread(stepExecution);
step.setItemHandler(new SimpleItemHandler(new AbstractItemReader() {
step.setItemHandler(new SimpleItemHandler<Object>(new AbstractItemReader<Object>() {
public Object read() throws Exception {
return null;
}
@@ -145,7 +145,7 @@ public class StepExecutorInterruptionTests extends TestCase {
* @return
*/
private Thread createThread(final StepExecution stepExecution) {
step.setItemHandler(new SimpleItemHandler(new AbstractItemReader() {
step.setItemHandler(new SimpleItemHandler<Object>(new AbstractItemReader<Object>() {
public Object read() throws Exception {
// do something non-trivial (and not Thread.sleep())
double foo = 1;