Align XML and Java based configuration

This commit aligns the XML and Java based validations.

When using XML to configure a chunk oriented step both an ItemReader and
ItemWriter are requied. However when using Java based configuration the
ItemWriter is optional if an ItemProcessor is present.

Having no ItemWriter and only an ItemProcessor lead to strange results
in one of our batch jobs, which was accidentily configured without an
ItemProcessor.

Related: BATCH-1520
Fixes: BATCH-2624
This commit is contained in:
Michael Minella
2017-06-02 17:17:53 -05:00
committed by Mahmoud Ben Hassine
parent 32692f9583
commit 3ccc4ff430
4 changed files with 7 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2017 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.
@@ -372,30 +372,6 @@ public class FaultTolerantStepFactoryBeanTests {
.getName()));
}
@Test
public void testNullWriter() throws Exception {
factory.setItemWriter(null);
Step step = factory.getObject();
step.execute(stepExecution);
assertEquals(0, stepExecution.getSkipCount());
assertEquals(0, stepExecution.getReadSkipCount());
assertEquals(5, stepExecution.getReadCount());
// Write count is incremented even if nothing happens
assertEquals(5, stepExecution.getWriteCount());
assertEquals(0, stepExecution.getFilterCount());
assertEquals(0, stepExecution.getRollbackCount());
// writer skips "4"
assertTrue(reader.getRead().contains("4"));
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
.getName()));
}
/**
* Check items causing errors are skipped as expected.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2017 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.
@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
@@ -475,32 +476,6 @@ public class SimpleStepFactoryBeanTests {
}
@Test
public void testNullWriter() throws Exception {
SimpleStepFactoryBean<String, String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setItemWriter(null);
factory.setItemProcessor(new ItemProcessor<String, String>() {
@Override
public String process(String item) throws Exception {
written.add(item);
return null;
}
});
Step step = factory.getObject();
job.setSteps(Collections.singletonList(step));
JobExecution jobExecution = repository.createJobExecution(job.getName(), new JobParameters());
job.execute(jobExecution);
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals("[foo, bar, spam]", written.toString());
}
private SimpleStepFactoryBean<String, String> getStepFactory(String... args) throws Exception {
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<String, String>();