RESOLVED - issue BATCH-1093: Make AbstractJobTests.makeUniqueJobParameters() public
RESOLVED - issue BATCH-1096: Add late binding to some io samples RESOLVED - issue BATCH-1087: ClassPathXmlJobRegistry does not accept patterns for resources RESOLVED - BATCH-1098: added test for @AfterWrite in FaultTolerantChinkProcessorTests
This commit is contained in:
@@ -28,6 +28,13 @@ public class JobParametersBuilderTests extends TestCase {
|
||||
assertEquals("string value", parameters.getString("STRING"));
|
||||
}
|
||||
|
||||
public void testCopy(){
|
||||
parametersBuilder.addString("STRING", "string value");
|
||||
parametersBuilder = new JobParametersBuilder(parametersBuilder.toJobParameters());
|
||||
Iterator<String> parameters = parametersBuilder.toJobParameters().getParameters().keySet().iterator();
|
||||
assertEquals("STRING", parameters.next());
|
||||
}
|
||||
|
||||
public void testOrderedTypes(){
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date);
|
||||
parametersBuilder.addLong("LONG", new Long(1));
|
||||
|
||||
@@ -3,14 +3,20 @@ package org.springframework.batch.core.step.item;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.ItemListenerSupport;
|
||||
import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.PassThroughItemProcessor;
|
||||
import org.springframework.batch.retry.policy.NeverRetryPolicy;
|
||||
|
||||
public class FaultTolerantChunkProcessorTests {
|
||||
|
||||
@@ -18,37 +24,74 @@ public class FaultTolerantChunkProcessorTests {
|
||||
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
FaultTolerantChunkProcessor<String, String> processor = new FaultTolerantChunkProcessor<String, String>(
|
||||
new PassThroughItemProcessor<String>(), new ItemWriter<String>() {
|
||||
private List<String> after = new ArrayList<String>();
|
||||
|
||||
private FaultTolerantChunkProcessor<String, String> processor;
|
||||
|
||||
private StepContribution contribution = new StepExecution("foo", new JobExecution(0L)).createStepContribution();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
processor = new FaultTolerantChunkProcessor<String, String>(new PassThroughItemProcessor<String>(),
|
||||
new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
if (items.contains("fail")) {
|
||||
throw new RuntimeException("Planned failure!");
|
||||
}
|
||||
list.addAll(items);
|
||||
}
|
||||
}, batchRetryTemplate);
|
||||
Chunk<String> inputs = new Chunk<String>();
|
||||
inputs.add("1");
|
||||
inputs.add("2");
|
||||
processor.process(new StepExecution("foo", new JobExecution(0L)).createStepContribution(), inputs);
|
||||
batchRetryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
Chunk<String> inputs = new Chunk<String>(Arrays.asList("1", "2"));
|
||||
processor.process(contribution, inputs);
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransform() throws Exception {
|
||||
FaultTolerantChunkProcessor<String, String> processor = new FaultTolerantChunkProcessor<String, String>(
|
||||
new ItemProcessor<String, String>() {
|
||||
public String process(String item) throws Exception {
|
||||
return item.equals("1") ? null : item;
|
||||
}
|
||||
}, new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
list.addAll(items);
|
||||
}
|
||||
}, batchRetryTemplate);
|
||||
Chunk<String> inputs = new Chunk<String>();
|
||||
inputs.add("1");
|
||||
inputs.add("2");
|
||||
processor.process(new StepExecution("foo", new JobExecution(0L)).createStepContribution(), inputs);
|
||||
processor.setItemProcessor(new ItemProcessor<String, String>() {
|
||||
public String process(String item) throws Exception {
|
||||
return item.equals("1") ? null : item;
|
||||
}
|
||||
});
|
||||
Chunk<String> inputs = new Chunk<String>(Arrays.asList("1", "2"));
|
||||
processor.process(contribution, inputs);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterWrite() throws Exception {
|
||||
Chunk<String> chunk = new Chunk<String>(Arrays.asList("foo", "fail", "bar"));
|
||||
processor.setListeners(Arrays.asList(new ItemListenerSupport<String, String>() {
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> item) {
|
||||
after.addAll(item);
|
||||
}
|
||||
}));
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
try {
|
||||
processor.process(contribution, chunk);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("Planned failure!", e.getMessage());
|
||||
}
|
||||
try {
|
||||
processor.process(contribution, chunk);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("Planned failure!", e.getMessage());
|
||||
}
|
||||
assertEquals(2, chunk.getItems().size());
|
||||
processor.process(contribution, chunk);
|
||||
// foo is written twice because the failure is detected on the second
|
||||
// attempt when throttling
|
||||
assertEquals("[foo, foo, bar]", list.toString());
|
||||
// but the after listener is only called once, which is important
|
||||
assertEquals(2, after.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,19 @@ public class SimpleChunkProcessorTests {
|
||||
private StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(
|
||||
new JobInstance(123L, new JobParameters(), "job"))));
|
||||
|
||||
protected List<String> list = new ArrayList<String>();
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
processor = new SimpleChunkProcessor<String,String>(new PassThroughItemProcessor<String>(), new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
list.addAll(items);
|
||||
}
|
||||
});
|
||||
processor = new SimpleChunkProcessor<String, String>(new PassThroughItemProcessor<String>(),
|
||||
new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
if (items.contains("fail")) {
|
||||
throw new RuntimeException("Planned failure!");
|
||||
}
|
||||
list.addAll(items);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user