Reorganized the execution.step package to contain all Step implementations
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.batch.execution.configuration;
|
||||
|
||||
import org.springframework.batch.execution.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.execution.step.TaskletStep;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
import org.springframework.batch.core.domain.ItemSkipPolicy;
|
||||
@@ -22,6 +22,8 @@ import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepSupport;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.execution.step.simple.DefaultItemFailureHandler;
|
||||
import org.springframework.batch.execution.step.simple.NeverSkipItemSkipPolicy;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
@@ -40,6 +40,12 @@ import org.springframework.batch.execution.scope.SimpleStepContext;
|
||||
import org.springframework.batch.execution.scope.StepContext;
|
||||
import org.springframework.batch.execution.scope.StepScope;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.execution.step.simple.DefaultItemFailureHandler;
|
||||
import org.springframework.batch.execution.step.simple.ItemChunker;
|
||||
import org.springframework.batch.execution.step.simple.ItemDechunker;
|
||||
import org.springframework.batch.execution.step.simple.SimpleExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.execution.step.simple.StepInterruptionPolicy;
|
||||
import org.springframework.batch.execution.step.simple.ThreadStepInterruptionPolicy;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.io.exception.WriteFailureException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -357,14 +363,29 @@ public class ChunkedStep extends StepSupport implements InitializingBean {
|
||||
// Before starting a new transaction, check for
|
||||
// interruption.
|
||||
interruptionPolicy.checkInterrupted(context);
|
||||
|
||||
final StepContribution contribution = stepExecution
|
||||
.createStepContribution();
|
||||
|
||||
ChunkingResult chunkingResult = chunker.chunk(chunkSize,
|
||||
contribution);
|
||||
|
||||
if (chunkingResult == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
final Chunk chunk = chunkingResult.getChunk();
|
||||
for(Iterator it = chunkingResult.getExceptions().iterator();it.hasNext();){
|
||||
failureLog.handleReadFailure((Exception)it.next());
|
||||
}
|
||||
|
||||
ExitStatus result = (ExitStatus) retryTemplate
|
||||
.execute(new RetryCallback() {
|
||||
|
||||
public Object doWithRetry(RetryContext context)
|
||||
throws Throwable {
|
||||
return processChunk(stepExecution,
|
||||
stepContext);
|
||||
return processChunk(contribution, stepExecution,
|
||||
stepContext, chunk);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -435,29 +456,14 @@ public class ChunkedStep extends StepSupport implements InitializingBean {
|
||||
* the current step context.
|
||||
* @return true if there is more data to process.
|
||||
*/
|
||||
ExitStatus processChunk(final StepExecution stepExecution,
|
||||
StepContext stepContext) {
|
||||
ExitStatus processChunk(final StepContribution contribution,StepExecution stepExecution,
|
||||
StepContext stepContext, final Chunk chunk) {
|
||||
|
||||
TransactionStatus transaction = streamManager
|
||||
.getTransaction(stepExecution);
|
||||
|
||||
final StepContribution contribution = stepExecution
|
||||
.createStepContribution();
|
||||
|
||||
try {
|
||||
|
||||
ChunkingResult chunkingResult = chunker.chunk(chunkSize,
|
||||
contribution);
|
||||
|
||||
if (chunkingResult == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
final Chunk chunk = chunkingResult.getChunk();
|
||||
for(Iterator it = chunkingResult.getExceptions().iterator();it.hasNext();){
|
||||
failureLog.handleReadFailure((Exception)it.next());
|
||||
}
|
||||
|
||||
DechunkingResult dechunkingResult = dechunker.dechunk(chunk,
|
||||
contribution);
|
||||
for(Iterator it = dechunkingResult.getExceptions().iterator(); it.hasNext();){
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -31,6 +31,9 @@ import org.springframework.batch.execution.scope.SimpleStepContext;
|
||||
import org.springframework.batch.execution.scope.StepContext;
|
||||
import org.springframework.batch.execution.scope.StepScope;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.execution.step.simple.SimpleExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.execution.step.simple.StepInterruptionPolicy;
|
||||
import org.springframework.batch.execution.step.simple.ThreadStepInterruptionPolicy;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -110,14 +113,14 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link RepeatOperations} to use for the inner loop of the batch
|
||||
* processing. Should be set up by the caller through a factory. Defaults to
|
||||
* a plain {@link RepeatTemplate}.
|
||||
* the {@link repeatoperations} to use for the inner loop of the batch
|
||||
* processing. should be set up by the caller through a factory. defaults to
|
||||
* a plain {@link repeattemplate}.
|
||||
*
|
||||
* @param chunkOperations a {@link RepeatOperations} instance.
|
||||
* @param chunkoperations a {@link repeatoperations} instance.
|
||||
*/
|
||||
public void setChunkOperations(RepeatOperations chunkOperations) {
|
||||
this.chunkOperations = chunkOperations;
|
||||
public void setChunkOperations(RepeatOperations chunkoperations) {
|
||||
this.chunkOperations = chunkoperations;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,14 +199,6 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
|
||||
*/
|
||||
void applyConfiguration(AbstractStep step) {
|
||||
|
||||
if (step instanceof SimpleStep) {
|
||||
SimpleStep simple = (SimpleStep) step;
|
||||
if (this.chunkOperations instanceof RepeatTemplate) {
|
||||
RepeatTemplate template = (RepeatTemplate) this.chunkOperations;
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(simple.getCommitInterval()));
|
||||
}
|
||||
}
|
||||
|
||||
ExceptionHandler exceptionHandler = step.getExceptionHandler();
|
||||
|
||||
if (step.getSkipLimit() > 0 && exceptionHandler == null) {
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.tasklet;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.batch.core.domain.Chunker;
|
||||
import org.springframework.batch.core.domain.ChunkingResult;
|
||||
import org.springframework.batch.core.domain.ItemSkipPolicy;
|
||||
import org.springframework.batch.core.domain.StepContribution;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.io.exception.ReadFailureException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.execution.step.ItemOrientedStep;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
|
||||
/**
|
||||
* {@link Step} implementation that allows full step of the
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
|
||||
/**
|
||||
* Simple {@link Step} good enough for most purposes and easy to configure simple properties, principally the commit
|
||||
* interval.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
* @author Ben Hale
|
||||
*/
|
||||
public class SimpleStep extends AbstractStep {
|
||||
|
||||
// default commit interval is one
|
||||
private int commitInterval = 1;
|
||||
|
||||
public SimpleStep() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SimpleStep(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setCommitInterval(int commitInterval) {
|
||||
this.commitInterval = commitInterval;
|
||||
}
|
||||
|
||||
public int getCommitInterval() {
|
||||
return commitInterval;
|
||||
}
|
||||
|
||||
public void execute(StepExecution stepExecution)
|
||||
throws JobInterruptedException, BatchCriticalException {
|
||||
throw new UnsupportedOperationException(
|
||||
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.execution.configuration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.execution.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.execution.step.TaskletStep;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -53,5 +53,13 @@ public class StubDataSource implements DataSource {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class arg0) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object unwrap(Class arg0) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import org.springframework.batch.execution.repository.dao.JobInstanceDao;
|
||||
import org.springframework.batch.execution.repository.dao.MapJobDao;
|
||||
import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.repository.dao.StepExecutionDao;
|
||||
import org.springframework.batch.execution.step.simple.SimpleStep;
|
||||
import org.springframework.batch.execution.step.AbstractStep;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -265,7 +265,7 @@ public class SimpleJobTests extends TestCase {
|
||||
checkRepository(status, null);
|
||||
}
|
||||
|
||||
private class StubStep extends SimpleStep {
|
||||
private class StubStep extends AbstractStep {
|
||||
|
||||
private Runnable runnable;
|
||||
private Exception exception;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.execution.job.simple.SimpleJob;
|
||||
import org.springframework.batch.execution.repository.SimpleJobRepository;
|
||||
import org.springframework.batch.execution.repository.dao.MapJobDao;
|
||||
import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.step.simple.AbstractStep;
|
||||
import org.springframework.batch.execution.step.AbstractStep;
|
||||
import org.springframework.batch.execution.step.simple.RepeatOperationsStep;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -31,6 +31,9 @@ import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.execution.scope.StepScope;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.execution.step.simple.ItemChunker;
|
||||
import org.springframework.batch.execution.step.simple.ItemDechunker;
|
||||
import org.springframework.batch.execution.step.simple.JobRepositorySupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -37,6 +37,10 @@ import org.springframework.batch.execution.repository.dao.MapJobDao;
|
||||
import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.scope.StepScope;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.execution.step.ItemOrientedStep;
|
||||
import org.springframework.batch.execution.step.simple.JobRepositorySupport;
|
||||
import org.springframework.batch.execution.step.simple.StepInterruptionPolicy;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -357,7 +361,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testApplyConfigurationWithExceptionHandler() throws Exception {
|
||||
AbstractStep stepConfiguration = new SimpleStep("foo");
|
||||
AbstractStep stepConfiguration = new StubStep("foo");
|
||||
final List list = new ArrayList();
|
||||
itemOrientedStep.setStepOperations(new RepeatTemplate() {
|
||||
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
|
||||
@@ -370,7 +374,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testApplyConfigurationWithZeroSkipLimit() throws Exception {
|
||||
AbstractStep stepConfiguration = new SimpleStep("foo");
|
||||
AbstractStep stepConfiguration = new StubStep("foo");
|
||||
stepConfiguration.setSkipLimit(0);
|
||||
final List list = new ArrayList();
|
||||
itemOrientedStep.setStepOperations(new RepeatTemplate() {
|
||||
@@ -383,7 +387,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testApplyConfigurationWithNonZeroSkipLimit() throws Exception {
|
||||
AbstractStep stepConfiguration = new SimpleStep("foo");
|
||||
AbstractStep stepConfiguration = new StubStep("foo");
|
||||
stepConfiguration.setSkipLimit(1);
|
||||
final List list = new ArrayList();
|
||||
itemOrientedStep.setStepOperations(new RepeatTemplate() {
|
||||
@@ -554,5 +558,17 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
assertEquals("Foo", ex.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private class StubStep extends AbstractStep{
|
||||
|
||||
public StubStep(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void execute(StepExecution stepExecution)
|
||||
throws JobInterruptedException, BatchCriticalException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.execution.step.tasklet;
|
||||
package org.springframework.batch.execution.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -11,6 +11,7 @@ import org.springframework.batch.core.domain.JobInterruptedException;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.step.TaskletStep;
|
||||
import org.springframework.batch.execution.step.simple.JobRepositorySupport;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -20,11 +20,11 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.ItemFailureHandler;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.execution.step.ItemOrientedStep;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.ItemReaderAdapter;
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
import org.springframework.batch.repeat.exception.handler.DefaultExceptionHandler;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStepConfigurationTests extends TestCase {
|
||||
|
||||
SimpleStep configuration = new SimpleStep("foo");
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.SimpleStep#SimpleStepConfiguration()}.
|
||||
*/
|
||||
public void testSimpleStepConfiguration() {
|
||||
assertNotNull(configuration.getName());
|
||||
configuration = new SimpleStep();
|
||||
assertNull(configuration.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.execution.step.simple.SimpleStep#SimpleStepConfiguration(org.springframework.batch.core.tasklet.Tasklet)}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testSimpleStepConfigurationTasklet() throws Exception {
|
||||
configuration = new SimpleStep();
|
||||
configuration.setItemReader(new AbstractItemReader() {
|
||||
|
||||
public Object read() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
});
|
||||
configuration.setItemWriter(new AbstractItemWriter() {
|
||||
|
||||
public void write(Object item) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
configuration.setJobRepository(new JobRepositorySupport());
|
||||
configuration.setTransactionManager(new ResourcelessTransactionManager());
|
||||
configuration.afterPropertiesSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.SimpleStep#getCommitInterval()}.
|
||||
*/
|
||||
public void testGetCommitInterval() {
|
||||
assertEquals(1, configuration.getCommitInterval());
|
||||
configuration.setCommitInterval(20);
|
||||
assertEquals(20, configuration.getCommitInterval());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getExceptionHandler()}.
|
||||
*/
|
||||
public void testGetExceptionHandler() {
|
||||
assertNull(configuration.getExceptionHandler());
|
||||
configuration.setExceptionHandler(new DefaultExceptionHandler());
|
||||
assertNotNull(configuration.getExceptionHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getExceptionHandler()}.
|
||||
*/
|
||||
public void testSkipLimit() {
|
||||
assertEquals(0, configuration.getSkipLimit());
|
||||
configuration.setSkipLimit(2);
|
||||
assertEquals(2, configuration.getSkipLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#getSkipLimit()}.
|
||||
*/
|
||||
public void testGetSkipLimit() {
|
||||
assertEquals(0, configuration.getSkipLimit());
|
||||
configuration.setSkipLimit(20);
|
||||
assertEquals(20, configuration.getSkipLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.step.simple.AbstractStep#isSaveExecutionContext()}.
|
||||
*/
|
||||
public void testIsSaveExecutionContext() {
|
||||
assertEquals(false, configuration.isSaveExecutionContext());
|
||||
configuration.setSaveExecutionContext(true);
|
||||
assertEquals(true, configuration.isSaveExecutionContext());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.simple;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.stream.SimpleStreamManager;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
|
||||
/**
|
||||
* Most of the tests have been commented out, since SimpleStep
|
||||
* will likely be removed soon.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStepTests extends TestCase {
|
||||
|
||||
// public void testSuccessfulStepExecutor() throws Exception {
|
||||
// SimpleStep step = new SimpleStep();
|
||||
// step.setJobRepository(new JobRepositorySupport());
|
||||
// step.setTransactionManager(new ResourcelessTransactionManager());
|
||||
// step.setItemReader(new ItemReaderAdapter());
|
||||
// step.setItemWriter(new ItemWriterAdapter());
|
||||
// assertNotNull(step.createStepExecutor());
|
||||
// }
|
||||
//
|
||||
// public void testSuccessfulExceptionHandler() throws Exception {
|
||||
// SimpleStep step = new SimpleStep("foo");
|
||||
// step.setItemReader(new ItemReaderAdapter());
|
||||
// step.setItemWriter(new ItemWriterAdapter());
|
||||
// step.setJobRepository(new JobRepositorySupport());
|
||||
// step.setTransactionManager(new ResourcelessTransactionManager());
|
||||
// final List list = new ArrayList();
|
||||
// step.setExceptionHandler(new ExceptionHandler() {
|
||||
// public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException {
|
||||
// list.add(throwable);
|
||||
// throw new RuntimeException("Oops");
|
||||
// }
|
||||
// });
|
||||
// ItemOrientedStep executor = (ItemOrientedStep) step.createStepExecutor();
|
||||
// StepExecution stepExecution = new StepExecution("stepName", new JobExecution(
|
||||
// new JobInstance(new Long(0L), new JobParameters()), new Long(12)));
|
||||
// try {
|
||||
// executor.execute(stepExecution);
|
||||
// fail("Expected RuntimeException");
|
||||
// }
|
||||
// catch (NullPointerException e) {
|
||||
// throw e;
|
||||
// }
|
||||
// catch (RuntimeException e) {
|
||||
// assertEquals("Oops", e.getMessage());
|
||||
// }
|
||||
// assertEquals(1, list.size());
|
||||
// }
|
||||
|
||||
// public void testUnsuccessfulNoJobRepository() throws Exception {
|
||||
// try {
|
||||
// new SimpleStep().createStepExecutor();
|
||||
// fail("Expected IllegalArgumentException");
|
||||
// }
|
||||
// catch (IllegalArgumentException e) {
|
||||
// // expected
|
||||
// assertTrue("Error message does not contain JobRepository: " + e.getMessage(), e.getMessage().indexOf(
|
||||
// "JobRepository") >= 0);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void testMandatoryProperties() throws Exception {
|
||||
try {
|
||||
new SimpleStep().afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testMandatoryPropertiesNoTransactionManagerOrStreamManager() throws Exception {
|
||||
try {
|
||||
SimpleStep configuration = new SimpleStep("foo");
|
||||
configuration.setJobRepository(new JobRepositorySupport());
|
||||
configuration.assertMandatoryProperties();
|
||||
fail("Experetscted IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testMandatoryPropertiesTransactionManagerAndStreamManager() throws Exception {
|
||||
try {
|
||||
SimpleStep configuration = new SimpleStep("foo");
|
||||
configuration.setJobRepository(new JobRepositorySupport());
|
||||
configuration.setTransactionManager(new ResourcelessTransactionManager());
|
||||
configuration.setStreamManager(new SimpleStreamManager());
|
||||
configuration.assertMandatoryProperties();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
// public void testMandatoryPropertiesAfterExecution() throws Exception {
|
||||
// SimpleStep step = new SimpleStep();
|
||||
// step.setItemReader(new ItemReaderAdapter());
|
||||
// step.setItemWriter(new ItemWriterAdapter());
|
||||
// step.setJobRepository(new JobRepositorySupport());
|
||||
// step.setTransactionManager(new ResourcelessTransactionManager());
|
||||
// assertNotNull(step.createStepExecutor());
|
||||
// // If we do that again, we don't expect a different result (e.g.
|
||||
// // mandatory properties test failing).
|
||||
// assertNotNull(step.createStepExecutor());
|
||||
// }
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
class="org.springframework.batch.core.domain.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStep">
|
||||
class="org.springframework.batch.execution.step.ItemOrientedStep">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class="org.springframework.batch.core.domain.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStep">
|
||||
class="org.springframework.batch.execution.step.ItemOrientedStep">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<bean id="test-job"
|
||||
class="org.springframework.batch.core.domain.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.simple.SimpleStep">
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.ItemOrientedStep">
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="simpleStep"
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStep"
|
||||
class="org.springframework.batch.execution.step.ItemOrientedStep"
|
||||
abstract="true">
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
<property name="saveExecutionContext" value="false" />
|
||||
|
||||
Reference in New Issue
Block a user