RESOLVED - issue BATCH-541: pull commit interval from the job parameters
Added StepExecutionSimpleCompletionPolicy (a la StepExecution*) as s one-off solution to the commit interval problem initially posed
This commit is contained in:
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.support;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ClassPathXmlApplicationContextJobFactoryTests extends TestCase {
|
||||
|
||||
private ClassPathXmlApplicationContextJobFactory factory = new ClassPathXmlApplicationContextJobFactory("test-job", ClassUtils.addResourcePathToPackagePath(getClass(), "test-context.xml"), null);
|
||||
private ClassPathXmlApplicationContextJobFactory factory = new ClassPathXmlApplicationContextJobFactory("test-job", ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"), null);
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJobFactory#createJob()}.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.core.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StepExecutionSimpleCompletionPolicy}
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class StepExecutionSimpleCompletionPolicyTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Object under test
|
||||
*/
|
||||
private StepExecutionSimpleCompletionPolicy policy = new StepExecutionSimpleCompletionPolicy();
|
||||
|
||||
private JobInstance jobInstance;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
/**
|
||||
* mock step context
|
||||
*/
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("commit.interval", new Long(2L)).toJobParameters();
|
||||
jobInstance = new JobInstance(new Long(0), jobParameters, "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
Step step = new StepSupport("bar");
|
||||
stepExecution = jobExecution.createStepExecution(step);
|
||||
policy.beforeStep(stepExecution);
|
||||
|
||||
}
|
||||
|
||||
public void testToString() throws Exception {
|
||||
String msg = policy.toString();
|
||||
assertTrue("String does not contain chunk size", msg.indexOf("chunkSize=2")>=0);
|
||||
}
|
||||
|
||||
public void testKeyName() throws Exception, IOException {
|
||||
RepeatContext context = policy.start(null);
|
||||
assertFalse(policy.isComplete(context));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.ExceptionHandler;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
|
||||
@@ -241,24 +242,34 @@ public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
// nothing wrong here
|
||||
factory.getObject();
|
||||
|
||||
// but exception excpected after setting commit interval to value <= 0
|
||||
factory.setCommitInterval(0);
|
||||
try {
|
||||
factory.getObject();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
// but exception expected after setting commit interval to value < 0
|
||||
factory.setCommitInterval(-1);
|
||||
try {
|
||||
factory.getObject();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit interval specified is not allowed to be zero or negative.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCommitIntervalAndCompletionPolicyBothSet() throws Exception {
|
||||
SimpleStepFactoryBean factory = getStepFactory("foo");
|
||||
|
||||
// but exception expected after setting commit interval and completion policy
|
||||
factory.setCommitInterval(1);
|
||||
factory.setChunkCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
try {
|
||||
factory.getObject();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user