BATCH-1743: loosen partition handler validation
This commit is contained in:
@@ -284,10 +284,7 @@ class StepParserStepFactoryBean<I, O> implements FactoryBean, BeanNameAware {
|
||||
Assert.state(partitioner != null, "A Partitioner must be provided for a partition step");
|
||||
configureAbstractStep(ts);
|
||||
|
||||
PartitionHandler handler;
|
||||
|
||||
if (partitionHandler != null) {
|
||||
handler = partitionHandler;
|
||||
ts.setPartitionHandler(partitionHandler);
|
||||
}
|
||||
else {
|
||||
@@ -299,29 +296,23 @@ class StepParserStepFactoryBean<I, O> implements FactoryBean, BeanNameAware {
|
||||
partitionHandler.setGridSize(gridSize);
|
||||
partitionHandler.setTaskExecutor(taskExecutor);
|
||||
ts.setPartitionHandler(partitionHandler);
|
||||
handler = partitionHandler;
|
||||
}
|
||||
|
||||
PartitionHandler targetHandler = (PartitionHandler) extractTarget(handler, PartitionHandler.class);
|
||||
// BATCH-1659
|
||||
if (targetHandler instanceof TaskExecutorPartitionHandler) {
|
||||
// Only for a local partition handler is the step required
|
||||
Assert.state(step != null,
|
||||
"A Step must be provided for a partition step with a TaskExecutorPartitionHandler");
|
||||
try {
|
||||
TaskExecutorPartitionHandler taskExecutorPartitionHandler = (TaskExecutorPartitionHandler) targetHandler;
|
||||
taskExecutorPartitionHandler.setStep(step);
|
||||
taskExecutorPartitionHandler.afterPropertiesSet();
|
||||
if (partitionHandler instanceof TaskExecutorPartitionHandler) {
|
||||
TaskExecutorPartitionHandler taskExecutorPartitionHandler = (TaskExecutorPartitionHandler) partitionHandler;
|
||||
if (taskExecutorPartitionHandler.getStep() == null) {
|
||||
// Only for a local partition handler is the step required
|
||||
Assert.state(step != null,
|
||||
"A Step must be provided for a partition step with a TaskExecutorPartitionHandler");
|
||||
try {
|
||||
taskExecutorPartitionHandler.setStep(step);
|
||||
taskExecutorPartitionHandler.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanCreationException("Could not configure TaskExecutorPartitionHandler", e);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanCreationException("Could not configure TaskExecutorPartitionHandler", e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Only for a local partition handler is the step required
|
||||
Assert.state(step == null,
|
||||
"A Step must not be provided for a custom partition handler (unless it extends TaskExecutorPartitionHandler). "
|
||||
+ "It should be configured with its own step reference.");
|
||||
}
|
||||
|
||||
boolean allowStartIfComplete = this.allowStartIfComplete != null ? this.allowStartIfComplete : false;
|
||||
@@ -671,7 +662,7 @@ class StepParserStepFactoryBean<I, O> implements FactoryBean, BeanNameAware {
|
||||
public void setPartitioner(Partitioner partitioner) {
|
||||
this.partitioner = partitioner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param stepExecutionAggregator the stepExecutionAggregator to set
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Josh Long
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class PartitionStepWithLateBindingParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("job1")
|
||||
private Job job1;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("nameStoringTasklet")
|
||||
private NameStoringTasklet nameStoringTasklet;
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean;
|
||||
|
||||
private List<String> savedStepNames = new ArrayList<String>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
nameStoringTasklet.setStepNamesList(savedStepNames);
|
||||
mapJobRepositoryFactoryBean.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitHandlerStep() throws Exception {
|
||||
assertNotNull(job1);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParametersBuilder()
|
||||
.addLong("gridSize", 1L).toJobParameters());
|
||||
job1.execute(jobExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
Collections.sort(savedStepNames);
|
||||
assertEquals("[s1:partition0]", savedStepNames.toString());
|
||||
List<String> stepNames = getStepNames(jobExecution);
|
||||
assertEquals(2, stepNames.size());
|
||||
assertEquals("[s1, s1:partition0]", stepNames.toString());
|
||||
}
|
||||
|
||||
private List<String> getStepNames(JobExecution jobExecution) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
list.add(stepExecution.getStepName());
|
||||
}
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -272,8 +272,9 @@ public class StepParserStepFactoryBeanTests {
|
||||
|
||||
SimplePartitioner partitioner = new SimplePartitioner();
|
||||
fb.setPartitioner(partitioner);
|
||||
fb.setStep(new StepSupport("foo"));
|
||||
ProxyFactory factory = new ProxyFactory(new TaskExecutorPartitionHandler());
|
||||
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
|
||||
partitionHandler.setStep(new StepSupport("foo"));
|
||||
ProxyFactory factory = new ProxyFactory(partitionHandler);
|
||||
fb.setPartitionHandler((PartitionHandler) factory.getProxy());
|
||||
|
||||
Object step = fb.getObject();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<beans:import resource="common-context.xml" />
|
||||
|
||||
<job id="job1">
|
||||
<step id="s1">
|
||||
<partition partitioner="partitioner" handler="handler"/>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
<bean id="handler" class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler" scope="step"
|
||||
xmlns="http://www.springframework.org/schema/beans">
|
||||
<property name="gridSize" value="#{jobParameters['gridSize']}" />
|
||||
<property name="step" ref="step1"/>
|
||||
</bean>
|
||||
|
||||
<beans:bean id="partitioner" class="org.springframework.batch.core.partition.support.SimplePartitioner" />
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user