Added code to default item count to 10 when not provided in JSR DSL
This commit is contained in:
@@ -74,13 +74,25 @@ public class ChunkParser {
|
||||
String checkpointPolicy = element.getAttribute(CHECKPOINT_POLICY_ATTRIBUTE);
|
||||
if(StringUtils.hasText(checkpointPolicy)) {
|
||||
if(checkpointPolicy.equals(ITEM_CHECKPOINT_POLICY)) {
|
||||
parseSimpleAttribute(element, propertyValues, ITEM_COUNT_ATTRIBUTE, "commitInterval");
|
||||
String itemCount = element.getAttribute(ITEM_COUNT_ATTRIBUTE);
|
||||
if (StringUtils.hasText(itemCount)) {
|
||||
propertyValues.addPropertyValue("commitInterval", itemCount);
|
||||
} else {
|
||||
propertyValues.addPropertyValue("commitInterval", "10");
|
||||
}
|
||||
|
||||
parseSimpleAttribute(element, propertyValues, TIME_LIMIT_ATTRIBUTE, "timeout");
|
||||
} else if(checkpointPolicy.equals(CUSTOM_CHECKPOINT_POLICY)) {
|
||||
parseCustomCheckpointAlgorithm(element, parserContext, propertyValues);
|
||||
}
|
||||
} else {
|
||||
parseSimpleAttribute(element, propertyValues, ITEM_COUNT_ATTRIBUTE, "commitInterval");
|
||||
String itemCount = element.getAttribute(ITEM_COUNT_ATTRIBUTE);
|
||||
if (StringUtils.hasText(itemCount)) {
|
||||
propertyValues.addPropertyValue("commitInterval", itemCount);
|
||||
} else {
|
||||
propertyValues.addPropertyValue("commitInterval", "10");
|
||||
}
|
||||
|
||||
parseSimpleAttribute(element, propertyValues, TIME_LIMIT_ATTRIBUTE, "timeout");
|
||||
}
|
||||
|
||||
@@ -97,9 +109,9 @@ public class ChunkParser {
|
||||
|
||||
private void parseSimpleAttribute(Element element,
|
||||
MutablePropertyValues propertyValues, String attributeName, String propertyName) {
|
||||
String skipLimit = element.getAttribute(attributeName);
|
||||
if (StringUtils.hasText(skipLimit)) {
|
||||
propertyValues.addPropertyValue(propertyName, skipLimit);
|
||||
String propertyValue = element.getAttribute(attributeName);
|
||||
if (StringUtils.hasText(propertyValue)) {
|
||||
propertyValues.addPropertyValue(propertyName, propertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.batch.api.chunk.CheckpointAlgorithm;
|
||||
import javax.batch.api.chunk.ItemWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -26,9 +31,6 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -49,46 +51,72 @@ public class SimpleItemBasedJobParsingTests {
|
||||
@Autowired
|
||||
public CountingCompletionPolicy policy;
|
||||
|
||||
@Autowired
|
||||
public CountingItemWriter writer;
|
||||
|
||||
@Autowired
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertNotNull(job);
|
||||
assertEquals("job1", job.getName());
|
||||
assertNotNull(step1);
|
||||
assertEquals("step1", step1.getName());
|
||||
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(3, execution.getStepExecutions().size());
|
||||
assertEquals(2, processor.count);
|
||||
assertEquals(3, policy.counter);
|
||||
assertEquals(4, execution.getStepExecutions().size());
|
||||
assertEquals(27, processor.count);
|
||||
assertEquals(2, policy.checkpointCount);
|
||||
assertEquals(8, writer.writeCount);
|
||||
assertEquals(27, writer.itemCount);
|
||||
}
|
||||
|
||||
public static class CountingCompletionPolicy implements CompletionPolicy {
|
||||
public static class CountingItemWriter implements ItemWriter {
|
||||
|
||||
protected int counter;
|
||||
protected int writeCount = 0;
|
||||
protected int itemCount = 0;
|
||||
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context, RepeatStatus result) {
|
||||
return counter == 3;
|
||||
public void open(Serializable checkpoint) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context) {
|
||||
return counter == 3;
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepeatContext start(RepeatContext parent) {
|
||||
counter = 0;
|
||||
return parent;
|
||||
public void writeItems(List<Object> items) throws Exception {
|
||||
System.err.println("Items to be written: " + items);
|
||||
writeCount++;
|
||||
itemCount += items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RepeatContext context) {
|
||||
counter++;
|
||||
public Serializable checkpointInfo() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CountingCompletionPolicy implements CheckpointAlgorithm {
|
||||
|
||||
protected int itemCount = 0;
|
||||
protected int checkpointCount = 0;
|
||||
|
||||
@Override
|
||||
public int checkpointTimeout() throws Exception {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginCheckpoint() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyToCheckpoint() throws Exception {
|
||||
itemCount++;
|
||||
return itemCount % 3 == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endCheckpoint() throws Exception {
|
||||
checkpointCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,29 @@
|
||||
<chunk checkpoint-policy="item" item-count="3">
|
||||
<reader ref="generatingItemReader1" />
|
||||
<processor ref="countingItemProcessor" />
|
||||
<writer ref="sysoutItemWriter" />
|
||||
<writer ref="countingItemWriter" />
|
||||
</chunk>
|
||||
</step>
|
||||
<step id="step2" next="step3">
|
||||
<step id="step2" next="step3">
|
||||
<chunk checkpoint-policy="custom">
|
||||
<reader ref="generatingItemReader1" />
|
||||
<reader ref="generatingItemReader2" />
|
||||
<processor ref="countingItemProcessor" />
|
||||
<writer ref="sysoutItemWriter" />
|
||||
<writer ref="countingItemWriter" />
|
||||
<checkpoint-algorithm ref="testCompletionPolicy" />
|
||||
</chunk>
|
||||
</step>
|
||||
<step id="step3">
|
||||
<step id="step3" next="step4">
|
||||
<chunk checkpoint-policy="item" item-count="3" time-limit="1">
|
||||
<reader ref="generatingItemReader1" />
|
||||
<reader ref="generatingItemReader3" />
|
||||
<processor ref="countingItemProcessor" />
|
||||
<writer ref="sysoutItemWriter" />
|
||||
<checkpoint-algorithm ref="testCompletionPolicy" />
|
||||
<writer ref="countingItemWriter" />
|
||||
</chunk>
|
||||
</step>
|
||||
<step id="step4">
|
||||
<chunk checkpoint-policy="item">
|
||||
<reader ref="generatingItemReader4" />
|
||||
<processor ref="countingItemProcessor" />
|
||||
<writer ref="countingItemWriter" />
|
||||
</chunk>
|
||||
</step>
|
||||
</job>
|
||||
@@ -43,6 +49,9 @@
|
||||
<list>
|
||||
<value>One</value>
|
||||
<value>Two</value>
|
||||
<value>Three</value>
|
||||
<value>Four</value>
|
||||
<value>Five</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
@@ -50,8 +59,11 @@
|
||||
<bean id="generatingItemReader2" class="org.springframework.batch.item.support.ListItemReader">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<value>One</value>
|
||||
<value>Two</value>
|
||||
<value>Three</value>
|
||||
<value>Four</value>
|
||||
<value>Five</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
@@ -59,20 +71,37 @@
|
||||
<bean id="generatingItemReader3" class="org.springframework.batch.item.support.ListItemReader">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<value>One</value>
|
||||
<value>Two</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="generatingItemReader4" class="org.springframework.batch.item.support.ListItemReader">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<value>One</value>
|
||||
<value>Two</value>
|
||||
<value>Three</value>
|
||||
<value>Four</value>
|
||||
<value>Five</value>
|
||||
<value>Six</value>
|
||||
<value>Seven</value>
|
||||
<value>Eight</value>
|
||||
<value>Nine</value>
|
||||
<value>Ten</value>
|
||||
<value>Eleven</value>
|
||||
<value>Twelve</value>
|
||||
<value>Thirteen</value>
|
||||
<value>Fourteen</value>
|
||||
<value>Fifteen</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="countingItemProcessor" class="org.springframework.batch.core.jsr.configuration.xml.CountingItemProcessor"/>
|
||||
|
||||
<bean id="sysoutItemWriter" class="org.springframework.batch.item.adapter.ItemWriterAdapter">
|
||||
<property name="targetObject">
|
||||
<util:constant static-field="java.lang.System.out"/>
|
||||
</property>
|
||||
<property name="targetMethod" value="println"/>
|
||||
</bean>
|
||||
<bean id="countingItemWriter" class="org.springframework.batch.core.jsr.configuration.xml.SimpleItemBasedJobParsingTests$CountingItemWriter"/>
|
||||
|
||||
<bean id="testCompletionPolicy" class="org.springframework.batch.core.jsr.configuration.xml.SimpleItemBasedJobParsingTests.CountingCompletionPolicy"/>
|
||||
<bean id="testCompletionPolicy" class="org.springframework.batch.core.jsr.configuration.xml.SimpleItemBasedJobParsingTests$CountingCompletionPolicy"/>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user