BATCH-325:Added close() to readers and writers.

This commit is contained in:
lucasward
2008-01-29 17:12:14 +00:00
parent f9619e345e
commit 16c59d915f
16 changed files with 135 additions and 13 deletions

View File

@@ -70,6 +70,9 @@ public class HibernateAwareItemWriterTests extends TestCase {
public void open(RepeatContext context) {
list.add(context);
}
public void close() throws Exception {
}
}
HibernateAwareItemWriter writer = new HibernateAwareItemWriter();

View File

@@ -88,6 +88,35 @@ public class CompositeItemWriterTests extends TestCase {
}
public void testClose() throws Exception {
final int NUMBER_OF_PROCESSORS = 10;
Object data = new Object();
List controls = new ArrayList(NUMBER_OF_PROCESSORS);
List processors = new ArrayList(NUMBER_OF_PROCESSORS);
for (int i = 0; i < NUMBER_OF_PROCESSORS; i++) {
MockControl control = MockControl.createStrictControl(ItemWriter.class);
ItemWriter processor = (ItemWriter) control.getMock();
processor.close();
control.setVoidCallable();
control.replay();
processors.add(processor);
controls.add(control);
}
itemProcessor.setItemWriters(processors);
itemProcessor.close();
for (Iterator iterator = controls.iterator(); iterator.hasNext();) {
MockControl control = (MockControl) iterator.next();
control.verify();
}
}
/**
* Stub for testing restart. Checks the restart data received is the same that was returned by
* <code>getRestartData()</code>
@@ -125,6 +154,10 @@ public class CompositeItemWriterTests extends TestCase {
setProperty(STATS_KEY, String.valueOf(hashCode));
}};
}
public void close() throws Exception {
}
}

View File

@@ -24,6 +24,7 @@ import junit.framework.TestCase;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.reader.ListItemReader;
import org.springframework.batch.item.writer.AbstractItemWriter;
public class ItemReaderRepeatCallbackTests extends TestCase {
@@ -33,7 +34,7 @@ public class ItemReaderRepeatCallbackTests extends TestCase {
public void testDoWithRepeat() throws Exception {
callback = new ItemReaderRepeatCallback(new ListItemReader(Arrays.asList(new String[] { "foo", "bar" })),
new ItemWriter() {
new AbstractItemWriter() {
public void write(Object data) {
list.add(data);
}

View File

@@ -23,6 +23,7 @@ import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.reader.DelegatingItemReader;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -69,7 +70,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
}
}
protected static class TradeWriter implements ItemWriter {
protected static class TradeWriter extends AbstractItemWriter {
int count = 0;
// This has to be synchronized because we are going to test the state

View File

@@ -24,6 +24,7 @@ import junit.framework.TestCase;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.reader.ListItemReader;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.retry.ListItemReaderRecoverer;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.context.RetryContextSupport;
@@ -57,7 +58,7 @@ public class ItemReaderRetryCallbackTests extends TestCase {
return "key" + (count++);
}
};
callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
if (data.equals("bar")) {

View File

@@ -27,6 +27,7 @@ import org.springframework.batch.item.FailedItemIdentifier;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.reader.ListItemReader;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
@@ -61,7 +62,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
}
public void testOpenSunnyDay() throws Exception {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -92,7 +93,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testCanRetry() {
policy.setDelegate(new AlwaysRetryPolicy());
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
}
@@ -105,7 +106,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testRegisterThrowable() {
policy.setDelegate(new NeverRetryPolicy());
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -118,7 +119,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testClose() throws Exception {
policy.setDelegate(new NeverRetryPolicy());
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -137,7 +138,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
}
public void testOpenTwice() throws Exception {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -168,7 +169,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testRecover() throws Exception {
policy = new ItemReaderRetryPolicy();
policy.setDelegate(new SimpleRetryPolicy(1));
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
}
});
@@ -207,7 +208,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testRecoverWithTemplate() throws Exception {
policy = new ItemReaderRetryPolicy();
policy.setDelegate(new SimpleRetryPolicy(1));
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
throw new RuntimeException("Barf!");
}
@@ -230,7 +231,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
}
public void testExhaustedClearsHistoryAfterLastAttempt() throws Exception {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -258,7 +259,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
public void testRetryCount() throws Exception {
policy = new ItemReaderRetryPolicy();
policy.setDelegate(new SimpleRetryPolicy(1));
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);
@@ -273,7 +274,7 @@ public class ItemReaderRetryPolicyTests extends TestCase {
}
public void testRetryCountPreservedBetweenRetries() throws Exception {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(Object data) {
count++;
list.add(data);