Added ExecutionContextUserSupport to the ItemStream Support class

Changed child classes to use this shared object
Changed some classes that previously extended ExecutionContextUserSupport
to rather use the same common parent class as everything else.
Changes all for issue BATCH-1966
This commit is contained in:
Dean de Bree
2013-02-27 08:52:36 +02:00
committed by Michael Minella
parent b1bd3d3d1e
commit d1b84f3e2f
21 changed files with 168 additions and 142 deletions

View File

@@ -43,16 +43,16 @@ public class TestReader extends AbstractTestComponent implements ItemStreamReade
}
@Override
public void close() throws ItemStreamException {
public void close() {
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
public void open(ExecutionContext executionContext) {
opened = true;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
public void update(ExecutionContext executionContext) {
}
}

View File

@@ -5,11 +5,13 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.support.AbstractItemStreamItemReader;
import org.springframework.util.ClassUtils;
/**
* {@link ItemStreamReader} with hard-coded input data.
*/
public class ExampleItemReader implements ItemStreamReader<String> {
public class ExampleItemReader extends AbstractItemStreamItemReader<String> {
private Log logger = LogFactory.getLog(getClass());
@@ -23,6 +25,10 @@ public class ExampleItemReader implements ItemStreamReader<String> {
public static volatile boolean fail = false;
public ExampleItemReader() {
this.setExecutionContextName(ClassUtils.getShortName(this.getClass()));
}
/**
* @param min the min to set
*/
@@ -61,18 +67,16 @@ public class ExampleItemReader implements ItemStreamReader<String> {
return input[index++];
}
@Override
public void close() throws ItemStreamException {
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
index = (int) executionContext.getLong("POSITION", min);
super.open(executionContext);
index = (int) executionContext.getLong(getExecutionContextKey("POSITION"), min);
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
executionContext.putLong("POSITION", index);
super.update(executionContext);
executionContext.putLong(getExecutionContextKey("POSITION"), index);
}
}

View File

@@ -54,7 +54,8 @@ public class ChunkMonitorTests {
});
monitor.registerItemStream(new ItemStreamSupport() {
@Override
public void close() throws ItemStreamException {
public void close() {
super.close();
closed = true;
}
});

View File

@@ -49,6 +49,7 @@ import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.item.WriteFailedException;
import org.springframework.batch.item.WriterNotOpenException;
import org.springframework.batch.item.support.AbstractItemStreamItemReader;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
@@ -830,23 +831,21 @@ public class FaultTolerantStepFactoryBeanTests {
public void testItemStreamOpenedEvenWithTaskExecutor() throws Exception {
writer.setFailures("4");
ItemStreamReader<String> reader = new ItemStreamReader<String>() {
ItemStreamReader<String> reader = new AbstractItemStreamItemReader<String>() {
@Override
public void close() throws ItemStreamException {
public void close() {
super.close();
closed = true;
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
public void open(ExecutionContext executionContext) {
super.open(executionContext);
opened = true;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
public String read() throws Exception, UnexpectedInputException, ParseException {
public String read() {
return null;
}
};
@@ -870,42 +869,29 @@ public class FaultTolerantStepFactoryBeanTests {
public void testNestedItemStreamOpened() throws Exception {
writer.setFailures("4");
ItemStreamReader<String> reader = new ItemStreamReader<String>() {
@Override
public void close() throws ItemStreamException {
}
ItemStreamReader<String> reader = new AbstractItemStreamItemReader<String>() {
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
public String read() throws Exception, UnexpectedInputException, ParseException {
public String read() {
return null;
}
};
ItemStreamReader<String> stream = new ItemStreamReader<String>() {
ItemStreamReader<String> stream = new AbstractItemStreamItemReader<String>() {
@Override
public void close() throws ItemStreamException {
public void close() {
super.close();
closed = true;
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
public void open(ExecutionContext executionContext) {
super.open(executionContext);
opened = true;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
public String read() throws Exception, UnexpectedInputException, ParseException {
public String read() {
return null;
}
};
@@ -930,23 +916,21 @@ public class FaultTolerantStepFactoryBeanTests {
public void testProxiedItemStreamOpened() throws Exception {
writer.setFailures("4");
ItemStreamReader<String> reader = new ItemStreamReader<String>() {
ItemStreamReader<String> reader = new AbstractItemStreamItemReader<String>() {
@Override
public void close() throws ItemStreamException {
public void close() {
super.close();
closed = true;
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
public void open(ExecutionContext executionContext) {
super.open(executionContext);
opened = true;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
}
@Override
public String read() throws Exception, UnexpectedInputException, ParseException {
public String read() {
return null;
}
};

View File

@@ -184,6 +184,7 @@ public class TaskletStepExceptionTests {
taskletStep.setStreams(new ItemStream[] { new ItemStreamSupport() {
@Override
public void close() throws ItemStreamException {
super.close();
throw exception;
}
} });

View File

@@ -103,6 +103,7 @@ public class AsyncTaskletStepTests {
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
executionContext.putInt("counter", count++);
}
});

View File

@@ -429,12 +429,13 @@ public class TaskletStepTests {
public void testStreamManager() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
@Override
public String read() throws Exception {
public String read() {
return "foo";
}
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
executionContext.putString("foo", "bar");
}
};
@@ -457,6 +458,7 @@ public class TaskletStepTests {
step.setStreams(new ItemStream[] { new ItemStreamSupport() {
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
executionContext.putString("foo", "bar");
}
} });
@@ -500,6 +502,7 @@ public class TaskletStepTests {
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
assertEquals(1, list.size());
}
};
@@ -547,7 +550,7 @@ public class TaskletStepTests {
});
step.setTasklet(new TestingChunkOrientedTasklet<String>(new MockRestartableItemReader() {
@Override
public String read() throws Exception {
public String read() throws RuntimeException {
throw new RuntimeException("FOO");
}
}, itemWriter));
@@ -562,12 +565,13 @@ public class TaskletStepTests {
public void testDirectlyInjectedStreamWhichIsAlsoReader() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
@Override
public String read() throws Exception {
public String read() {
return "foo";
}
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
executionContext.putString("foo", "bar");
}
};
@@ -740,6 +744,7 @@ public class TaskletStepTests {
step.setStreams(new ItemStream[] { new ItemStreamSupport() {
@Override
public void close() throws ItemStreamException {
super.close();
throw new RuntimeException("Bar");
}
} });
@@ -797,7 +802,7 @@ public class TaskletStepTests {
public void testRestartAfterFailureInFirstChunk() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
@Override
public String read() throws Exception {
public String read() throws RuntimeException {
// fail on the very first item
throw new RuntimeException("CRASH!");
}
@@ -927,12 +932,13 @@ public class TaskletStepTests {
private boolean restoreFromCalled = false;
@Override
public String read() throws Exception {
public String read() {
return "item";
}
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
getExecutionAttributesCalled = true;
executionContext.putString("spam", "bucket");
}