BATCH-&*&: work in progress (some tests disabled)

This commit is contained in:
dsyer
2008-08-19 13:49:38 +00:00
parent cfc9529bab
commit 75fca027cb
39 changed files with 276 additions and 362 deletions

View File

@@ -28,8 +28,8 @@ import org.springframework.batch.support.transaction.TransactionAwareProxyFactor
import org.springframework.beans.factory.InitializingBean;
/**
* Mock {@link ItemWriter} that will throw an exception when a certain
* number of items have been written.
* Mock {@link ItemWriter} that will throw an exception when a certain number of
* items have been written.
*/
public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
@@ -43,7 +43,8 @@ public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
List<Object> list;
public void afterPropertiesSet() throws Exception {
TransactionAwareProxyFactory<List<Object>> factory = new TransactionAwareProxyFactory<List<Object>>(new ArrayList<Object>());
TransactionAwareProxyFactory<List<Object>> factory = new TransactionAwareProxyFactory<List<Object>>(
new ArrayList<Object>());
list = factory.createInstance();
}
@@ -51,13 +52,15 @@ public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
this.failurePoint = failurePoint;
}
public void write(T data) {
if (!failed && list.size() == failurePoint) {
failed = true;
throw new RuntimeException("Failed processing: [" + data + "]");
public void write(List<? extends T> items) {
for (T data : items) {
if (!failed && list.size() == failurePoint) {
failed = true;
throw new RuntimeException("Failed processing: [" + data + "]");
}
logger.info("Processing: [" + data + "]");
list.add(data);
}
logger.info("Processing: [" + data + "]");
list.add(data);
}
public List<Object> getList() {
@@ -65,11 +68,11 @@ public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
}
public void clear() throws ClearFailedException {
//no-op
// no-op
}
public void flush() throws FlushFailedException {
//no-op
// no-op
}
}

View File

@@ -17,6 +17,8 @@ package org.springframework.batch.core.step.item;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
@@ -91,8 +93,10 @@ public class ItemOrientedStepHandlerTests {
private final class StubItemWriter extends AbstractItemWriter<String> {
private String values = "";
public void write(String item) throws Exception {
values += item;
public void write(List<? extends String> items) throws Exception {
for (String item : items) {
values += item;
}
}
}

View File

@@ -64,8 +64,8 @@ public class SimpleStepFactoryBeanTests extends TestCase {
private List<String> written = new ArrayList<String>();
private ItemWriter<String> writer = new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
written.add(data);
public void write(List<? extends String> data) throws Exception {
written.addAll(data);
}
};
@@ -166,7 +166,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
SimpleStepFactoryBean<String,String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setItemWriter(new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
public void write(List<? extends String> data) throws Exception {
throw new RuntimeException("Error!");
}
});
@@ -199,7 +199,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
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 {
public void write(List<? extends String> data) throws Exception {
throw new RuntimeException("Foo");
}
});
@@ -225,7 +225,7 @@ public class SimpleStepFactoryBeanTests extends TestCase {
factory.setItemWriter(new AbstractItemWriter<String>() {
int count = 0;
public void write(String data) throws Exception {
public void write(List<? extends String> data) throws Exception {
if (count++ == 0) {
throw new RuntimeException("Foo");
}

View File

@@ -42,7 +42,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
protected final Log logger = LogFactory.getLog(getClass());
private SkipLimitStepFactoryBean<String,String> factory = new SkipLimitStepFactoryBean<String,String>();
private SkipLimitStepFactoryBean<String, String> factory = new SkipLimitStepFactoryBean<String, String>();
private Class<?>[] skippableExceptions = new Class[] { SkippableException.class, SkippableRuntimeException.class };
@@ -132,7 +132,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
public void testFatalException() throws Exception {
factory.setFatalExceptionClasses(new Class[] { FatalRuntimeException.class });
factory.setItemWriter(new SkipWriterStub() {
public void write(String item) {
public void write(List<? extends String> items) {
throw new FatalRuntimeException("Ouch!");
}
});
@@ -255,7 +255,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
assertEquals(1, stepExecution.getSkipCount());
assertEquals(1, stepExecution.getReadSkipCount());
assertEquals(0, stepExecution.getWriteSkipCount());
}
/**
@@ -292,7 +292,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
assertEquals(1, stepExecution.getSkipCount());
assertEquals(0, stepExecution.getReadSkipCount());
assertEquals(1, stepExecution.getWriteSkipCount());
}
/**
@@ -470,12 +470,14 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
flushIndex = written.size() - 1;
}
public void write(String item) throws Exception {
if (failures.contains(item)) {
logger.debug("Throwing write exception on [" + item + "]");
throw new SkippableRuntimeException("exception in writer");
public void write(List<? extends String> items) throws Exception {
for (String item : items) {
if (failures.contains(item)) {
logger.debug("Throwing write exception on [" + item + "]");
throw new SkippableRuntimeException("exception in writer");
}
written.add(item);
}
written.add(item);
}
}

View File

@@ -73,8 +73,8 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
JobExecution jobExecution;
private ItemWriter<Object> processor = new AbstractItemWriter<Object>() {
public void write(Object data) throws Exception {
processed.add(data);
public void write(List<? extends Object> data) throws Exception {
processed.addAll(data);
}
};
@@ -199,9 +199,9 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
};
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
public void write(List<? extends Object> item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
if ("b".equals(item) || "d".equals(item)) {
if (item.contains("b") || item.contains("d")) {
throw new RuntimeException("Read error - planned but skippable.");
}
}
@@ -237,7 +237,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
}
};
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
public void write(List<? extends Object> item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");
}
@@ -274,7 +274,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
}
};
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
public void write(List<? extends Object> item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");
}
@@ -312,7 +312,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
}
};
ItemWriter<Object> itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
public void write(List<? extends Object> item) throws Exception {
logger.debug("Write Called! Item: [" + item + "]");
throw new RuntimeException("Write error - planned but retryable.");
}

View File

@@ -16,6 +16,8 @@
package org.springframework.batch.core.step.item;
import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.BatchStatus;
@@ -63,7 +65,7 @@ public class StepExecutorInterruptionTests extends TestCase {
step.setJobRepository(jobRepository);
step.setTransactionManager(new ResourcelessTransactionManager());
itemWriter = new AbstractItemWriter<Object>() {
public void write(Object item) throws Exception {
public void write(List<? extends Object> item) throws Exception {
}
};
step.setItemHandler(new SimpleStepHandler<Object>(new AbstractItemReader<Object>() {

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.List;
import javax.sql.DataSource;
@@ -112,7 +113,7 @@ public class StepHandlerStepIntegrationTests {
step.setItemHandler(new SimpleStepHandler<String>(getReader(new String[] { "a", "b", "c" }),
new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
public void write(List<? extends String> data) throws Exception {
TransactionSynchronizationManager
.registerSynchronization(new TransactionSynchronizationAdapter() {
public void beforeCommit(boolean readOnly) {

View File

@@ -71,8 +71,8 @@ public class StepHandlerStepTests extends TestCase {
private List<Serializable> list = new ArrayList<Serializable>();
ItemWriter<String> itemWriter = new AbstractItemWriter<String>() {
public void write(String data) throws Exception {
processed.add(data);
public void write(List<? extends String> data) throws Exception {
processed.addAll(data);
}
};